Skip to content
Browse files

Fix validate_uniqueness_of matcher. Delete :if, :unless options from …

…matching.
  • Loading branch information...
1 parent ffe655b commit b1cb0e726abc3e4b83a9ee9e60045b130edded1a @unitymind committed Mar 25, 2011
Showing with 5 additions and 4 deletions.
  1. +5 −4 lib/rspec_rails_matchers/validations/uniqueness_of.rb
View
9 lib/rspec_rails_matchers/validations/uniqueness_of.rb
@@ -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

0 comments on commit b1cb0e7

Please sign in to comment.
Something went wrong with that request. Please try again.