test/unit/model_test.rb in paper_trail-2.2.9 vs test/unit/model_test.rb in paper_trail-2.3.0
- old
+ new
@@ -831,9 +831,60 @@
assert_equal 3, @doc.paper_trail_versions.length
assert_equal 'Doc 1', @doc.previous_version.name
end
end
+ context 'The `on` option' do
+ context 'on create' do
+ setup do
+ Fluxor.instance_eval <<-END
+ has_paper_trail :on => [:create]
+ END
+ @fluxor = Fluxor.create
+ @fluxor.update_attributes :name => 'blah'
+ @fluxor.destroy
+ end
+ should 'only have a version for the create event' do
+ assert_equal 1, @fluxor.versions.length
+ assert_equal 'create', @fluxor.versions.last.event
+ end
+ end
+ context 'on update' do
+ setup do
+ Fluxor.reset_callbacks :create
+ Fluxor.reset_callbacks :update
+ Fluxor.reset_callbacks :destroy
+ Fluxor.instance_eval <<-END
+ has_paper_trail :on => [:update]
+ END
+ @fluxor = Fluxor.create
+ @fluxor.update_attributes :name => 'blah'
+ @fluxor.destroy
+ end
+ should 'only have a version for the update event' do
+ assert_equal 1, @fluxor.versions.length
+ assert_equal 'update', @fluxor.versions.last.event
+ end
+ end
+ context 'on destroy' do
+ setup do
+ Fluxor.reset_callbacks :create
+ Fluxor.reset_callbacks :update
+ Fluxor.reset_callbacks :destroy
+ Fluxor.instance_eval <<-END
+ has_paper_trail :on => [:destroy]
+ END
+ @fluxor = Fluxor.create
+ @fluxor.update_attributes :name => 'blah'
+ @fluxor.destroy
+ end
+ should 'only have a version for the destroy event' do
+ assert_equal 1, @fluxor.versions.length
+ assert_equal 'destroy', @fluxor.versions.last.event
+ end
+ end
+ end
+
private
# Updates `model`'s last version so it looks like the version was
# created 2 seconds ago.
def make_last_version_earlier(model)