Skip to content

Commit

Permalink
Fix validate_uniqueness_of matcher. Delete :if, :unless options from …
Browse files Browse the repository at this point in the history
…matching.
  • Loading branch information
Vitaliy V. Shopov committed Mar 25, 2011
1 parent ffe655b commit b1cb0e7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/rspec_rails_matchers/validations/uniqueness_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ def validate_uniqueness_of(attribute, options = {})
match do |model|
if validator = model.class.validators.find(Proc.new {false}) { |v| v.to_s.demodulize =~ /^UniquenessValidator/ &&
v.attributes.include?(_attr_) }
actual_options = validator.options
validator.options.deep_include?(options) && validator.options.keys.sort == options.keys.sort
options_unfrozen = validator.options.dup.delete_if { |k| [:if, :unless].include? k}
actual_options = options_unfrozen
options_unfrozen.deep_include?(options) && options_unfrozen.keys.sort == options.keys.sort
end
end

failure_message_for_should do |model|
RspecRailsMatchers::Message.error(
:expected => [ "%s to validate uniqueness of %s, %s", model, _attr_, options ],
:actual => [ "%s to validate uniqueness of %s, %s", model, _attr_, actual_options]
:expected => [ "%s should validate uniqueness of %s with %s", model, _attr_, options ],
:actual => [ "%s has validate uniqueness of %s with %s", model, _attr_, actual_options]
)
end
end
Expand Down

0 comments on commit b1cb0e7

Please sign in to comment.