Skip to content

Commit

Permalink
Added check to not save an update action unless model is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Rizvi committed Mar 17, 2017
1 parent 93ed5d9 commit f038f5c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/public_activity/actions/update.rb
Expand Up @@ -11,7 +11,7 @@ module Update

# Creates activity upon modification of the tracked model
def activity_on_update
create_activity(:update)
create_activity(:update) if changed?
end
end
end
10 changes: 10 additions & 0 deletions test/test_common.rb
Expand Up @@ -48,6 +48,16 @@
subject.create_activity("some.key").wont_be_nil
end

it 'update action should not create activity on save unless model changed' do
subject.save
before_count = subject.activities.count
subject.save
subject.save
after_count = subject.activities.count
before_count.must_equal after_count
end


it 'allows passing owner through #create_activity' do
article = article().new
article.save
Expand Down
1 change: 1 addition & 0 deletions test/test_tracking.rb
Expand Up @@ -154,6 +154,7 @@ class ActivistAndTrackedArticle < ActiveRecord::Base
PublicActivity::Activity.count.must_equal activity_count_before

klass.public_activity_on
@article.name = 'Changed Article'
@article.save
PublicActivity::Activity.count.must_be :>, activity_count_before
end
Expand Down

0 comments on commit f038f5c

Please sign in to comment.