From c6c412fd459dfc054ac020af6e6e576ac72b7e69 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 4 Jun 2014 11:41:42 +1000 Subject: [PATCH] BUGFIX: no reading credit for posts you create --- lib/post_creator.rb | 12 ++++++++++-- spec/components/post_creator_spec.rb | 14 +++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index e55c1aaf40b..69b9240c609 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 45a880c2bf5..b567dc5b7a4 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