Skip to content

Commit

Permalink
ignored keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasc committed Dec 9, 2010
1 parent 79370c5 commit 6b9087c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/mongo_mapper/plugins/versioned.rb
Expand Up @@ -42,7 +42,7 @@ def version_count
end

def current_version
Version.new(:data => self.attributes, :versioned_id => self.id, :version_number => self.version_number)
Version.new(:data => self.attributes.slice!(*ignored_keys), :versioned_id => self.id, :version_number => self.version_number)
end

def version_at(target_version_number)
Expand Down
24 changes: 17 additions & 7 deletions test/mongo_mapper_versioned_test.rb
Expand Up @@ -9,8 +9,9 @@ class VersionedDoc
plugin MongoMapper::Plugins::Versioned

key :title, String
key :body, String

versioned
versioned :ignored_keys => ['body']
end


Expand Down Expand Up @@ -74,11 +75,11 @@ class VersionedTest < ActiveSupport::TestCase

context "when reverting" do
setup do
@doc = VersionedDoc.create(:title => "Famfula")
@doc.update_attributes(:title => "Slavoj")
@doc.update_attributes(:title => "Karel")
@doc.update_attributes(:title => "Keren")
@doc.update_attributes(:title => "Jon")
@doc = VersionedDoc.create(:title => "Vaclav", :body => "Kroupa")
@doc.update_attributes(:title => "Slavoj", :body => "Zizek")
@doc.update_attributes(:title => "Karel", :body => "Martens")
@doc.update_attributes(:title => "Keren", :body => "Cytter")
@doc.update_attributes(:title => "Jon", :body => "Arnett")
end

context "to first version" do
Expand All @@ -89,7 +90,10 @@ class VersionedTest < ActiveSupport::TestCase
assert_equal 1, @doc.version_number
end
should "have correct attributes" do
assert_equal "Famfula", @doc.title
assert_equal "Vaclav", @doc.title
end
should "not revert ignored attributes" do
assert_equal "Arnett", @doc.body
end
should "not create new version" do
assert_equal 5, @doc.version_count
Expand All @@ -106,6 +110,9 @@ class VersionedTest < ActiveSupport::TestCase
should "have correct attributes" do
assert_equal "Slavoj", @doc.title
end
should "not revert ignored attributes" do
assert_equal "Arnett", @doc.body
end
should "not create new version" do
assert_equal 5, @doc.version_count
end
Expand Down Expand Up @@ -133,6 +140,9 @@ class VersionedTest < ActiveSupport::TestCase
should "have correct attributes" do
assert_equal "Jon", @doc.title
end
should "not revert ignored attributes" do
assert_equal "Arnett", @doc.body
end
should "not create new version" do
assert_equal 5, @doc.version_count
end
Expand Down

0 comments on commit 6b9087c

Please sign in to comment.