2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2014-08-04 05:07:55 -04:00
|
|
|
|
2014-08-05 02:14:10 -04:00
|
|
|
describe TopicViewItem do
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
def add(topic_id, ip, user_id = nil)
|
2014-08-05 02:14:10 -04:00
|
|
|
skip_redis = true
|
|
|
|
TopicViewItem.add(topic_id, ip, user_id, nil, skip_redis)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises nothing for dupes" do
|
|
|
|
add(2, "1.1.1.1")
|
|
|
|
add(2, "1.1.1.1", 1)
|
|
|
|
|
|
|
|
TopicViewItem.create!(topic_id: 1, ip_address: "1.1.1.1", viewed_at: 1.day.ago)
|
|
|
|
add(1, "1.1.1.1")
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(TopicViewItem.count).to eq(3)
|
2014-08-05 02:14:10 -04:00
|
|
|
end
|
2014-08-04 05:07:55 -04:00
|
|
|
|
2014-08-07 00:20:42 -04:00
|
|
|
it "increases a users view count" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
|
|
|
|
add(1, "1.1.1.1", user.id)
|
|
|
|
add(1, "1.1.1.1", user.id)
|
|
|
|
|
|
|
|
user.user_stat.reload
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(user.user_stat.topics_entered).to eq(1)
|
2014-08-07 00:20:42 -04:00
|
|
|
end
|
|
|
|
|
2014-08-04 05:07:55 -04:00
|
|
|
end
|