Skip to content

When using validate_uniqueness_of with scope of boolean column, throws error #457

Closed
@PikachuEXE

Description

I have the following code:
(is_rental is a boolean column)

it {should validate_uniqueness_of(:remote_reference_id).scoped_to(:scraping_source_name, :is_rental).allow_nil}

Backtrace:

# /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/shoulda-matchers-2.5.0/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb:157:in `each'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/shoulda-matchers-2.5.0/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb:157:in `max'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/shoulda-matchers-2.5.0/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb:157:in `block in validate_after_scope_change?'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/shoulda-matchers-2.5.0/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb:156:in `each'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/shoulda-matchers-2.5.0/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb:156:in `all?'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/shoulda-matchers-2.5.0/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb:156:in `validate_after_scope_change?'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/shoulda-matchers-2.5.0/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb:76:in `matches?'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-expectations-2.14.5/lib/rspec/expectations/handler.rb:24:in `handle_matcher'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/memoized_helpers.rb:68:in `should'
     # ./spec/shared_examples/models/listings/listings_with_scraping.rb:20:in `block (5 levels) in <top (required)>'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:114:in `instance_eval'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:114:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:179:in `call'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:179:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_exec'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/extensions/instance_eval_with_args.rb:16:in `instance_eval_with_args'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:247:in `instance_eval_with_args'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:106:in `block (2 levels) in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:108:in `call'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:108:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/hooks.rb:446:in `run_hook'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:340:in `run_around_each_hooks'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:256:in `with_around_each_hooks'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example.rb:111:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:390:in `block in run_examples'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:386:in `run_examples'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:371:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/example_group.rb:372:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `map'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:28:in `block in run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/reporter.rb:58:in `report'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/command_line.rb:25:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:80:in `run'
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-2.14.8/lib/rspec/core/runner.rb:17:in `block in autorun'

So it should be this line

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions