2014-08-04 17:07:55 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-08-05 14:14:10 +08:00
|
|
|
describe TopicViewItem do
|
|
|
|
|
|
|
|
def add(topic_id, ip, user_id=nil)
|
|
|
|
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")
|
|
|
|
|
|
|
|
TopicViewItem.count.should == 3
|
|
|
|
end
|
2014-08-04 17:07:55 +08:00
|
|
|
|
2014-08-07 12:20:42 +08: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
|
|
|
|
user.user_stat.topics_entered.should == 1
|
|
|
|
end
|
|
|
|
|
2014-08-04 17:07:55 +08:00
|
|
|
end
|