Promotion fails if the user account isn't old enough yet.

This commit is contained in:
Robin Ward 2015-04-14 12:05:09 -04:00
parent eaf5d21c41
commit 869d8e25ad
4 changed files with 40 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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