test/unit/model_test.rb in paper_trail-3.0.0 vs test/unit/model_test.rb in paper_trail-3.0.1

- old
+ new

@@ -476,15 +476,15 @@ end end context 'with its paper trail turned off' do setup do - Widget.paper_trail_off + Widget.paper_trail_off! @count = @widget.versions.length end - teardown { Widget.paper_trail_on } + teardown { Widget.paper_trail_on! } context 'when updated' do setup { @widget.update_attributes :name => 'Beeblebrox' } should 'not add to its trail' do @@ -493,16 +493,16 @@ end context 'when destroyed "without versioning"' do should 'leave paper trail off after call' do @widget.without_versioning :destroy - assert !Widget.paper_trail_enabled_for_model + assert !Widget.paper_trail_enabled_for_model? end end context 'and then its paper trail turned on' do - setup { Widget.paper_trail_on } + setup { Widget.paper_trail_on! } context 'when updated' do setup { @widget.update_attributes :name => 'Ford' } should 'add to its trail' do @@ -513,20 +513,34 @@ context 'when updated "without versioning"' do setup do @widget.without_versioning do @widget.update_attributes :name => 'Ford' end + # The model instance should yield itself for convenience purposes + @widget.without_versioning { |w| w.update_attributes :name => 'Nixon' } end should 'not create new version' do - assert_equal 1, @widget.versions.length + assert_equal @count, @widget.versions.length end should 'enable paper trail after call' do - assert Widget.paper_trail_enabled_for_model + assert Widget.paper_trail_enabled_for_model? end end + + context 'when receiving a method name as an argument' do + setup { @widget.without_versioning(:touch_with_version) } + + should 'not create new version' do + assert_equal @count, @widget.versions.length + end + + should 'enable paper trail after call' do + assert Widget.paper_trail_enabled_for_model? + end + end end end end @@ -613,11 +627,11 @@ @foo.update_attributes! :name => 'Foo' end should 'reify with the correct type' do # For some reason this test appears to be broken on AR4 in the test env. Executing it manually in the Rails console seems to work.. not sure what the issues is here. - assert_kind_of FooWidget, @foo.versions.last.reify if ActiveRecord::VERSION::STRING.to_f < 4.0 + assert_kind_of FooWidget, @foo.versions.last.reify if ActiveRecord::VERSION::MAJOR < 4 assert_equal @foo.versions.first, PaperTrail::Version.last.previous assert_nil PaperTrail::Version.last.next end should 'should return the correct originator' do @@ -769,11 +783,11 @@ end should 'store dynamic meta data based on a method of the item' do assert_equal @article.action_data_provider_method, @article.versions.last.action end - + should 'store dynamic meta data based on an attribute of the item prior to creation' do assert_equal nil, @article.versions.last.title end @@ -791,11 +805,11 @@ end should 'store dynamic meta data which depends on the item' do assert_equal @article.id, @article.versions.last.article_id end - + should 'store dynamic meta data based on an attribute of the item prior to the update' do assert_equal @initial_title, @article.versions.last.title end end @@ -812,11 +826,11 @@ end should 'store dynamic meta data which depends on the item' do assert_equal @article.id, @article.versions.last.article_id end - + should 'store dynamic meta data based on an attribute of the item prior to the destruction' do assert_equal @initial_title, @article.versions.last.title end end end @@ -835,11 +849,10 @@ end should 'return its previous self' do assert_equal @widget.versions[-2].reify, @widget.previous_version end - end context 'A non-reified item' do setup { @widget = Widget.new } @@ -1058,10 +1071,10 @@ should 'version.object should not have stored the default, ridiculously long (to_yaml) serialization of the TimeZone object' do assert @person.versions.last.object. length < 105, "object length was #{@person.versions.last.object .length}" end # Need an additional clause to detect what version of ActiveRecord is being used for this test because AR4 injects the `updated_at` column into the changeset for updates to models should 'version.object_changes should not have stored the default, ridiculously long (to_yaml) serialization of the TimeZone object' do - assert @person.versions.last.object_changes.length < (ActiveRecord::VERSION::STRING.to_f < 4.0 ? 105 : 118), "object_changes length was #{@person.versions.last.object_changes.length}" + assert @person.versions.last.object_changes.length < (ActiveRecord::VERSION::MAJOR < 4 ? 105 : 118), "object_changes length was #{@person.versions.last.object_changes.length}" end # But now it stores the short, serialized value. should 'version.object attribute should have stored the value returned by the attribute serializer' do as_stored_in_version = HashWithIndifferentAccess[YAML::load(@person.versions.last.object)] assert_equal 'Samoa', as_stored_in_version[:time_zone]