Browse files

Enforce attr_protected on #attributes=

Refs #342
  • Loading branch information...
1 parent 3b61c4e commit 9bd14c766950eb8529e9656a8f414407747f640c @bkeepers bkeepers committed Nov 7, 2011
Showing with 7 additions and 1 deletion.
  1. +1 −1 lib/mongo_mapper/plugins/protected.rb
  2. +6 −0 test/functional/test_protected.rb
View
2 lib/mongo_mapper/plugins/protected.rb
@@ -24,7 +24,7 @@ def key(*args)
end
module InstanceMethods
- def assign(attrs={})
+ def attributes=(attrs={})
super(filter_protected_attrs(attrs))
end
View
6 test/functional/test_protected.rb
@@ -76,6 +76,12 @@ class ProtectedTest < Test::Unit::TestCase
@doc.admin.should be_false
end
+ should "ignore protecteds attribute on #attributes=" do
+ @doc.attributes = {:name => 'Stimpson J. Cat', :admin => true}
+ @doc.name.should == 'Stimpson J. Cat'
+ @doc.admin.should be_false
+ end
+
should "be indifferent to whether the protected keys are strings or symbols" do
@doc.update_attributes!("name" => 'Stimpson J. Cat', "admin" => true)
@doc.name.should == 'Stimpson J. Cat'

0 comments on commit 9bd14c7

Please sign in to comment.