diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/relationships_controller_spec.rb (renamed from spec/controllers/settings/follower_domains_controller_spec.rb) | 26 | ||||
-rw-r--r-- | spec/helpers/admin/action_log_helper_spec.rb | 272 | ||||
-rw-r--r-- | spec/lib/language_detector_spec.rb | 4 |
3 files changed, 283 insertions, 19 deletions
diff --git a/spec/controllers/settings/follower_domains_controller_spec.rb b/spec/controllers/relationships_controller_spec.rb index 6d415a654..16e255afe 100644 --- a/spec/controllers/settings/follower_domains_controller_spec.rb +++ b/spec/controllers/relationships_controller_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -describe Settings::FollowerDomainsController do +describe RelationshipsController do render_views let(:user) { Fabricate(:user) } @@ -12,24 +12,17 @@ describe Settings::FollowerDomainsController do end describe 'GET #show' do - subject { get :show, params: { page: 2 } } + subject { get :show, params: { page: 2, relationship: 'followed_by' } } - it 'assigns @account' do - sign_in user, scope: :user - subject - expect(assigns(:account)).to eq user.account - end - - it 'assigns @domains' do + it 'assigns @accounts' do Fabricate(:account, domain: 'old').follow!(user.account) Fabricate(:account, domain: 'recent').follow!(user.account) sign_in user, scope: :user subject - assigned = assigns(:domains).per(1).to_a + assigned = assigns(:accounts).per(1).to_a expect(assigned.size).to eq 1 - expect(assigned[0].accounts_from_domain).to eq 1 expect(assigned[0].domain).to eq 'old' end @@ -49,25 +42,24 @@ describe Settings::FollowerDomainsController do stub_request(:post, 'http://example.com/salmon').to_return(status: 200) end - shared_examples 'redirects back to followers page' do |notice| + shared_examples 'redirects back to followers page' do it 'redirects back to followers page' do poopfeast.follow!(user.account) sign_in user, scope: :user subject - expect(flash[:notice]).to eq notice - expect(response).to redirect_to(settings_follower_domains_path) + expect(response).to redirect_to(relationships_path) end end context 'when select parameter is not provided' do subject { patch :update } - include_examples 'redirects back to followers page', 'In the process of soft-blocking followers from 0 domains...' + include_examples 'redirects back to followers page' end context 'when select parameter is provided' do - subject { patch :update, params: { select: ['example.com'] } } + subject { patch :update, params: { form_account_batch: { account_ids: [poopfeast.id] }, block_domains: '' } } it 'soft-blocks followers from selected domains' do poopfeast.follow!(user.account) @@ -79,7 +71,7 @@ describe Settings::FollowerDomainsController do end include_examples 'authenticate user' - include_examples 'redirects back to followers page', 'In the process of soft-blocking followers from one domain...' + include_examples 'redirects back to followers page' end end end diff --git a/spec/helpers/admin/action_log_helper_spec.rb b/spec/helpers/admin/action_log_helper_spec.rb new file mode 100644 index 000000000..d7af6b939 --- /dev/null +++ b/spec/helpers/admin/action_log_helper_spec.rb @@ -0,0 +1,272 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Admin::ActionLogsHelper, type: :helper do + klass = Class.new do + include ActionView::Helpers + include Admin::ActionLogsHelper + end + + let(:hoge) { klass.new } + + describe '#log_target' do + after do + hoge.log_target(log) + end + + context 'log.target' do + let(:log) { double(target: true) } + + it 'calls linkable_log_target' do + expect(hoge).to receive(:linkable_log_target).with(log.target) + end + end + + context '!log.target' do + let(:log) { double(target: false, target_type: :type, recorded_changes: :change) } + + it 'calls log_target_from_history' do + expect(hoge).to receive(:log_target_from_history).with(log.target_type, log.recorded_changes) + end + end + end + + describe '#relevant_log_changes' do + let(:log) { double(target_type: target_type, action: log_action, recorded_changes: recorded_changes) } + let(:recorded_changes) { double } + + after do + hoge.relevant_log_changes(log) + end + + context "log.target_type == 'CustomEmoji' && [:enable, :disable, :destroy].include?(log.action)" do + let(:target_type) { 'CustomEmoji' } + let(:log_action) { :enable } + + it "calls log.recorded_changes.slice('domain')" do + expect(recorded_changes).to receive(:slice).with('domain') + end + end + + context "log.target_type == 'CustomEmoji' && log.action == :update" do + let(:target_type) { 'CustomEmoji' } + let(:log_action) { :update } + + it "calls log.recorded_changes.slice('domain', 'visible_in_picker')" do + expect(recorded_changes).to receive(:slice).with('domain', 'visible_in_picker') + end + end + + context "log.target_type == 'User' && [:promote, :demote].include?(log.action)" do + let(:target_type) { 'User' } + let(:log_action) { :promote } + + it "calls log.recorded_changes.slice('moderator', 'admin')" do + expect(recorded_changes).to receive(:slice).with('moderator', 'admin') + end + end + + context "log.target_type == 'User' && [:change_email].include?(log.action)" do + let(:target_type) { 'User' } + let(:log_action) { :change_email } + + it "calls log.recorded_changes.slice('email', 'unconfirmed_email')" do + expect(recorded_changes).to receive(:slice).with('email', 'unconfirmed_email') + end + end + + context "log.target_type == 'DomainBlock'" do + let(:target_type) { 'DomainBlock' } + let(:log_action) { nil } + + it "calls log.recorded_changes.slice('severity', 'reject_media')" do + expect(recorded_changes).to receive(:slice).with('severity', 'reject_media') + end + end + + context "log.target_type == 'Status' && log.action == :update" do + let(:target_type) { 'Status' } + let(:log_action) { :update } + + it "log.recorded_changes.slice('sensitive')" do + expect(recorded_changes).to receive(:slice).with('sensitive') + end + end + end + + describe '#log_extra_attributes' do + after do + hoge.log_extra_attributes(hoge: 'hoge') + end + + it "calls content_tag(:span, key, class: 'diff-key')" do + allow(hoge).to receive(:log_change).with(anything) + expect(hoge).to receive(:content_tag).with(:span, :hoge, class: 'diff-key') + end + + it 'calls safe_join twice' do + expect(hoge).to receive(:safe_join).with( + ['<span class="diff-key">hoge</span>', + '=', + '<span class="diff-neutral">hoge</span>'] + ) + + expect(hoge).to receive(:safe_join).with([nil], ' ') + end + end + + describe '#log_change' do + after do + hoge.log_change(val) + end + + context '!val.is_a?(Array)' do + let(:val) { 'hoge' } + + it "calls content_tag(:span, val, class: 'diff-neutral')" do + expect(hoge).to receive(:content_tag).with(:span, val, class: 'diff-neutral') + end + end + + context 'val.is_a?(Array)' do + let(:val) { %w(foo bar) } + + it 'calls #content_tag twice and #safe_join' do + expect(hoge).to receive(:content_tag).with(:span, 'foo', class: 'diff-old') + expect(hoge).to receive(:content_tag).with(:span, 'bar', class: 'diff-new') + expect(hoge).to receive(:safe_join).with([nil, nil], '→') + end + end + end + + describe '#icon_for_log' do + subject { hoge.icon_for_log(log) } + + context "log.target_type == 'Account'" do + let(:log) { double(target_type: 'Account') } + + it 'returns "user"' do + expect(subject).to be 'user' + end + end + + context "log.target_type == 'User'" do + let(:log) { double(target_type: 'User') } + + it 'returns "user"' do + expect(subject).to be 'user' + end + end + + context "log.target_type == 'CustomEmoji'" do + let(:log) { double(target_type: 'CustomEmoji') } + + it 'returns "file"' do + expect(subject).to be 'file' + end + end + + context "log.target_type == 'Report'" do + let(:log) { double(target_type: 'Report') } + + it 'returns "flag"' do + expect(subject).to be 'flag' + end + end + + context "log.target_type == 'DomainBlock'" do + let(:log) { double(target_type: 'DomainBlock') } + + it 'returns "lock"' do + expect(subject).to be 'lock' + end + end + + context "log.target_type == 'EmailDomainBlock'" do + let(:log) { double(target_type: 'EmailDomainBlock') } + + it 'returns "envelope"' do + expect(subject).to be 'envelope' + end + end + + context "log.target_type == 'Status'" do + let(:log) { double(target_type: 'Status') } + + it 'returns "pencil"' do + expect(subject).to be 'pencil' + end + end + end + + describe '#class_for_log_icon' do + subject { hoge.class_for_log_icon(log) } + + %i(enable unsuspend unsilence confirm promote resolve).each do |action| + context "log.action == #{action}" do + let(:log) { double(action: action) } + + it 'returns "positive"' do + expect(subject).to be 'positive' + end + end + end + + context 'log.action == :create' do + context 'opposite_verbs?(log)' do + let(:log) { double(action: :create, target_type: 'DomainBlock') } + + it 'returns "negative"' do + expect(subject).to be 'negative' + end + end + + context '!opposite_verbs?(log)' do + let(:log) { double(action: :create, target_type: '') } + + it 'returns "positive"' do + expect(subject).to be 'positive' + end + end + end + + %i(update reset_password disable_2fa memorialize change_email).each do |action| + context "log.action == #{action}" do + let(:log) { double(action: action) } + + it 'returns "neutral"' do + expect(subject).to be 'neutral' + end + end + end + + %i(demote silence disable suspend remove_avatar remove_header reopen).each do |action| + context "log.action == #{action}" do + let(:log) { double(action: action) } + + it 'returns "negative"' do + expect(subject).to be 'negative' + end + end + end + + context 'log.action == :destroy' do + context 'opposite_verbs?(log)' do + let(:log) { double(action: :destroy, target_type: 'DomainBlock') } + + it 'returns "positive"' do + expect(subject).to be 'positive' + end + end + + context '!opposite_verbs?(log)' do + let(:log) { double(action: :destroy, target_type: '') } + + it 'returns "negative"' do + expect(subject).to be 'negative' + end + end + end + end +end diff --git a/spec/lib/language_detector_spec.rb b/spec/lib/language_detector_spec.rb index 0fa2a59ef..0cb70605a 100644 --- a/spec/lib/language_detector_spec.rb +++ b/spec/lib/language_detector_spec.rb @@ -106,11 +106,11 @@ describe LanguageDetector do end describe 'remote user' do - it 'nil for foreign user when language is not present' do + it 'detects Korean language' do string = '안녕하세요' result = described_class.instance.detect(string, account_remote) - expect(result).to eq nil + expect(result).to eq :ko end end |