Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ignore mass assignment rules when cloning. [ fix #2360 ]

  • Loading branch information...
commit 51c0708ed0ee6e34ef8d5905bf8a75d44f4f7e86 1 parent 9b3e234
@durran durran authored
View
2  CHANGELOG.md
@@ -14,6 +14,8 @@ For instructions on upgrading to newer versions, visit
needed. (When there is not more than one polymorphic parent defined on the
same class).
+* \#2360 Cloning documents should ignore mass assignment protection rules.
+
* \#2356 When limiting fields returned in queries via `only` ensure that the
limitation is scoped to the model.
View
2  lib/mongoid/copyable.rb
@@ -22,7 +22,7 @@ def clone
if attrs.delete("versions")
attrs["version"] = 1
end
- self.class.new(attrs)
+ self.class.new(attrs, without_protection: true)
end
alias :dup :clone
end
View
8 spec/mongoid/copyable_spec.rb
@@ -12,7 +12,9 @@
version: 4,
created_at: Time.now,
updated_at: Time.now
- )
+ ) do |p|
+ p.owner_id = 5
+ end
end
let!(:address) do
@@ -52,6 +54,10 @@
it "flags the document as changed" do
copy.should be_changed
end
+
+ it "copies protected fields" do
+ copy.owner_id.should eq(5)
+ end
end
context "when the document is new" do
Please sign in to comment.
Something went wrong with that request. Please try again.