From a7f8417795a7306e10c9bec7202359a8e73f6e46 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 27 Aug 2024 04:12:39 -0400 Subject: [PATCH] Convert "CSV export" settings controller specs to request specs (#31601) --- .../blocked_accounts_controller_spec.rb | 19 -------- .../blocked_domains_controller_spec.rb | 20 --------- .../exports/bookmarks_controller_spec.rb | 24 ---------- .../following_accounts_controller_spec.rb | 19 -------- .../settings/exports/lists_controller_spec.rb | 21 --------- .../exports/muted_accounts_controller_spec.rb | 19 -------- .../settings/exports/blocked_accounts_spec.rb | 42 ++++++++++++++++++ .../settings/exports/blocked_domains_spec.rb | 39 ++++++++++++++++ .../settings/exports/bookmarks_spec.rb | 44 +++++++++++++++++++ .../exports/following_accounts_spec.rb | 44 +++++++++++++++++++ spec/requests/settings/exports/lists_spec.rb | 40 +++++++++++++++++ .../settings/exports/muted_accounts_spec.rb | 43 ++++++++++++++++++ 12 files changed, 252 insertions(+), 122 deletions(-) delete mode 100644 spec/controllers/settings/exports/blocked_accounts_controller_spec.rb delete mode 100644 spec/controllers/settings/exports/blocked_domains_controller_spec.rb delete mode 100644 spec/controllers/settings/exports/bookmarks_controller_spec.rb delete mode 100644 spec/controllers/settings/exports/following_accounts_controller_spec.rb delete mode 100644 spec/controllers/settings/exports/lists_controller_spec.rb delete mode 100644 spec/controllers/settings/exports/muted_accounts_controller_spec.rb create mode 100644 spec/requests/settings/exports/blocked_accounts_spec.rb create mode 100644 spec/requests/settings/exports/blocked_domains_spec.rb create mode 100644 spec/requests/settings/exports/bookmarks_spec.rb create mode 100644 spec/requests/settings/exports/following_accounts_spec.rb create mode 100644 spec/requests/settings/exports/lists_spec.rb create mode 100644 spec/requests/settings/exports/muted_accounts_spec.rb diff --git a/spec/controllers/settings/exports/blocked_accounts_controller_spec.rb b/spec/controllers/settings/exports/blocked_accounts_controller_spec.rb deleted file mode 100644 index 459b278d6..000000000 --- a/spec/controllers/settings/exports/blocked_accounts_controller_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Settings::Exports::BlockedAccountsController do - render_views - - describe 'GET #index' do - it 'returns a csv of the blocking accounts' do - user = Fabricate(:user) - user.account.block!(Fabricate(:account, username: 'username', domain: 'domain')) - - sign_in user, scope: :user - get :index, format: :csv - - expect(response.body).to eq "username@domain\n" - end - end -end diff --git a/spec/controllers/settings/exports/blocked_domains_controller_spec.rb b/spec/controllers/settings/exports/blocked_domains_controller_spec.rb deleted file mode 100644 index ac72fd9dd..000000000 --- a/spec/controllers/settings/exports/blocked_domains_controller_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Settings::Exports::BlockedDomainsController do - render_views - - describe 'GET #index' do - it 'returns a csv of the domains' do - account = Fabricate(:account, domain: 'example.com') - user = Fabricate(:user, account: account) - Fabricate(:account_domain_block, domain: 'example.com', account: account) - - sign_in user, scope: :user - get :index, format: :csv - - expect(response.body).to eq "example.com\n" - end - end -end diff --git a/spec/controllers/settings/exports/bookmarks_controller_spec.rb b/spec/controllers/settings/exports/bookmarks_controller_spec.rb deleted file mode 100644 index 9982eff16..000000000 --- a/spec/controllers/settings/exports/bookmarks_controller_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Settings::Exports::BookmarksController do - render_views - - let(:user) { Fabricate(:user) } - let(:account) { Fabricate(:account, domain: 'foo.bar') } - let(:status) { Fabricate(:status, account: account, uri: 'https://foo.bar/statuses/1312') } - - describe 'GET #index' do - before do - user.account.bookmarks.create!(status: status) - end - - it 'returns a csv of the bookmarked toots' do - sign_in user, scope: :user - get :index, format: :csv - - expect(response.body).to eq "https://foo.bar/statuses/1312\n" - 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 deleted file mode 100644 index 72b0b94e1..000000000 --- a/spec/controllers/settings/exports/following_accounts_controller_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Settings::Exports::FollowingAccountsController do - render_views - - describe 'GET #index' do - it 'returns a csv of the following accounts' do - user = Fabricate(:user) - user.account.follow!(Fabricate(:account, username: 'username', domain: 'domain')) - - sign_in user, scope: :user - get :index, format: :csv - - 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/controllers/settings/exports/lists_controller_spec.rb b/spec/controllers/settings/exports/lists_controller_spec.rb deleted file mode 100644 index 29623ba49..000000000 --- a/spec/controllers/settings/exports/lists_controller_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Settings::Exports::ListsController do - render_views - - describe 'GET #index' do - it 'returns a csv of the domains' do - account = Fabricate(:account) - user = Fabricate(:user, account: account) - list = Fabricate(:list, account: account, title: 'The List') - Fabricate(:list_account, list: list, account: account) - - sign_in user, scope: :user - get :index, format: :csv - - expect(response.body).to match 'The List' - end - end -end diff --git a/spec/controllers/settings/exports/muted_accounts_controller_spec.rb b/spec/controllers/settings/exports/muted_accounts_controller_spec.rb deleted file mode 100644 index b4170cb16..000000000 --- a/spec/controllers/settings/exports/muted_accounts_controller_spec.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe Settings::Exports::MutedAccountsController do - render_views - - describe 'GET #index' do - it 'returns a csv of the muting accounts' do - user = Fabricate(:user) - user.account.mute!(Fabricate(:account, username: 'username', domain: 'domain')) - - sign_in user, scope: :user - get :index, format: :csv - - expect(response.body).to eq "Account address,Hide notifications\nusername@domain,true\n" - end - end -end diff --git a/spec/requests/settings/exports/blocked_accounts_spec.rb b/spec/requests/settings/exports/blocked_accounts_spec.rb new file mode 100644 index 000000000..f335ba18c --- /dev/null +++ b/spec/requests/settings/exports/blocked_accounts_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Settings / Exports / Blocked Accounts' do + describe 'GET /settings/exports/blocks' do + context 'with a signed in user who has blocked accounts' do + let(:user) { Fabricate :user } + + before do + Fabricate( + :block, + account: user.account, + target_account: Fabricate(:account, username: 'username', domain: 'domain') + ) + sign_in user + end + + it 'returns a CSV with the blocking accounts' do + get '/settings/exports/blocks.csv' + + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to eq('text/csv') + expect(response.body) + .to eq(<<~CSV) + username@domain + CSV + end + end + + describe 'when signed out' do + it 'returns unauthorized' do + get '/settings/exports/blocks.csv' + + expect(response) + .to have_http_status(401) + end + end + end +end diff --git a/spec/requests/settings/exports/blocked_domains_spec.rb b/spec/requests/settings/exports/blocked_domains_spec.rb new file mode 100644 index 000000000..762907585 --- /dev/null +++ b/spec/requests/settings/exports/blocked_domains_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Settings / Exports / Blocked Domains' do + describe 'GET /settings/exports/domain_blocks' do + context 'with a signed in user who has blocked domains' do + let(:account) { Fabricate :account, domain: 'example.com' } + let(:user) { Fabricate :user, account: account } + + before do + Fabricate(:account_domain_block, domain: 'example.com', account: account) + sign_in user + end + + it 'returns a CSV with the domains' do + get '/settings/exports/domain_blocks.csv' + + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to eq('text/csv') + expect(response.body) + .to eq(<<~CSV) + example.com + CSV + end + end + + describe 'when signed out' do + it 'returns unauthorized' do + get '/settings/exports/domain_blocks.csv' + + expect(response) + .to have_http_status(401) + end + end + end +end diff --git a/spec/requests/settings/exports/bookmarks_spec.rb b/spec/requests/settings/exports/bookmarks_spec.rb new file mode 100644 index 000000000..f200e7038 --- /dev/null +++ b/spec/requests/settings/exports/bookmarks_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Settings / Exports / Bookmarks' do + describe 'GET /settings/exports/bookmarks' do + context 'with a signed in user who has bookmarks' do + let(:account) { Fabricate(:account, domain: 'foo.bar') } + let(:status) { Fabricate(:status, account: account, uri: 'https://foo.bar/statuses/1312') } + let(:user) { Fabricate(:user) } + + before do + Fabricate( + :bookmark, + account: user.account, + status: status + ) + sign_in user + end + + it 'returns a CSV with the bookmarked statuses' do + get '/settings/exports/bookmarks.csv' + + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to eq('text/csv') + expect(response.body) + .to eq(<<~CSV) + https://foo.bar/statuses/1312 + CSV + end + end + + describe 'when signed out' do + it 'returns unauthorized' do + get '/settings/exports/bookmarks.csv' + + expect(response) + .to have_http_status(401) + end + end + end +end diff --git a/spec/requests/settings/exports/following_accounts_spec.rb b/spec/requests/settings/exports/following_accounts_spec.rb new file mode 100644 index 000000000..268b72c41 --- /dev/null +++ b/spec/requests/settings/exports/following_accounts_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Settings / Exports / Following Accounts' do + describe 'GET /settings/exports/follows' do + context 'with a signed in user who is following accounts' do + let(:user) { Fabricate :user } + + before do + Fabricate( + :follow, + account: user.account, + target_account: Fabricate(:account, username: 'username', domain: 'domain'), + languages: ['en'] + ) + sign_in user + end + + it 'returns a CSV with the accounts' do + get '/settings/exports/follows.csv' + + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to eq('text/csv') + expect(response.body) + .to eq(<<~CSV) + Account address,Show boosts,Notify on new posts,Languages + username@domain,true,false,en + CSV + end + end + + describe 'when signed out' do + it 'returns unauthorized' do + get '/settings/exports/follows.csv' + + expect(response) + .to have_http_status(401) + end + end + end +end diff --git a/spec/requests/settings/exports/lists_spec.rb b/spec/requests/settings/exports/lists_spec.rb new file mode 100644 index 000000000..b868f8dfd --- /dev/null +++ b/spec/requests/settings/exports/lists_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Settings / Exports / Lists' do + describe 'GET /settings/exports/lists' do + context 'with a signed in user who has lists' do + let(:account) { Fabricate(:account, username: 'test', domain: 'example.com') } + let(:list) { Fabricate :list, account: account, title: 'The List' } + let(:user) { Fabricate(:user, account: account) } + + before do + Fabricate(:list_account, list: list, account: account) + sign_in user + end + + it 'returns a CSV with the list' do + get '/settings/exports/lists.csv' + + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to eq('text/csv') + expect(response.body) + .to eq(<<~CSV) + The List,test@example.com + CSV + end + end + + describe 'when signed out' do + it 'returns unauthorized' do + get '/settings/exports/lists.csv' + + expect(response) + .to have_http_status(401) + end + end + end +end diff --git a/spec/requests/settings/exports/muted_accounts_spec.rb b/spec/requests/settings/exports/muted_accounts_spec.rb new file mode 100644 index 000000000..efdb0d822 --- /dev/null +++ b/spec/requests/settings/exports/muted_accounts_spec.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Settings / Exports / Muted Accounts' do + describe 'GET /settings/exports/mutes' do + context 'with a signed in user who has muted accounts' do + let(:user) { Fabricate :user } + + before do + Fabricate( + :mute, + account: user.account, + target_account: Fabricate(:account, username: 'username', domain: 'domain') + ) + sign_in user + end + + it 'returns a CSV with the muted accounts' do + get '/settings/exports/mutes.csv' + + expect(response) + .to have_http_status(200) + expect(response.content_type) + .to eq('text/csv') + expect(response.body) + .to eq(<<~CSV) + Account address,Hide notifications + username@domain,true + CSV + end + end + + describe 'when signed out' do + it 'returns unauthorized' do + get '/settings/exports/mutes.csv' + + expect(response) + .to have_http_status(401) + end + end + end +end