From 50948b46aabc0756d85bc6641f0bd3bcc09bf7d4 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 20 Sep 2022 23:51:21 +0200 Subject: Add ability to filter followed accounts' posts by language (#19095) --- spec/controllers/api/v1/accounts_controller_spec.rb | 11 +++++++++++ .../settings/exports/following_accounts_controller_spec.rb | 2 +- spec/lib/feed_manager_spec.rb | 12 ++++++++++++ spec/models/concerns/account_interactions_spec.rb | 2 +- spec/models/export_spec.rb | 4 ++-- spec/models/follow_request_spec.rb | 2 +- spec/services/follow_service_spec.rb | 13 +++++++++++++ spec/workers/refollow_worker_spec.rb | 4 ++-- 8 files changed, 43 insertions(+), 7 deletions(-) (limited to 'spec') diff --git a/spec/controllers/api/v1/accounts_controller_spec.rb b/spec/controllers/api/v1/accounts_controller_spec.rb index 5d5c245c5..d6bbcefd7 100644 --- a/spec/controllers/api/v1/accounts_controller_spec.rb +++ b/spec/controllers/api/v1/accounts_controller_spec.rb @@ -145,6 +145,17 @@ RSpec.describe Api::V1::AccountsController, type: :controller do expect(json[:showing_reblogs]).to be false expect(json[:notifying]).to be true end + + it 'changes languages option' do + post :follow, params: { id: other_account.id, languages: %w(en es) } + + json = body_as_json + + expect(json[:following]).to be true + expect(json[:showing_reblogs]).to be false + expect(json[:notifying]).to be false + expect(json[:languages]).to match_array %w(en es) + end end end diff --git a/spec/controllers/settings/exports/following_accounts_controller_spec.rb b/spec/controllers/settings/exports/following_accounts_controller_spec.rb index 78858e772..bfe010555 100644 --- a/spec/controllers/settings/exports/following_accounts_controller_spec.rb +++ b/spec/controllers/settings/exports/following_accounts_controller_spec.rb @@ -11,7 +11,7 @@ describe Settings::Exports::FollowingAccountsController do sign_in user, scope: :user get :index, format: :csv - expect(response.body).to eq "Account address,Show boosts\nusername@domain,true\n" + expect(response.body).to eq "Account address,Show boosts,Notify on new posts,Languages\nusername@domain,true,false,\n" end end end diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb index 48c57b86e..0f3b05e5a 100644 --- a/spec/lib/feed_manager_spec.rb +++ b/spec/lib/feed_manager_spec.rb @@ -127,6 +127,18 @@ RSpec.describe FeedManager do reblog = Fabricate(:status, reblog: status, account: jeff) expect(FeedManager.instance.filter?(:home, reblog, alice)).to be true end + + it 'returns true for German post when follow is set to English only' do + alice.follow!(bob, languages: %w(en)) + status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de') + expect(FeedManager.instance.filter?(:home, status, alice)).to be true + end + + it 'returns false for German post when follow is set to German' do + alice.follow!(bob, languages: %w(de)) + status = Fabricate(:status, text: 'Hallo Welt', account: bob, language: 'de') + expect(FeedManager.instance.filter?(:home, status, alice)).to be false + end end context 'for mentions feed' do diff --git a/spec/models/concerns/account_interactions_spec.rb b/spec/models/concerns/account_interactions_spec.rb index 0369aff10..1d1898ab0 100644 --- a/spec/models/concerns/account_interactions_spec.rb +++ b/spec/models/concerns/account_interactions_spec.rb @@ -14,7 +14,7 @@ describe AccountInteractions do context 'account with Follow' do it 'returns { target_account_id => true }' do Fabricate(:follow, account: account, target_account: target_account) - is_expected.to eq(target_account_id => { reblogs: true, notify: false }) + is_expected.to eq(target_account_id => { reblogs: true, notify: false, languages: nil }) end end diff --git a/spec/models/export_spec.rb b/spec/models/export_spec.rb index 4e6b824bb..135d7a36b 100644 --- a/spec/models/export_spec.rb +++ b/spec/models/export_spec.rb @@ -35,8 +35,8 @@ describe Export do results = export.strip.split("\n") expect(results.size).to eq 3 - expect(results.first).to eq 'Account address,Show boosts' - expect(results.second).to eq 'one@local.host,true' + expect(results.first).to eq 'Account address,Show boosts,Notify on new posts,Languages' + expect(results.second).to eq 'one@local.host,true,false,' end end diff --git a/spec/models/follow_request_spec.rb b/spec/models/follow_request_spec.rb index 36ce8ee60..901eabc9d 100644 --- a/spec/models/follow_request_spec.rb +++ b/spec/models/follow_request_spec.rb @@ -7,7 +7,7 @@ RSpec.describe FollowRequest, type: :model do let(:target_account) { Fabricate(:account) } it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do - expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, bypass_limit: true) + expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, languages: nil, bypass_limit: true) expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id) expect(follow_request).to receive(:destroy!) follow_request.authorize! diff --git a/spec/services/follow_service_spec.rb b/spec/services/follow_service_spec.rb index 02bc87c58..88346ec54 100644 --- a/spec/services/follow_service_spec.rb +++ b/spec/services/follow_service_spec.rb @@ -121,6 +121,19 @@ RSpec.describe FollowService, type: :service do expect(sender.muting_reblogs?(bob)).to be false end end + + describe 'already followed account, changing languages' do + let(:bob) { Fabricate(:account, username: 'bob') } + + before do + sender.follow!(bob) + subject.call(sender, bob, languages: %w(en es)) + end + + it 'changes languages' do + expect(Follow.find_by(account: sender, target_account: bob)&.languages).to match_array %w(en es) + end + end end context 'remote ActivityPub account' do diff --git a/spec/workers/refollow_worker_spec.rb b/spec/workers/refollow_worker_spec.rb index df6731b64..d9c2293b6 100644 --- a/spec/workers/refollow_worker_spec.rb +++ b/spec/workers/refollow_worker_spec.rb @@ -23,8 +23,8 @@ describe RefollowWorker do result = subject.perform(account.id) expect(result).to be_nil - expect(service).to have_received(:call).with(alice, account, reblogs: true, notify: false, bypass_limit: true) - expect(service).to have_received(:call).with(bob, account, reblogs: false, notify: false, bypass_limit: true) + expect(service).to have_received(:call).with(alice, account, reblogs: true, notify: false, languages: nil, bypass_limit: true) + expect(service).to have_received(:call).with(bob, account, reblogs: false, notify: false, languages: nil, bypass_limit: true) end end end -- cgit