Permalink
Browse files

Added should_allow_mass_assignment_of, the reverse of should_not_allo…

…w_mass_assignment_of
  • Loading branch information...
1 parent f937c08 commit 10feba9de635d0d09969aca4a119be649bb10a8d @jferris jferris committed Jan 30, 2009
Showing with 17 additions and 0 deletions.
  1. +16 −0 lib/shoulda/active_record/macros.rb
  2. +1 −0 test/unit/tag_test.rb
@@ -105,6 +105,22 @@ def should_require_unique_attributes(*attributes)
should_validate_uniqueness_of(*attributes)
end
+ # Ensures that the attribute can be set on mass update.
+ #
+ # should_allow_mass_assignment_of :first_name, :last_name
+ #
+ def should_allow_mass_assignment_of(*attributes)
+ get_options!(attributes)
+ klass = model_class
+
+ attributes.each do |attribute|
+ matcher = allow_mass_assignment_of(attribute)
+ should matcher.description do
+ assert_accepts matcher, klass.new
+ end
+ end
+ end
+
# Ensures that the attribute cannot be set on mass update.
#
# should_not_allow_mass_assignment_of :password, :admin_flag
View
@@ -7,6 +7,7 @@ class TagTest < Test::Unit::TestCase
should_ensure_length_at_least :name, 2
should_protect_attributes :secret
+ should_allow_mass_assignment_of :name
should_fail do
should_not_allow_mass_assignment_of :name

0 comments on commit 10feba9

Please sign in to comment.