FIX: Incorrect rate limit applied to topics invitation flow.

This commit is contained in:
Guo Xiang Tan
2018-03-01 12:41:36 +08:00
parent 5a462b930d
commit 947b6fdf46
3 changed files with 46 additions and 10 deletions

View File

@ -469,6 +469,35 @@ describe Topic do
let(:topic) { Fabricate(:topic, user: user) }
let(:another_user) { Fabricate(:user) }
context 'rate limits' do
before do
SiteSetting.max_topic_invitations_per_day = 2
RateLimiter.enable
end
after do
RateLimiter.clear_all!
RateLimiter.disable
end
it "rate limits topic invitations" do
start = Time.now.tomorrow.beginning_of_day
freeze_time(start)
user = Fabricate(:user)
trust_level_2 = Fabricate(:user, trust_level: 2)
topic = Fabricate(:topic, user: trust_level_2)
topic.invite(topic.user, user.username)
topic.invite(topic.user, "walter@white.com")
expect {
topic.invite(topic.user, "user@example.com")
}.to raise_error(RateLimiter::LimitExceeded)
end
end
describe 'when username_or_email is not valid' do
it 'should return the right value' do
expect do