diff --git a/lib/post_creator.rb b/lib/post_creator.rb index e55c1aaf4..69b9240c6 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -269,13 +269,21 @@ class PostCreator def track_topic return if @opts[:auto_track] == false - TopicUser.auto_track(@user.id, @topic.id, TopicUser.notification_reasons[:created_post]) - # Update topic user data TopicUser.change(@post.user.id, @post.topic.id, posted: true, last_read_post_number: @post.post_number, seen_post_count: @post.post_number) + + + # assume it took us 5 seconds of reading time to make a post + PostTiming.record_timing(topic_id: @post.topic_id, + user_id: @post.user_id, + post_number: @post.post_number, + msecs: 5000) + + + TopicUser.auto_track(@user.id, @topic.id, TopicUser.notification_reasons[:created_post]) end def enqueue_jobs diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 45a880c2b..b567dc5b7 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -429,10 +429,22 @@ describe PostCreator do embed_url: embed_url, title: 'Reviews of Science Ovens', raw: 'Did you know that you can use microwaves to cook your dinner? Science!') - post = creator.create + creator.create TopicEmbed.where(embed_url: embed_url).exists?.should be_true end end + describe "read credit for creator" do + it "should give credit to creator" do + post = create_post + PostTiming.find_by(topic_id: post.topic_id, + post_number: post.post_number, + user_id: post.user_id).msecs.should be > 0 + + TopicUser.find_by(topic_id: post.topic_id, + user_id: post.user_id).last_read_post_number.should == 1 + end + end + end