Browse files

Ensure validate_presence_of matcher works with non AR classes.

  • Loading branch information...
1 parent 3e37f94 commit 9b591f16b3043edaf753ad96d3ff1bc3a64cd773 @carlosantoniodasilva carlosantoniodasilva committed with josevalim Feb 5, 2010
View
10 remarkable_activerecord/lib/remarkable_activerecord/matchers/validate_presence_of_matcher.rb
@@ -54,13 +54,21 @@ def blank_value
end
def collection?
- if reflection = subject_class.reflect_on_association(@attribute)
+ if reflection = find_reflection
[:has_many, :has_and_belongs_to_many].include?(reflection.macro)
else
false
end
end
+ private
+
+ def find_reflection
+ if subject_class.respond_to?(:reflect_on_association)
+ subject_class.reflect_on_association(@attribute)
+ end
+ end
+
end
# Ensures that the model cannot be saved if one of the attributes listed is not present.

0 comments on commit 9b591f1

Please sign in to comment.