Trigger UserActionObserver when tracking visit

This commit is contained in:
Chris Hunt 2013-05-21 20:45:03 -07:00
parent 685f4960f1
commit d0bc8c95d3
2 changed files with 6 additions and 0 deletions

View File

@ -100,6 +100,8 @@ class TopicUser < ActiveRecord::Base
rows = TopicUser.update_all({last_visited_at: now}, {topic_id: topic.id, user_id: user.id})
if rows == 0
TopicUser.create(topic_id: topic.id, user_id: user.id, last_visited_at: now, first_visited_at: now)
else
observe_after_save_callbacks_for topic.id, user.id
end
end

View File

@ -107,6 +107,10 @@ describe TopicUser do
topic_user.last_visited_at.to_i.should == today.to_i
end
it 'triggers the observer callbacks when updating' do
UserActionObserver.instance.expects(:after_save).twice
2.times { TopicUser.track_visit!(topic, user) }
end
end
describe 'read tracking' do