1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-27 14:29:03 +09:00

Combine API request spec assertions (#31970)

This commit is contained in:
Matt Jankowski 2024-09-19 06:15:21 -04:00 committed by GitHub
parent 1fce55cf5d
commit b071e618e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 36 additions and 232 deletions

View File

@ -193,15 +193,11 @@ RSpec.describe 'Accounts' do
it_behaves_like 'forbidden for wrong scope', 'write write:accounts read admin:read' it_behaves_like 'forbidden for wrong scope', 'write write:accounts read admin:read'
it_behaves_like 'forbidden for wrong role', '' it_behaves_like 'forbidden for wrong role', ''
it 'removes the user successfully', :aggregate_failures do it 'removes the user successfully and logs action', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(User.where(id: account.user.id)).to_not exist expect(User.where(id: account.user.id)).to_not exist
end
it 'logs action', :aggregate_failures do
subject
expect(latest_admin_action_log) expect(latest_admin_action_log)
.to be_present .to be_present

View File

@ -73,14 +73,10 @@ RSpec.describe 'Tags' do
it_behaves_like 'forbidden for wrong scope', 'write:statuses' it_behaves_like 'forbidden for wrong scope', 'write:statuses'
it_behaves_like 'forbidden for wrong role', '' it_behaves_like 'forbidden for wrong role', ''
it 'returns http success' do it 'returns http success and expected tag content' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns expected tag content' do
subject
expect(response.parsed_body[:id].to_i).to eq(tag.id) expect(response.parsed_body[:id].to_i).to eq(tag.id)
expect(response.parsed_body[:name]).to eq(tag.name) expect(response.parsed_body[:name]).to eq(tag.name)
@ -107,14 +103,10 @@ RSpec.describe 'Tags' do
it_behaves_like 'forbidden for wrong scope', 'admin:read' it_behaves_like 'forbidden for wrong scope', 'admin:read'
it_behaves_like 'forbidden for wrong role', '' it_behaves_like 'forbidden for wrong role', ''
it 'returns http success' do it 'returns http success and updates tag' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns updated tag' do
subject
expect(response.parsed_body[:id].to_i).to eq(tag.id) expect(response.parsed_body[:id].to_i).to eq(tag.id)
expect(response.parsed_body[:name]).to eq(tag.name.upcase) expect(response.parsed_body[:name]).to eq(tag.name.upcase)

View File

@ -47,14 +47,10 @@ RSpec.describe 'Credentials' do
let(:token) { Fabricate(:accessible_access_token, application: application) } let(:token) { Fabricate(:accessible_access_token, application: application) }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } } let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
it 'returns http success' do it 'returns http success and returns app information' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns the app information correctly' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including( a_hash_including(
@ -108,14 +104,10 @@ RSpec.describe 'Credentials' do
let(:token) { Fabricate(:accessible_access_token, application: application) } let(:token) { Fabricate(:accessible_access_token, application: application) }
let(:headers) { { 'Authorization' => "Bearer #{token.token}-invalid" } } let(:headers) { { 'Authorization' => "Bearer #{token.token}-invalid" } }
it 'returns http authorization error' do it 'returns http authorization error with json error' do
subject subject
expect(response).to have_http_status(401) expect(response).to have_http_status(401)
end
it 'returns the error in the json response' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including( a_hash_including(

View File

@ -32,15 +32,10 @@ RSpec.describe 'Blocks' do
context 'with limit param' do context 'with limit param' do
let(:params) { { limit: 2 } } let(:params) { { limit: 2 } }
it 'returns only the requested number of blocked accounts' do it 'returns only the requested number of blocked accounts and sets link header pagination' do
subject subject
expect(response.parsed_body.size).to eq(params[:limit]) expect(response.parsed_body.size).to eq(params[:limit])
end
it 'sets correct link header pagination' do
subject
expect(response) expect(response)
.to include_pagination_headers( .to include_pagination_headers(
prev: api_v1_blocks_url(limit: params[:limit], since_id: blocks.last.id), prev: api_v1_blocks_url(limit: params[:limit], since_id: blocks.last.id),

View File

@ -24,15 +24,10 @@ RSpec.describe 'Bookmarks' do
it_behaves_like 'forbidden for wrong scope', 'write' it_behaves_like 'forbidden for wrong scope', 'write'
it 'returns http success' do it 'returns http success and the bookmarked statuses' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns the bookmarked statuses' do
subject
expect(response.parsed_body).to match_array(expected_response) expect(response.parsed_body).to match_array(expected_response)
end end

View File

@ -24,30 +24,20 @@ RSpec.describe 'Favourites' do
it_behaves_like 'forbidden for wrong scope', 'write' it_behaves_like 'forbidden for wrong scope', 'write'
it 'returns http success' do it 'returns http success and includes the favourites' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns the favourites' do
subject
expect(response.parsed_body).to match_array(expected_response) expect(response.parsed_body).to match_array(expected_response)
end end
context 'with limit param' do context 'with limit param' do
let(:params) { { limit: 1 } } let(:params) { { limit: 1 } }
it 'returns only the requested number of favourites' do it 'returns only the requested number of favourites and sets pagination headers' do
subject subject
expect(response.parsed_body.size).to eq(params[:limit]) expect(response.parsed_body.size).to eq(params[:limit])
end
it 'sets the correct pagination headers' do
subject
expect(response) expect(response)
.to include_pagination_headers( .to include_pagination_headers(
prev: api_v1_favourites_url(limit: params[:limit], min_id: favourites.last.id), prev: api_v1_favourites_url(limit: params[:limit], min_id: favourites.last.id),

View File

@ -58,15 +58,10 @@ RSpec.describe 'FeaturedTags' do
describe 'POST /api/v1/featured_tags' do describe 'POST /api/v1/featured_tags' do
let(:params) { { name: 'tag' } } let(:params) { { name: 'tag' } }
it 'returns http success' do it 'returns http success and includes correct tag name' do
post '/api/v1/featured_tags', headers: headers, params: params post '/api/v1/featured_tags', headers: headers, params: params
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns the correct tag name' do
post '/api/v1/featured_tags', headers: headers, params: params
expect(response.parsed_body) expect(response.parsed_body)
.to include( .to include(
name: params[:name] name: params[:name]
@ -132,23 +127,13 @@ RSpec.describe 'FeaturedTags' do
let!(:featured_tag) { FeaturedTag.create(name: 'tag', account: user.account) } let!(:featured_tag) { FeaturedTag.create(name: 'tag', account: user.account) }
let(:id) { featured_tag.id } let(:id) { featured_tag.id }
it 'returns http success' do it 'returns http success with an empty body and deletes the featured tag', :inline_jobs do
delete "/api/v1/featured_tags/#{id}", headers: headers delete "/api/v1/featured_tags/#{id}", headers: headers
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns an empty body' do
delete "/api/v1/featured_tags/#{id}", headers: headers
expect(response.parsed_body).to be_empty expect(response.parsed_body).to be_empty
end
it 'deletes the featured tag', :inline_jobs do
delete "/api/v1/featured_tags/#{id}", headers: headers
featured_tag = FeaturedTag.find_by(id: id) featured_tag = FeaturedTag.find_by(id: id)
expect(featured_tag).to be_nil expect(featured_tag).to be_nil
end end

View File

@ -28,15 +28,10 @@ RSpec.describe 'Followed tags' do
it_behaves_like 'forbidden for wrong scope', 'write write:follows' it_behaves_like 'forbidden for wrong scope', 'write write:follows'
it 'returns http success' do it 'returns http success and includes followed tags' do
subject subject
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end
it 'returns the followed tags correctly' do
subject
expect(response.parsed_body).to match_array(expected_response) expect(response.parsed_body).to match_array(expected_response)
end end

View File

@ -8,11 +8,8 @@ RSpec.describe 'Languages' do
get '/api/v1/instance/languages' get '/api/v1/instance/languages'
end end
it 'returns http success' do it 'returns http success and includes supported languages' do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns the supported languages' do
expect(response.parsed_body.pluck(:code)).to match_array LanguagesHelper::SUPPORTED_LOCALES.keys.map(&:to_s) expect(response.parsed_body.pluck(:code)).to match_array LanguagesHelper::SUPPORTED_LOCALES.keys.map(&:to_s)
end end
end end

View File

@ -139,16 +139,11 @@ RSpec.describe 'Accounts' do
list.accounts << [bob, peter] list.accounts << [bob, peter]
end end
it 'removes the specified account from the list', :aggregate_failures do it 'removes the specified account from the list but keeps other accounts in the list', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(list.accounts).to_not include(bob) expect(list.accounts).to_not include(bob)
end
it 'does not remove any other account from the list' do
subject
expect(list.accounts).to include(peter) expect(list.accounts).to include(peter)
end end

View File

@ -17,15 +17,10 @@ RSpec.describe 'Media' do
it_behaves_like 'forbidden for wrong scope', 'read' it_behaves_like 'forbidden for wrong scope', 'read'
it 'returns http success' do it 'returns http success with media information' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns the media information' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including( a_hash_including(
id: media.id.to_s, id: media.id.to_s,

View File

@ -18,32 +18,22 @@ RSpec.describe 'Mutes' do
it_behaves_like 'forbidden for wrong scope', 'write write:mutes' it_behaves_like 'forbidden for wrong scope', 'write write:mutes'
it 'returns http success' do it 'returns http success with muted accounts' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns the muted accounts' do
subject
muted_accounts = mutes.map(&:target_account) muted_accounts = mutes.map(&:target_account)
expect(response.parsed_body.pluck(:id)).to match_array(muted_accounts.map { |account| account.id.to_s }) expect(response.parsed_body.pluck(:id)).to match_array(muted_accounts.map { |account| account.id.to_s })
end end
context 'with limit param' do context 'with limit param' do
let(:params) { { limit: 1 } } let(:params) { { limit: 1 } }
it 'returns only the requested number of muted accounts' do it 'returns only the requested number of muted accounts with pagination headers' do
subject subject
expect(response.parsed_body.size).to eq(params[:limit]) expect(response.parsed_body.size).to eq(params[:limit])
end
it 'sets the correct pagination headers', :aggregate_failures do
subject
expect(response) expect(response)
.to include_pagination_headers( .to include_pagination_headers(
prev: api_v1_mutes_url(limit: params[:limit], since_id: mutes.last.id), prev: api_v1_mutes_url(limit: params[:limit], since_id: mutes.last.id),

View File

@ -39,15 +39,10 @@ RSpec.describe 'Requests' do
it_behaves_like 'forbidden for wrong scope', 'read read:notifications' it_behaves_like 'forbidden for wrong scope', 'read read:notifications'
it 'returns http success' do it 'returns http success and creates notification permission' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'creates notification permission' do
subject
expect(NotificationPermission.find_by(account: notification_request.account, from_account: notification_request.from_account)).to_not be_nil expect(NotificationPermission.find_by(account: notification_request.account, from_account: notification_request.from_account)).to_not be_nil
end end

View File

@ -28,31 +28,14 @@ RSpec.describe 'Deleting profile images' do
it_behaves_like 'forbidden for wrong scope', 'read' it_behaves_like 'forbidden for wrong scope', 'read'
end end
it 'returns http success' do it 'returns http success and deletes the avatar, preserves the header, queues up distribution' do
delete '/api/v1/profile/avatar', headers: headers delete '/api/v1/profile/avatar', headers: headers
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'deletes the avatar' do
delete '/api/v1/profile/avatar', headers: headers
account.reload account.reload
expect(account.avatar).to_not exist expect(account.avatar).to_not exist
end
it 'does not delete the header' do
delete '/api/v1/profile/avatar', headers: headers
account.reload
expect(account.header).to exist expect(account.header).to exist
end
it 'queues up an account update distribution' do
delete '/api/v1/profile/avatar', headers: headers
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id) expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
end end
end end
@ -66,31 +49,14 @@ RSpec.describe 'Deleting profile images' do
it_behaves_like 'forbidden for wrong scope', 'read' it_behaves_like 'forbidden for wrong scope', 'read'
end end
it 'returns http success' do it 'returns http success, preserves the avatar, deletes the header, queues up distribution' do
delete '/api/v1/profile/header', headers: headers delete '/api/v1/profile/header', headers: headers
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'does not delete the avatar' do
delete '/api/v1/profile/header', headers: headers
account.reload account.reload
expect(account.avatar).to exist expect(account.avatar).to exist
end
it 'deletes the header' do
delete '/api/v1/profile/header', headers: headers
account.reload
expect(account.header).to_not exist expect(account.header).to_not exist
end
it 'queues up an account update distribution' do
delete '/api/v1/profile/header', headers: headers
expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id) expect(ActivityPub::UpdateDistributionWorker).to have_received(:perform_async).with(account.id)
end end
end end

View File

@ -18,15 +18,11 @@ RSpec.describe 'Bookmarks' do
it_behaves_like 'forbidden for wrong scope', 'read' it_behaves_like 'forbidden for wrong scope', 'read'
context 'with public status' do context 'with public status' do
it 'bookmarks the status successfully', :aggregate_failures do it 'bookmarks the status successfully and includes updated json', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(user.account.bookmarked?(status)).to be true expect(user.account.bookmarked?(status)).to be true
end
it 'returns json with updated attributes' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including(id: status.id.to_s, bookmarked: true) a_hash_including(id: status.id.to_s, bookmarked: true)
@ -93,15 +89,11 @@ RSpec.describe 'Bookmarks' do
Bookmark.find_or_create_by!(account: user.account, status: status) Bookmark.find_or_create_by!(account: user.account, status: status)
end end
it 'unbookmarks the status successfully', :aggregate_failures do it 'unbookmarks the status successfully and includes updated json', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(user.account.bookmarked?(status)).to be false expect(user.account.bookmarked?(status)).to be false
end
it 'returns json with updated attributes' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including(id: status.id.to_s, bookmarked: false) a_hash_including(id: status.id.to_s, bookmarked: false)
@ -117,15 +109,11 @@ RSpec.describe 'Bookmarks' do
status.account.block!(user.account) status.account.block!(user.account)
end end
it 'unbookmarks the status successfully', :aggregate_failures do it 'unbookmarks the status successfully and includes updated json', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(user.account.bookmarked?(status)).to be false expect(user.account.bookmarked?(status)).to be false
end
it 'returns json with updated attributes' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including(id: status.id.to_s, bookmarked: false) a_hash_including(id: status.id.to_s, bookmarked: false)

View File

@ -18,15 +18,11 @@ RSpec.describe 'Favourites', :inline_jobs do
it_behaves_like 'forbidden for wrong scope', 'read read:favourites' it_behaves_like 'forbidden for wrong scope', 'read read:favourites'
context 'with public status' do context 'with public status' do
it 'favourites the status successfully', :aggregate_failures do it 'favourites the status successfully and includes updated json', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(user.account.favourited?(status)).to be true expect(user.account.favourited?(status)).to be true
end
it 'returns json with updated attributes' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including(id: status.id.to_s, favourites_count: 1, favourited: true) a_hash_including(id: status.id.to_s, favourites_count: 1, favourited: true)
@ -84,16 +80,12 @@ RSpec.describe 'Favourites', :inline_jobs do
FavouriteService.new.call(user.account, status) FavouriteService.new.call(user.account, status)
end end
it 'unfavourites the status successfully', :aggregate_failures do it 'unfavourites the status successfully and includes updated json', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(user.account.favourited?(status)).to be false expect(user.account.favourited?(status)).to be false
end
it 'returns json with updated attributes' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including(id: status.id.to_s, favourites_count: 0, favourited: false) a_hash_including(id: status.id.to_s, favourites_count: 0, favourited: false)
@ -107,16 +99,12 @@ RSpec.describe 'Favourites', :inline_jobs do
status.account.block!(user.account) status.account.block!(user.account)
end end
it 'unfavourites the status successfully', :aggregate_failures do it 'unfavourites the status successfully and includes updated json', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(user.account.favourited?(status)).to be false expect(user.account.favourited?(status)).to be false
end
it 'returns json with updated attributes' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including(id: status.id.to_s, favourites_count: 0, favourited: false) a_hash_including(id: status.id.to_s, favourites_count: 0, favourited: false)

View File

@ -18,15 +18,11 @@ RSpec.describe 'Pins' do
it_behaves_like 'forbidden for wrong scope', 'read read:accounts' it_behaves_like 'forbidden for wrong scope', 'read read:accounts'
context 'when the status is public' do context 'when the status is public' do
it 'pins the status successfully', :aggregate_failures do it 'pins the status successfully and returns updated json', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(user.account.pinned?(status)).to be true expect(user.account.pinned?(status)).to be true
end
it 'return json with updated attributes' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including(id: status.id.to_s, pinned: true) a_hash_including(id: status.id.to_s, pinned: true)
@ -86,15 +82,11 @@ RSpec.describe 'Pins' do
Fabricate(:status_pin, status: status, account: user.account) Fabricate(:status_pin, status: status, account: user.account)
end end
it 'unpins the status successfully', :aggregate_failures do it 'unpins the status successfully and includes updated json', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(user.account.pinned?(status)).to be false expect(user.account.pinned?(status)).to be false
end
it 'return json with updated attributes' do
subject
expect(response.parsed_body).to match( expect(response.parsed_body).to match(
a_hash_including(id: status.id.to_s, pinned: false) a_hash_including(id: status.id.to_s, pinned: false)

View File

@ -23,15 +23,10 @@ RSpec.describe 'Suggestions' do
it_behaves_like 'forbidden for wrong scope', 'write' it_behaves_like 'forbidden for wrong scope', 'write'
it 'returns http success' do it 'returns http success with accounts' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns accounts' do
subject
expect(response.parsed_body) expect(response.parsed_body)
.to contain_exactly(include(id: bob.id.to_s), include(id: jeff.id.to_s)) .to contain_exactly(include(id: bob.id.to_s), include(id: jeff.id.to_s))
end end
@ -72,15 +67,10 @@ RSpec.describe 'Suggestions' do
it_behaves_like 'forbidden for wrong scope', 'read' it_behaves_like 'forbidden for wrong scope', 'read'
it 'returns http success' do it 'returns http success and removes suggestion' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'removes the specified suggestion' do
subject
expect(FollowRecommendationMute.exists?(account: user.account, target_account: jeff)).to be true expect(FollowRecommendationMute.exists?(account: user.account, target_account: jeff)).to be true
end end

View File

@ -31,14 +31,10 @@ RSpec.describe 'Home', :inline_jobs do
PostStatusService.new.call(ana, text: 'New toot from ana.') PostStatusService.new.call(ana, text: 'New toot from ana.')
end end
it 'returns http success' do it 'returns http success and statuses of followed users' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns the statuses of followed users' do
subject
expect(response.parsed_body.pluck(:id)).to match_array(home_statuses.map { |status| status.id.to_s }) expect(response.parsed_body.pluck(:id)).to match_array(home_statuses.map { |status| status.id.to_s })
end end
@ -46,14 +42,10 @@ RSpec.describe 'Home', :inline_jobs do
context 'with limit param' do context 'with limit param' do
let(:params) { { limit: 1 } } let(:params) { { limit: 1 } }
it 'returns only the requested number of statuses' do it 'returns only the requested number of statuses with pagination headers', :aggregate_failures do
subject subject
expect(response.parsed_body.size).to eq(params[:limit]) expect(response.parsed_body.size).to eq(params[:limit])
end
it 'sets the correct pagination headers', :aggregate_failures do
subject
expect(response) expect(response)
.to include_pagination_headers( .to include_pagination_headers(

View File

@ -123,15 +123,11 @@ RSpec.describe 'Link' do
context 'with limit param' do context 'with limit param' do
let(:params) { { limit: 1, url: url } } let(:params) { { limit: 1, url: url } }
it 'returns only the requested number of statuses', :aggregate_failures do it 'returns only the requested number of statuses with pagination headers', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(response.parsed_body.size).to eq(params[:limit]) expect(response.parsed_body.size).to eq(params[:limit])
end
it 'sets the correct pagination headers', :aggregate_failures do
subject
expect(response) expect(response)
.to include_pagination_headers( .to include_pagination_headers(

View File

@ -49,14 +49,10 @@ RSpec.describe 'Filters' do
context 'with valid params' do context 'with valid params' do
let(:params) { { title: 'magic', context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } } let(:params) { { title: 'magic', context: %w(home), filter_action: 'hide', keywords_attributes: [keyword: 'magic'] } }
it 'returns http success' do it 'returns http success with a filter with keywords in json and creates a filter', :aggregate_failures do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'returns a filter with keywords', :aggregate_failures do
subject
expect(response.parsed_body) expect(response.parsed_body)
.to include( .to include(
@ -67,10 +63,6 @@ RSpec.describe 'Filters' do
include(keyword: 'magic', whole_word: true) include(keyword: 'magic', whole_word: true)
) )
) )
end
it 'creates a filter', :aggregate_failures do
subject
filter = user.account.custom_filters.first filter = user.account.custom_filters.first
@ -189,20 +181,12 @@ RSpec.describe 'Filters' do
allow(redis).to receive_messages(publish: nil) allow(redis).to receive_messages(publish: nil)
end end
it 'returns http success' do it 'returns http success and updates keyword and sends a filters_changed event' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'updates the keyword' do
subject
expect(keyword.reload.keyword).to eq 'updated' expect(keyword.reload.keyword).to eq 'updated'
end
it 'sends exactly one filters_changed event' do
subject
expect(redis).to have_received(:publish).with("timeline:#{user.account.id}", Oj.dump(event: :filters_changed)).once expect(redis).to have_received(:publish).with("timeline:#{user.account.id}", Oj.dump(event: :filters_changed)).once
end end
@ -229,14 +213,10 @@ RSpec.describe 'Filters' do
it_behaves_like 'forbidden for wrong scope', 'read read:filters' it_behaves_like 'forbidden for wrong scope', 'read read:filters'
it_behaves_like 'unauthorized for invalid token' it_behaves_like 'unauthorized for invalid token'
it 'returns http success' do it 'returns http success and removes the filter' do
subject subject
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end
it 'removes the filter' do
subject
expect { filter.reload }.to raise_error ActiveRecord::RecordNotFound expect { filter.reload }.to raise_error ActiveRecord::RecordNotFound
end end