Skip to content

Commit

Permalink
Ignore mass assignment rules when cloning. [ fix #2360 ]
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Sep 11, 2012
1 parent 9b3e234 commit 51c0708
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/copyable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion spec/mongoid/copyable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 51c0708

Please sign in to comment.