diff --git a/app/models/trust_level3_requirements.rb b/app/models/trust_level3_requirements.rb index 641708710a0..2fb1671d471 100644 --- a/app/models/trust_level3_requirements.rb +++ b/app/models/trust_level3_requirements.rb @@ -174,7 +174,9 @@ class TrustLevel3Requirements end def min_likes_received_days - (min_likes_received.to_f / 3.0).ceil + # Since min_likes_received / 3 can be greater than the number of days in time_period, + # cap this result to be less than time_period. + [(min_likes_received.to_f / 3.0).ceil, (0.75 * time_period.to_f).ceil].min end def num_likes_received_users diff --git a/spec/models/trust_level3_requirements_spec.rb b/spec/models/trust_level3_requirements_spec.rb index f39b1e4d4c2..764aef8ac91 100644 --- a/spec/models/trust_level3_requirements_spec.rb +++ b/spec/models/trust_level3_requirements_spec.rb @@ -67,6 +67,20 @@ describe TrustLevel3Requirements do expect(tl3_requirements.min_likes_received_days).to eq(7) expect(tl3_requirements.min_likes_received_users).to eq(5) end + + it "min_likes_received_days is capped" do + SiteSetting.tl3_requires_likes_received = 600 + expect(tl3_requirements.min_likes_received).to eq(600) + expect(tl3_requirements.min_likes_received_days).to eq(75) # 0.75 * tl3_time_period + end + + it "min_likes_received_days works when time_period is 1" do + SiteSetting.tl3_requires_likes_received = 20 + SiteSetting.tl3_time_period = 1 + expect(tl3_requirements.min_likes_received).to eq(20) + expect(tl3_requirements.min_likes_received_days).to eq(1) + expect(tl3_requirements.min_likes_received_users).to eq(5) + end end describe "days_visited" do