Skip to content

Commit

Permalink
Use send as opposed to [] to make sure we catch virtual attributes
Browse files Browse the repository at this point in the history
git-svn-id: https://rspec-on-rails-matchers.googlecode.com/svn/trunk@4 11e6f158-dd3c-0410-a69b-4d739fb74d9d
  • Loading branch information
joshknowles committed Dec 10, 2007
1 parent 9cc8084 commit c5b1045
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/spec/rails/matchers/validations.rb
Expand Up @@ -3,7 +3,7 @@ module Rails
module Matchers
def validate_presence_of(attribute)
return simple_matcher("model to validate the presence of #{attribute}") do |model|
model[attribute] = nil
model.send("#{attribute}=", nil)
!model.valid? && model.errors.invalid?(attribute)
end
end
Expand All @@ -13,11 +13,11 @@ def validate_length_of(attribute, options)
max = options[:between].last

return simple_matcher("model to validate the length of #{attribute} between #{min} and #{max}") do |model|
model[attribute] = 'a' * (min - 1)
model.send("#{attribute}=", 'a' * (min - 1))

invalid = !model.valid? && model.errors.invalid?(attribute)

model[attribute] = 'a' * (max + 1)
model.send("#{attribute}=", 'a' * (max + 1))

invalid && !model.valid? && model.errors.invalid?(attribute)
end
Expand Down

0 comments on commit c5b1045

Please sign in to comment.