|
|
@ -2,16 +2,16 @@ require 'test_helper'
|
|
|
|
|
|
|
|
|
|
|
|
class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
|
|
|
|
context 'A record with defined "only" and "ignore" attributes' do
|
|
|
|
describe "A record with defined 'only' and 'ignore' attributes" do
|
|
|
|
setup { @article = Article.create }
|
|
|
|
setup { @article = Article.create }
|
|
|
|
should 'creation should change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
should 'creation should change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which updates an ignored column' do
|
|
|
|
describe 'which updates an ignored column' do
|
|
|
|
setup { @article.update_attributes :title => 'My first title' }
|
|
|
|
setup { @article.update_attributes :title => 'My first title' }
|
|
|
|
should 'not change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which updates an ignored column and a selected column' do
|
|
|
|
describe 'which updates an ignored column and a selected column' do
|
|
|
|
setup { @article.update_attributes :title => 'My first title', :content => 'Some text here.' }
|
|
|
|
setup { @article.update_attributes :title => 'My first title', :content => 'Some text here.' }
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
@ -24,7 +24,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which updates a selected column' do
|
|
|
|
describe 'which updates a selected column' do
|
|
|
|
setup { @article.update_attributes :content => 'Some text here.' }
|
|
|
|
setup { @article.update_attributes :content => 'Some text here.' }
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
@ -33,17 +33,17 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which updates a non-ignored and non-selected column' do
|
|
|
|
describe 'which updates a non-ignored and non-selected column' do
|
|
|
|
setup { @article.update_attributes :abstract => 'Other abstract'}
|
|
|
|
setup { @article.update_attributes :abstract => 'Other abstract'}
|
|
|
|
should 'not change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which updates a skipped column' do
|
|
|
|
describe 'which updates a skipped column' do
|
|
|
|
setup { @article.update_attributes :file_upload => 'Your data goes here' }
|
|
|
|
setup { @article.update_attributes :file_upload => 'Your data goes here' }
|
|
|
|
should 'not change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which updates a skipped column and a selected column' do
|
|
|
|
describe 'which updates a skipped column and a selected column' do
|
|
|
|
setup { @article.update_attributes :file_upload => 'Your data goes here', :content => 'Some text here.' }
|
|
|
|
setup { @article.update_attributes :file_upload => 'Your data goes here', :content => 'Some text here.' }
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
@ -55,7 +55,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_equal ({'content' => [nil, 'Some text here.']}), @article.versions.last.changeset
|
|
|
|
assert_equal ({'content' => [nil, 'Some text here.']}), @article.versions.last.changeset
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'and when updated again' do
|
|
|
|
describe 'and when updated again' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@article.update_attributes :file_upload => 'More data goes here', :content => 'More text here.'
|
|
|
|
@article.update_attributes :file_upload => 'More data goes here', :content => 'More text here.'
|
|
|
|
@old_article = @article.versions.last
|
|
|
|
@old_article = @article.versions.last
|
|
|
@ -71,7 +71,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which gets destroyed' do
|
|
|
|
describe 'which gets destroyed' do
|
|
|
|
setup { @article.destroy }
|
|
|
|
setup { @article.destroy }
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
@ -81,37 +81,37 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'A record with defined "ignore" attribute' do
|
|
|
|
describe "A record with defined 'ignore' attribute" do
|
|
|
|
setup { @legacy_widget = LegacyWidget.create }
|
|
|
|
setup { @legacy_widget = LegacyWidget.create }
|
|
|
|
|
|
|
|
|
|
|
|
context 'which updates an ignored column' do
|
|
|
|
describe 'which updates an ignored column' do
|
|
|
|
setup { @legacy_widget.update_attributes :version => 1 }
|
|
|
|
setup { @legacy_widget.update_attributes :version => 1 }
|
|
|
|
should 'not change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'A record with defined "if" and "unless" attributes' do
|
|
|
|
describe 'A record with defined "if" and "unless" attributes' do
|
|
|
|
setup { @translation = Translation.new :headline => 'Headline' }
|
|
|
|
setup { @translation = Translation.new :headline => 'Headline' }
|
|
|
|
|
|
|
|
|
|
|
|
context 'for non-US translations' do
|
|
|
|
describe 'for non-US translations' do
|
|
|
|
setup { @translation.save }
|
|
|
|
setup { @translation.save }
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
|
context 'after update' do
|
|
|
|
describe 'after update' do
|
|
|
|
setup { @translation.update_attributes :content => 'Content' }
|
|
|
|
setup { @translation.update_attributes :content => 'Content' }
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'after destroy' do
|
|
|
|
describe 'after destroy' do
|
|
|
|
setup { @translation.destroy }
|
|
|
|
setup { @translation.destroy }
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'for US translations' do
|
|
|
|
describe 'for US translations' do
|
|
|
|
setup { @translation.language_code = "US" }
|
|
|
|
setup { @translation.language_code = "US" }
|
|
|
|
|
|
|
|
|
|
|
|
context 'that are drafts' do
|
|
|
|
describe 'that are drafts' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@translation.type = 'DRAFT'
|
|
|
|
@translation.type = 'DRAFT'
|
|
|
|
@translation.save
|
|
|
|
@translation.save
|
|
|
@ -119,18 +119,18 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
|
context 'after update' do
|
|
|
|
describe 'after update' do
|
|
|
|
setup { @translation.update_attributes :content => 'Content' }
|
|
|
|
setup { @translation.update_attributes :content => 'Content' }
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'that are not drafts' do
|
|
|
|
describe 'that are not drafts' do
|
|
|
|
setup { @translation.save }
|
|
|
|
setup { @translation.save }
|
|
|
|
|
|
|
|
|
|
|
|
should 'change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
should 'change the number of versions' do assert_equal(1, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
|
context 'after update' do
|
|
|
|
describe 'after update' do
|
|
|
|
setup { @translation.update_attributes :content => 'Content' }
|
|
|
|
setup { @translation.update_attributes :content => 'Content' }
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
@ -139,7 +139,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'after destroy' do
|
|
|
|
describe 'after destroy' do
|
|
|
|
setup { @translation.destroy }
|
|
|
|
setup { @translation.destroy }
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
should 'change the number of versions' do assert_equal(2, Version.count) end
|
|
|
|
|
|
|
|
|
|
|
@ -151,7 +151,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'A new record' do
|
|
|
|
describe 'A new record' do
|
|
|
|
setup { @widget = Widget.new }
|
|
|
|
setup { @widget = Widget.new }
|
|
|
|
|
|
|
|
|
|
|
|
should 'not have any previous versions' do
|
|
|
|
should 'not have any previous versions' do
|
|
|
@ -163,7 +163,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'which is then created' do
|
|
|
|
describe 'which is then created' do
|
|
|
|
setup { @widget.update_attributes :name => 'Henry' }
|
|
|
|
setup { @widget.update_attributes :name => 'Henry' }
|
|
|
|
|
|
|
|
|
|
|
|
should 'have one previous version' do
|
|
|
|
should 'have one previous version' do
|
|
|
@ -194,7 +194,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_equal changes, @widget.versions.last.changeset
|
|
|
|
assert_equal changes, @widget.versions.last.changeset
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'and then updated without any changes' do
|
|
|
|
describe 'and then updated without any changes' do
|
|
|
|
setup { @widget.touch }
|
|
|
|
setup { @widget.touch }
|
|
|
|
|
|
|
|
|
|
|
|
should 'not have a new version' do
|
|
|
|
should 'not have a new version' do
|
|
|
@ -203,7 +203,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'and then updated with changes' do
|
|
|
|
describe 'and then updated with changes' do
|
|
|
|
setup { @widget.update_attributes :name => 'Harry' }
|
|
|
|
setup { @widget.update_attributes :name => 'Harry' }
|
|
|
|
|
|
|
|
|
|
|
|
should 'have two previous versions' do
|
|
|
|
should 'have two previous versions' do
|
|
|
@ -257,7 +257,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'and has one associated object' do
|
|
|
|
describe 'and has one associated object' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@wotsit = @widget.create_wotsit :name => 'John'
|
|
|
|
@wotsit = @widget.create_wotsit :name => 'John'
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -276,7 +276,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'and has many associated objects' do
|
|
|
|
describe 'and has many associated objects' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@f0 = @widget.fluxors.create :name => 'f-zero'
|
|
|
|
@f0 = @widget.fluxors.create :name => 'f-zero'
|
|
|
|
@f1 = @widget.fluxors.create :name => 'f-one'
|
|
|
|
@f1 = @widget.fluxors.create :name => 'f-one'
|
|
|
@ -293,7 +293,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'and then destroyed' do
|
|
|
|
describe 'and then destroyed' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@fluxor = @widget.fluxors.create :name => 'flux'
|
|
|
|
@fluxor = @widget.fluxors.create :name => 'flux'
|
|
|
|
@widget.destroy
|
|
|
|
@widget.destroy
|
|
|
@ -333,7 +333,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
|
|
|
|
# Test the serialisation and deserialisation.
|
|
|
|
# Test the serialisation and deserialisation.
|
|
|
|
# TODO: binary
|
|
|
|
# TODO: binary
|
|
|
|
context "A record's papertrail" do
|
|
|
|
describe "A record's papertrail" do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@date_time = DateTime.now.utc
|
|
|
|
@date_time = DateTime.now.utc
|
|
|
|
@time = Time.now
|
|
|
|
@time = Time.now
|
|
|
@ -397,7 +397,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "after a column is removed from the record's schema" do
|
|
|
|
describe "after a column is removed from the record's schema" do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
change_schema
|
|
|
|
change_schema
|
|
|
|
Widget.connection.schema_cache.clear!
|
|
|
|
Widget.connection.schema_cache.clear!
|
|
|
@ -425,10 +425,10 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'A record' do
|
|
|
|
describe 'A record' do
|
|
|
|
setup { @widget = Widget.create :name => 'Zaphod' }
|
|
|
|
setup { @widget = Widget.create :name => 'Zaphod' }
|
|
|
|
|
|
|
|
|
|
|
|
context 'with PaperTrail globally disabled' do
|
|
|
|
describe 'with PaperTrail globally disabled' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
PaperTrail.enabled = false
|
|
|
|
PaperTrail.enabled = false
|
|
|
|
@count = @widget.versions.length
|
|
|
|
@count = @widget.versions.length
|
|
|
@ -436,7 +436,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
|
|
|
|
teardown { PaperTrail.enabled = true }
|
|
|
|
teardown { PaperTrail.enabled = true }
|
|
|
|
|
|
|
|
|
|
|
|
context 'when updated' do
|
|
|
|
describe 'when updated' do
|
|
|
|
setup { @widget.update_attributes :name => 'Beeblebrox' }
|
|
|
|
setup { @widget.update_attributes :name => 'Beeblebrox' }
|
|
|
|
|
|
|
|
|
|
|
|
should 'not add to its trail' do
|
|
|
|
should 'not add to its trail' do
|
|
|
@ -445,7 +445,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'with its paper trail turned off' do
|
|
|
|
describe 'with its paper trail turned off' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
Widget.paper_trail_off
|
|
|
|
Widget.paper_trail_off
|
|
|
|
@count = @widget.versions.length
|
|
|
|
@count = @widget.versions.length
|
|
|
@ -453,7 +453,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
|
|
|
|
teardown { Widget.paper_trail_on }
|
|
|
|
teardown { Widget.paper_trail_on }
|
|
|
|
|
|
|
|
|
|
|
|
context 'when updated' do
|
|
|
|
describe 'when updated' do
|
|
|
|
setup { @widget.update_attributes :name => 'Beeblebrox' }
|
|
|
|
setup { @widget.update_attributes :name => 'Beeblebrox' }
|
|
|
|
|
|
|
|
|
|
|
|
should 'not add to its trail' do
|
|
|
|
should 'not add to its trail' do
|
|
|
@ -461,17 +461,17 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when destroyed "without versioning"' do
|
|
|
|
describe 'when destroyed "without versioning"' do
|
|
|
|
should 'leave paper trail off after call' do
|
|
|
|
should 'leave paper trail off after call' do
|
|
|
|
@widget.without_versioning :destroy
|
|
|
|
@widget.without_versioning :destroy
|
|
|
|
assert !Widget.paper_trail_enabled_for_model
|
|
|
|
assert !Widget.paper_trail_enabled_for_model
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'and then its paper trail turned on' do
|
|
|
|
describe 'and then its paper trail turned on' do
|
|
|
|
setup { Widget.paper_trail_on }
|
|
|
|
setup { Widget.paper_trail_on }
|
|
|
|
|
|
|
|
|
|
|
|
context 'when updated' do
|
|
|
|
describe 'when updated' do
|
|
|
|
setup { @widget.update_attributes :name => 'Ford' }
|
|
|
|
setup { @widget.update_attributes :name => 'Ford' }
|
|
|
|
|
|
|
|
|
|
|
|
should 'add to its trail' do
|
|
|
|
should 'add to its trail' do
|
|
|
@ -479,7 +479,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when updated "without versioning"' do
|
|
|
|
describe 'when updated "without versioning"' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@widget.without_versioning do
|
|
|
|
@widget.without_versioning do
|
|
|
|
@widget.update_attributes :name => 'Ford'
|
|
|
|
@widget.update_attributes :name => 'Ford'
|
|
|
@ -499,12 +499,12 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'A papertrail with somebody making changes' do
|
|
|
|
describe 'A papertrail with somebody making changes' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@widget = Widget.new :name => 'Fidget'
|
|
|
|
@widget = Widget.new :name => 'Fidget'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when a record is created' do
|
|
|
|
describe 'when a record is created' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
PaperTrail.whodunnit = 'Alice'
|
|
|
|
PaperTrail.whodunnit = 'Alice'
|
|
|
|
@widget.save
|
|
|
|
@widget.save
|
|
|
@ -518,7 +518,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_equal 'Alice', @widget.originator
|
|
|
|
assert_equal 'Alice', @widget.originator
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when a record is updated' do
|
|
|
|
describe 'when a record is updated' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
PaperTrail.whodunnit = 'Bob'
|
|
|
|
PaperTrail.whodunnit = 'Bob'
|
|
|
|
@widget.update_attributes :name => 'Rivet'
|
|
|
|
@widget.update_attributes :name => 'Rivet'
|
|
|
@ -532,7 +532,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_equal 'Bob', @widget.originator
|
|
|
|
assert_equal 'Bob', @widget.originator
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when a record is destroyed' do
|
|
|
|
describe 'when a record is destroyed' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
PaperTrail.whodunnit = 'Charlie'
|
|
|
|
PaperTrail.whodunnit = 'Charlie'
|
|
|
|
@widget.destroy
|
|
|
|
@widget.destroy
|
|
|
@ -551,7 +551,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'A subclass' do
|
|
|
|
describe 'A subclass' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@foo = FooWidget.create
|
|
|
|
@foo = FooWidget.create
|
|
|
|
@foo.update_attributes :name => 'Fooey'
|
|
|
|
@foo.update_attributes :name => 'Fooey'
|
|
|
@ -570,7 +570,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_equal PaperTrail.whodunnit, @foo.originator
|
|
|
|
assert_equal PaperTrail.whodunnit, @foo.originator
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when destroyed' do
|
|
|
|
describe 'when destroyed' do
|
|
|
|
setup { @foo.destroy }
|
|
|
|
setup { @foo.destroy }
|
|
|
|
|
|
|
|
|
|
|
|
should 'reify with the correct type' do
|
|
|
|
should 'reify with the correct type' do
|
|
|
@ -583,14 +583,14 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'An item with versions' do
|
|
|
|
describe 'An item with versions' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@widget = Widget.create :name => 'Widget'
|
|
|
|
@widget = Widget.create :name => 'Widget'
|
|
|
|
@widget.update_attributes :name => 'Fidget'
|
|
|
|
@widget.update_attributes :name => 'Fidget'
|
|
|
|
@widget.update_attributes :name => 'Digit'
|
|
|
|
@widget.update_attributes :name => 'Digit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which were created over time' do
|
|
|
|
describe 'which were created over time' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@created = 2.days.ago
|
|
|
|
@created = 2.days.ago
|
|
|
|
@first_update = 1.day.ago
|
|
|
|
@first_update = 1.day.ago
|
|
|
@ -630,7 +630,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context '.versions_between' do
|
|
|
|
describe '.versions_between' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@created = 30.days.ago
|
|
|
|
@created = 30.days.ago
|
|
|
|
@first_update = 15.days.ago
|
|
|
|
@first_update = 15.days.ago
|
|
|
@ -649,7 +649,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'on the first version' do
|
|
|
|
describe 'on the first version' do
|
|
|
|
setup { @version = @widget.versions.first }
|
|
|
|
setup { @version = @widget.versions.first }
|
|
|
|
|
|
|
|
|
|
|
|
should 'have a nil previous version' do
|
|
|
|
should 'have a nil previous version' do
|
|
|
@ -665,7 +665,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'on the last version' do
|
|
|
|
describe 'on the last version' do
|
|
|
|
setup { @version = @widget.versions.last }
|
|
|
|
setup { @version = @widget.versions.last }
|
|
|
|
|
|
|
|
|
|
|
|
should 'return the previous version' do
|
|
|
|
should 'return the previous version' do
|
|
|
@ -683,13 +683,13 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'An item' do
|
|
|
|
describe 'An item' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@initial_title = 'Foobar'
|
|
|
|
@initial_title = 'Foobar'
|
|
|
|
@article = Article.new :title => @initial_title
|
|
|
|
@article = Article.new :title => @initial_title
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which is created' do
|
|
|
|
describe 'which is created' do
|
|
|
|
setup { @article.save }
|
|
|
|
setup { @article.save }
|
|
|
|
|
|
|
|
|
|
|
|
should 'store fixed meta data' do
|
|
|
|
should 'store fixed meta data' do
|
|
|
@ -713,7 +713,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'and updated' do
|
|
|
|
describe 'and updated' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@article.update_attributes! :content => 'Better text.', :title => 'Rhubarb'
|
|
|
|
@article.update_attributes! :content => 'Better text.', :title => 'Rhubarb'
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -736,7 +736,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'and destroyed' do
|
|
|
|
describe 'and destroyed' do
|
|
|
|
setup { @article.destroy }
|
|
|
|
setup { @article.destroy }
|
|
|
|
|
|
|
|
|
|
|
|
should 'store fixed meta data' do
|
|
|
|
should 'store fixed meta data' do
|
|
|
@ -758,7 +758,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'A reified item' do
|
|
|
|
describe 'A reified item' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
widget = Widget.create :name => 'Bob'
|
|
|
|
widget = Widget.create :name => 'Bob'
|
|
|
|
%w( Tom Dick Jane ).each { |name| widget.update_attributes :name => name }
|
|
|
|
%w( Tom Dick Jane ).each { |name| widget.update_attributes :name => name }
|
|
|
@ -777,7 +777,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'A non-reified item' do
|
|
|
|
describe 'A non-reified item' do
|
|
|
|
setup { @widget = Widget.new }
|
|
|
|
setup { @widget = Widget.new }
|
|
|
|
|
|
|
|
|
|
|
|
should 'not have a previous version' do
|
|
|
|
should 'not have a previous version' do
|
|
|
@ -788,7 +788,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_nil @widget.next_version
|
|
|
|
assert_nil @widget.next_version
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'with versions' do
|
|
|
|
describe 'with versions' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@widget.save
|
|
|
|
@widget.save
|
|
|
|
%w( Tom Dick Jane ).each { |name| @widget.update_attributes :name => name }
|
|
|
|
%w( Tom Dick Jane ).each { |name| @widget.update_attributes :name => name }
|
|
|
@ -804,7 +804,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'A reified item' do
|
|
|
|
describe 'A reified item' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
widget = Widget.create :name => 'Bob'
|
|
|
|
widget = Widget.create :name => 'Bob'
|
|
|
|
%w( Tom Dick Jane ).each { |name| widget.update_attributes :name => name }
|
|
|
|
%w( Tom Dick Jane ).each { |name| widget.update_attributes :name => name }
|
|
|
@ -824,7 +824,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context ":has_many :through" do
|
|
|
|
describe ":has_many :through" do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@book = Book.create :title => 'War and Peace'
|
|
|
|
@book = Book.create :title => 'War and Peace'
|
|
|
|
@dostoyevsky = Person.create :name => 'Dostoyevsky'
|
|
|
|
@dostoyevsky = Person.create :name => 'Dostoyevsky'
|
|
|
@ -865,16 +865,16 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'A model with a has_one association' do
|
|
|
|
describe 'A model with a has_one association' do
|
|
|
|
setup { @widget = Widget.create :name => 'widget_0' }
|
|
|
|
setup { @widget = Widget.create :name => 'widget_0' }
|
|
|
|
|
|
|
|
|
|
|
|
context 'before the associated was created' do
|
|
|
|
describe 'before the associated was created' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@widget.update_attributes :name => 'widget_1'
|
|
|
|
@widget.update_attributes :name => 'widget_1'
|
|
|
|
@wotsit = @widget.create_wotsit :name => 'wotsit_0'
|
|
|
|
@wotsit = @widget.create_wotsit :name => 'wotsit_0'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when reified' do
|
|
|
|
describe 'when reified' do
|
|
|
|
setup { @widget_0 = @widget.versions.last.reify(:has_one => 1) }
|
|
|
|
setup { @widget_0 = @widget.versions.last.reify(:has_one => 1) }
|
|
|
|
|
|
|
|
|
|
|
|
should 'see the associated as it was at the time' do
|
|
|
|
should 'see the associated as it was at the time' do
|
|
|
@ -883,7 +883,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'where the associated is created between model versions' do
|
|
|
|
describe 'where the associated is created between model versions' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@wotsit = @widget.create_wotsit :name => 'wotsit_0'
|
|
|
|
@wotsit = @widget.create_wotsit :name => 'wotsit_0'
|
|
|
|
make_last_version_earlier @wotsit
|
|
|
|
make_last_version_earlier @wotsit
|
|
|
@ -891,7 +891,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
@widget.update_attributes :name => 'widget_1'
|
|
|
|
@widget.update_attributes :name => 'widget_1'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when reified' do
|
|
|
|
describe 'when reified' do
|
|
|
|
setup { @widget_0 = @widget.versions.last.reify(:has_one => 1) }
|
|
|
|
setup { @widget_0 = @widget.versions.last.reify(:has_one => 1) }
|
|
|
|
|
|
|
|
|
|
|
|
should 'see the associated as it was at the time' do
|
|
|
|
should 'see the associated as it was at the time' do
|
|
|
@ -899,7 +899,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'and then the associated is updated between model versions' do
|
|
|
|
describe 'and then the associated is updated between model versions' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@wotsit.update_attributes :name => 'wotsit_1'
|
|
|
|
@wotsit.update_attributes :name => 'wotsit_1'
|
|
|
|
make_last_version_earlier @wotsit
|
|
|
|
make_last_version_earlier @wotsit
|
|
|
@ -910,7 +910,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
@wotsit.update_attributes :name => 'wotsit_3'
|
|
|
|
@wotsit.update_attributes :name => 'wotsit_3'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when reified' do
|
|
|
|
describe 'when reified' do
|
|
|
|
setup { @widget_1 = @widget.versions.last.reify(:has_one => 1) }
|
|
|
|
setup { @widget_1 = @widget.versions.last.reify(:has_one => 1) }
|
|
|
|
|
|
|
|
|
|
|
|
should 'see the associated as it was at the time' do
|
|
|
|
should 'see the associated as it was at the time' do
|
|
|
@ -918,7 +918,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when reified opting out of has_one reification' do
|
|
|
|
describe 'when reified opting out of has_one reification' do
|
|
|
|
setup { @widget_1 = @widget.versions.last.reify(:has_one => false) }
|
|
|
|
setup { @widget_1 = @widget.versions.last.reify(:has_one => false) }
|
|
|
|
|
|
|
|
|
|
|
|
should 'see the associated as it is live' do
|
|
|
|
should 'see the associated as it is live' do
|
|
|
@ -927,7 +927,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'and then the associated is destroyed between model versions' do
|
|
|
|
describe 'and then the associated is destroyed between model versions' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@wotsit.destroy
|
|
|
|
@wotsit.destroy
|
|
|
|
make_last_version_earlier @wotsit
|
|
|
|
make_last_version_earlier @wotsit
|
|
|
@ -935,7 +935,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
@widget.update_attributes :name => 'widget_3'
|
|
|
|
@widget.update_attributes :name => 'widget_3'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when reified' do
|
|
|
|
describe 'when reified' do
|
|
|
|
setup { @widget_2 = @widget.versions.last.reify(:has_one => 1) }
|
|
|
|
setup { @widget_2 = @widget.versions.last.reify(:has_one => 1) }
|
|
|
|
|
|
|
|
|
|
|
|
should 'see the associated as it was at the time' do
|
|
|
|
should 'see the associated as it was at the time' do
|
|
|
@ -946,14 +946,14 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'When an attribute has a custom serializer' do
|
|
|
|
describe 'When an attribute has a custom serializer' do
|
|
|
|
setup { @person = Person.new(:time_zone => "Samoa") }
|
|
|
|
setup { @person = Person.new(:time_zone => "Samoa") }
|
|
|
|
|
|
|
|
|
|
|
|
should "be an instance of ActiveSupport::TimeZone" do
|
|
|
|
should "be an instance of ActiveSupport::TimeZone" do
|
|
|
|
assert_equal ActiveSupport::TimeZone, @person.time_zone.class
|
|
|
|
assert_equal ActiveSupport::TimeZone, @person.time_zone.class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when the model is saved' do
|
|
|
|
describe 'when the model is saved' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@changes_before_save = @person.changes.dup
|
|
|
|
@changes_before_save = @person.changes.dup
|
|
|
|
@person.save!
|
|
|
|
@person.save!
|
|
|
@ -982,7 +982,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_equal [NilClass, ActiveSupport::TimeZone], @person.versions.last.changeset[:time_zone].map(&:class)
|
|
|
|
assert_equal [NilClass, ActiveSupport::TimeZone], @person.versions.last.changeset[:time_zone].map(&:class)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'when that attribute is updated' do
|
|
|
|
describe 'when that attribute is updated' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@attribute_value_before_change = @person.instance_variable_get(:@attributes)['time_zone']
|
|
|
|
@attribute_value_before_change = @person.instance_variable_get(:@attributes)['time_zone']
|
|
|
|
@person.assign_attributes({ :time_zone => 'Pacific Time (US & Canada)' })
|
|
|
|
@person.assign_attributes({ :time_zone => 'Pacific Time (US & Canada)' })
|
|
|
@ -1030,21 +1030,21 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'A new model instance which uses a custom Version class' do
|
|
|
|
describe 'A new model instance which uses a custom Version class' do
|
|
|
|
setup { @post = Post.new }
|
|
|
|
setup { @post = Post.new }
|
|
|
|
|
|
|
|
|
|
|
|
context 'which is then saved' do
|
|
|
|
describe 'which is then saved' do
|
|
|
|
setup { @post.save }
|
|
|
|
setup { @post.save }
|
|
|
|
should 'change the number of post versions' do assert_equal 1, PostVersion.count end
|
|
|
|
should 'change the number of post versions' do assert_equal 1, PostVersion.count end
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'An existing model instance which uses a custom Version class' do
|
|
|
|
describe 'An existing model instance which uses a custom Version class' do
|
|
|
|
setup { @post = Post.create }
|
|
|
|
setup { @post = Post.create }
|
|
|
|
should 'have one post version' do assert_equal(1, PostVersion.count) end
|
|
|
|
should 'have one post version' do assert_equal(1, PostVersion.count) end
|
|
|
|
|
|
|
|
|
|
|
|
context 'on the first version' do
|
|
|
|
describe 'on the first version' do
|
|
|
|
setup { @version = @post.versions.first }
|
|
|
|
setup { @version = @post.versions.first }
|
|
|
|
|
|
|
|
|
|
|
|
should 'have the correct index' do
|
|
|
|
should 'have the correct index' do
|
|
|
@ -1056,7 +1056,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_equal "PostVersion", @post.versions.first.class.name
|
|
|
|
assert_equal "PostVersion", @post.versions.first.class.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'which is modified' do
|
|
|
|
describe 'which is modified' do
|
|
|
|
setup { @post.update_attributes({ :content => "Some new content" }) }
|
|
|
|
setup { @post.update_attributes({ :content => "Some new content" }) }
|
|
|
|
should 'change the number of post versions' do assert_equal(2, PostVersion.count) end
|
|
|
|
should 'change the number of post versions' do assert_equal(2, PostVersion.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
|
should 'not change the number of versions' do assert_equal(0, Version.count) end
|
|
|
@ -1067,7 +1067,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'An overwritten default accessor' do
|
|
|
|
describe 'An overwritten default accessor' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@song = Song.create :length => 4
|
|
|
|
@song = Song.create :length => 4
|
|
|
|
@song.update_attributes :length => 5
|
|
|
|
@song.update_attributes :length => 5
|
|
|
@ -1082,7 +1082,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context 'An unsaved record' do
|
|
|
|
describe 'An unsaved record' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@widget = Widget.new
|
|
|
|
@widget = Widget.new
|
|
|
|
@widget.destroy
|
|
|
|
@widget.destroy
|
|
|
@ -1092,7 +1092,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'A model with a custom association' do
|
|
|
|
describe 'A model with a custom association' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@doc = Document.create
|
|
|
|
@doc = Document.create
|
|
|
|
@doc.update_attributes :name => 'Doc 1'
|
|
|
|
@doc.update_attributes :name => 'Doc 1'
|
|
|
@ -1113,8 +1113,8 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'The `on` option' do
|
|
|
|
describe 'The `on` option' do
|
|
|
|
context 'on create' do
|
|
|
|
describe 'on create' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
Fluxor.instance_eval <<-END
|
|
|
|
Fluxor.instance_eval <<-END
|
|
|
|
has_paper_trail :on => [:create]
|
|
|
|
has_paper_trail :on => [:create]
|
|
|
@ -1128,7 +1128,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_equal 'create', @fluxor.versions.last.event
|
|
|
|
assert_equal 'create', @fluxor.versions.last.event
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'on update' do
|
|
|
|
describe 'on update' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
Fluxor.reset_callbacks :create
|
|
|
|
Fluxor.reset_callbacks :create
|
|
|
|
Fluxor.reset_callbacks :update
|
|
|
|
Fluxor.reset_callbacks :update
|
|
|
@ -1145,7 +1145,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
assert_equal 'update', @fluxor.versions.last.event
|
|
|
|
assert_equal 'update', @fluxor.versions.last.event
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'on destroy' do
|
|
|
|
describe 'on destroy' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
Fluxor.reset_callbacks :create
|
|
|
|
Fluxor.reset_callbacks :create
|
|
|
|
Fluxor.reset_callbacks :update
|
|
|
|
Fluxor.reset_callbacks :update
|
|
|
@ -1164,7 +1164,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'A model with column version and custom version_method' do
|
|
|
|
describe 'A model with column version and custom version_method' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
@legacy_widget = LegacyWidget.create(:name => "foo", :version => 2)
|
|
|
|
@legacy_widget = LegacyWidget.create(:name => "foo", :version => 2)
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -1183,7 +1183,7 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
context 'A reified item with a column -version- and custom version_method' do
|
|
|
|
describe 'A reified item with a column -version- and custom version_method' do
|
|
|
|
setup do
|
|
|
|
setup do
|
|
|
|
widget = LegacyWidget.create(:name => "foo", :version => 2)
|
|
|
|
widget = LegacyWidget.create(:name => "foo", :version => 2)
|
|
|
|
%w( bar baz ).each { |name| widget.update_attributes :name => name }
|
|
|
|
%w( bar baz ).each { |name| widget.update_attributes :name => name }
|
|
|
|