diff --git a/lib/promotion.rb b/lib/promotion.rb index 14e89c86886..82dd5a998cf 100644 --- a/lib/promotion.rb +++ b/lib/promotion.rb @@ -83,6 +83,7 @@ class Promotion return false if stat.topics_entered < SiteSetting.tl2_requires_topics_entered return false if stat.posts_read_count < SiteSetting.tl2_requires_read_posts return false if (stat.time_read / 60) < SiteSetting.tl2_requires_time_spent_mins + return false if ((Time.now - user.created_at) / 60) < SiteSetting.tl2_requires_time_spent_mins return false if stat.days_visited < SiteSetting.tl2_requires_days_visited return false if stat.likes_received < SiteSetting.tl2_requires_likes_received return false if stat.likes_given < SiteSetting.tl2_requires_likes_given @@ -96,6 +97,8 @@ class Promotion return false if stat.topics_entered < SiteSetting.tl1_requires_topics_entered return false if stat.posts_read_count < SiteSetting.tl1_requires_read_posts return false if (stat.time_read / 60) < SiteSetting.tl1_requires_time_spent_mins + return false if ((Time.now - user.created_at) / 60) < SiteSetting.tl1_requires_time_spent_mins + return true end diff --git a/spec/components/promotion_spec.rb b/spec/components/promotion_spec.rb index 0729e636722..71d80a27381 100644 --- a/spec/components/promotion_spec.rb +++ b/spec/components/promotion_spec.rb @@ -15,7 +15,7 @@ describe Promotion do context "newuser" do - let(:user) { Fabricate(:user, trust_level: TrustLevel[0])} + let(:user) { Fabricate(:user, trust_level: TrustLevel[0], created_at: 2.days.ago)} let(:promotion) { Promotion.new(user) } it "doesn't raise an error with a nil user" do @@ -53,11 +53,24 @@ describe Promotion do end end + context "that has done the requisite things" do + it "does not promote the user" do + user.created_at = 1.minute.ago + stat = user.user_stat + stat.topics_entered = SiteSetting.tl1_requires_topics_entered + stat.posts_read_count = SiteSetting.tl1_requires_read_posts + stat.time_read = SiteSetting.tl1_requires_time_spent_mins * 60 + @result = promotion.review + expect(@result).to eq(false) + expect(user.trust_level).to eq(TrustLevel[0]) + end + end + end context "basic" do - let(:user) { Fabricate(:user, trust_level: TrustLevel[1])} + let(:user) { Fabricate(:user, trust_level: TrustLevel[1], created_at: 2.days.ago)} let(:promotion) { Promotion.new(user) } context 'that has done nothing' do @@ -96,6 +109,25 @@ describe Promotion do end end + context "when the account hasn't existed long enough" do + it "does not promote the user" do + user.created_at = 1.minute.ago + + stat = user.user_stat + stat.topics_entered = SiteSetting.tl2_requires_topics_entered + stat.posts_read_count = SiteSetting.tl2_requires_read_posts + stat.time_read = SiteSetting.tl2_requires_time_spent_mins * 60 + stat.days_visited = SiteSetting.tl2_requires_days_visited * 60 + stat.likes_received = SiteSetting.tl2_requires_likes_received + stat.likes_given = SiteSetting.tl2_requires_likes_given + stat.topic_reply_count = SiteSetting.tl2_requires_topic_reply_count + + result = promotion.review + expect(result).to eq(false) + expect(user.trust_level).to eq(TrustLevel[1]) + end + end + end context "regular" do diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb index c10fc0128a2..dedc080b9f2 100644 --- a/spec/components/topic_view_spec.rb +++ b/spec/components/topic_view_spec.rb @@ -214,6 +214,8 @@ describe TopicView do # random user has nothing expect(topic_view.read?(1)).to eq(false) + coding_horror.created_at = 2.days.ago + # a real user that just read it should have it marked PostTiming.process_timings(coding_horror, topic.id, 1, [[1,1000]]) expect(TopicView.new(topic.id, coding_horror).read?(1)).to eq(true) diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 114b62b67cc..d76ea7c696d 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -187,7 +187,7 @@ describe Admin::UsersController do context '.trust_level' do before do - @another_user = Fabricate(:coding_horror) + @another_user = Fabricate(:coding_horror, created_at: 1.month.ago) end it "raises an error when the user doesn't have permission" do