Skip to content

Commit a89852d

Browse files
ysksnhiyuki2578
authored andcommitted
Add specs for FollowLimitValidator (mastodon#9655)
1 parent 3592267 commit a89852d

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe FollowLimitValidator, type: :validator do
6+
describe '#validate' do
7+
before do
8+
allow_any_instance_of(described_class).to receive(:limit_reached?).with(account) do
9+
limit_reached
10+
end
11+
12+
described_class.new.validate(follow)
13+
end
14+
15+
let(:follow) { double(account: account, errors: errors) }
16+
let(:errors) { double(add: nil) }
17+
let(:account) { double(nil?: _nil, local?: local, following_count: 0, followers_count: 0) }
18+
let(:_nil) { true }
19+
let(:local) { false }
20+
21+
context 'follow.account.nil? || !follow.account.local?' do
22+
let(:_nil) { true }
23+
24+
it 'not calls errors.add' do
25+
expect(errors).not_to have_received(:add).with(:base, any_args)
26+
end
27+
end
28+
29+
context '!(follow.account.nil? || !follow.account.local?)' do
30+
let(:_nil) { false }
31+
let(:local) { true }
32+
33+
context 'limit_reached?' do
34+
let(:limit_reached) { true }
35+
36+
it 'calls errors.add' do
37+
expect(errors).to have_received(:add)
38+
.with(:base, I18n.t('users.follow_limit_reached', limit: FollowLimitValidator::LIMIT))
39+
end
40+
end
41+
42+
context '!limit_reached?' do
43+
let(:limit_reached) { false }
44+
45+
it 'not calls errors.add' do
46+
expect(errors).not_to have_received(:add).with(:base, any_args)
47+
end
48+
end
49+
end
50+
end
51+
end

0 commit comments

Comments
 (0)