gearheads
/
mastodon
Archived
2
0
Fork 0

Fix RSpec/ContextWording cop (#24739)

gh/dev
Matt Jankowski 2023-05-03 23:49:08 -04:00 committed by GitHub
parent cf18cc2891
commit 710745e16b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
105 changed files with 559 additions and 668 deletions

View File

@ -328,115 +328,6 @@ RSpec/AnyInstance:
- 'spec/workers/activitypub/delivery_worker_spec.rb' - 'spec/workers/activitypub/delivery_worker_spec.rb'
- 'spec/workers/web/push_notification_worker_spec.rb' - 'spec/workers/web/push_notification_worker_spec.rb'
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/config/initializers/rack_attack_spec.rb'
- 'spec/controllers/accounts_controller_spec.rb'
- 'spec/controllers/activitypub/collections_controller_spec.rb'
- 'spec/controllers/activitypub/inboxes_controller_spec.rb'
- 'spec/controllers/admin/domain_blocks_controller_spec.rb'
- 'spec/controllers/admin/reports/actions_controller_spec.rb'
- 'spec/controllers/admin/statuses_controller_spec.rb'
- 'spec/controllers/api/v1/accounts/relationships_controller_spec.rb'
- 'spec/controllers/api/v1/accounts_controller_spec.rb'
- 'spec/controllers/api/v1/admin/domain_blocks_controller_spec.rb'
- 'spec/controllers/api/v1/emails/confirmations_controller_spec.rb'
- 'spec/controllers/api/v1/instances/activity_controller_spec.rb'
- 'spec/controllers/api/v1/instances/peers_controller_spec.rb'
- 'spec/controllers/api/v1/media_controller_spec.rb'
- 'spec/controllers/api/v2/filters_controller_spec.rb'
- 'spec/controllers/application_controller_spec.rb'
- 'spec/controllers/auth/registrations_controller_spec.rb'
- 'spec/controllers/auth/sessions_controller_spec.rb'
- 'spec/controllers/concerns/cache_concern_spec.rb'
- 'spec/controllers/concerns/challengable_concern_spec.rb'
- 'spec/controllers/concerns/localized_spec.rb'
- 'spec/controllers/concerns/rate_limit_headers_spec.rb'
- 'spec/controllers/instance_actors_controller_spec.rb'
- 'spec/controllers/settings/applications_controller_spec.rb'
- 'spec/controllers/settings/two_factor_authentication/webauthn_credentials_controller_spec.rb'
- 'spec/controllers/statuses_controller_spec.rb'
- 'spec/helpers/admin/account_moderation_notes_helper_spec.rb'
- 'spec/helpers/jsonld_helper_spec.rb'
- 'spec/helpers/routing_helper_spec.rb'
- 'spec/lib/activitypub/activity/accept_spec.rb'
- 'spec/lib/activitypub/activity/announce_spec.rb'
- 'spec/lib/activitypub/activity/create_spec.rb'
- 'spec/lib/activitypub/activity/follow_spec.rb'
- 'spec/lib/activitypub/activity/reject_spec.rb'
- 'spec/lib/emoji_formatter_spec.rb'
- 'spec/lib/entity_cache_spec.rb'
- 'spec/lib/feed_manager_spec.rb'
- 'spec/lib/html_aware_formatter_spec.rb'
- 'spec/lib/link_details_extractor_spec.rb'
- 'spec/lib/ostatus/tag_manager_spec.rb'
- 'spec/lib/scope_transformer_spec.rb'
- 'spec/lib/status_cache_hydrator_spec.rb'
- 'spec/lib/status_reach_finder_spec.rb'
- 'spec/lib/text_formatter_spec.rb'
- 'spec/models/account/field_spec.rb'
- 'spec/models/account_spec.rb'
- 'spec/models/admin/account_action_spec.rb'
- 'spec/models/concerns/account_interactions_spec.rb'
- 'spec/models/concerns/remotable_spec.rb'
- 'spec/models/custom_emoji_filter_spec.rb'
- 'spec/models/custom_emoji_spec.rb'
- 'spec/models/email_domain_block_spec.rb'
- 'spec/models/media_attachment_spec.rb'
- 'spec/models/notification_spec.rb'
- 'spec/models/remote_follow_spec.rb'
- 'spec/models/report_spec.rb'
- 'spec/models/session_activation_spec.rb'
- 'spec/models/setting_spec.rb'
- 'spec/models/status_spec.rb'
- 'spec/models/web/push_subscription_spec.rb'
- 'spec/policies/account_moderation_note_policy_spec.rb'
- 'spec/policies/account_policy_spec.rb'
- 'spec/policies/backup_policy_spec.rb'
- 'spec/policies/custom_emoji_policy_spec.rb'
- 'spec/policies/domain_block_policy_spec.rb'
- 'spec/policies/email_domain_block_policy_spec.rb'
- 'spec/policies/instance_policy_spec.rb'
- 'spec/policies/invite_policy_spec.rb'
- 'spec/policies/relay_policy_spec.rb'
- 'spec/policies/report_note_policy_spec.rb'
- 'spec/policies/report_policy_spec.rb'
- 'spec/policies/settings_policy_spec.rb'
- 'spec/policies/tag_policy_spec.rb'
- 'spec/policies/user_policy_spec.rb'
- 'spec/presenters/account_relationships_presenter_spec.rb'
- 'spec/presenters/status_relationships_presenter_spec.rb'
- 'spec/services/account_search_service_spec.rb'
- 'spec/services/account_statuses_cleanup_service_spec.rb'
- 'spec/services/activitypub/fetch_remote_status_service_spec.rb'
- 'spec/services/activitypub/process_account_service_spec.rb'
- 'spec/services/activitypub/process_status_update_service_spec.rb'
- 'spec/services/fetch_link_card_service_spec.rb'
- 'spec/services/fetch_oembed_service_spec.rb'
- 'spec/services/fetch_remote_status_service_spec.rb'
- 'spec/services/follow_service_spec.rb'
- 'spec/services/import_service_spec.rb'
- 'spec/services/notify_service_spec.rb'
- 'spec/services/process_mentions_service_spec.rb'
- 'spec/services/reblog_service_spec.rb'
- 'spec/services/report_service_spec.rb'
- 'spec/services/resolve_account_service_spec.rb'
- 'spec/services/resolve_url_service_spec.rb'
- 'spec/services/search_service_spec.rb'
- 'spec/services/unallow_domain_service_spec.rb'
- 'spec/services/verify_link_service_spec.rb'
- 'spec/validators/disallowed_hashtags_validator_spec.rb'
- 'spec/validators/email_mx_validator_spec.rb'
- 'spec/validators/follow_limit_validator_spec.rb'
- 'spec/validators/poll_validator_spec.rb'
- 'spec/validators/status_pin_validator_spec.rb'
- 'spec/validators/unreserved_username_validator_spec.rb'
- 'spec/validators/url_validator_spec.rb'
- 'spec/workers/move_worker_spec.rb'
- 'spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb'
# This cop supports unsafe autocorrection (--autocorrect-all). # This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle. # Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit # SupportedStyles: described_class, explicit

View File

@ -46,36 +46,36 @@ describe Rack::Attack, type: :request do
let(:remote_ip) { '1.2.3.5' } let(:remote_ip) { '1.2.3.5' }
describe 'throttle excessive sign-up requests by IP address' do describe 'throttle excessive sign-up requests by IP address' do
context 'through the website' do context 'when accessed through the website' do
let(:limit) { 25 } let(:limit) { 25 }
let(:period) { 5.minutes } let(:period) { 5.minutes }
let(:request) { -> { post path, headers: { 'REMOTE_ADDR' => remote_ip } } } let(:request) { -> { post path, headers: { 'REMOTE_ADDR' => remote_ip } } }
context 'for exact path' do context 'with exact path' do
let(:path) { '/auth' } let(:path) { '/auth' }
it_behaves_like 'throttled endpoint' it_behaves_like 'throttled endpoint'
end end
context 'for path with format' do context 'with path with format' do
let(:path) { '/auth.html' } let(:path) { '/auth.html' }
it_behaves_like 'throttled endpoint' it_behaves_like 'throttled endpoint'
end end
end end
context 'through the API' do context 'when accessed through the API' do
let(:limit) { 5 } let(:limit) { 5 }
let(:period) { 30.minutes } let(:period) { 30.minutes }
let(:request) { -> { post path, headers: { 'REMOTE_ADDR' => remote_ip } } } let(:request) { -> { post path, headers: { 'REMOTE_ADDR' => remote_ip } } }
context 'for exact path' do context 'with exact path' do
let(:path) { '/api/v1/accounts' } let(:path) { '/api/v1/accounts' }
it_behaves_like 'throttled endpoint' it_behaves_like 'throttled endpoint'
end end
context 'for path with format' do context 'with path with format' do
let(:path) { '/api/v1/accounts.json' } let(:path) { '/api/v1/accounts.json' }
it 'returns http not found' do it 'returns http not found' do
@ -91,13 +91,13 @@ describe Rack::Attack, type: :request do
let(:period) { 5.minutes } let(:period) { 5.minutes }
let(:request) { -> { post path, headers: { 'REMOTE_ADDR' => remote_ip } } } let(:request) { -> { post path, headers: { 'REMOTE_ADDR' => remote_ip } } }
context 'for exact path' do context 'with exact path' do
let(:path) { '/auth/sign_in' } let(:path) { '/auth/sign_in' }
it_behaves_like 'throttled endpoint' it_behaves_like 'throttled endpoint'
end end
context 'for path with format' do context 'with path with format' do
let(:path) { '/auth/sign_in.html' } let(:path) { '/auth/sign_in.html' }
it_behaves_like 'throttled endpoint' it_behaves_like 'throttled endpoint'

View File

@ -57,7 +57,7 @@ RSpec.describe AccountsController, type: :controller do
end end
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it_behaves_like 'preliminary checks' it_behaves_like 'preliminary checks'
@ -140,7 +140,7 @@ RSpec.describe AccountsController, type: :controller do
end end
end end
context 'as JSON' do context 'with JSON' do
let(:authorized_fetch_mode) { false } let(:authorized_fetch_mode) { false }
let(:format) { 'json' } let(:format) { 'json' }
@ -193,7 +193,7 @@ RSpec.describe AccountsController, type: :controller do
expect(json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary) expect(json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
end end
context 'in authorized fetch mode' do context 'with authorized fetch mode' do
let(:authorized_fetch_mode) { true } let(:authorized_fetch_mode) { true }
it 'returns http unauthorized' do it 'returns http unauthorized' do
@ -251,7 +251,7 @@ RSpec.describe AccountsController, type: :controller do
expect(json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary) expect(json).to include(:id, :type, :preferredUsername, :inbox, :publicKey, :name, :summary)
end end
context 'in authorized fetch mode' do context 'with authorized fetch mode' do
let(:authorized_fetch_mode) { true } let(:authorized_fetch_mode) { true }
it 'returns http success' do it 'returns http success' do
@ -278,7 +278,7 @@ RSpec.describe AccountsController, type: :controller do
end end
end end
context 'as RSS' do context 'with RSS' do
let(:format) { 'rss' } let(:format) { 'rss' }
it_behaves_like 'preliminary checks' it_behaves_like 'preliminary checks'

View File

@ -119,7 +119,7 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
end end
end end
context 'in authorized fetch mode' do context 'with authorized fetch mode' do
before do before do
allow(controller).to receive(:authorized_fetch_mode?).and_return(true) allow(controller).to receive(:authorized_fetch_mode?).and_return(true)
end end

View File

@ -21,7 +21,7 @@ RSpec.describe ActivityPub::InboxesController, type: :controller do
expect(response).to have_http_status(202) expect(response).to have_http_status(202)
end end
context 'for a specific account' do context 'with a specific account' do
subject(:response) { post :create, params: { account_username: account.username }, body: '{}' } subject(:response) { post :create, params: { account_username: account.username }, body: '{}' }
let(:account) { Fabricate(:account) } let(:account) { Fabricate(:account) }

View File

@ -83,7 +83,7 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
BlockDomainService.new.call(domain_block) BlockDomainService.new.call(domain_block)
end end
context 'downgrading a domain suspension to silence' do context 'when downgrading a domain suspension to silence' do
let(:original_severity) { 'suspend' } let(:original_severity) { 'suspend' }
let(:new_severity) { 'silence' } let(:new_severity) { 'silence' }
@ -100,7 +100,7 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
end end
end end
context 'upgrading a domain silence to suspend' do context 'when upgrading a domain silence to suspend' do
let(:original_severity) { 'silence' } let(:original_severity) { 'silence' }
let(:new_severity) { 'suspend' } let(:new_severity) { 'suspend' }

View File

@ -146,13 +146,13 @@ describe Admin::Reports::ActionsController do
end end
end end
context 'action as submit button' do context 'with Action as submit button' do
subject { post :create, params: common_params.merge({ action => '' }) } subject { post :create, params: common_params.merge({ action => '' }) }
it_behaves_like 'all action types' it_behaves_like 'all action types'
end end
context 'action as submit button' do context 'with Action as submit button' do
subject { post :create, params: common_params.merge({ moderation_action: action }) } subject { post :create, params: common_params.merge({ moderation_action: action }) }
it_behaves_like 'all action types' it_behaves_like 'all action types'

View File

@ -30,7 +30,7 @@ describe Admin::StatusesController do
end end
end end
context 'filtering by media' do context 'when filtering by media' do
before do before do
get :index, params: { account_id: account.id, media: '1' } get :index, params: { account_id: account.id, media: '1' }
end end

View File

@ -21,7 +21,7 @@ describe Api::V1::Accounts::RelationshipsController do
lewis.follow!(user.account) lewis.follow!(user.account)
end end
context 'provided only one ID' do context 'when provided only one ID' do
before do before do
get :index, params: { id: simon.id } get :index, params: { id: simon.id }
end end
@ -39,7 +39,7 @@ describe Api::V1::Accounts::RelationshipsController do
end end
end end
context 'provided multiple IDs' do context 'when provided multiple IDs' do
before do before do
get :index, params: { id: [simon.id, lewis.id] } get :index, params: { id: [simon.id, lewis.id] }
end end

View File

@ -30,7 +30,7 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
post :create, params: { username: 'test', password: '12345678', email: 'hello@world.tld', agreement: agreement } post :create, params: { username: 'test', password: '12345678', email: 'hello@world.tld', agreement: agreement }
end end
context 'given truthy agreement' do context 'when given truthy agreement' do
let(:agreement) { 'true' } let(:agreement) { 'true' }
it 'returns http success' do it 'returns http success' do
@ -48,7 +48,7 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
end end
end end
context 'given no agreement' do context 'when given no agreement' do
it 'returns http unprocessable entity' do it 'returns http unprocessable entity' do
expect(response).to have_http_status(422) expect(response).to have_http_status(422)
end end
@ -121,7 +121,7 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
end end
end end
context 'modifying follow options' do context 'when modifying follow options' do
let(:locked) { false } let(:locked) { false }
before do before do

View File

@ -84,7 +84,7 @@ RSpec.describe Api::V1::Admin::DomainBlocksController, type: :controller do
BlockDomainService.new.call(domain_block) BlockDomainService.new.call(domain_block)
end end
context 'downgrading a domain suspension to silence' do context 'when downgrading a domain suspension to silence' do
let(:original_severity) { 'suspend' } let(:original_severity) { 'suspend' }
let(:new_severity) { 'silence' } let(:new_severity) { 'silence' }
@ -101,7 +101,7 @@ RSpec.describe Api::V1::Admin::DomainBlocksController, type: :controller do
end end
end end
context 'upgrading a domain silence to suspend' do context 'when upgrading a domain silence to suspend' do
let(:original_severity) { 'silence' } let(:original_severity) { 'silence' }
let(:new_severity) { 'suspend' } let(:new_severity) { 'suspend' }

View File

@ -15,14 +15,14 @@ RSpec.describe Api::V1::Emails::ConfirmationsController, type: :controller do
allow(controller).to receive(:doorkeeper_token) { token } allow(controller).to receive(:doorkeeper_token) { token }
end end
context 'from a random app' do context 'when from a random app' do
it 'returns http forbidden' do it 'returns http forbidden' do
post :create post :create
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
end end
context 'from an app that created the account' do context 'when from an app that created the account' do
before do before do
user.update(created_by_application: token.application) user.update(created_by_application: token.application)
end end
@ -35,7 +35,7 @@ RSpec.describe Api::V1::Emails::ConfirmationsController, type: :controller do
expect(response).to have_http_status(403) expect(response).to have_http_status(403)
end end
context 'but user changed e-mail and has not confirmed it' do context 'with user changed e-mail and has not confirmed it' do
before do before do
user.update(email: 'foo@bar.com') user.update(email: 'foo@bar.com')
end end

View File

@ -9,7 +9,7 @@ RSpec.describe Api::V1::Instances::ActivityController, type: :controller do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
context '!Setting.activity_api_enabled' do context 'with !Setting.activity_api_enabled' do
it 'returns 404' do it 'returns 404' do
Setting.activity_api_enabled = false Setting.activity_api_enabled = false

View File

@ -9,7 +9,7 @@ RSpec.describe Api::V1::Instances::PeersController, type: :controller do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
end end
context '!Setting.peers_api_enabled' do context 'with !Setting.peers_api_enabled' do
it 'returns 404' do it 'returns 404' do
Setting.peers_api_enabled = false Setting.peers_api_enabled = false

View File

@ -37,7 +37,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
end end
end end
context 'image/jpeg' do context 'with image/jpeg' do
before do before do
post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') } post :create, params: { file: fixture_file_upload('attachment.jpg', 'image/jpeg') }
end end
@ -59,7 +59,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
end end
end end
context 'image/gif' do context 'with image/gif' do
before do before do
post :create, params: { file: fixture_file_upload('attachment.gif', 'image/gif') } post :create, params: { file: fixture_file_upload('attachment.gif', 'image/gif') }
end end
@ -81,7 +81,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
end end
end end
context 'video/webm' do context 'with video/webm' do
before do before do
post :create, params: { file: fixture_file_upload('attachment.webm', 'video/webm') } post :create, params: { file: fixture_file_upload('attachment.webm', 'video/webm') }
end end

View File

@ -66,7 +66,7 @@ RSpec.describe Api::V2::FiltersController, type: :controller do
let!(:filter) { Fabricate(:custom_filter, account: user.account) } let!(:filter) { Fabricate(:custom_filter, account: user.account) }
let!(:keyword) { Fabricate(:custom_filter_keyword, custom_filter: filter) } let!(:keyword) { Fabricate(:custom_filter_keyword, custom_filter: filter) }
context 'updating filter parameters' do context 'when updating filter parameters' do
before do before do
put :update, params: { id: filter.id, title: 'updated', context: %w(home public) } put :update, params: { id: filter.id, title: 'updated', context: %w(home public) }
end end
@ -84,7 +84,7 @@ RSpec.describe Api::V2::FiltersController, type: :controller do
end end
end end
context 'updating keywords in bulk' do context 'when updating keywords in bulk' do
before do before do
allow(redis).to receive_messages(publish: nil) allow(redis).to receive_messages(publish: nil)
put :update, params: { id: filter.id, keywords_attributes: [{ id: keyword.id, keyword: 'updated' }] } put :update, params: { id: filter.id, keywords_attributes: [{ id: keyword.id, keyword: 'updated' }] }

View File

@ -32,7 +32,7 @@ describe ApplicationController, type: :controller do
end end
end end
context 'forgery' do context 'with a forgery' do
subject do subject do
ActionController::Base.allow_forgery_protection = true ActionController::Base.allow_forgery_protection = true
routes.draw { post 'success' => 'anonymous#success' } routes.draw { post 'success' => 'anonymous#success' }
@ -105,7 +105,7 @@ describe ApplicationController, type: :controller do
end end
end end
context 'ActionController::RoutingError' do context 'with ActionController::RoutingError' do
subject do subject do
routes.draw { get 'routing_error' => 'anonymous#routing_error' } routes.draw { get 'routing_error' => 'anonymous#routing_error' }
get 'routing_error' get 'routing_error'
@ -114,7 +114,7 @@ describe ApplicationController, type: :controller do
include_examples 'respond_with_error', 404 include_examples 'respond_with_error', 404
end end
context 'ActiveRecord::RecordNotFound' do context 'with ActiveRecord::RecordNotFound' do
subject do subject do
routes.draw { get 'record_not_found' => 'anonymous#record_not_found' } routes.draw { get 'record_not_found' => 'anonymous#record_not_found' }
get 'record_not_found' get 'record_not_found'
@ -123,7 +123,7 @@ describe ApplicationController, type: :controller do
include_examples 'respond_with_error', 404 include_examples 'respond_with_error', 404
end end
context 'ActionController::InvalidAuthenticityToken' do context 'with ActionController::InvalidAuthenticityToken' do
subject do subject do
routes.draw { get 'invalid_authenticity_token' => 'anonymous#invalid_authenticity_token' } routes.draw { get 'invalid_authenticity_token' => 'anonymous#invalid_authenticity_token' }
get 'invalid_authenticity_token' get 'invalid_authenticity_token'
@ -252,7 +252,7 @@ describe ApplicationController, type: :controller do
expect(subject.new.cache_collection(raw, Object)).to eq raw expect(subject.new.cache_collection(raw, Object)).to eq raw
end end
context 'Status' do context 'with a Status' do
include_examples 'cacheable', :status, Status include_examples 'cacheable', :status, Status
end end
end end

View File

@ -157,7 +157,7 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end end
end end
context 'approval-based registrations without invite' do context 'with Approval-based registrations without invite' do
subject do subject do
Setting.registrations_mode = 'approved' Setting.registrations_mode = 'approved'
request.headers['Accept-Language'] = accept_language request.headers['Accept-Language'] = accept_language
@ -184,7 +184,7 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end end
end end
context 'approval-based registrations with expired invite' do context 'with Approval-based registrations with expired invite' do
subject do subject do
Setting.registrations_mode = 'approved' Setting.registrations_mode = 'approved'
request.headers['Accept-Language'] = accept_language request.headers['Accept-Language'] = accept_language
@ -212,7 +212,7 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end end
end end
context 'approval-based registrations with valid invite and required invite text' do context 'with Approval-based registrations with valid invite and required invite text' do
subject do subject do
inviter = Fabricate(:user, confirmed_at: 2.days.ago) inviter = Fabricate(:user, confirmed_at: 2.days.ago)
Setting.registrations_mode = 'approved' Setting.registrations_mode = 'approved'

View File

@ -51,8 +51,8 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
describe 'POST #create' do describe 'POST #create' do
context 'using PAM authentication', if: ENV['PAM_ENABLED'] == 'true' do context 'when using PAM authentication', if: ENV['PAM_ENABLED'] == 'true' do
context 'using a valid password' do context 'when using a valid password' do
before do before do
post :create, params: { user: { email: 'pam_user1', password: '123456' } } post :create, params: { user: { email: 'pam_user1', password: '123456' } }
end end
@ -66,7 +66,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using an invalid password' do context 'when using an invalid password' do
before do before do
post :create, params: { user: { email: 'pam_user1', password: 'WRONGPW' } } post :create, params: { user: { email: 'pam_user1', password: 'WRONGPW' } }
end end
@ -80,7 +80,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using a valid email and existing user' do context 'when using a valid email and existing user' do
let!(:user) do let!(:user) do
account = Fabricate.build(:account, username: 'pam_user1', user: nil) account = Fabricate.build(:account, username: 'pam_user1', user: nil)
account.save!(validate: false) account.save!(validate: false)
@ -102,10 +102,10 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using password authentication' do context 'when using password authentication' do
let(:user) { Fabricate(:user, email: 'foo@bar.com', password: 'abcdefgh') } let(:user) { Fabricate(:user, email: 'foo@bar.com', password: 'abcdefgh') }
context 'using a valid password' do context 'when using a valid password' do
before do before do
post :create, params: { user: { email: user.email, password: user.password } } post :create, params: { user: { email: user.email, password: user.password } }
end end
@ -119,7 +119,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using a valid password on a previously-used account with a new IP address' do context 'when using a valid password on a previously-used account with a new IP address' do
let(:previous_ip) { '1.2.3.4' } let(:previous_ip) { '1.2.3.4' }
let(:current_ip) { '4.3.2.1' } let(:current_ip) { '4.3.2.1' }
@ -145,7 +145,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using email with uppercase letters' do context 'when using email with uppercase letters' do
before do before do
post :create, params: { user: { email: user.email.upcase, password: user.password } } post :create, params: { user: { email: user.email.upcase, password: user.password } }
end end
@ -159,7 +159,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using an invalid password' do context 'when using an invalid password' do
before do before do
post :create, params: { user: { email: user.email, password: 'wrongpw' } } post :create, params: { user: { email: user.email, password: 'wrongpw' } }
end end
@ -173,7 +173,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using an unconfirmed password' do context 'when using an unconfirmed password' do
before do before do
request.headers['Accept-Language'] = accept_language request.headers['Accept-Language'] = accept_language
post :create, params: { user: { email: unconfirmed_user.email, password: unconfirmed_user.password } } post :create, params: { user: { email: unconfirmed_user.email, password: unconfirmed_user.password } }
@ -187,14 +187,14 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context "logging in from the user's page" do context "when logging in from the user's page" do
before do before do
allow(controller).to receive(:single_user_mode?).and_return(single_user_mode) allow(controller).to receive(:single_user_mode?).and_return(single_user_mode)
allow(controller).to receive(:stored_location_for).with(:user).and_return("/@#{user.account.username}") allow(controller).to receive(:stored_location_for).with(:user).and_return("/@#{user.account.username}")
post :create, params: { user: { email: user.email, password: user.password } } post :create, params: { user: { email: user.email, password: user.password } }
end end
context 'in single user mode' do context 'with single user mode' do
let(:single_user_mode) { true } let(:single_user_mode) { true }
it 'redirects to home' do it 'redirects to home' do
@ -202,7 +202,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'in non-single user mode' do context 'with non-single user mode' do
let(:single_user_mode) { false } let(:single_user_mode) { false }
it "redirects back to the user's page" do it "redirects back to the user's page" do
@ -212,7 +212,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using two-factor authentication' do context 'when using two-factor authentication' do
context 'with OTP enabled as second factor' do context 'with OTP enabled as second factor' do
let!(:user) do let!(:user) do
Fabricate(:user, email: 'x@y.com', password: 'abcdefgh', otp_required_for_login: true, otp_secret: User.generate_otp_secret(32)) Fabricate(:user, email: 'x@y.com', password: 'abcdefgh', otp_required_for_login: true, otp_secret: User.generate_otp_secret(32))
@ -224,7 +224,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
return codes return codes
end end
context 'using email and password' do context 'when using email and password' do
before do before do
post :create, params: { user: { email: user.email, password: user.password } } post :create, params: { user: { email: user.email, password: user.password } }
end end
@ -235,7 +235,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using email and password after an unfinished log-in attempt to a 2FA-protected account' do context 'when using email and password after an unfinished log-in attempt to a 2FA-protected account' do
let!(:other_user) do let!(:other_user) do
Fabricate(:user, email: 'z@y.com', password: 'abcdefgh', otp_required_for_login: true, otp_secret: User.generate_otp_secret(32)) Fabricate(:user, email: 'z@y.com', password: 'abcdefgh', otp_required_for_login: true, otp_secret: User.generate_otp_secret(32))
end end
@ -251,7 +251,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using upcase email and password' do context 'when using upcase email and password' do
before do before do
post :create, params: { user: { email: user.email.upcase, password: user.password } } post :create, params: { user: { email: user.email.upcase, password: user.password } }
end end
@ -262,7 +262,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using a valid OTP' do context 'when using a valid OTP' do
before do before do
post :create, params: { user: { otp_attempt: user.current_otp } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s } post :create, params: { user: { otp_attempt: user.current_otp } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
end end
@ -291,7 +291,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using a valid recovery code' do context 'when using a valid recovery code' do
before do before do
post :create, params: { user: { otp_attempt: recovery_codes.first } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s } post :create, params: { user: { otp_attempt: recovery_codes.first } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
end end
@ -305,7 +305,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using an invalid OTP' do context 'when using an invalid OTP' do
before do before do
post :create, params: { user: { otp_attempt: 'wrongotp' } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s } post :create, params: { user: { otp_attempt: 'wrongotp' } }, session: { attempt_user_id: user.id, attempt_user_updated_at: user.updated_at.to_s }
end end
@ -353,7 +353,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
let(:fake_credential) { fake_client.get(challenge: challenge, sign_count: sign_count) } let(:fake_credential) { fake_client.get(challenge: challenge, sign_count: sign_count) }
context 'using email and password' do context 'when using email and password' do
before do before do
post :create, params: { user: { email: user.email, password: user.password } } post :create, params: { user: { email: user.email, password: user.password } }
end end
@ -364,7 +364,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using upcase email and password' do context 'when using upcase email and password' do
before do before do
post :create, params: { user: { email: user.email.upcase, password: user.password } } post :create, params: { user: { email: user.email.upcase, password: user.password } }
end end
@ -375,7 +375,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
end end
end end
context 'using a valid webauthn credential' do context 'when using a valid webauthn credential' do
before do before do
@controller.session[:webauthn_challenge] = challenge @controller.session[:webauthn_challenge] = challenge

View File

@ -23,14 +23,14 @@ RSpec.describe CacheConcern, type: :controller do
end end
describe '#cache_collection' do describe '#cache_collection' do
context 'given an empty array' do context 'when given an empty array' do
it 'returns an empty array' do it 'returns an empty array' do
get :empty_array get :empty_array
expect(response.body).to eq '0' expect(response.body).to eq '0'
end end
end end
context 'given an empty relation' do context 'when given an empty relation' do
it 'returns an empty array' do it 'returns an empty array' do
get :empty_relation get :empty_relation
expect(response.body).to eq '0' expect(response.body).to eq '0'

View File

@ -31,7 +31,7 @@ RSpec.describe ChallengableConcern, type: :controller do
sign_in user sign_in user
end end
context 'for GET requests' do context 'with GET requests' do
before { get :foo } before { get :foo }
it 'does not ask for password' do it 'does not ask for password' do
@ -39,7 +39,7 @@ RSpec.describe ChallengableConcern, type: :controller do
end end
end end
context 'for POST requests' do context 'with POST requests' do
before { post :bar } before { post :bar }
it 'does not ask for password' do it 'does not ask for password' do
@ -56,7 +56,7 @@ RSpec.describe ChallengableConcern, type: :controller do
sign_in user sign_in user
end end
context 'for GET requests' do context 'with GET requests' do
before { get :foo, session: { challenge_passed_at: Time.now.utc } } before { get :foo, session: { challenge_passed_at: Time.now.utc } }
it 'does not ask for password' do it 'does not ask for password' do
@ -64,7 +64,7 @@ RSpec.describe ChallengableConcern, type: :controller do
end end
end end
context 'for POST requests' do context 'with POST requests' do
before { post :bar, session: { challenge_passed_at: Time.now.utc } } before { post :bar, session: { challenge_passed_at: Time.now.utc } }
it 'does not ask for password' do it 'does not ask for password' do
@ -81,7 +81,7 @@ RSpec.describe ChallengableConcern, type: :controller do
sign_in user sign_in user
end end
context 'for GET requests' do context 'with GET requests' do
before { get :foo } before { get :foo }
it 'renders challenge' do it 'renders challenge' do
@ -91,7 +91,7 @@ RSpec.describe ChallengableConcern, type: :controller do
# See Auth::ChallengesControllerSpec # See Auth::ChallengesControllerSpec
end end
context 'for POST requests' do context 'with POST requests' do
before { post :bar } before { post :bar }
it 'renders challenge' do it 'renders challenge' do

View File

@ -41,7 +41,7 @@ describe ApplicationController, type: :controller do
end end
end end
context 'user with valid locale has signed in' do context 'with a user with valid locale has signed in' do
it "sets user's locale" do it "sets user's locale" do
user = Fabricate(:user, locale: :ca) user = Fabricate(:user, locale: :ca)
@ -52,7 +52,7 @@ describe ApplicationController, type: :controller do
end end
end end
context 'user with invalid locale has signed in' do context 'with a user with invalid locale has signed in' do
before do before do
user = Fabricate.build(:user, locale: :invalid) user = Fabricate.build(:user, locale: :invalid)
user.save!(validate: false) user.save!(validate: false)
@ -62,7 +62,7 @@ describe ApplicationController, type: :controller do
include_examples 'default locale' include_examples 'default locale'
end end
context 'user has not signed in' do context 'with a user who has not signed in' do
include_examples 'default locale' include_examples 'default locale'
end end
end end

View File

@ -16,7 +16,7 @@ describe ApplicationController do
end end
describe 'rate limiting' do describe 'rate limiting' do
context 'throttling is off' do context 'when throttling is off' do
before do before do
request.env['rack.attack.throttle_data'] = nil request.env['rack.attack.throttle_data'] = nil
end end
@ -30,7 +30,7 @@ describe ApplicationController do
end end
end end
context 'throttling is on' do context 'when throttling is on' do
let(:start_time) { DateTime.new(2017, 1, 1, 12, 0, 0).utc } let(:start_time) { DateTime.new(2017, 1, 1, 12, 0, 0).utc }
before do before do

View File

@ -4,7 +4,7 @@ require 'rails_helper'
RSpec.describe InstanceActorsController, type: :controller do RSpec.describe InstanceActorsController, type: :controller do
describe 'GET #show' do describe 'GET #show' do
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
shared_examples 'shared behavior' do shared_examples 'shared behavior' do

View File

@ -50,7 +50,7 @@ describe Settings::ApplicationsController do
end end
describe 'POST #create' do describe 'POST #create' do
context 'success (passed scopes as a String)' do context 'when success (passed scopes as a String)' do
def call_create def call_create
post :create, params: { post :create, params: {
doorkeeper_application: { doorkeeper_application: {
@ -72,7 +72,7 @@ describe Settings::ApplicationsController do
end end
end end
context 'success (passed scopes as an Array)' do context 'when success (passed scopes as an Array)' do
def call_create def call_create
post :create, params: { post :create, params: {
doorkeeper_application: { doorkeeper_application: {
@ -94,7 +94,7 @@ describe Settings::ApplicationsController do
end end
end end
context 'failure' do context 'with failure request' do
before do before do
post :create, params: { post :create, params: {
doorkeeper_application: { doorkeeper_application: {
@ -117,7 +117,7 @@ describe Settings::ApplicationsController do
end end
describe 'PATCH #update' do describe 'PATCH #update' do
context 'success' do context 'when success' do
let(:opts) do let(:opts) do
{ {
website: 'https://foo.bar/', website: 'https://foo.bar/',
@ -142,7 +142,7 @@ describe Settings::ApplicationsController do
end end
end end
context 'failure' do context 'with failure request' do
before do before do
patch :update, params: { patch :update, params: {
id: app.id, id: app.id,

View File

@ -275,7 +275,7 @@ describe Settings::TwoFactorAuthentication::WebauthnCredentialsController do
end end
context 'when user have not enabled webauthn' do context 'when user have not enabled webauthn' do
context 'creation succeeds' do context 'when creation succeeds' do
it 'creates a webauthn credential' do it 'creates a webauthn credential' do
@controller.session[:webauthn_challenge] = challenge @controller.session[:webauthn_challenge] = challenge

View File

@ -72,7 +72,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http success' do it 'returns http success' do
@ -97,7 +97,7 @@ describe StatusesController do
end end
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http success' do it 'returns http success' do
@ -132,7 +132,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http not found' do it 'returns http not found' do
@ -140,7 +140,7 @@ describe StatusesController do
end end
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http not found' do it 'returns http not found' do
@ -156,7 +156,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http not found' do it 'returns http not found' do
@ -164,7 +164,7 @@ describe StatusesController do
end end
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http not found' do it 'returns http not found' do
@ -196,7 +196,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http success' do it 'returns http success' do
@ -221,7 +221,7 @@ describe StatusesController do
end end
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http success' do it 'returns http success' do
@ -260,7 +260,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http success' do it 'returns http success' do
@ -285,7 +285,7 @@ describe StatusesController do
end end
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http success' do it 'returns http success' do
@ -320,7 +320,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http not found' do it 'returns http not found' do
@ -328,7 +328,7 @@ describe StatusesController do
end end
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http not found' do it 'returns http not found' do
@ -347,7 +347,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http success' do it 'returns http success' do
@ -372,7 +372,7 @@ describe StatusesController do
end end
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http success' do it 'returns http success' do
@ -407,7 +407,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http not found' do it 'returns http not found' do
@ -415,7 +415,7 @@ describe StatusesController do
end end
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http not found' do it 'returns http not found' do
@ -460,7 +460,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http success' do it 'returns http success' do
@ -485,7 +485,7 @@ describe StatusesController do
end end
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http success' do it 'returns http success' do
@ -522,7 +522,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http success' do it 'returns http success' do
@ -547,7 +547,7 @@ describe StatusesController do
end end
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http success' do it 'returns http success' do
@ -582,7 +582,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http not found' do it 'returns http not found' do
@ -590,7 +590,7 @@ describe StatusesController do
end end
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http not found' do it 'returns http not found' do
@ -609,7 +609,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http success' do it 'returns http success' do
@ -634,7 +634,7 @@ describe StatusesController do
end end
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http success' do it 'returns http success' do
@ -669,7 +669,7 @@ describe StatusesController do
get :show, params: { account_username: status.account.username, id: status.id, format: format } get :show, params: { account_username: status.account.username, id: status.id, format: format }
end end
context 'as JSON' do context 'with JSON' do
let(:format) { 'json' } let(:format) { 'json' }
it 'returns http not found' do it 'returns http not found' do
@ -677,7 +677,7 @@ describe StatusesController do
end end
end end
context 'as HTML' do context 'with HTML' do
let(:format) { 'html' } let(:format) { 'html' }
it 'returns http not found' do it 'returns http not found' do

View File

@ -6,7 +6,7 @@ RSpec.describe Admin::AccountModerationNotesHelper, type: :helper do
include AccountsHelper include AccountsHelper
describe '#admin_account_link_to' do describe '#admin_account_link_to' do
context 'account is nil' do context 'when Account is nil' do
let(:account) { nil } let(:account) { nil }
it 'returns nil' do it 'returns nil' do
@ -30,7 +30,7 @@ RSpec.describe Admin::AccountModerationNotesHelper, type: :helper do
end end
describe '#admin_account_inline_link_to' do describe '#admin_account_inline_link_to' do
context 'account is nil' do context 'when Account is nil' do
let(:account) { nil } let(:account) { nil }
it 'returns nil' do it 'returns nil' do

View File

@ -22,14 +22,14 @@ describe JsonLdHelper do
end end
describe '#first_of_value' do describe '#first_of_value' do
context 'value.is_a?(Array)' do context 'when value.is_a?(Array)' do
it 'returns value.first' do it 'returns value.first' do
value = ['a'] value = ['a']
expect(helper.first_of_value(value)).to be 'a' expect(helper.first_of_value(value)).to be 'a'
end end
end end
context '!value.is_a?(Array)' do context 'with !value.is_a?(Array)' do
it 'returns value' do it 'returns value' do
value = 'a' value = 'a'
expect(helper.first_of_value(value)).to be 'a' expect(helper.first_of_value(value)).to be 'a'
@ -38,14 +38,14 @@ describe JsonLdHelper do
end end
describe '#supported_context?' do describe '#supported_context?' do
context "!json.nil? && equals_or_includes?(json['@context'], ActivityPub::TagManager::CONTEXT)" do context 'when json is present and in an activitypub tagmanager context' do
it 'returns true' do it 'returns true' do
json = { '@context' => ActivityPub::TagManager::CONTEXT }.as_json json = { '@context' => ActivityPub::TagManager::CONTEXT }.as_json
expect(helper.supported_context?(json)).to be true expect(helper.supported_context?(json)).to be true
end end
end end
context 'else' do context 'when not in activitypub tagmanager context' do
it 'returns false' do it 'returns false' do
json = nil json = nil
expect(helper.supported_context?(json)).to be false expect(helper.supported_context?(json)).to be false
@ -90,7 +90,7 @@ describe JsonLdHelper do
end end
end end
context 'compaction and forwarding' do context 'with compaction and forwarding' do
let(:json) do let(:json) do
{ {
'@context' => [ '@context' => [

View File

@ -24,7 +24,7 @@ RSpec.describe RoutingHelper, type: :helper do
end end
end end
context 'Do not use S3' do context 'when not using S3' do
before do before do
Rails.configuration.x.use_s3 = false Rails.configuration.x.use_s3 = false
end end
@ -32,7 +32,7 @@ RSpec.describe RoutingHelper, type: :helper do
it_behaves_like 'returns full path URL' it_behaves_like 'returns full path URL'
end end
context 'Use S3' do context 'when using S3' do
before do before do
Rails.configuration.x.use_s3 = true Rails.configuration.x.use_s3 = true
end end

View File

@ -43,7 +43,7 @@ RSpec.describe ActivityPub::Activity::Accept do
end end
end end
context 'given a relay' do context 'when given a relay' do
subject { described_class.new(json, sender) } subject { described_class.new(json, sender) }
let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') } let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') }

View File

@ -39,7 +39,7 @@ RSpec.describe ActivityPub::Activity::Announce do
subject.perform subject.perform
end end
context 'a known status' do context 'with known status' do
let(:object_json) do let(:object_json) do
ActivityPub::TagManager.instance.uri_for(status) ActivityPub::TagManager.instance.uri_for(status)
end end
@ -49,7 +49,7 @@ RSpec.describe ActivityPub::Activity::Announce do
end end
end end
context 'an unknown status' do context 'with unknown status' do
let(:object_json) { 'https://example.com/actor/hello-world' } let(:object_json) { 'https://example.com/actor/hello-world' }
it 'creates a reblog by sender of status' do it 'creates a reblog by sender of status' do
@ -60,7 +60,7 @@ RSpec.describe ActivityPub::Activity::Announce do
end end
end end
context 'self-boost of a previously unknown status with correct attributedTo' do context 'when self-boost of a previously unknown status with correct attributedTo' do
let(:object_json) do let(:object_json) do
{ {
id: 'https://example.com/actor#bar', id: 'https://example.com/actor#bar',
@ -76,7 +76,7 @@ RSpec.describe ActivityPub::Activity::Announce do
end end
end end
context 'self-boost of a previously unknown status with correct attributedTo, inlined Collection in audience' do context 'when self-boost of a previously unknown status with correct attributedTo, inlined Collection in audience' do
let(:object_json) do let(:object_json) do
{ {
id: 'https://example.com/actor#bar', id: 'https://example.com/actor#bar',
@ -123,7 +123,7 @@ RSpec.describe ActivityPub::Activity::Announce do
stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json)) stub_request(:get, 'https://example.com/actor/hello-world').to_return(body: Oj.dump(unknown_object_json))
end end
context 'and the relay is enabled' do context 'when the relay is enabled' do
before do before do
relay.update(state: :accepted) relay.update(state: :accepted)
subject.perform subject.perform
@ -135,7 +135,7 @@ RSpec.describe ActivityPub::Activity::Announce do
end end
end end
context 'and the relay is disabled' do context 'when the relay is disabled' do
before do before do
subject.perform subject.perform
end end

View File

@ -31,7 +31,7 @@ RSpec.describe ActivityPub::Activity::Create do
subject.perform subject.perform
end end
context 'object has been edited' do context 'when object has been edited' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -57,7 +57,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'object has update date equal to creation date' do context 'when object has update date equal to creation date' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -83,7 +83,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'unknown object type' do context 'with an unknown object type' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -97,7 +97,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'standalone' do context 'with a standalone' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -121,7 +121,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'public with explicit public address' do context 'when public with explicit public address' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -139,7 +139,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'public with as:Public' do context 'when public with as:Public' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -157,7 +157,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'public with Public' do context 'when public with Public' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -175,7 +175,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'unlisted with explicit public address' do context 'when unlisted with explicit public address' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -193,7 +193,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'unlisted with as:Public' do context 'when unlisted with as:Public' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -211,7 +211,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'unlisted with Public' do context 'when unlisted with Public' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -229,7 +229,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'private' do context 'when private' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -247,7 +247,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'private with inlined Collection in audience' do context 'when private with inlined Collection in audience' do
let(:object_json) do let(:object_json) do
{ {
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join, id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
@ -269,7 +269,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'limited' do context 'when limited' do
let(:recipient) { Fabricate(:account) } let(:recipient) { Fabricate(:account) }
let(:object_json) do let(:object_json) do
@ -294,7 +294,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'direct' do context 'when direct' do
let(:recipient) { Fabricate(:account) } let(:recipient) { Fabricate(:account) }
let(:object_json) do let(:object_json) do
@ -318,7 +318,7 @@ RSpec.describe ActivityPub::Activity::Create do
end end
end end
context 'as a reply' do context 'with a reply' do
let(:original_status) { Fabricate(:status) } let(:original_status) { Fabricate(:status) }
let(:object_json) do let(:object_json) do

View File

@ -20,7 +20,7 @@ RSpec.describe ActivityPub::Activity::Follow do
subject { described_class.new(json, sender) } subject { described_class.new(json, sender) }
context 'with no prior follow' do context 'with no prior follow' do
context 'unlocked account' do context 'with an unlocked account' do
before do before do
subject.perform subject.perform
end end
@ -35,7 +35,7 @@ RSpec.describe ActivityPub::Activity::Follow do
end end
end end
context 'silenced account following an unlocked account' do context 'when silenced account following an unlocked account' do
before do before do
sender.touch(:silenced_at) sender.touch(:silenced_at)
subject.perform subject.perform
@ -51,7 +51,7 @@ RSpec.describe ActivityPub::Activity::Follow do
end end
end end
context 'unlocked account muting the sender' do context 'with an unlocked account muting the sender' do
before do before do
recipient.mute!(sender) recipient.mute!(sender)
subject.perform subject.perform
@ -67,7 +67,7 @@ RSpec.describe ActivityPub::Activity::Follow do
end end
end end
context 'locked account' do context 'when locked account' do
before do before do
recipient.update(locked: true) recipient.update(locked: true)
subject.perform subject.perform
@ -89,7 +89,7 @@ RSpec.describe ActivityPub::Activity::Follow do
sender.active_relationships.create!(target_account: recipient, uri: 'bar') sender.active_relationships.create!(target_account: recipient, uri: 'bar')
end end
context 'unlocked account' do context 'with an unlocked account' do
before do before do
subject.perform subject.perform
end end
@ -103,7 +103,7 @@ RSpec.describe ActivityPub::Activity::Follow do
end end
end end
context 'silenced account following an unlocked account' do context 'when silenced account following an unlocked account' do
before do before do
sender.touch(:silenced_at) sender.touch(:silenced_at)
subject.perform subject.perform
@ -118,7 +118,7 @@ RSpec.describe ActivityPub::Activity::Follow do
end end
end end
context 'unlocked account muting the sender' do context 'with an unlocked account muting the sender' do
before do before do
recipient.mute!(sender) recipient.mute!(sender)
subject.perform subject.perform
@ -133,7 +133,7 @@ RSpec.describe ActivityPub::Activity::Follow do
end end
end end
context 'locked account' do context 'when locked account' do
before do before do
recipient.update(locked: true) recipient.update(locked: true)
subject.perform subject.perform
@ -154,7 +154,7 @@ RSpec.describe ActivityPub::Activity::Follow do
sender.follow_requests.create!(target_account: recipient, uri: 'bar') sender.follow_requests.create!(target_account: recipient, uri: 'bar')
end end
context 'silenced account following an unlocked account' do context 'when silenced account following an unlocked account' do
before do before do
sender.touch(:silenced_at) sender.touch(:silenced_at)
subject.perform subject.perform
@ -170,7 +170,7 @@ RSpec.describe ActivityPub::Activity::Follow do
end end
end end
context 'locked account' do context 'when locked account' do
before do before do
recipient.update(locked: true) recipient.update(locked: true)
subject.perform subject.perform

View File

@ -27,7 +27,7 @@ RSpec.describe ActivityPub::Activity::Reject do
describe '#perform' do describe '#perform' do
subject { described_class.new(json, sender) } subject { described_class.new(json, sender) }
context 'rejecting a pending follow request by target' do context 'when rejecting a pending follow request by target' do
before do before do
Fabricate(:follow_request, account: recipient, target_account: sender) Fabricate(:follow_request, account: recipient, target_account: sender)
subject.perform subject.perform
@ -42,7 +42,7 @@ RSpec.describe ActivityPub::Activity::Reject do
end end
end end
context 'rejecting a pending follow request by uri' do context 'when rejecting a pending follow request by uri' do
before do before do
Fabricate(:follow_request, account: recipient, target_account: sender, uri: 'bar') Fabricate(:follow_request, account: recipient, target_account: sender, uri: 'bar')
subject.perform subject.perform
@ -57,7 +57,7 @@ RSpec.describe ActivityPub::Activity::Reject do
end end
end end
context 'rejecting a pending follow request by uri only' do context 'when rejecting a pending follow request by uri only' do
let(:object_json) { 'bar' } let(:object_json) { 'bar' }
before do before do
@ -74,7 +74,7 @@ RSpec.describe ActivityPub::Activity::Reject do
end end
end end
context 'rejecting an existing follow relationship by target' do context 'when rejecting an existing follow relationship by target' do
before do before do
Fabricate(:follow, account: recipient, target_account: sender) Fabricate(:follow, account: recipient, target_account: sender)
subject.perform subject.perform
@ -89,7 +89,7 @@ RSpec.describe ActivityPub::Activity::Reject do
end end
end end
context 'rejecting an existing follow relationship by uri' do context 'when rejecting an existing follow relationship by uri' do
before do before do
Fabricate(:follow, account: recipient, target_account: sender, uri: 'bar') Fabricate(:follow, account: recipient, target_account: sender, uri: 'bar')
subject.perform subject.perform
@ -104,7 +104,7 @@ RSpec.describe ActivityPub::Activity::Reject do
end end
end end
context 'rejecting an existing follow relationship by uri only' do context 'when rejecting an existing follow relationship by uri only' do
let(:object_json) { 'bar' } let(:object_json) { 'bar' }
before do before do
@ -122,7 +122,7 @@ RSpec.describe ActivityPub::Activity::Reject do
end end
end end
context 'given a relay' do context 'when given a relay' do
subject { described_class.new(json, sender) } subject { described_class.new(json, sender) }
let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') } let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') }

View File

@ -14,7 +14,7 @@ RSpec.describe EmojiFormatter do
let(:emojis) { [emoji] } let(:emojis) { [emoji] }
context 'given text that is not marked as html-safe' do context 'when given text that is not marked as html-safe' do
let(:text) { 'Foo' } let(:text) { 'Foo' }
it 'raises an argument error' do it 'raises an argument error' do
@ -22,7 +22,7 @@ RSpec.describe EmojiFormatter do
end end
end end
context 'given text with an emoji shortcode at the start' do context 'when given text with an emoji shortcode at the start' do
let(:text) { preformat_text(':coolcat: Beep boop') } let(:text) { preformat_text(':coolcat: Beep boop') }
it 'converts the shortcode to an image tag' do it 'converts the shortcode to an image tag' do
@ -30,7 +30,7 @@ RSpec.describe EmojiFormatter do
end end
end end
context 'given text with an emoji shortcode in the middle' do context 'when given text with an emoji shortcode in the middle' do
let(:text) { preformat_text('Beep :coolcat: boop') } let(:text) { preformat_text('Beep :coolcat: boop') }
it 'converts the shortcode to an image tag' do it 'converts the shortcode to an image tag' do
@ -38,7 +38,7 @@ RSpec.describe EmojiFormatter do
end end
end end
context 'given text with concatenated emoji shortcodes' do context 'when given text with concatenated emoji shortcodes' do
let(:text) { preformat_text(':coolcat::coolcat:') } let(:text) { preformat_text(':coolcat::coolcat:') }
it 'does not touch the shortcodes' do it 'does not touch the shortcodes' do
@ -46,7 +46,7 @@ RSpec.describe EmojiFormatter do
end end
end end
context 'given text with an emoji shortcode at the end' do context 'when given text with an emoji shortcode at the end' do
let(:text) { preformat_text('Beep boop :coolcat:') } let(:text) { preformat_text('Beep boop :coolcat:') }
it 'converts the shortcode to an image tag' do it 'converts the shortcode to an image tag' do

View File

@ -9,7 +9,7 @@ RSpec.describe EntityCache do
describe '#emoji' do describe '#emoji' do
subject { EntityCache.instance.emoji(shortcodes, domain) } subject { EntityCache.instance.emoji(shortcodes, domain) }
context 'called with an empty list of shortcodes' do context 'when called with an empty list of shortcodes' do
let(:shortcodes) { [] } let(:shortcodes) { [] }
let(:domain) { 'example.org' } let(:domain) { 'example.org' }

View File

@ -27,7 +27,7 @@ RSpec.describe FeedManager do
let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') } let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
let(:jeff) { Fabricate(:account, username: 'jeff') } let(:jeff) { Fabricate(:account, username: 'jeff') }
context 'for home feed' do context 'with home feed' do
it 'returns false for followee\'s status' do it 'returns false for followee\'s status' do
status = Fabricate(:status, text: 'Hello world', account: alice) status = Fabricate(:status, text: 'Hello world', account: alice)
bob.follow!(alice) bob.follow!(alice)
@ -155,7 +155,7 @@ RSpec.describe FeedManager do
end end
end end
context 'for mentions feed' do context 'with mentions feed' do
it 'returns true for status that mentions blocked account' do it 'returns true for status that mentions blocked account' do
bob.block!(jeff) bob.block!(jeff)
status = PostStatusService.new.call(alice, text: 'Hey @jeff') status = PostStatusService.new.call(alice, text: 'Hey @jeff')
@ -196,7 +196,7 @@ RSpec.describe FeedManager do
expect(redis.zcard("feed:home:#{account.id}")).to eq FeedManager::MAX_ITEMS expect(redis.zcard("feed:home:#{account.id}")).to eq FeedManager::MAX_ITEMS
end end
context 'reblogs' do context 'with reblogs' do
it 'saves reblogs of unseen statuses' do it 'saves reblogs of unseen statuses' do
account = Fabricate(:account) account = Fabricate(:account)
reblogged = Fabricate(:status) reblogged = Fabricate(:status)

View File

@ -18,7 +18,7 @@ RSpec.describe HtmlAwareFormatter do
context 'when remote' do context 'when remote' do
let(:local) { false } let(:local) { false }
context 'given plain text' do context 'when given plain text' do
let(:text) { 'Beep boop' } let(:text) { 'Beep boop' }
it 'keeps the plain text' do it 'keeps the plain text' do
@ -26,7 +26,7 @@ RSpec.describe HtmlAwareFormatter do
end end
end end
context 'given text containing script tags' do context 'when given text containing script tags' do
let(:text) { '<script>alert("Hello")</script>' } let(:text) { '<script>alert("Hello")</script>' }
it 'strips the scripts' do it 'strips the scripts' do
@ -34,7 +34,7 @@ RSpec.describe HtmlAwareFormatter do
end end
end end
context 'given text containing malicious classes' do context 'when given text containing malicious classes' do
let(:text) { '<span class="mention status__content__spoiler-link">Show more</span>' } let(:text) { '<span class="mention status__content__spoiler-link">Show more</span>' }
it 'strips the malicious classes' do it 'strips the malicious classes' do

View File

@ -40,7 +40,7 @@ RSpec.describe LinkDetailsExtractor do
context 'when structured data is present' do context 'when structured data is present' do
let(:original_url) { 'https://example.com/page.html' } let(:original_url) { 'https://example.com/page.html' }
context 'and is wrapped in CDATA tags' do context 'when is wrapped in CDATA tags' do
let(:html) { <<~HTML } let(:html) { <<~HTML }
<!doctype html> <!doctype html>
<html> <html>
@ -79,7 +79,7 @@ RSpec.describe LinkDetailsExtractor do
end end
end end
context 'but the first tag is invalid JSON' do context 'with the first tag is invalid JSON' do
let(:html) { <<~HTML } let(:html) { <<~HTML }
<!doctype html> <!doctype html>
<html> <html>

View File

@ -40,7 +40,7 @@ describe OStatus::TagManager do
describe '#uri_for' do describe '#uri_for' do
subject { OStatus::TagManager.instance.uri_for(target) } subject { OStatus::TagManager.instance.uri_for(target) }
context 'comment object' do context 'with comment object' do
let(:target) { Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reply: true) } let(:target) { Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reply: true) }
it 'returns the unique tag for status' do it 'returns the unique tag for status' do
@ -49,7 +49,7 @@ describe OStatus::TagManager do
end end
end end
context 'note object' do context 'with note object' do
let(:target) { Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reply: false, thread: nil) } let(:target) { Fabricate(:status, created_at: '2000-01-01T00:00:00Z', reply: false, thread: nil) }
it 'returns the unique tag for status' do it 'returns the unique tag for status' do
@ -58,7 +58,7 @@ describe OStatus::TagManager do
end end
end end
context 'person object' do context 'when person object' do
let(:target) { Fabricate(:account, username: 'alice') } let(:target) { Fabricate(:account, username: 'alice') }
it 'returns the URL for account' do it 'returns the URL for account' do

View File

@ -20,67 +20,67 @@ describe ScopeTransformer do
end end
end end
context 'for scope "read"' do context 'with scope "read"' do
let(:input) { 'read' } let(:input) { 'read' }
it_behaves_like 'a scope', nil, 'all', 'read' it_behaves_like 'a scope', nil, 'all', 'read'
end end
context 'for scope "write"' do context 'with scope "write"' do
let(:input) { 'write' } let(:input) { 'write' }
it_behaves_like 'a scope', nil, 'all', 'write' it_behaves_like 'a scope', nil, 'all', 'write'
end end
context 'for scope "follow"' do context 'with scope "follow"' do
let(:input) { 'follow' } let(:input) { 'follow' }
it_behaves_like 'a scope', nil, 'follow', 'read/write' it_behaves_like 'a scope', nil, 'follow', 'read/write'
end end
context 'for scope "crypto"' do context 'with scope "crypto"' do
let(:input) { 'crypto' } let(:input) { 'crypto' }
it_behaves_like 'a scope', nil, 'crypto', 'read/write' it_behaves_like 'a scope', nil, 'crypto', 'read/write'
end end
context 'for scope "push"' do context 'with scope "push"' do
let(:input) { 'push' } let(:input) { 'push' }
it_behaves_like 'a scope', nil, 'push', 'read/write' it_behaves_like 'a scope', nil, 'push', 'read/write'
end end
context 'for scope "admin:read"' do context 'with scope "admin:read"' do
let(:input) { 'admin:read' } let(:input) { 'admin:read' }
it_behaves_like 'a scope', 'admin', 'all', 'read' it_behaves_like 'a scope', 'admin', 'all', 'read'
end end
context 'for scope "admin:write"' do context 'with scope "admin:write"' do
let(:input) { 'admin:write' } let(:input) { 'admin:write' }
it_behaves_like 'a scope', 'admin', 'all', 'write' it_behaves_like 'a scope', 'admin', 'all', 'write'
end end
context 'for scope "admin:read:accounts"' do context 'with scope "admin:read:accounts"' do
let(:input) { 'admin:read:accounts' } let(:input) { 'admin:read:accounts' }
it_behaves_like 'a scope', 'admin', 'accounts', 'read' it_behaves_like 'a scope', 'admin', 'accounts', 'read'
end end
context 'for scope "admin:write:accounts"' do context 'with scope "admin:write:accounts"' do
let(:input) { 'admin:write:accounts' } let(:input) { 'admin:write:accounts' }
it_behaves_like 'a scope', 'admin', 'accounts', 'write' it_behaves_like 'a scope', 'admin', 'accounts', 'write'
end end
context 'for scope "read:accounts"' do context 'with scope "read:accounts"' do
let(:input) { 'read:accounts' } let(:input) { 'read:accounts' }
it_behaves_like 'a scope', nil, 'accounts', 'read' it_behaves_like 'a scope', nil, 'accounts', 'read'
end end
context 'for scope "write:accounts"' do context 'with scope "write:accounts"' do
let(:input) { 'write:accounts' } let(:input) { 'write:accounts' }
it_behaves_like 'a scope', nil, 'accounts', 'write' it_behaves_like 'a scope', nil, 'accounts', 'write'

View File

@ -44,7 +44,7 @@ describe StatusCacheHydrator do
let(:reblog) { Fabricate(:status) } let(:reblog) { Fabricate(:status) }
let(:status) { Fabricate(:status, reblog: reblog) } let(:status) { Fabricate(:status, reblog: reblog) }
context 'that has been favourited' do context 'when it has been favourited' do
before do before do
FavouriteService.new.call(account, reblog) FavouriteService.new.call(account, reblog)
end end
@ -54,7 +54,7 @@ describe StatusCacheHydrator do
end end
end end
context 'that has been reblogged' do context 'when it has been reblogged' do
before do before do
ReblogService.new.call(account, reblog) ReblogService.new.call(account, reblog)
end end
@ -64,7 +64,7 @@ describe StatusCacheHydrator do
end end
end end
context 'that has been pinned' do context 'when it has been pinned' do
let(:reblog) { Fabricate(:status, account: account) } let(:reblog) { Fabricate(:status, account: account) }
before do before do
@ -76,7 +76,7 @@ describe StatusCacheHydrator do
end end
end end
context 'that has been followed tags' do context 'when it has been followed tags' do
let(:followed_tag) { Fabricate(:tag) } let(:followed_tag) { Fabricate(:tag) }
before do before do
@ -90,7 +90,7 @@ describe StatusCacheHydrator do
end end
end end
context 'that has a poll authored by the user' do context 'when it has a poll authored by the user' do
let(:poll) { Fabricate(:poll, account: account) } let(:poll) { Fabricate(:poll, account: account) }
let(:reblog) { Fabricate(:status, poll: poll, account: account) } let(:reblog) { Fabricate(:status, poll: poll, account: account) }
@ -99,7 +99,7 @@ describe StatusCacheHydrator do
end end
end end
context 'that has been voted in' do context 'when it has been voted in' do
let(:poll) { Fabricate(:poll, options: %w(Yellow Blue)) } let(:poll) { Fabricate(:poll, options: %w(Yellow Blue)) }
let(:reblog) { Fabricate(:status, poll: poll) } let(:reblog) { Fabricate(:status, poll: poll) }
@ -112,7 +112,7 @@ describe StatusCacheHydrator do
end end
end end
context 'that matches account filters' do context 'when it matches account filters' do
let(:reblog) { Fabricate(:status, text: 'this toot is about that banned word') } let(:reblog) { Fabricate(:status, text: 'this toot is about that banned word') }
before do before do

View File

@ -4,7 +4,7 @@ require 'rails_helper'
describe StatusReachFinder do describe StatusReachFinder do
describe '#inboxes' do describe '#inboxes' do
context 'for a local status' do context 'with a local status' do
subject { described_class.new(status) } subject { described_class.new(status) }
let(:parent_status) { nil } let(:parent_status) { nil }

View File

@ -8,7 +8,7 @@ RSpec.describe TextFormatter do
let(:preloaded_accounts) { nil } let(:preloaded_accounts) { nil }
context 'given text containing plain text' do context 'when given text containing plain text' do
let(:text) { 'text' } let(:text) { 'text' }
it 'paragraphizes the text' do it 'paragraphizes the text' do
@ -16,7 +16,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text containing line feeds' do context 'when given text containing line feeds' do
let(:text) { "line\nfeed" } let(:text) { "line\nfeed" }
it 'removes line feeds' do it 'removes line feeds' do
@ -24,7 +24,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text containing linkable mentions' do context 'when given text containing linkable mentions' do
let(:preloaded_accounts) { [Fabricate(:account, username: 'alice')] } let(:preloaded_accounts) { [Fabricate(:account, username: 'alice')] }
let(:text) { '@alice' } let(:text) { '@alice' }
@ -33,7 +33,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text containing unlinkable mentions' do context 'when given text containing unlinkable mentions' do
let(:preloaded_accounts) { [] } let(:preloaded_accounts) { [] }
let(:text) { '@alice' } let(:text) { '@alice' }
@ -42,7 +42,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a stand-alone medium URL' do context 'when given a stand-alone medium URL' do
let(:text) { 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4' } let(:text) { 'https://hackernoon.com/the-power-to-build-communities-a-response-to-mark-zuckerberg-3f2cac9148a4' }
it 'matches the full URL' do it 'matches the full URL' do
@ -50,7 +50,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a stand-alone google URL' do context 'when given a stand-alone google URL' do
let(:text) { 'http://google.com' } let(:text) { 'http://google.com' }
it 'matches the full URL' do it 'matches the full URL' do
@ -58,7 +58,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a stand-alone URL with a newer TLD' do context 'when given a stand-alone URL with a newer TLD' do
let(:text) { 'http://example.gay' } let(:text) { 'http://example.gay' }
it 'matches the full URL' do it 'matches the full URL' do
@ -66,7 +66,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a stand-alone IDN URL' do context 'when given a stand-alone IDN URL' do
let(:text) { 'https://nic.みんな/' } let(:text) { 'https://nic.みんな/' }
it 'matches the full URL' do it 'matches the full URL' do
@ -78,7 +78,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with a trailing period' do context 'when given a URL with a trailing period' do
let(:text) { 'http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona. ' } let(:text) { 'http://www.mcmansionhell.com/post/156408871451/50-states-of-mcmansion-hell-scottsdale-arizona. ' }
it 'matches the full URL but not the period' do it 'matches the full URL but not the period' do
@ -86,7 +86,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL enclosed with parentheses' do context 'when given a URL enclosed with parentheses' do
let(:text) { '(http://google.com/)' } let(:text) { '(http://google.com/)' }
it 'matches the full URL but not the parentheses' do it 'matches the full URL but not the parentheses' do
@ -94,7 +94,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with a trailing exclamation point' do context 'when given a URL with a trailing exclamation point' do
let(:text) { 'http://www.google.com!' } let(:text) { 'http://www.google.com!' }
it 'matches the full URL but not the exclamation point' do it 'matches the full URL but not the exclamation point' do
@ -102,7 +102,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with a trailing single quote' do context 'when given a URL with a trailing single quote' do
let(:text) { "http://www.google.com'" } let(:text) { "http://www.google.com'" }
it 'matches the full URL but not the single quote' do it 'matches the full URL but not the single quote' do
@ -110,7 +110,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with a trailing angle bracket' do context 'when given a URL with a trailing angle bracket' do
let(:text) { 'http://www.google.com>' } let(:text) { 'http://www.google.com>' }
it 'matches the full URL but not the angle bracket' do it 'matches the full URL but not the angle bracket' do
@ -118,7 +118,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with a query string' do context 'when given a URL with a query string' do
context 'with escaped unicode character' do context 'with escaped unicode character' do
let(:text) { 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink' } let(:text) { 'https://www.ruby-toolbox.com/search?utf8=%E2%9C%93&q=autolink' }
@ -152,7 +152,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with parentheses in it' do context 'when given a URL with parentheses in it' do
let(:text) { 'https://en.wikipedia.org/wiki/Diaspora_(software)' } let(:text) { 'https://en.wikipedia.org/wiki/Diaspora_(software)' }
it 'matches the full URL' do it 'matches the full URL' do
@ -160,7 +160,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL in quotation marks' do context 'when given a URL in quotation marks' do
let(:text) { '"https://example.com/"' } let(:text) { '"https://example.com/"' }
it 'does not match the quotation marks' do it 'does not match the quotation marks' do
@ -168,7 +168,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL in angle brackets' do context 'when given a URL in angle brackets' do
let(:text) { '<https://example.com/>' } let(:text) { '<https://example.com/>' }
it 'does not match the angle brackets' do it 'does not match the angle brackets' do
@ -176,7 +176,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with Japanese path string' do context 'when given a URL with Japanese path string' do
let(:text) { 'https://ja.wikipedia.org/wiki/日本' } let(:text) { 'https://ja.wikipedia.org/wiki/日本' }
it 'matches the full URL' do it 'matches the full URL' do
@ -184,7 +184,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with Korean path string' do context 'when given a URL with Korean path string' do
let(:text) { 'https://ko.wikipedia.org/wiki/대한민국' } let(:text) { 'https://ko.wikipedia.org/wiki/대한민국' }
it 'matches the full URL' do it 'matches the full URL' do
@ -192,7 +192,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with a full-width space' do context 'when given a URL with a full-width space' do
let(:text) { 'https://example.com/ abc123' } let(:text) { 'https://example.com/ abc123' }
it 'does not match the full-width space' do it 'does not match the full-width space' do
@ -200,7 +200,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL in Japanese quotation marks' do context 'when given a URL in Japanese quotation marks' do
let(:text) { '「[https://example.org/」' } let(:text) { '「[https://example.org/」' }
it 'does not match the quotation marks' do it 'does not match the quotation marks' do
@ -208,7 +208,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with Simplified Chinese path string' do context 'when given a URL with Simplified Chinese path string' do
let(:text) { 'https://baike.baidu.com/item/中华人民共和国' } let(:text) { 'https://baike.baidu.com/item/中华人民共和国' }
it 'matches the full URL' do it 'matches the full URL' do
@ -216,7 +216,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL with Traditional Chinese path string' do context 'when given a URL with Traditional Chinese path string' do
let(:text) { 'https://zh.wikipedia.org/wiki/臺灣' } let(:text) { 'https://zh.wikipedia.org/wiki/臺灣' }
it 'matches the full URL' do it 'matches the full URL' do
@ -224,7 +224,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL containing unsafe code (XSS attack, visible part)' do context 'when given a URL containing unsafe code (XSS attack, visible part)' do
let(:text) { 'http://example.com/b<del>b</del>' } let(:text) { 'http://example.com/b<del>b</del>' }
it 'does not include the HTML in the URL' do it 'does not include the HTML in the URL' do
@ -236,7 +236,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given a URL containing unsafe code (XSS attack, invisible part)' do context 'when given a URL containing unsafe code (XSS attack, invisible part)' do
let(:text) { 'http://example.com/blahblahblahblah/a<script>alert("Hello")</script>' } let(:text) { 'http://example.com/blahblahblahblah/a<script>alert("Hello")</script>' }
it 'does not include the HTML in the URL' do it 'does not include the HTML in the URL' do
@ -248,7 +248,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text containing HTML code (script tag)' do context 'when given text containing HTML code (script tag)' do
let(:text) { '<script>alert("Hello")</script>' } let(:text) { '<script>alert("Hello")</script>' }
it 'escapes the HTML' do it 'escapes the HTML' do
@ -256,7 +256,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text containing HTML (XSS attack)' do context 'when given text containing HTML (XSS attack)' do
let(:text) { %q{<img src="javascript:alert('XSS');">} } let(:text) { %q{<img src="javascript:alert('XSS');">} }
it 'escapes the HTML' do it 'escapes the HTML' do
@ -264,7 +264,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given an invalid URL' do context 'when given an invalid URL' do
let(:text) { 'http://www\.google\.com' } let(:text) { 'http://www\.google\.com' }
it 'outputs the raw URL' do it 'outputs the raw URL' do
@ -272,7 +272,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text containing a hashtag' do context 'when given text containing a hashtag' do
let(:text) { '#hashtag' } let(:text) { '#hashtag' }
it 'creates a hashtag link' do it 'creates a hashtag link' do
@ -280,7 +280,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text containing a hashtag with Unicode chars' do context 'when given text containing a hashtag with Unicode chars' do
let(:text) { '#hashtagタグ' } let(:text) { '#hashtagタグ' }
it 'creates a hashtag link' do it 'creates a hashtag link' do
@ -288,7 +288,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text with a stand-alone xmpp: URI' do context 'when given text with a stand-alone xmpp: URI' do
let(:text) { 'xmpp:user@instance.com' } let(:text) { 'xmpp:user@instance.com' }
it 'matches the full URI' do it 'matches the full URI' do
@ -296,7 +296,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text with an xmpp: URI with a query-string' do context 'when given text with an xmpp: URI with a query-string' do
let(:text) { 'please join xmpp:muc@instance.com?join right now' } let(:text) { 'please join xmpp:muc@instance.com?join right now' }
it 'matches the full URI' do it 'matches the full URI' do
@ -304,7 +304,7 @@ RSpec.describe TextFormatter do
end end
end end
context 'given text containing a magnet: URI' do context 'when given text containing a magnet: URI' do
let(:text) { 'wikipedia gives this example of a magnet uri: magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a' } let(:text) { 'wikipedia gives this example of a magnet uri: magnet:?xt=urn:btih:c12fe1c06bba254a9dc9f519b335aa7c1367a88a' }
it 'matches the full URI' do it 'matches the full URI' do

View File

@ -49,10 +49,10 @@ RSpec.describe Account::Field, type: :model do
let(:account) { double('Account', local?: local) } let(:account) { double('Account', local?: local) }
context 'for local accounts' do context 'with local accounts' do
let(:local) { true } let(:local) { true }
context 'for a URL with misleading authentication' do context 'with a URL with misleading authentication' do
let(:value) { 'https://spacex.com @h.43z.one' } let(:value) { 'https://spacex.com @h.43z.one' }
it 'returns false' do it 'returns false' do
@ -60,7 +60,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for a URL' do context 'with a URL' do
let(:value) { 'https://example.com' } let(:value) { 'https://example.com' }
it 'returns true' do it 'returns true' do
@ -68,7 +68,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for an IDN URL' do context 'with an IDN URL' do
let(:value) { 'https://twitter.comdougalljstatus1590357240443437057.ê.cc/twitter.html' } let(:value) { 'https://twitter.comdougalljstatus1590357240443437057.ê.cc/twitter.html' }
it 'returns false' do it 'returns false' do
@ -76,7 +76,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for a URL with a non-normalized path' do context 'with a URL with a non-normalized path' do
let(:value) { 'https://github.com/octocatxxxxxxxx/../mastodon' } let(:value) { 'https://github.com/octocatxxxxxxxx/../mastodon' }
it 'returns false' do it 'returns false' do
@ -84,7 +84,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for text that is not a URL' do context 'with text that is not a URL' do
let(:value) { 'Hello world' } let(:value) { 'Hello world' }
it 'returns false' do it 'returns false' do
@ -92,7 +92,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for text that contains a URL' do context 'with text that contains a URL' do
let(:value) { 'Hello https://example.com world' } let(:value) { 'Hello https://example.com world' }
it 'returns false' do it 'returns false' do
@ -100,7 +100,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for text which is blank' do context 'with text which is blank' do
let(:value) { '' } let(:value) { '' }
it 'returns false' do it 'returns false' do
@ -109,10 +109,10 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for remote accounts' do context 'with remote accounts' do
let(:local) { false } let(:local) { false }
context 'for a link' do context 'with a link' do
let(:value) { '<a href="https://www.patreon.com/mastodon" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://www.</span><span class="">patreon.com/mastodon</span><span class="invisible"></span></a>' } let(:value) { '<a href="https://www.patreon.com/mastodon" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://www.</span><span class="">patreon.com/mastodon</span><span class="invisible"></span></a>' }
it 'returns true' do it 'returns true' do
@ -120,7 +120,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for a link with misleading authentication' do context 'with a link with misleading authentication' do
let(:value) { '<a href="https://google.com @h.43z.one" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://</span><span class="">google.com</span><span class="invisible"> @h.43z.one</span></a>' } let(:value) { '<a href="https://google.com @h.43z.one" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://</span><span class="">google.com</span><span class="invisible"> @h.43z.one</span></a>' }
it 'returns false' do it 'returns false' do
@ -128,7 +128,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for HTML that has more than just a link' do context 'with HTML that has more than just a link' do
let(:value) { '<a href="https://google.com" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://</span><span class="">google.com</span><span class="invisible"></span></a> @h.43z.one' } let(:value) { '<a href="https://google.com" target="_blank" rel="nofollow noopener noreferrer me"><span class="invisible">https://</span><span class="">google.com</span><span class="invisible"></span></a> @h.43z.one' }
it 'returns false' do it 'returns false' do
@ -136,7 +136,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for a link with different visible text' do context 'with a link with different visible text' do
let(:value) { '<a href="https://google.com/bar">https://example.com/foo</a>' } let(:value) { '<a href="https://google.com/bar">https://example.com/foo</a>' }
it 'returns false' do it 'returns false' do
@ -144,7 +144,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for text that is a URL but is not linked' do context 'with text that is a URL but is not linked' do
let(:value) { 'https://example.com/foo' } let(:value) { 'https://example.com/foo' }
it 'returns false' do it 'returns false' do
@ -152,7 +152,7 @@ RSpec.describe Account::Field, type: :model do
end end
end end
context 'for text which is blank' do context 'with text which is blank' do
let(:value) { '' } let(:value) { '' }
it 'returns false' do it 'returns false' do

View File

@ -171,7 +171,7 @@ RSpec.describe Account, type: :model do
describe '#possibly_stale?' do describe '#possibly_stale?' do
let(:account) { Fabricate(:account, last_webfingered_at: last_webfingered_at) } let(:account) { Fabricate(:account, last_webfingered_at: last_webfingered_at) }
context 'last_webfingered_at is nil' do context 'when last_webfingered_at is nil' do
let(:last_webfingered_at) { nil } let(:last_webfingered_at) { nil }
it 'returns true' do it 'returns true' do
@ -179,7 +179,7 @@ RSpec.describe Account, type: :model do
end end
end end
context 'last_webfingered_at is more than 24 hours before' do context 'when last_webfingered_at is more than 24 hours before' do
let(:last_webfingered_at) { 25.hours.ago } let(:last_webfingered_at) { 25.hours.ago }
it 'returns true' do it 'returns true' do
@ -187,7 +187,7 @@ RSpec.describe Account, type: :model do
end end
end end
context 'last_webfingered_at is less than 24 hours before' do context 'when last_webfingered_at is less than 24 hours before' do
let(:last_webfingered_at) { 23.hours.ago } let(:last_webfingered_at) { 23.hours.ago }
it 'returns false' do it 'returns false' do
@ -200,7 +200,7 @@ RSpec.describe Account, type: :model do
let(:account) { Fabricate(:account, domain: domain) } let(:account) { Fabricate(:account, domain: domain) }
let(:acct) { account.acct } let(:acct) { account.acct }
context 'domain is nil' do context 'when domain is nil' do
let(:domain) { nil } let(:domain) { nil }
it 'returns nil' do it 'returns nil' do
@ -213,7 +213,7 @@ RSpec.describe Account, type: :model do
end end
end end
context 'domain is present' do context 'when domain is present' do
let(:domain) { 'example.com' } let(:domain) { 'example.com' }
it 'calls ResolveAccountService#call' do it 'calls ResolveAccountService#call' do

View File

@ -20,7 +20,7 @@ RSpec.describe Admin::AccountAction, type: :model do
) )
end end
context 'type is "disable"' do context 'when type is "disable"' do
let(:type) { 'disable' } let(:type) { 'disable' }
it 'disable user' do it 'disable user' do
@ -29,7 +29,7 @@ RSpec.describe Admin::AccountAction, type: :model do
end end
end end
context 'type is "silence"' do context 'when type is "silence"' do
let(:type) { 'silence' } let(:type) { 'silence' }
it 'silences account' do it 'silences account' do
@ -38,7 +38,7 @@ RSpec.describe Admin::AccountAction, type: :model do
end end
end end
context 'type is "suspend"' do context 'when type is "suspend"' do
let(:type) { 'suspend' } let(:type) { 'suspend' }
it 'suspends account' do it 'suspends account' do
@ -75,7 +75,7 @@ RSpec.describe Admin::AccountAction, type: :model do
describe '#report' do describe '#report' do
subject { account_action.report } subject { account_action.report }
context 'report_id.present?' do context 'with report_id.present?' do
before do before do
account_action.report_id = Fabricate(:report).id account_action.report_id = Fabricate(:report).id
end end
@ -85,7 +85,7 @@ RSpec.describe Admin::AccountAction, type: :model do
end end
end end
context '!report_id.present?' do context 'with !report_id.present?' do
it 'returns nil' do it 'returns nil' do
expect(subject).to be_nil expect(subject).to be_nil
end end
@ -95,7 +95,7 @@ RSpec.describe Admin::AccountAction, type: :model do
describe '#with_report?' do describe '#with_report?' do
subject { account_action.with_report? } subject { account_action.with_report? }
context '!report.nil?' do context 'with !report.nil?' do
before do before do
account_action.report_id = Fabricate(:report).id account_action.report_id = Fabricate(:report).id
end end
@ -105,7 +105,7 @@ RSpec.describe Admin::AccountAction, type: :model do
end end
end end
context '!(!report.nil?)' do context 'with !(!report.nil?)' do
it 'returns false' do it 'returns false' do
expect(subject).to be false expect(subject).to be false
end end
@ -115,7 +115,7 @@ RSpec.describe Admin::AccountAction, type: :model do
describe '.types_for_account' do describe '.types_for_account' do
subject { described_class.types_for_account(account) } subject { described_class.types_for_account(account) }
context 'account.local?' do context 'when Account.local?' do
let(:account) { Fabricate(:account, domain: nil) } let(:account) { Fabricate(:account, domain: nil) }
it 'returns ["none", "disable", "sensitive", "silence", "suspend"]' do it 'returns ["none", "disable", "sensitive", "silence", "suspend"]' do
@ -123,7 +123,7 @@ RSpec.describe Admin::AccountAction, type: :model do
end end
end end
context '!account.local?' do context 'with !account.local?' do
let(:account) { Fabricate(:account, domain: 'hoge.com') } let(:account) { Fabricate(:account, domain: 'hoge.com') }
it 'returns ["sensitive", "silence", "suspend"]' do it 'returns ["sensitive", "silence", "suspend"]' do

View File

@ -13,14 +13,14 @@ describe AccountInteractions do
describe '.following_map' do describe '.following_map' do
subject { Account.following_map(target_account_ids, account_id) } subject { Account.following_map(target_account_ids, account_id) }
context 'account with Follow' do context 'when Account with Follow' do
it 'returns { target_account_id => true }' do it 'returns { target_account_id => true }' do
Fabricate(:follow, account: account, target_account: target_account) Fabricate(:follow, account: account, target_account: target_account)
expect(subject).to eq(target_account_id => { reblogs: true, notify: false, languages: nil }) expect(subject).to eq(target_account_id => { reblogs: true, notify: false, languages: nil })
end end
end end
context 'account without Follow' do context 'when Account without Follow' do
it 'returns {}' do it 'returns {}' do
expect(subject).to eq({}) expect(subject).to eq({})
end end
@ -30,14 +30,14 @@ describe AccountInteractions do
describe '.followed_by_map' do describe '.followed_by_map' do
subject { Account.followed_by_map(target_account_ids, account_id) } subject { Account.followed_by_map(target_account_ids, account_id) }
context 'account with Follow' do context 'when Account with Follow' do
it 'returns { target_account_id => true }' do it 'returns { target_account_id => true }' do
Fabricate(:follow, account: target_account, target_account: account) Fabricate(:follow, account: target_account, target_account: account)
expect(subject).to eq(target_account_id => true) expect(subject).to eq(target_account_id => true)
end end
end end
context 'account without Follow' do context 'when Account without Follow' do
it 'returns {}' do it 'returns {}' do
expect(subject).to eq({}) expect(subject).to eq({})
end end
@ -47,14 +47,14 @@ describe AccountInteractions do
describe '.blocking_map' do describe '.blocking_map' do
subject { Account.blocking_map(target_account_ids, account_id) } subject { Account.blocking_map(target_account_ids, account_id) }
context 'account with Block' do context 'when Account with Block' do
it 'returns { target_account_id => true }' do it 'returns { target_account_id => true }' do
Fabricate(:block, account: account, target_account: target_account) Fabricate(:block, account: account, target_account: target_account)
expect(subject).to eq(target_account_id => true) expect(subject).to eq(target_account_id => true)
end end
end end
context 'account without Block' do context 'when Account without Block' do
it 'returns {}' do it 'returns {}' do
expect(subject).to eq({}) expect(subject).to eq({})
end end
@ -64,12 +64,12 @@ describe AccountInteractions do
describe '.muting_map' do describe '.muting_map' do
subject { Account.muting_map(target_account_ids, account_id) } subject { Account.muting_map(target_account_ids, account_id) }
context 'account with Mute' do context 'when Account with Mute' do
before do before do
Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide) Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
end end
context 'if Mute#hide_notifications?' do context 'when Mute#hide_notifications?' do
let(:hide) { true } let(:hide) { true }
it 'returns { target_account_id => { notifications: true } }' do it 'returns { target_account_id => { notifications: true } }' do
@ -77,7 +77,7 @@ describe AccountInteractions do
end end
end end
context 'unless Mute#hide_notifications?' do context 'when not Mute#hide_notifications?' do
let(:hide) { false } let(:hide) { false }
it 'returns { target_account_id => { notifications: false } }' do it 'returns { target_account_id => { notifications: false } }' do
@ -86,7 +86,7 @@ describe AccountInteractions do
end end
end end
context 'account without Mute' do context 'when Account without Mute' do
it 'returns {}' do it 'returns {}' do
expect(subject).to eq({}) expect(subject).to eq({})
end end
@ -112,8 +112,8 @@ describe AccountInteractions do
describe '#mute!' do describe '#mute!' do
subject { account.mute!(target_account, notifications: arg_notifications) } subject { account.mute!(target_account, notifications: arg_notifications) }
context 'Mute does not exist yet' do context 'when Mute does not exist yet' do
context 'arg :notifications is nil' do context 'when arg :notifications is nil' do
let(:arg_notifications) { nil } let(:arg_notifications) { nil }
it 'creates Mute, and returns Mute' do it 'creates Mute, and returns Mute' do
@ -123,7 +123,7 @@ describe AccountInteractions do
end end
end end
context 'arg :notifications is false' do context 'when arg :notifications is false' do
let(:arg_notifications) { false } let(:arg_notifications) { false }
it 'creates Mute, and returns Mute' do it 'creates Mute, and returns Mute' do
@ -133,7 +133,7 @@ describe AccountInteractions do
end end
end end
context 'arg :notifications is true' do context 'when arg :notifications is true' do
let(:arg_notifications) { true } let(:arg_notifications) { true }
it 'creates Mute, and returns Mute' do it 'creates Mute, and returns Mute' do
@ -144,7 +144,7 @@ describe AccountInteractions do
end end
end end
context 'Mute already exists' do context 'when Mute already exists' do
before do before do
account.mute_relationships << mute account.mute_relationships << mute
end end
@ -156,10 +156,10 @@ describe AccountInteractions do
hide_notifications: hide_notifications) hide_notifications: hide_notifications)
end end
context 'mute.hide_notifications is true' do context 'when mute.hide_notifications is true' do
let(:hide_notifications) { true } let(:hide_notifications) { true }
context 'arg :notifications is nil' do context 'when arg :notifications is nil' do
let(:arg_notifications) { nil } let(:arg_notifications) { nil }
it 'returns Mute without updating mute.hide_notifications' do it 'returns Mute without updating mute.hide_notifications' do
@ -169,7 +169,7 @@ describe AccountInteractions do
end end
end end
context 'arg :notifications is false' do context 'when arg :notifications is false' do
let(:arg_notifications) { false } let(:arg_notifications) { false }
it 'returns Mute, and updates mute.hide_notifications false' do it 'returns Mute, and updates mute.hide_notifications false' do
@ -179,7 +179,7 @@ describe AccountInteractions do
end end
end end
context 'arg :notifications is true' do context 'when arg :notifications is true' do
let(:arg_notifications) { true } let(:arg_notifications) { true }
it 'returns Mute without updating mute.hide_notifications' do it 'returns Mute without updating mute.hide_notifications' do
@ -190,10 +190,10 @@ describe AccountInteractions do
end end
end end
context 'mute.hide_notifications is false' do context 'when mute.hide_notifications is false' do
let(:hide_notifications) { false } let(:hide_notifications) { false }
context 'arg :notifications is nil' do context 'when arg :notifications is nil' do
let(:arg_notifications) { nil } let(:arg_notifications) { nil }
it 'returns Mute, and updates mute.hide_notifications true' do it 'returns Mute, and updates mute.hide_notifications true' do
@ -203,7 +203,7 @@ describe AccountInteractions do
end end
end end
context 'arg :notifications is false' do context 'when arg :notifications is false' do
let(:arg_notifications) { false } let(:arg_notifications) { false }
it 'returns Mute without updating mute.hide_notifications' do it 'returns Mute without updating mute.hide_notifications' do
@ -213,7 +213,7 @@ describe AccountInteractions do
end end
end end
context 'arg :notifications is true' do context 'when arg :notifications is true' do
let(:arg_notifications) { true } let(:arg_notifications) { true }
it 'returns Mute, and updates mute.hide_notifications true' do it 'returns Mute, and updates mute.hide_notifications true' do
@ -253,7 +253,7 @@ describe AccountInteractions do
describe '#unfollow!' do describe '#unfollow!' do
subject { account.unfollow!(target_account) } subject { account.unfollow!(target_account) }
context 'following target_account' do context 'when following target_account' do
it 'returns destroyed Follow' do it 'returns destroyed Follow' do
account.active_relationships.create(target_account: target_account) account.active_relationships.create(target_account: target_account)
expect(subject).to be_a Follow expect(subject).to be_a Follow
@ -261,7 +261,7 @@ describe AccountInteractions do
end end
end end
context 'not following target_account' do context 'when not following target_account' do
it 'returns nil' do it 'returns nil' do
expect(subject).to be_nil expect(subject).to be_nil
end end
@ -271,7 +271,7 @@ describe AccountInteractions do
describe '#unblock!' do describe '#unblock!' do
subject { account.unblock!(target_account) } subject { account.unblock!(target_account) }
context 'blocking target_account' do context 'when blocking target_account' do
it 'returns destroyed Block' do it 'returns destroyed Block' do
account.block_relationships.create(target_account: target_account) account.block_relationships.create(target_account: target_account)
expect(subject).to be_a Block expect(subject).to be_a Block
@ -279,7 +279,7 @@ describe AccountInteractions do
end end
end end
context 'not blocking target_account' do context 'when not blocking target_account' do
it 'returns nil' do it 'returns nil' do
expect(subject).to be_nil expect(subject).to be_nil
end end
@ -289,7 +289,7 @@ describe AccountInteractions do
describe '#unmute!' do describe '#unmute!' do
subject { account.unmute!(target_account) } subject { account.unmute!(target_account) }
context 'muting target_account' do context 'when muting target_account' do
it 'returns destroyed Mute' do it 'returns destroyed Mute' do
account.mute_relationships.create(target_account: target_account) account.mute_relationships.create(target_account: target_account)
expect(subject).to be_a Mute expect(subject).to be_a Mute
@ -297,7 +297,7 @@ describe AccountInteractions do
end end
end end
context 'not muting target_account' do context 'when not muting target_account' do
it 'returns nil' do it 'returns nil' do
expect(subject).to be_nil expect(subject).to be_nil
end end
@ -309,7 +309,7 @@ describe AccountInteractions do
let(:conversation) { Fabricate(:conversation) } let(:conversation) { Fabricate(:conversation) }
context 'muting the conversation' do context 'when muting the conversation' do
it 'returns destroyed ConversationMute' do it 'returns destroyed ConversationMute' do
account.conversation_mutes.create(conversation: conversation) account.conversation_mutes.create(conversation: conversation)
expect(subject).to be_a ConversationMute expect(subject).to be_a ConversationMute
@ -317,7 +317,7 @@ describe AccountInteractions do
end end
end end
context 'not muting the conversation' do context 'when not muting the conversation' do
it 'returns nil' do it 'returns nil' do
expect(subject).to be_nil expect(subject).to be_nil
end end
@ -329,7 +329,7 @@ describe AccountInteractions do
let(:domain) { 'example.com' } let(:domain) { 'example.com' }
context 'blocking the domain' do context 'when blocking the domain' do
it 'returns destroyed AccountDomainBlock' do it 'returns destroyed AccountDomainBlock' do
account_domain_block = Fabricate(:account_domain_block, domain: domain) account_domain_block = Fabricate(:account_domain_block, domain: domain)
account.domain_blocks << account_domain_block account.domain_blocks << account_domain_block
@ -338,7 +338,7 @@ describe AccountInteractions do
end end
end end
context 'unblocking the domain' do context 'when unblocking the domain' do
it 'returns nil' do it 'returns nil' do
expect(subject).to be_nil expect(subject).to be_nil
end end
@ -348,14 +348,14 @@ describe AccountInteractions do
describe '#following?' do describe '#following?' do
subject { account.following?(target_account) } subject { account.following?(target_account) }
context 'following target_account' do context 'when following target_account' do
it 'returns true' do it 'returns true' do
account.active_relationships.create(target_account: target_account) account.active_relationships.create(target_account: target_account)
expect(subject).to be true expect(subject).to be true
end end
end end
context 'not following target_account' do context 'when not following target_account' do
it 'returns false' do it 'returns false' do
expect(subject).to be false expect(subject).to be false
end end
@ -365,14 +365,14 @@ describe AccountInteractions do
describe '#followed_by?' do describe '#followed_by?' do
subject { account.followed_by?(target_account) } subject { account.followed_by?(target_account) }
context 'followed by target_account' do context 'when followed by target_account' do
it 'returns true' do it 'returns true' do
account.passive_relationships.create(account: target_account) account.passive_relationships.create(account: target_account)
expect(subject).to be true expect(subject).to be true
end end
end end
context 'not followed by target_account' do context 'when not followed by target_account' do
it 'returns false' do it 'returns false' do
expect(subject).to be false expect(subject).to be false
end end
@ -382,14 +382,14 @@ describe AccountInteractions do
describe '#blocking?' do describe '#blocking?' do
subject { account.blocking?(target_account) } subject { account.blocking?(target_account) }
context 'blocking target_account' do context 'when blocking target_account' do
it 'returns true' do it 'returns true' do
account.block_relationships.create(target_account: target_account) account.block_relationships.create(target_account: target_account)
expect(subject).to be true expect(subject).to be true
end end
end end
context 'not blocking target_account' do context 'when not blocking target_account' do
it 'returns false' do it 'returns false' do
expect(subject).to be false expect(subject).to be false
end end
@ -401,7 +401,7 @@ describe AccountInteractions do
let(:domain) { 'example.com' } let(:domain) { 'example.com' }
context 'blocking the domain' do context 'when blocking the domain' do
it 'returns true' do it 'returns true' do
account_domain_block = Fabricate(:account_domain_block, domain: domain) account_domain_block = Fabricate(:account_domain_block, domain: domain)
account.domain_blocks << account_domain_block account.domain_blocks << account_domain_block
@ -409,7 +409,7 @@ describe AccountInteractions do
end end
end end
context 'not blocking the domain' do context 'when not blocking the domain' do
it 'returns false' do it 'returns false' do
expect(subject).to be false expect(subject).to be false
end end
@ -419,7 +419,7 @@ describe AccountInteractions do
describe '#muting?' do describe '#muting?' do
subject { account.muting?(target_account) } subject { account.muting?(target_account) }
context 'muting target_account' do context 'when muting target_account' do
it 'returns true' do it 'returns true' do
mute = Fabricate(:mute, account: account, target_account: target_account) mute = Fabricate(:mute, account: account, target_account: target_account)
account.mute_relationships << mute account.mute_relationships << mute
@ -427,7 +427,7 @@ describe AccountInteractions do
end end
end end
context 'not muting target_account' do context 'when not muting target_account' do
it 'returns false' do it 'returns false' do
expect(subject).to be false expect(subject).to be false
end end
@ -439,14 +439,14 @@ describe AccountInteractions do
let(:conversation) { Fabricate(:conversation) } let(:conversation) { Fabricate(:conversation) }
context 'muting the conversation' do context 'when muting the conversation' do
it 'returns true' do it 'returns true' do
account.conversation_mutes.create(conversation: conversation) account.conversation_mutes.create(conversation: conversation)
expect(subject).to be true expect(subject).to be true
end end
end end
context 'not muting the conversation' do context 'when not muting the conversation' do
it 'returns false' do it 'returns false' do
expect(subject).to be false expect(subject).to be false
end end
@ -461,7 +461,7 @@ describe AccountInteractions do
account.mute_relationships << mute account.mute_relationships << mute
end end
context 'muting notifications of target_account' do context 'when muting notifications of target_account' do
let(:hide) { true } let(:hide) { true }
it 'returns true' do it 'returns true' do
@ -469,7 +469,7 @@ describe AccountInteractions do
end end
end end
context 'not muting notifications of target_account' do context 'when not muting notifications of target_account' do
let(:hide) { false } let(:hide) { false }
it 'returns false' do it 'returns false' do
@ -481,14 +481,14 @@ describe AccountInteractions do
describe '#requested?' do describe '#requested?' do
subject { account.requested?(target_account) } subject { account.requested?(target_account) }
context 'requested by target_account' do context 'with requested by target_account' do
it 'returns true' do it 'returns true' do
Fabricate(:follow_request, account: account, target_account: target_account) Fabricate(:follow_request, account: account, target_account: target_account)
expect(subject).to be true expect(subject).to be true
end end
end end
context 'not requested by target_account' do context 'when not requested by target_account' do
it 'returns false' do it 'returns false' do
expect(subject).to be false expect(subject).to be false
end end
@ -500,7 +500,7 @@ describe AccountInteractions do
let(:status) { Fabricate(:status, account: account, favourites: favourites) } let(:status) { Fabricate(:status, account: account, favourites: favourites) }
context 'favorited' do context 'when favorited' do
let(:favourites) { [Fabricate(:favourite, account: account)] } let(:favourites) { [Fabricate(:favourite, account: account)] }
it 'returns true' do it 'returns true' do
@ -508,7 +508,7 @@ describe AccountInteractions do
end end
end end
context 'not favorited' do context 'when not favorited' do
let(:favourites) { [] } let(:favourites) { [] }
it 'returns false' do it 'returns false' do
@ -522,7 +522,7 @@ describe AccountInteractions do
let(:status) { Fabricate(:status, account: account, reblogs: reblogs) } let(:status) { Fabricate(:status, account: account, reblogs: reblogs) }
context 'reblogged' do context 'with reblogged' do
let(:reblogs) { [Fabricate(:status, account: account)] } let(:reblogs) { [Fabricate(:status, account: account)] }
it 'returns true' do it 'returns true' do
@ -530,7 +530,7 @@ describe AccountInteractions do
end end
end end
context 'not reblogged' do context 'when not reblogged' do
let(:reblogs) { [] } let(:reblogs) { [] }
it 'returns false' do it 'returns false' do
@ -544,14 +544,14 @@ describe AccountInteractions do
let(:status) { Fabricate(:status, account: account) } let(:status) { Fabricate(:status, account: account) }
context 'pinned' do context 'when pinned' do
it 'returns true' do it 'returns true' do
Fabricate(:status_pin, account: account, status: status) Fabricate(:status_pin, account: account, status: status)
expect(subject).to be true expect(subject).to be true
end end
end end
context 'not pinned' do context 'when not pinned' do
it 'returns false' do it 'returns false' do
expect(subject).to be false expect(subject).to be false
end end

View File

@ -156,7 +156,7 @@ RSpec.describe Remotable do
context 'when the response is successful' do context 'when the response is successful' do
let(:code) { 200 } let(:code) { 200 }
context 'and contains Content-Disposition header' do context 'when contains Content-Disposition header' do
let(:file) { 'filename="foo.txt"' } let(:file) { 'filename="foo.txt"' }
let(:headers) { { 'content-disposition' => file } } let(:headers) { { 'content-disposition' => file } }

View File

@ -10,8 +10,8 @@ RSpec.describe CustomEmojiFilter do
let!(:custom_emoji_1) { Fabricate(:custom_emoji, domain: 'b') } let!(:custom_emoji_1) { Fabricate(:custom_emoji, domain: 'b') }
let!(:custom_emoji_2) { Fabricate(:custom_emoji, domain: nil, shortcode: 'hoge') } let!(:custom_emoji_2) { Fabricate(:custom_emoji, domain: nil, shortcode: 'hoge') }
context 'params have values' do context 'when params have values' do
context 'local' do context 'when local' do
let(:params) { { local: true } } let(:params) { { local: true } }
it 'returns ActiveRecord::Relation' do it 'returns ActiveRecord::Relation' do
@ -20,7 +20,7 @@ RSpec.describe CustomEmojiFilter do
end end
end end
context 'remote' do context 'when remote' do
let(:params) { { remote: true } } let(:params) { { remote: true } }
it 'returns ActiveRecord::Relation' do it 'returns ActiveRecord::Relation' do
@ -29,7 +29,7 @@ RSpec.describe CustomEmojiFilter do
end end
end end
context 'by_domain' do context 'with by_domain' do
let(:params) { { by_domain: 'a' } } let(:params) { { by_domain: 'a' } }
it 'returns ActiveRecord::Relation' do it 'returns ActiveRecord::Relation' do
@ -38,7 +38,7 @@ RSpec.describe CustomEmojiFilter do
end end
end end
context 'shortcode' do context 'when shortcode' do
let(:params) { { shortcode: 'hoge' } } let(:params) { { shortcode: 'hoge' } }
it 'returns ActiveRecord::Relation' do it 'returns ActiveRecord::Relation' do
@ -47,7 +47,7 @@ RSpec.describe CustomEmojiFilter do
end end
end end
context 'else' do context 'when some other case' do
let(:params) { { else: 'else' } } let(:params) { { else: 'else' } }
it 'raises Mastodon::InvalidParameterError' do it 'raises Mastodon::InvalidParameterError' do
@ -58,7 +58,7 @@ RSpec.describe CustomEmojiFilter do
end end
end end
context 'params without value' do context 'when params without value' do
let(:params) { { hoge: nil } } let(:params) { { hoge: nil } }
it 'returns ActiveRecord::Relation' do it 'returns ActiveRecord::Relation' do

View File

@ -8,7 +8,7 @@ RSpec.describe CustomEmoji, type: :model do
let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: shortcode) } let(:custom_emoji) { Fabricate(:custom_emoji, shortcode: shortcode) }
context 'shortcode is exact' do context 'when shortcode is exact' do
let(:shortcode) { 'blobpats' } let(:shortcode) { 'blobpats' }
let(:search_term) { 'blobpats' } let(:search_term) { 'blobpats' }
@ -17,7 +17,7 @@ RSpec.describe CustomEmoji, type: :model do
end end
end end
context 'shortcode is partial' do context 'when shortcode is partial' do
let(:shortcode) { 'blobpats' } let(:shortcode) { 'blobpats' }
let(:search_term) { 'blob' } let(:search_term) { 'blob' }
@ -32,7 +32,7 @@ RSpec.describe CustomEmoji, type: :model do
let(:custom_emoji) { Fabricate(:custom_emoji, domain: domain) } let(:custom_emoji) { Fabricate(:custom_emoji, domain: domain) }
context 'domain is nil' do context 'when domain is nil' do
let(:domain) { nil } let(:domain) { nil }
it 'returns true' do it 'returns true' do
@ -40,7 +40,7 @@ RSpec.describe CustomEmoji, type: :model do
end end
end end
context 'domain is present' do context 'when domain is present' do
let(:domain) { 'example.com' } let(:domain) { 'example.com' }
it 'returns false' do it 'returns false' do

View File

@ -6,7 +6,7 @@ RSpec.describe EmailDomainBlock, type: :model do
describe 'block?' do describe 'block?' do
let(:input) { nil } let(:input) { nil }
context 'given an e-mail address' do context 'when given an e-mail address' do
let(:input) { "foo@#{domain}" } let(:input) { "foo@#{domain}" }
context do context do
@ -33,7 +33,7 @@ RSpec.describe EmailDomainBlock, type: :model do
end end
end end
context 'given an array of domains' do context 'when given an array of domains' do
let(:input) { %w(foo.com mail.foo.com) } let(:input) { %w(foo.com mail.foo.com) }
it 'returns true if the domain is blocked' do it 'returns true if the domain is blocked' do

View File

@ -8,7 +8,7 @@ RSpec.describe MediaAttachment, type: :model do
let(:media_attachment) { Fabricate(:media_attachment, remote_url: remote_url) } let(:media_attachment) { Fabricate(:media_attachment, remote_url: remote_url) }
context 'remote_url is blank' do context 'when remote_url is blank' do
let(:remote_url) { '' } let(:remote_url) { '' }
it 'returns true' do it 'returns true' do
@ -16,7 +16,7 @@ RSpec.describe MediaAttachment, type: :model do
end end
end end
context 'remote_url is present' do context 'when remote_url is present' do
let(:remote_url) { 'remote_url' } let(:remote_url) { 'remote_url' }
it 'returns false' do it 'returns false' do
@ -30,10 +30,10 @@ RSpec.describe MediaAttachment, type: :model do
let(:media_attachment) { Fabricate(:media_attachment, remote_url: remote_url, file: file) } let(:media_attachment) { Fabricate(:media_attachment, remote_url: remote_url, file: file) }
context 'file is blank' do context 'when file is blank' do
let(:file) { nil } let(:file) { nil }
context 'remote_url is present' do context 'when remote_url is present' do
let(:remote_url) { 'remote_url' } let(:remote_url) { 'remote_url' }
it 'returns true' do it 'returns true' do
@ -42,10 +42,10 @@ RSpec.describe MediaAttachment, type: :model do
end end
end end
context 'file is present' do context 'when file is present' do
let(:file) { attachment_fixture('avatar.gif') } let(:file) { attachment_fixture('avatar.gif') }
context 'remote_url is blank' do context 'when remote_url is blank' do
let(:remote_url) { '' } let(:remote_url) { '' }
it 'returns false' do it 'returns false' do
@ -53,7 +53,7 @@ RSpec.describe MediaAttachment, type: :model do
end end
end end
context 'remote_url is present' do context 'when remote_url is present' do
let(:remote_url) { 'remote_url' } let(:remote_url) { 'remote_url' }
it 'returns true' do it 'returns true' do

View File

@ -10,7 +10,7 @@ RSpec.describe Notification, type: :model do
let(:favourite) { Fabricate(:favourite, status: status) } let(:favourite) { Fabricate(:favourite, status: status) }
let(:mention) { Fabricate(:mention, status: status) } let(:mention) { Fabricate(:mention, status: status) }
context 'activity is reblog' do context 'when Activity is reblog' do
let(:activity) { reblog } let(:activity) { reblog }
it 'returns status' do it 'returns status' do
@ -18,7 +18,7 @@ RSpec.describe Notification, type: :model do
end end
end end
context 'activity is favourite' do context 'when Activity is favourite' do
let(:type) { :favourite } let(:type) { :favourite }
let(:activity) { favourite } let(:activity) { favourite }
@ -27,7 +27,7 @@ RSpec.describe Notification, type: :model do
end end
end end
context 'activity is mention' do context 'when Activity is mention' do
let(:activity) { mention } let(:activity) { mention }
it 'returns status' do it 'returns status' do
@ -66,7 +66,7 @@ RSpec.describe Notification, type: :model do
end end
end end
context 'notifications are empty' do context 'when notifications are empty' do
let(:notifications) { [] } let(:notifications) { [] }
it 'returns []' do it 'returns []' do
@ -74,7 +74,7 @@ RSpec.describe Notification, type: :model do
end end
end end
context 'notifications are present' do context 'when notifications are present' do
before do before do
notifications.each(&:reload) notifications.each(&:reload)
end end

View File

@ -13,7 +13,7 @@ RSpec.describe RemoteFollow do
describe '.initialize' do describe '.initialize' do
subject { remote_follow.acct } subject { remote_follow.acct }
context 'attrs with acct' do context 'when attrs with acct' do
let(:attrs) { { acct: 'gargron@quitter.no' } } let(:attrs) { { acct: 'gargron@quitter.no' } }
it 'returns acct' do it 'returns acct' do
@ -21,7 +21,7 @@ RSpec.describe RemoteFollow do
end end
end end
context 'attrs without acct' do context 'when attrs without acct' do
let(:attrs) { {} } let(:attrs) { {} }
it do it do
@ -33,7 +33,7 @@ RSpec.describe RemoteFollow do
describe '#valid?' do describe '#valid?' do
subject { remote_follow.valid? } subject { remote_follow.valid? }
context 'attrs with acct' do context 'when attrs with acct' do
let(:attrs) { { acct: 'gargron@quitter.no' } } let(:attrs) { { acct: 'gargron@quitter.no' } }
it do it do
@ -41,7 +41,7 @@ RSpec.describe RemoteFollow do
end end
end end
context 'attrs without acct' do context 'when attrs without acct' do
let(:attrs) { {} } let(:attrs) { {} }
it do it do

View File

@ -89,13 +89,13 @@ describe Report do
let(:report) { Fabricate(:report, action_taken_at: action_taken) } let(:report) { Fabricate(:report, action_taken_at: action_taken) }
context 'if action is taken' do context 'when action is taken' do
let(:action_taken) { Time.now.utc } let(:action_taken) { Time.now.utc }
it { is_expected.to be false } it { is_expected.to be false }
end end
context 'if action not is taken' do context 'when action not is taken' do
let(:action_taken) { nil } let(:action_taken) { nil }
it { is_expected.to be true } it { is_expected.to be true }

View File

@ -40,7 +40,7 @@ RSpec.describe SessionActivation, type: :model do
describe '.active?' do describe '.active?' do
subject { described_class.active?(id) } subject { described_class.active?(id) }
context 'id is absent' do context 'when id is absent' do
let(:id) { nil } let(:id) { nil }
it 'returns nil' do it 'returns nil' do
@ -48,17 +48,17 @@ RSpec.describe SessionActivation, type: :model do
end end
end end
context 'id is present' do context 'when id is present' do
let(:id) { '1' } let(:id) { '1' }
let!(:session_activation) { Fabricate(:session_activation, session_id: id) } let!(:session_activation) { Fabricate(:session_activation, session_id: id) }
context 'id exists as session_id' do context 'when id exists as session_id' do
it 'returns true' do it 'returns true' do
expect(subject).to be true expect(subject).to be true
end end
end end
context 'id does not exist as session_id' do context 'when id does not exist as session_id' do
before do before do
session_activation.update!(session_id: '2') session_activation.update!(session_id: '2')
end end
@ -85,7 +85,7 @@ RSpec.describe SessionActivation, type: :model do
end end
describe '.deactivate' do describe '.deactivate' do
context 'id is absent' do context 'when id is absent' do
let(:id) { nil } let(:id) { nil }
it 'returns nil' do it 'returns nil' do
@ -93,7 +93,7 @@ RSpec.describe SessionActivation, type: :model do
end end
end end
context 'id exists' do context 'when id exists' do
let(:id) { '1' } let(:id) { '1' }
it 'calls where.destroy_all' do it 'calls where.destroy_all' do

View File

@ -19,7 +19,7 @@ RSpec.describe Setting, type: :model do
let(:key) { 'key' } let(:key) { 'key' }
context 'rails_initialized? is falsey' do context 'when rails_initialized? is falsey' do
let(:rails_initialized) { false } let(:rails_initialized) { false }
it 'calls RailsSettings::Base#[]' do it 'calls RailsSettings::Base#[]' do
@ -28,7 +28,7 @@ RSpec.describe Setting, type: :model do
end end
end end
context 'rails_initialized? is truthy' do context 'when rails_initialized? is truthy' do
before do before do
allow(RailsSettings::Base).to receive(:cache_key).with(key, nil).and_return(cache_key) allow(RailsSettings::Base).to receive(:cache_key).with(key, nil).and_return(cache_key)
end end
@ -42,7 +42,7 @@ RSpec.describe Setting, type: :model do
described_class[key] described_class[key]
end end
context 'Rails.cache does not exists' do context 'when Rails.cache does not exists' do
before do before do
allow(RailsSettings::Settings).to receive(:object).with(key).and_return(object) allow(RailsSettings::Settings).to receive(:object).with(key).and_return(object)
allow(described_class).to receive(:default_settings).and_return(default_settings) allow(described_class).to receive(:default_settings).and_return(default_settings)
@ -60,11 +60,11 @@ RSpec.describe Setting, type: :model do
described_class[key] described_class[key]
end end
context 'RailsSettings::Settings.object returns truthy' do context 'when RailsSettings::Settings.object returns truthy' do
let(:object) { db_val } let(:object) { db_val }
let(:db_val) { double(value: 'db_val') } let(:db_val) { double(value: 'db_val') }
context 'default_value is a Hash' do context 'when default_value is a Hash' do
let(:default_value) { { default_value: 'default_value' } } let(:default_value) { { default_value: 'default_value' } }
it 'calls default_value.with_indifferent_access.merge!' do it 'calls default_value.with_indifferent_access.merge!' do
@ -75,7 +75,7 @@ RSpec.describe Setting, type: :model do
end end
end end
context 'default_value is not a Hash' do context 'when default_value is not a Hash' do
let(:default_value) { 'default_value' } let(:default_value) { 'default_value' }
it 'returns db_val.value' do it 'returns db_val.value' do
@ -84,7 +84,7 @@ RSpec.describe Setting, type: :model do
end end
end end
context 'RailsSettings::Settings.object returns falsey' do context 'when RailsSettings::Settings.object returns falsey' do
let(:object) { nil } let(:object) { nil }
it 'returns default_settings[key]' do it 'returns default_settings[key]' do
@ -93,7 +93,7 @@ RSpec.describe Setting, type: :model do
end end
end end
context 'Rails.cache exists' do context 'when Rails.cache exists' do
before do before do
Rails.cache.write(cache_key, cache_value) Rails.cache.write(cache_key, cache_value)
end end
@ -130,7 +130,7 @@ RSpec.describe Setting, type: :model do
expect(described_class.all_as_records).to be_a Hash expect(described_class.all_as_records).to be_a Hash
end end
context 'records includes Setting with var as the key' do context 'when records includes Setting with var as the key' do
let(:records) { [original_setting] } let(:records) { [original_setting] }
it 'includes the original Setting' do it 'includes the original Setting' do
@ -139,10 +139,10 @@ RSpec.describe Setting, type: :model do
end end
end end
context 'records includes nothing' do context 'when records includes nothing' do
let(:records) { [] } let(:records) { [] }
context 'default_value is not a Hash' do context 'when default_value is not a Hash' do
it 'includes Setting with value of default_value' do it 'includes Setting with value of default_value' do
setting = described_class.all_as_records[key] setting = described_class.all_as_records[key]
@ -152,7 +152,7 @@ RSpec.describe Setting, type: :model do
end end
end end
context 'default_value is a Hash' do context 'when default_value is a Hash' do
let(:default_value) { { 'foo' => 'fuga' } } let(:default_value) { { 'foo' => 'fuga' } }
it 'returns {}' do it 'returns {}' do
@ -169,7 +169,7 @@ RSpec.describe Setting, type: :model do
allow(RailsSettings::Default).to receive(:enabled?).and_return(enabled) allow(RailsSettings::Default).to receive(:enabled?).and_return(enabled)
end end
context 'RailsSettings::Default.enabled? is false' do context 'when RailsSettings::Default.enabled? is false' do
let(:enabled) { false } let(:enabled) { false }
it 'returns {}' do it 'returns {}' do
@ -177,7 +177,7 @@ RSpec.describe Setting, type: :model do
end end
end end
context 'RailsSettings::Settings.enabled? is true' do context 'when RailsSettings::Settings.enabled? is true' do
let(:enabled) { true } let(:enabled) { true }
it 'returns instance of RailsSettings::Default' do it 'returns instance of RailsSettings::Default' do

View File

@ -49,22 +49,22 @@ RSpec.describe Status, type: :model do
end end
describe '#verb' do describe '#verb' do
context 'if destroyed?' do context 'when destroyed?' do
it 'returns :delete' do it 'returns :delete' do
subject.destroy! subject.destroy!
expect(subject.verb).to be :delete expect(subject.verb).to be :delete
end end
end end
context 'unless destroyed?' do context 'when not destroyed?' do
context 'if reblog?' do context 'when reblog?' do
it 'returns :share' do it 'returns :share' do
subject.reblog = other subject.reblog = other
expect(subject.verb).to be :share expect(subject.verb).to be :share
end end
end end
context 'unless reblog?' do context 'when not reblog?' do
it 'returns :post' do it 'returns :post' do
subject.reblog = nil subject.reblog = nil
expect(subject.verb).to be :post expect(subject.verb).to be :post
@ -85,28 +85,28 @@ RSpec.describe Status, type: :model do
end end
describe '#hidden?' do describe '#hidden?' do
context 'if private_visibility?' do context 'when private_visibility?' do
it 'returns true' do it 'returns true' do
subject.visibility = :private subject.visibility = :private
expect(subject.hidden?).to be true expect(subject.hidden?).to be true
end end
end end
context 'if direct_visibility?' do context 'when direct_visibility?' do
it 'returns true' do it 'returns true' do
subject.visibility = :direct subject.visibility = :direct
expect(subject.hidden?).to be true expect(subject.hidden?).to be true
end end
end end
context 'if public_visibility?' do context 'when public_visibility?' do
it 'returns false' do it 'returns false' do
subject.visibility = :public subject.visibility = :public
expect(subject.hidden?).to be false expect(subject.hidden?).to be false
end end
end end
context 'if unlisted_visibility?' do context 'when unlisted_visibility?' do
it 'returns false' do it 'returns false' do
subject.visibility = :unlisted subject.visibility = :unlisted
expect(subject.hidden?).to be false expect(subject.hidden?).to be false

View File

@ -56,7 +56,7 @@ RSpec.describe Web::PushSubscription, type: :model do
context 'when policy is followed' do context 'when policy is followed' do
let(:policy) { 'followed' } let(:policy) { 'followed' }
context 'and notification is from someone you follow' do context 'when notification is from someone you follow' do
before do before do
account.follow!(notification.from_account) account.follow!(notification.from_account)
end end
@ -66,7 +66,7 @@ RSpec.describe Web::PushSubscription, type: :model do
end end
end end
context 'and notification is not from someone you follow' do context 'when notification is not from someone you follow' do
it 'returns false' do it 'returns false' do
expect(subject.pushable?(notification)).to be false expect(subject.pushable?(notification)).to be false
end end
@ -76,7 +76,7 @@ RSpec.describe Web::PushSubscription, type: :model do
context 'when policy is follower' do context 'when policy is follower' do
let(:policy) { 'follower' } let(:policy) { 'follower' }
context 'and notification is from someone who follows you' do context 'when notification is from someone who follows you' do
before do before do
notification.from_account.follow!(account) notification.from_account.follow!(account)
end end
@ -86,7 +86,7 @@ RSpec.describe Web::PushSubscription, type: :model do
end end
end end
context 'and notification is not from someone who follows you' do context 'when notification is not from someone who follows you' do
it 'returns false' do it 'returns false' do
expect(subject.pushable?(notification)).to be false expect(subject.pushable?(notification)).to be false
end end

View File

@ -9,13 +9,13 @@ RSpec.describe AccountModerationNotePolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :create? do permissions :create? do
context 'staff' do context 'when staff' do
it 'grants to create' do it 'grants to create' do
expect(subject).to permit(admin, AccountModerationNotePolicy) expect(subject).to permit(admin, AccountModerationNotePolicy)
end end
end end
context 'not staff' do context 'when not staff' do
it 'denies to create' do it 'denies to create' do
expect(subject).to_not permit(john, AccountModerationNotePolicy) expect(subject).to_not permit(john, AccountModerationNotePolicy)
end end
@ -29,19 +29,19 @@ RSpec.describe AccountModerationNotePolicy do
target_account: Fabricate(:account)) target_account: Fabricate(:account))
end end
context 'admin' do context 'when admin' do
it 'grants to destroy' do it 'grants to destroy' do
expect(subject).to permit(admin, account_moderation_note) expect(subject).to permit(admin, account_moderation_note)
end end
end end
context 'owner' do context 'when owner' do
it 'grants to destroy' do it 'grants to destroy' do
expect(subject).to permit(john, account_moderation_note) expect(subject).to permit(john, account_moderation_note)
end end
end end
context 'neither admin nor owner' do context 'when neither admin nor owner' do
let(:kevin) { Fabricate(:account) } let(:kevin) { Fabricate(:account) }
it 'denies to destroy' do it 'denies to destroy' do

View File

@ -10,13 +10,13 @@ RSpec.describe AccountPolicy do
let(:alice) { Fabricate(:account) } let(:alice) { Fabricate(:account) }
permissions :index? do permissions :index? do
context 'staff' do context 'when staff' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin) expect(subject).to permit(admin)
end end
end end
context 'not staff' do context 'when not staff' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john) expect(subject).to_not permit(john)
end end
@ -24,13 +24,13 @@ RSpec.describe AccountPolicy do
end end
permissions :show?, :unsilence?, :unsensitive?, :remove_avatar?, :remove_header? do permissions :show?, :unsilence?, :unsensitive?, :remove_avatar?, :remove_header? do
context 'staff' do context 'when staff' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, alice) expect(subject).to permit(admin, alice)
end end
end end
context 'not staff' do context 'when not staff' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, alice) expect(subject).to_not permit(john, alice)
end end
@ -42,13 +42,13 @@ RSpec.describe AccountPolicy do
alice.suspend! alice.suspend!
end end
context 'staff' do context 'when staff' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, alice) expect(subject).to permit(admin, alice)
end end
end end
context 'not staff' do context 'when not staff' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, alice) expect(subject).to_not permit(john, alice)
end end
@ -56,13 +56,13 @@ RSpec.describe AccountPolicy do
end end
permissions :redownload? do permissions :redownload? do
context 'admin' do context 'when admin' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin) expect(subject).to permit(admin)
end end
end end
context 'not admin' do context 'when not admin' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john) expect(subject).to_not permit(john)
end end
@ -72,21 +72,21 @@ RSpec.describe AccountPolicy do
permissions :suspend?, :silence? do permissions :suspend?, :silence? do
let(:staff) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:staff) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
context 'staff' do context 'when staff' do
context 'record is staff' do context 'when record is staff' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(admin, staff) expect(subject).to_not permit(admin, staff)
end end
end end
context 'record is not staff' do context 'when record is not staff' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, john) expect(subject).to permit(admin, john)
end end
end end
end end
context 'not staff' do context 'when not staff' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, Account) expect(subject).to_not permit(john, Account)
end end
@ -96,21 +96,21 @@ RSpec.describe AccountPolicy do
permissions :memorialize? do permissions :memorialize? do
let(:other_admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account } let(:other_admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
context 'admin' do context 'when admin' do
context 'record is admin' do context 'when record is admin' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(admin, other_admin) expect(subject).to_not permit(admin, other_admin)
end end
end end
context 'record is not admin' do context 'when record is not admin' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, john) expect(subject).to permit(admin, john)
end end
end end
end end
context 'not admin' do context 'when not admin' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, Account) expect(subject).to_not permit(john, Account)
end end
@ -118,13 +118,13 @@ RSpec.describe AccountPolicy do
end end
permissions :review? do permissions :review? do
context 'admin' do context 'when admin' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin) expect(subject).to permit(admin)
end end
end end
context 'not admin' do context 'when not admin' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john) expect(subject).to_not permit(john)
end end
@ -132,7 +132,7 @@ RSpec.describe AccountPolicy do
end end
permissions :destroy? do permissions :destroy? do
context 'admin' do context 'when admin' do
context 'with a temporarily suspended account' do context 'with a temporarily suspended account' do
before { allow(alice).to receive(:suspended_temporarily?).and_return(true) } before { allow(alice).to receive(:suspended_temporarily?).and_return(true) }
@ -150,7 +150,7 @@ RSpec.describe AccountPolicy do
end end
end end
context 'not admin' do context 'when not admin' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, alice) expect(subject).to_not permit(john, alice)
end end

View File

@ -8,20 +8,20 @@ RSpec.describe BackupPolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :create? do permissions :create? do
context 'not user_signed_in?' do context 'when not user_signed_in?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(nil, Backup) expect(subject).to_not permit(nil, Backup)
end end
end end
context 'user_signed_in?' do context 'when user_signed_in?' do
context 'no backups' do context 'with no backups' do
it 'permits' do it 'permits' do
expect(subject).to permit(john, Backup) expect(subject).to permit(john, Backup)
end end
end end
context 'backups are too old' do context 'when backups are too old' do
it 'permits' do it 'permits' do
travel(-8.days) do travel(-8.days) do
Fabricate(:backup, user: john.user) Fabricate(:backup, user: john.user)
@ -31,7 +31,7 @@ RSpec.describe BackupPolicy do
end end
end end
context 'backups are newer' do context 'when backups are newer' do
it 'denies' do it 'denies' do
travel(-3.days) do travel(-3.days) do
Fabricate(:backup, user: john.user) Fabricate(:backup, user: john.user)

View File

@ -9,13 +9,13 @@ RSpec.describe CustomEmojiPolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :index?, :enable?, :disable? do permissions :index?, :enable?, :disable? do
context 'staff' do context 'when staff' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, CustomEmoji) expect(subject).to permit(admin, CustomEmoji)
end end
end end
context 'not staff' do context 'when not staff' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, CustomEmoji) expect(subject).to_not permit(john, CustomEmoji)
end end
@ -23,13 +23,13 @@ RSpec.describe CustomEmojiPolicy do
end end
permissions :create?, :update?, :copy?, :destroy? do permissions :create?, :update?, :copy?, :destroy? do
context 'admin' do context 'when admin' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, CustomEmoji) expect(subject).to permit(admin, CustomEmoji)
end end
end end
context 'not admin' do context 'when not admin' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, CustomEmoji) expect(subject).to_not permit(john, CustomEmoji)
end end

View File

@ -9,13 +9,13 @@ RSpec.describe DomainBlockPolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :index?, :show?, :create?, :destroy? do permissions :index?, :show?, :create?, :destroy? do
context 'admin' do context 'when admin' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, DomainBlock) expect(subject).to permit(admin, DomainBlock)
end end
end end
context 'not admin' do context 'when not admin' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, DomainBlock) expect(subject).to_not permit(john, DomainBlock)
end end

View File

@ -9,13 +9,13 @@ RSpec.describe EmailDomainBlockPolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :index?, :show?, :create?, :destroy? do permissions :index?, :show?, :create?, :destroy? do
context 'admin' do context 'when admin' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, EmailDomainBlock) expect(subject).to permit(admin, EmailDomainBlock)
end end
end end
context 'not admin' do context 'when not admin' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, EmailDomainBlock) expect(subject).to_not permit(john, EmailDomainBlock)
end end

View File

@ -9,13 +9,13 @@ RSpec.describe InstancePolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :index?, :show?, :destroy? do permissions :index?, :show?, :destroy? do
context 'admin' do context 'when admin' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, Instance) expect(subject).to permit(admin, Instance)
end end
end end
context 'not admin' do context 'when not admin' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, Instance) expect(subject).to_not permit(john, Instance)
end end

View File

@ -9,7 +9,7 @@ RSpec.describe InvitePolicy do
let(:john) { Fabricate(:user).account } let(:john) { Fabricate(:user).account }
permissions :index? do permissions :index? do
context 'staff?' do context 'when staff?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, Invite) expect(subject).to permit(admin, Invite)
end end
@ -17,7 +17,7 @@ RSpec.describe InvitePolicy do
end end
permissions :create? do permissions :create? do
context 'has privilege' do context 'with privilege' do
before do before do
UserRole.everyone.update(permissions: UserRole::FLAGS[:invite_users]) UserRole.everyone.update(permissions: UserRole::FLAGS[:invite_users])
end end
@ -27,7 +27,7 @@ RSpec.describe InvitePolicy do
end end
end end
context 'does not have privilege' do context 'when does not have privilege' do
before do before do
UserRole.everyone.update(permissions: UserRole::Flags::NONE) UserRole.everyone.update(permissions: UserRole::Flags::NONE)
end end
@ -39,13 +39,13 @@ RSpec.describe InvitePolicy do
end end
permissions :deactivate_all? do permissions :deactivate_all? do
context 'admin?' do context 'when admin?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, Invite) expect(subject).to permit(admin, Invite)
end end
end end
context 'not admin?' do context 'when not admin?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, Invite) expect(subject).to_not permit(john, Invite)
end end
@ -53,20 +53,20 @@ RSpec.describe InvitePolicy do
end end
permissions :destroy? do permissions :destroy? do
context 'owner?' do context 'when owner?' do
it 'permits' do it 'permits' do
expect(subject).to permit(john, Fabricate(:invite, user: john.user)) expect(subject).to permit(john, Fabricate(:invite, user: john.user))
end end
end end
context 'not owner?' do context 'when not owner?' do
context 'admin?' do context 'when admin?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, Fabricate(:invite)) expect(subject).to permit(admin, Fabricate(:invite))
end end
end end
context 'not admin?' do context 'when not admin?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, Fabricate(:invite)) expect(subject).to_not permit(john, Fabricate(:invite))
end end

View File

@ -9,13 +9,13 @@ RSpec.describe RelayPolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :update? do permissions :update? do
context 'admin?' do context 'when admin?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, Relay) expect(subject).to permit(admin, Relay)
end end
end end
context '!admin?' do context 'with !admin?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, Relay) expect(subject).to_not permit(john, Relay)
end end

View File

@ -9,13 +9,13 @@ RSpec.describe ReportNotePolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :create? do permissions :create? do
context 'staff?' do context 'when staff?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, ReportNote) expect(subject).to permit(admin, ReportNote)
end end
end end
context '!staff?' do context 'with !staff?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, ReportNote) expect(subject).to_not permit(john, ReportNote)
end end
@ -23,22 +23,22 @@ RSpec.describe ReportNotePolicy do
end end
permissions :destroy? do permissions :destroy? do
context 'admin?' do context 'when admin?' do
it 'permit' do it 'permit' do
report_note = Fabricate(:report_note, account: john) report_note = Fabricate(:report_note, account: john)
expect(subject).to permit(admin, report_note) expect(subject).to permit(admin, report_note)
end end
end end
context 'admin?' do context 'when admin?' do
context 'owner?' do context 'when owner?' do
it 'permit' do it 'permit' do
report_note = Fabricate(:report_note, account: john) report_note = Fabricate(:report_note, account: john)
expect(subject).to permit(john, report_note) expect(subject).to permit(john, report_note)
end end
end end
context '!owner?' do context 'with !owner?' do
it 'denies' do it 'denies' do
report_note = Fabricate(:report_note) report_note = Fabricate(:report_note)
expect(subject).to_not permit(john, report_note) expect(subject).to_not permit(john, report_note)

View File

@ -9,13 +9,13 @@ RSpec.describe ReportPolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :update?, :index?, :show? do permissions :update?, :index?, :show? do
context 'staff?' do context 'when staff?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, Report) expect(subject).to permit(admin, Report)
end end
end end
context '!staff?' do context 'with !staff?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, Report) expect(subject).to_not permit(john, Report)
end end

View File

@ -9,13 +9,13 @@ RSpec.describe SettingsPolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :update?, :show?, :destroy? do permissions :update?, :show?, :destroy? do
context 'admin?' do context 'when admin?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, Settings) expect(subject).to permit(admin, Settings)
end end
end end
context '!admin?' do context 'with !admin?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, Settings) expect(subject).to_not permit(john, Settings)
end end

View File

@ -9,13 +9,13 @@ RSpec.describe TagPolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :index?, :show?, :update?, :review? do permissions :index?, :show?, :update?, :review? do
context 'staff?' do context 'when staff?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, Tag) expect(subject).to permit(admin, Tag)
end end
end end
context '!staff?' do context 'with !staff?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, Tag) expect(subject).to_not permit(john, Tag)
end end

View File

@ -9,21 +9,21 @@ RSpec.describe UserPolicy do
let(:john) { Fabricate(:account) } let(:john) { Fabricate(:account) }
permissions :reset_password?, :change_email? do permissions :reset_password?, :change_email? do
context 'staff?' do context 'when staff?' do
context '!record.staff?' do context 'with !record.staff?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, john.user) expect(subject).to permit(admin, john.user)
end end
end end
context 'record.staff?' do context 'when record.staff?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(admin, admin.user) expect(subject).to_not permit(admin, admin.user)
end end
end end
end end
context '!staff?' do context 'with !staff?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, User) expect(subject).to_not permit(john, User)
end end
@ -31,21 +31,21 @@ RSpec.describe UserPolicy do
end end
permissions :disable_2fa? do permissions :disable_2fa? do
context 'admin?' do context 'when admin?' do
context '!record.staff?' do context 'with !record.staff?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, john.user) expect(subject).to permit(admin, john.user)
end end
end end
context 'record.staff?' do context 'when record.staff?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(admin, admin.user) expect(subject).to_not permit(admin, admin.user)
end end
end end
end end
context '!admin?' do context 'with !admin?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, User) expect(subject).to_not permit(john, User)
end end
@ -53,15 +53,15 @@ RSpec.describe UserPolicy do
end end
permissions :confirm? do permissions :confirm? do
context 'staff?' do context 'when staff?' do
context '!record.confirmed?' do context 'with !record.confirmed?' do
it 'permits' do it 'permits' do
john.user.update(confirmed_at: nil) john.user.update(confirmed_at: nil)
expect(subject).to permit(admin, john.user) expect(subject).to permit(admin, john.user)
end end
end end
context 'record.confirmed?' do context 'when record.confirmed?' do
it 'denies' do it 'denies' do
john.user.confirm! john.user.confirm!
expect(subject).to_not permit(admin, john.user) expect(subject).to_not permit(admin, john.user)
@ -69,7 +69,7 @@ RSpec.describe UserPolicy do
end end
end end
context '!staff?' do context 'with !staff?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, User) expect(subject).to_not permit(john, User)
end end
@ -77,13 +77,13 @@ RSpec.describe UserPolicy do
end end
permissions :enable? do permissions :enable? do
context 'staff?' do context 'when staff?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, User) expect(subject).to permit(admin, User)
end end
end end
context '!staff?' do context 'with !staff?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, User) expect(subject).to_not permit(john, User)
end end
@ -91,21 +91,21 @@ RSpec.describe UserPolicy do
end end
permissions :disable? do permissions :disable? do
context 'staff?' do context 'when staff?' do
context '!record.admin?' do context 'with !record.admin?' do
it 'permits' do it 'permits' do
expect(subject).to permit(admin, john.user) expect(subject).to permit(admin, john.user)
end end
end end
context 'record.admin?' do context 'when record.admin?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(admin, admin.user) expect(subject).to_not permit(admin, admin.user)
end end
end end
end end
context '!staff?' do context 'with !staff?' do
it 'denies' do it 'denies' do
expect(subject).to_not permit(john, User) expect(subject).to_not permit(john, User)
end end

View File

@ -19,7 +19,7 @@ RSpec.describe AccountRelationshipsPresenter do
let(:account_ids) { [Fabricate(:account).id] } let(:account_ids) { [Fabricate(:account).id] }
let(:default_map) { { 1 => true } } let(:default_map) { { 1 => true } }
context 'options are not set' do context 'when options are not set' do
let(:options) { {} } let(:options) { {} }
it 'sets default maps' do it 'sets default maps' do
@ -32,7 +32,7 @@ RSpec.describe AccountRelationshipsPresenter do
end end
end end
context 'options[:following_map] is set' do context 'when options[:following_map] is set' do
let(:options) { { following_map: { 2 => true } } } let(:options) { { following_map: { 2 => true } } }
it 'sets @following merged with default_map and options[:following_map]' do it 'sets @following merged with default_map and options[:following_map]' do
@ -40,7 +40,7 @@ RSpec.describe AccountRelationshipsPresenter do
end end
end end
context 'options[:followed_by_map] is set' do context 'when options[:followed_by_map] is set' do
let(:options) { { followed_by_map: { 3 => true } } } let(:options) { { followed_by_map: { 3 => true } } }
it 'sets @followed_by merged with default_map and options[:followed_by_map]' do it 'sets @followed_by merged with default_map and options[:followed_by_map]' do
@ -48,7 +48,7 @@ RSpec.describe AccountRelationshipsPresenter do
end end
end end
context 'options[:blocking_map] is set' do context 'when options[:blocking_map] is set' do
let(:options) { { blocking_map: { 4 => true } } } let(:options) { { blocking_map: { 4 => true } } }
it 'sets @blocking merged with default_map and options[:blocking_map]' do it 'sets @blocking merged with default_map and options[:blocking_map]' do
@ -56,7 +56,7 @@ RSpec.describe AccountRelationshipsPresenter do
end end
end end
context 'options[:muting_map] is set' do context 'when options[:muting_map] is set' do
let(:options) { { muting_map: { 5 => true } } } let(:options) { { muting_map: { 5 => true } } }
it 'sets @muting merged with default_map and options[:muting_map]' do it 'sets @muting merged with default_map and options[:muting_map]' do
@ -64,7 +64,7 @@ RSpec.describe AccountRelationshipsPresenter do
end end
end end
context 'options[:requested_map] is set' do context 'when options[:requested_map] is set' do
let(:options) { { requested_map: { 6 => true } } } let(:options) { { requested_map: { 6 => true } } }
it 'sets @requested merged with default_map and options[:requested_map]' do it 'sets @requested merged with default_map and options[:requested_map]' do
@ -72,7 +72,7 @@ RSpec.describe AccountRelationshipsPresenter do
end end
end end
context 'options[:requested_by_map] is set' do context 'when options[:requested_by_map] is set' do
let(:options) { { requested_by_map: { 6 => true } } } let(:options) { { requested_by_map: { 6 => true } } }
it 'sets @requested merged with default_map and options[:requested_by_map]' do it 'sets @requested merged with default_map and options[:requested_by_map]' do
@ -80,7 +80,7 @@ RSpec.describe AccountRelationshipsPresenter do
end end
end end
context 'options[:domain_blocking_map] is set' do context 'when options[:domain_blocking_map] is set' do
let(:options) { { domain_blocking_map: { 7 => true } } } let(:options) { { domain_blocking_map: { 7 => true } } }
it 'sets @domain_blocking merged with default_map and options[:domain_blocking_map]' do it 'sets @domain_blocking merged with default_map and options[:domain_blocking_map]' do

View File

@ -18,7 +18,7 @@ RSpec.describe StatusRelationshipsPresenter do
let(:status_ids) { statuses.map(&:id) + statuses.map(&:reblog_of_id).compact } let(:status_ids) { statuses.map(&:id) + statuses.map(&:reblog_of_id).compact }
let(:default_map) { { 1 => true } } let(:default_map) { { 1 => true } }
context 'options are not set' do context 'when options are not set' do
let(:options) { {} } let(:options) { {} }
it 'sets default maps' do it 'sets default maps' do
@ -30,7 +30,7 @@ RSpec.describe StatusRelationshipsPresenter do
end end
end end
context 'options[:reblogs_map] is set' do context 'when options[:reblogs_map] is set' do
let(:options) { { reblogs_map: { 2 => true } } } let(:options) { { reblogs_map: { 2 => true } } }
it 'sets @reblogs_map merged with default_map and options[:reblogs_map]' do it 'sets @reblogs_map merged with default_map and options[:reblogs_map]' do
@ -38,7 +38,7 @@ RSpec.describe StatusRelationshipsPresenter do
end end
end end
context 'options[:favourites_map] is set' do context 'when options[:favourites_map] is set' do
let(:options) { { favourites_map: { 3 => true } } } let(:options) { { favourites_map: { 3 => true } } }
it 'sets @favourites_map merged with default_map and options[:favourites_map]' do it 'sets @favourites_map merged with default_map and options[:favourites_map]' do
@ -46,7 +46,7 @@ RSpec.describe StatusRelationshipsPresenter do
end end
end end
context 'options[:bookmarks_map] is set' do context 'when options[:bookmarks_map] is set' do
let(:options) { { bookmarks_map: { 4 => true } } } let(:options) { { bookmarks_map: { 4 => true } } }
it 'sets @bookmarks_map merged with default_map and options[:bookmarks_map]' do it 'sets @bookmarks_map merged with default_map and options[:bookmarks_map]' do
@ -54,7 +54,7 @@ RSpec.describe StatusRelationshipsPresenter do
end end
end end
context 'options[:mutes_map] is set' do context 'when options[:mutes_map] is set' do
let(:options) { { mutes_map: { 5 => true } } } let(:options) { { mutes_map: { 5 => true } } }
it 'sets @mutes_map merged with default_map and options[:mutes_map]' do it 'sets @mutes_map merged with default_map and options[:mutes_map]' do
@ -62,7 +62,7 @@ RSpec.describe StatusRelationshipsPresenter do
end end
end end
context 'options[:pins_map] is set' do context 'when options[:pins_map] is set' do
let(:options) { { pins_map: { 6 => true } } } let(:options) { { pins_map: { 6 => true } } }
it 'sets @pins_map merged with default_map and options[:pins_map]' do it 'sets @pins_map merged with default_map and options[:pins_map]' do

View File

@ -20,7 +20,7 @@ describe AccountSearchService, type: :service do
end end
end end
context 'searching for a simple term that is not an exact match' do context 'when searching for a simple term that is not an exact match' do
it 'does not return a nil entry in the array for the exact match' do it 'does not return a nil entry in the array for the exact match' do
account = Fabricate(:account, username: 'matchingusername') account = Fabricate(:account, username: 'matchingusername')
results = subject.call('match', nil, limit: 5) results = subject.call('match', nil, limit: 5)

View File

@ -20,13 +20,13 @@ describe AccountStatusesCleanupService, type: :service do
let!(:another_old_status) { Fabricate(:status, created_at: 1.year.ago, account: account) } let!(:another_old_status) { Fabricate(:status, created_at: 1.year.ago, account: account) }
let!(:recent_status) { Fabricate(:status, created_at: 1.day.ago, account: account) } let!(:recent_status) { Fabricate(:status, created_at: 1.day.ago, account: account) }
context 'given a budget of 1' do context 'when given a budget of 1' do
it 'reports 1 deleted toot' do it 'reports 1 deleted toot' do
expect(subject.call(account_policy, 1)).to eq 1 expect(subject.call(account_policy, 1)).to eq 1
end end
end end
context 'given a normal budget of 10' do context 'when given a normal budget of 10' do
it 'reports 3 deleted statuses' do it 'reports 3 deleted statuses' do
expect(subject.call(account_policy, 10)).to eq 3 expect(subject.call(account_policy, 10)).to eq 3
end end

View File

@ -226,12 +226,12 @@ RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do
end end
end end
context 'statuses referencing other statuses' do context 'with statuses referencing other statuses' do
before do before do
stub_const 'ActivityPub::FetchRemoteStatusService::DISCOVERIES_PER_REQUEST', 5 stub_const 'ActivityPub::FetchRemoteStatusService::DISCOVERIES_PER_REQUEST', 5
end end
context 'using inReplyTo' do context 'when using inReplyTo' do
let(:object) do let(:object) do
{ {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
@ -267,7 +267,7 @@ RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do
end end
end end
context 'using replies' do context 'when using replies' do
let(:object) do let(:object) do
{ {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',

View File

@ -5,7 +5,7 @@ require 'rails_helper'
RSpec.describe ActivityPub::ProcessAccountService, type: :service do RSpec.describe ActivityPub::ProcessAccountService, type: :service do
subject { described_class.new } subject { described_class.new }
context 'property values' do context 'with property values' do
let(:payload) do let(:payload) do
{ {
id: 'https://foo.test', id: 'https://foo.test',
@ -82,7 +82,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
account.suspend!(origin: suspension_origin) account.suspend!(origin: suspension_origin)
end end
context 'locally' do context 'when locally' do
let(:suspension_origin) { :local } let(:suspension_origin) { :local }
it 'does not unsuspend it' do it 'does not unsuspend it' do
@ -94,7 +94,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end end
end end
context 'remotely' do context 'when remotely' do
let(:suspension_origin) { :remote } let(:suspension_origin) { :remote }
it 'unsuspends it' do it 'unsuspends it' do
@ -112,7 +112,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end end
end end
context 'discovering many subdomains in a short timeframe' do context 'when discovering many subdomains in a short timeframe' do
before do before do
stub_const 'ActivityPub::ProcessAccountService::SUBDOMAINS_RATELIMIT', 5 stub_const 'ActivityPub::ProcessAccountService::SUBDOMAINS_RATELIMIT', 5
end end
@ -138,7 +138,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end end
end end
context 'accounts referencing other accounts' do context 'when Accounts referencing other accounts' do
before do before do
stub_const 'ActivityPub::ProcessAccountService::DISCOVERIES_PER_REQUEST', 5 stub_const 'ActivityPub::ProcessAccountService::DISCOVERIES_PER_REQUEST', 5
end end

View File

@ -269,7 +269,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end end
end end
context 'originally without tags' do context 'when originally without tags' do
before do before do
subject.call(status, json) subject.call(status, json)
end end
@ -279,7 +279,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end end
end end
context 'originally with tags' do context 'when originally with tags' do
let(:tags) { [Fabricate(:tag, name: 'test'), Fabricate(:tag, name: 'foo')] } let(:tags) { [Fabricate(:tag, name: 'test'), Fabricate(:tag, name: 'foo')] }
let(:payload) do let(:payload) do
@ -305,7 +305,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end end
end end
context 'originally without mentions' do context 'when originally without mentions' do
before do before do
subject.call(status, json) subject.call(status, json)
end end
@ -315,7 +315,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end end
end end
context 'originally with mentions' do context 'when originally with mentions' do
let(:mentions) { [alice, bob] } let(:mentions) { [alice, bob] }
before do before do
@ -327,7 +327,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end end
end end
context 'originally without media attachments' do context 'when originally without media attachments' do
before do before do
stub_request(:get, 'https://example.com/foo.png').to_return(body: attachment_fixture('emojo.png')) stub_request(:get, 'https://example.com/foo.png').to_return(body: attachment_fixture('emojo.png'))
subject.call(status, json) subject.call(status, json)
@ -362,7 +362,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end end
end end
context 'originally with media attachments' do context 'when originally with media attachments' do
let(:media_attachments) { [Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png'), Fabricate(:media_attachment, remote_url: 'https://example.com/unused.png')] } let(:media_attachments) { [Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png'), Fabricate(:media_attachment, remote_url: 'https://example.com/unused.png')] }
let(:payload) do let(:payload) do
@ -404,7 +404,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end end
end end
context 'originally with a poll' do context 'when originally with a poll' do
before do before do
poll = Fabricate(:poll, status: status) poll = Fabricate(:poll, status: status)
status.update(preloadable_poll: poll) status.update(preloadable_poll: poll)
@ -420,7 +420,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end end
end end
context 'originally without a poll' do context 'when originally without a poll' do
let(:payload) do let(:payload) do
{ {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',

View File

@ -18,7 +18,7 @@ RSpec.describe FetchLinkCardService, type: :service do
subject.call(status) subject.call(status)
end end
context 'in a local status' do context 'with a local status' do
context do context do
let(:status) { Fabricate(:status, text: 'Check out http://example.中国') } let(:status) { Fabricate(:status, text: 'Check out http://example.中国') }
@ -89,7 +89,7 @@ RSpec.describe FetchLinkCardService, type: :service do
end end
end end
context 'in a remote status' do context 'with a remote status' do
let(:status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com'), text: 'Habt ihr ein paar gute Links zu <a>foo</a> #<span class="tag"><a href="https://quitter.se/tag/wannacry" target="_blank" rel="tag noopener noreferrer" title="https://quitter.se/tag/wannacry">Wannacry</a></span> herumfliegen? Ich will mal unter <br> <a href="https://github.com/qbi/WannaCry" target="_blank" rel="noopener noreferrer" title="https://github.com/qbi/WannaCry">https://github.com/qbi/WannaCry</a> was sammeln. !<a href="http://sn.jonkman.ca/group/416/id" target="_blank" rel="noopener noreferrer" title="http://sn.jonkman.ca/group/416/id">security</a>&nbsp;') } let(:status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com'), text: 'Habt ihr ein paar gute Links zu <a>foo</a> #<span class="tag"><a href="https://quitter.se/tag/wannacry" target="_blank" rel="tag noopener noreferrer" title="https://quitter.se/tag/wannacry">Wannacry</a></span> herumfliegen? Ich will mal unter <br> <a href="https://github.com/qbi/WannaCry" target="_blank" rel="noopener noreferrer" title="https://github.com/qbi/WannaCry">https://github.com/qbi/WannaCry</a> was sammeln. !<a href="http://sn.jonkman.ca/group/416/id" target="_blank" rel="noopener noreferrer" title="http://sn.jonkman.ca/group/416/id">security</a>&nbsp;') }
it 'parses out URLs' do it 'parses out URLs' do

View File

@ -39,7 +39,7 @@ describe FetchOEmbedService, type: :service do
end end
end end
context 'Both of JSON and XML provider are discoverable' do context 'when both of JSON and XML provider are discoverable' do
before do before do
stub_request(:get, 'https://host.test/oembed.html').to_return( stub_request(:get, 'https://host.test/oembed.html').to_return(
status: 200, status: 200,
@ -66,7 +66,7 @@ describe FetchOEmbedService, type: :service do
end end
end end
context 'JSON provider is discoverable while XML provider is not' do context 'when JSON provider is discoverable while XML provider is not' do
before do before do
stub_request(:get, 'https://host.test/oembed.html').to_return( stub_request(:get, 'https://host.test/oembed.html').to_return(
status: 200, status: 200,
@ -87,7 +87,7 @@ describe FetchOEmbedService, type: :service do
end end
end end
context 'XML provider is discoverable while JSON provider is not' do context 'when XML provider is discoverable while JSON provider is not' do
before do before do
stub_request(:get, 'https://host.test/oembed.html').to_return( stub_request(:get, 'https://host.test/oembed.html').to_return(
status: 200, status: 200,
@ -108,7 +108,7 @@ describe FetchOEmbedService, type: :service do
end end
end end
context 'Invalid XML provider is discoverable while JSON provider is not' do context 'with Invalid XML provider is discoverable while JSON provider is not' do
before do before do
stub_request(:get, 'https://host.test/oembed.html').to_return( stub_request(:get, 'https://host.test/oembed.html').to_return(
status: 200, status: 200,
@ -122,7 +122,7 @@ describe FetchOEmbedService, type: :service do
end end
end end
context 'Neither of JSON and XML provider is discoverable' do context 'with neither of JSON and XML provider is discoverable' do
before do before do
stub_request(:get, 'https://host.test/oembed.html').to_return( stub_request(:get, 'https://host.test/oembed.html').to_return(
status: 200, status: 200,
@ -136,7 +136,7 @@ describe FetchOEmbedService, type: :service do
end end
end end
context 'Empty JSON provider is discoverable' do context 'when empty JSON provider is discoverable' do
before do before do
stub_request(:get, 'https://host.test/oembed.html').to_return( stub_request(:get, 'https://host.test/oembed.html').to_return(
status: 200, status: 200,

View File

@ -16,7 +16,7 @@ RSpec.describe FetchRemoteStatusService, type: :service do
} }
end end
context 'protocol is :activitypub' do context 'when protocol is :activitypub' do
subject { described_class.new.call(note[:id], prefetched_body: prefetched_body) } subject { described_class.new.call(note[:id], prefetched_body: prefetched_body) }
let(:prefetched_body) { Oj.dump(note) } let(:prefetched_body) { Oj.dump(note) }

View File

@ -7,7 +7,7 @@ RSpec.describe FollowService, type: :service do
let(:sender) { Fabricate(:account, username: 'alice') } let(:sender) { Fabricate(:account, username: 'alice') }
context 'local account' do context 'when local account' do
describe 'locked account' do describe 'locked account' do
let(:bob) { Fabricate(:account, locked: true, username: 'bob') } let(:bob) { Fabricate(:account, locked: true, username: 'bob') }
@ -138,7 +138,7 @@ RSpec.describe FollowService, type: :service do
end end
end end
context 'remote ActivityPub account' do context 'when remote ActivityPub account' do
let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') } let(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
before do before do

View File

@ -13,7 +13,7 @@ RSpec.describe ImportService, type: :service do
stub_request(:post, 'https://example.com/inbox').to_return(status: 200) stub_request(:post, 'https://example.com/inbox').to_return(status: 200)
end end
context 'import old-style list of muted users' do context 'when importing old-style list of muted users' do
subject { ImportService.new } subject { ImportService.new }
let(:csv) { attachment_fixture('mute-imports.txt') } let(:csv) { attachment_fixture('mute-imports.txt') }
@ -51,7 +51,7 @@ RSpec.describe ImportService, type: :service do
end end
end end
context 'import new-style list of muted users' do context 'when importing new-style list of muted users' do
subject { ImportService.new } subject { ImportService.new }
let(:csv) { attachment_fixture('new-mute-imports.txt') } let(:csv) { attachment_fixture('new-mute-imports.txt') }
@ -92,7 +92,7 @@ RSpec.describe ImportService, type: :service do
end end
end end
context 'import old-style list of followed users' do context 'when importing old-style list of followed users' do
subject { ImportService.new } subject { ImportService.new }
let(:csv) { attachment_fixture('mute-imports.txt') } let(:csv) { attachment_fixture('mute-imports.txt') }
@ -134,7 +134,7 @@ RSpec.describe ImportService, type: :service do
end end
end end
context 'import new-style list of followed users' do context 'when importing new-style list of followed users' do
subject { ImportService.new } subject { ImportService.new }
let(:csv) { attachment_fixture('new-following-imports.txt') } let(:csv) { attachment_fixture('new-following-imports.txt') }
@ -181,7 +181,7 @@ RSpec.describe ImportService, type: :service do
# Based on the bug report 20571 where UTF-8 encoded domains were rejecting import of their users # Based on the bug report 20571 where UTF-8 encoded domains were rejecting import of their users
# #
# https://github.com/mastodon/mastodon/issues/20571 # https://github.com/mastodon/mastodon/issues/20571
context 'utf-8 encoded domains' do context 'with a utf-8 encoded domains' do
subject { ImportService.new } subject { ImportService.new }
let!(:nare) { Fabricate(:account, username: 'nare', domain: 'թութ.հայ', locked: false, protocol: :activitypub, inbox_url: 'https://թութ.հայ/inbox') } let!(:nare) { Fabricate(:account, username: 'nare', domain: 'թութ.հայ', locked: false, protocol: :activitypub, inbox_url: 'https://թութ.հայ/inbox') }
@ -200,7 +200,7 @@ RSpec.describe ImportService, type: :service do
end end
end end
context 'import bookmarks' do context 'when importing bookmarks' do
subject { ImportService.new } subject { ImportService.new }
let(:csv) { attachment_fixture('bookmark-imports.txt') } let(:csv) { attachment_fixture('bookmark-imports.txt') }

View File

@ -49,7 +49,7 @@ RSpec.describe NotifyService, type: :service do
expect { subject }.to_not change(Notification, :count) expect { subject }.to_not change(Notification, :count)
end end
context 'for direct messages' do context 'with direct messages' do
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct)) } let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct)) }
let(:type) { :mention } let(:type) { :mention }
@ -58,14 +58,14 @@ RSpec.describe NotifyService, type: :service do
user.save user.save
end end
context 'if recipient is supposed to be following sender' do context 'when recipient is supposed to be following sender' do
let(:enabled) { true } let(:enabled) { true }
it 'does not notify' do it 'does not notify' do
expect { subject }.to_not change(Notification, :count) expect { subject }.to_not change(Notification, :count)
end end
context 'if the message chain is initiated by recipient, but is not direct message' do context 'when the message chain is initiated by recipient, but is not direct message' do
let(:reply_to) { Fabricate(:status, account: recipient) } let(:reply_to) { Fabricate(:status, account: recipient) }
let!(:mention) { Fabricate(:mention, account: sender, status: reply_to) } let!(:mention) { Fabricate(:mention, account: sender, status: reply_to) }
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) } let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) }
@ -75,7 +75,7 @@ RSpec.describe NotifyService, type: :service do
end end
end end
context 'if the message chain is initiated by recipient, but without a mention to the sender, even if the sender sends multiple messages in a row' do context 'when the message chain is initiated by recipient, but without a mention to the sender, even if the sender sends multiple messages in a row' do
let(:reply_to) { Fabricate(:status, account: recipient) } let(:reply_to) { Fabricate(:status, account: recipient) }
let!(:mention) { Fabricate(:mention, account: sender, status: reply_to) } let!(:mention) { Fabricate(:mention, account: sender, status: reply_to) }
let(:dummy_reply) { Fabricate(:status, account: sender, visibility: :direct, thread: reply_to) } let(:dummy_reply) { Fabricate(:status, account: sender, visibility: :direct, thread: reply_to) }
@ -86,7 +86,7 @@ RSpec.describe NotifyService, type: :service do
end end
end end
context 'if the message chain is initiated by the recipient with a mention to the sender' do context 'when the message chain is initiated by the recipient with a mention to the sender' do
let(:reply_to) { Fabricate(:status, account: recipient, visibility: :direct) } let(:reply_to) { Fabricate(:status, account: recipient, visibility: :direct) }
let!(:mention) { Fabricate(:mention, account: sender, status: reply_to) } let!(:mention) { Fabricate(:mention, account: sender, status: reply_to) }
let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) } let(:activity) { Fabricate(:mention, account: recipient, status: Fabricate(:status, account: sender, visibility: :direct, thread: reply_to)) }
@ -97,7 +97,7 @@ RSpec.describe NotifyService, type: :service do
end end
end end
context 'if recipient is NOT supposed to be following sender' do context 'when recipient is NOT supposed to be following sender' do
let(:enabled) { false } let(:enabled) { false }
it 'does notify' do it 'does notify' do

View File

@ -33,10 +33,10 @@ RSpec.describe ProcessMentionsService, type: :service do
end end
end end
context 'resolving a mention to a remote account' do context 'with resolving a mention to a remote account' do
let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}", visibility: :public) } let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}", visibility: :public) }
context 'ActivityPub' do context 'with ActivityPub' do
context do context do
let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
@ -49,7 +49,7 @@ RSpec.describe ProcessMentionsService, type: :service do
end end
end end
context 'mentioning a user several times when not saving records' do context 'when mentioning a user several times when not saving records' do
let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct} @#{remote_user.acct} @#{remote_user.acct}", visibility: :public) } let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct} @#{remote_user.acct} @#{remote_user.acct}", visibility: :public) }
@ -89,7 +89,7 @@ RSpec.describe ProcessMentionsService, type: :service do
end end
end end
context 'Temporarily-unreachable ActivityPub user' do context 'with a Temporarily-unreachable ActivityPub user' do
let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox', last_webfingered_at: nil) } let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox', last_webfingered_at: nil) }
before do before do

View File

@ -5,7 +5,7 @@ require 'rails_helper'
RSpec.describe ReblogService, type: :service do RSpec.describe ReblogService, type: :service do
let(:alice) { Fabricate(:account, username: 'alice') } let(:alice) { Fabricate(:account, username: 'alice') }
context 'creates a reblog with appropriate visibility' do context 'when creates a reblog with appropriate visibility' do
subject { ReblogService.new } subject { ReblogService.new }
let(:visibility) { :public } let(:visibility) { :public }
@ -61,7 +61,7 @@ RSpec.describe ReblogService, type: :service do
end end
end end
context 'ActivityPub' do context 'with ActivityPub' do
subject { ReblogService.new } subject { ReblogService.new }
let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') } let(:bob) { Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }

View File

@ -7,7 +7,7 @@ RSpec.describe ReportService, type: :service do
let(:source_account) { Fabricate(:account) } let(:source_account) { Fabricate(:account) }
context 'for a remote account' do context 'with a remote account' do
let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') } let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
before do before do

View File

@ -15,7 +15,7 @@ RSpec.describe ResolveAccountService, type: :service do
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:hoge@example.com').to_return(status: 410) stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:hoge@example.com').to_return(status: 410)
end end
context 'using skip_webfinger' do context 'when using skip_webfinger' do
context 'when account is known' do context 'when account is known' do
let!(:remote_account) { Fabricate(:account, username: 'foo', domain: 'ap.example.com', protocol: 'activitypub') } let!(:remote_account) { Fabricate(:account, username: 'foo', domain: 'ap.example.com', protocol: 'activitypub') }
@ -78,7 +78,7 @@ RSpec.describe ResolveAccountService, type: :service do
end end
context 'when webfinger returns http gone' do context 'when webfinger returns http gone' do
context 'for a previously known account' do context 'with a previously known account' do
before do before do
Fabricate(:account, username: 'hoge', domain: 'example.com', last_webfingered_at: nil) Fabricate(:account, username: 'hoge', domain: 'example.com', last_webfingered_at: nil)
allow(AccountDeletionWorker).to receive(:perform_async) allow(AccountDeletionWorker).to receive(:perform_async)
@ -94,7 +94,7 @@ RSpec.describe ResolveAccountService, type: :service do
end end
end end
context 'for a previously unknown account' do context 'with a previously unknown account' do
it 'returns nil' do it 'returns nil' do
expect(subject.call('hoge@example.com')).to be_nil expect(subject.call('hoge@example.com')).to be_nil
end end

View File

@ -30,7 +30,7 @@ describe ResolveURLService, type: :service do
expect(subject.call(url)).to eq known_account expect(subject.call(url)).to eq known_account
end end
context 'searching for a remote private status' do context 'when searching for a remote private status' do
let(:account) { Fabricate(:account) } let(:account) { Fabricate(:account) }
let(:poster) { Fabricate(:account, domain: 'example.com') } let(:poster) { Fabricate(:account, domain: 'example.com') }
let(:url) { 'https://example.com/@foo/42' } let(:url) { 'https://example.com/@foo/42' }
@ -95,7 +95,7 @@ describe ResolveURLService, type: :service do
end end
end end
context 'searching for a local private status' do context 'when searching for a local private status' do
let(:account) { Fabricate(:account) } let(:account) { Fabricate(:account) }
let(:poster) { Fabricate(:account) } let(:poster) { Fabricate(:account) }
let!(:status) { Fabricate(:status, account: poster, visibility: :private) } let!(:status) { Fabricate(:status, account: poster, visibility: :private) }
@ -127,7 +127,7 @@ describe ResolveURLService, type: :service do
end end
end end
context 'searching for a link that redirects to a local public status' do context 'when searching for a link that redirects to a local public status' do
let(:account) { Fabricate(:account) } let(:account) { Fabricate(:account) }
let(:poster) { Fabricate(:account) } let(:poster) { Fabricate(:account) }
let!(:status) { Fabricate(:status, account: poster, visibility: :public) } let!(:status) { Fabricate(:status, account: poster, visibility: :public) }

View File

@ -23,7 +23,7 @@ describe SearchService, type: :service do
@query = 'http://test.host/query' @query = 'http://test.host/query'
end end
context 'that does not find anything' do context 'when it does not find anything' do
it 'returns the empty results' do it 'returns the empty results' do
service = double(call: nil) service = double(call: nil)
allow(ResolveURLService).to receive(:new).and_return(service) allow(ResolveURLService).to receive(:new).and_return(service)
@ -34,7 +34,7 @@ describe SearchService, type: :service do
end end
end end
context 'that finds an account' do context 'when it finds an account' do
it 'includes the account in the results' do it 'includes the account in the results' do
account = Account.new account = Account.new
service = double(call: account) service = double(call: account)
@ -46,7 +46,7 @@ describe SearchService, type: :service do
end end
end end
context 'that finds a status' do context 'when it finds a status' do
it 'includes the status in the results' do it 'includes the status in the results' do
status = Status.new status = Status.new
service = double(call: status) service = double(call: status)
@ -60,7 +60,7 @@ describe SearchService, type: :service do
end end
describe 'with a non-url query' do describe 'with a non-url query' do
context 'that matches an account' do context 'when it matches an account' do
it 'includes the account in the results' do it 'includes the account in the results' do
query = 'username' query = 'username'
account = Account.new account = Account.new
@ -73,7 +73,7 @@ describe SearchService, type: :service do
end end
end end
context 'that matches a tag' do context 'when it matches a tag' do
it 'includes the tag in the results' do it 'includes the tag in the results' do
query = '#tag' query = '#tag'
tag = Tag.new tag = Tag.new

View File

@ -12,7 +12,7 @@ RSpec.describe UnallowDomainService, type: :service do
let!(:already_banned_account) { Fabricate(:account, username: 'badguy', domain: 'evil.org', suspended: true, silenced: true) } let!(:already_banned_account) { Fabricate(:account, username: 'badguy', domain: 'evil.org', suspended: true, silenced: true) }
let!(:domain_allow) { Fabricate(:domain_allow, domain: 'evil.org') } let!(:domain_allow) { Fabricate(:domain_allow, domain: 'evil.org') }
context 'in limited federation mode' do context 'with limited federation mode' do
before do before do
allow(subject).to receive(:whitelist_mode?).and_return(true) allow(subject).to receive(:whitelist_mode?).and_return(true)
end end

View File

@ -5,7 +5,7 @@ require 'rails_helper'
RSpec.describe VerifyLinkService, type: :service do RSpec.describe VerifyLinkService, type: :service do
subject { described_class.new } subject { described_class.new }
context 'given a local account' do context 'when given a local account' do
let(:account) { Fabricate(:account, username: 'alice') } let(:account) { Fabricate(:account, username: 'alice') }
let(:field) { Account::Field.new(account, 'name' => 'Website', 'value' => 'http://example.com') } let(:field) { Account::Field.new(account, 'name' => 'Website', 'value' => 'http://example.com') }
@ -129,7 +129,7 @@ RSpec.describe VerifyLinkService, type: :service do
end end
end end
context 'given a remote account' do context 'when given a remote account' do
let(:account) { Fabricate(:account, username: 'alice', domain: 'example.com', url: 'https://profile.example.com/alice') } let(:account) { Fabricate(:account, username: 'alice', domain: 'example.com', url: 'https://profile.example.com/alice') }
let(:field) { Account::Field.new(account, 'name' => 'Website', 'value' => '<a href="http://example.com" rel="me"><span class="invisible">http://</span><span class="">example.com</span><span class="invisible"></span></a>') } let(:field) { Account::Field.new(account, 'name' => 'Website', 'value' => '<a href="http://example.com" rel="me"><span class="invisible">http://</span><span class="">example.com</span><span class="invisible"></span></a>') }

View File

@ -14,7 +14,7 @@ RSpec.describe DisallowedHashtagsValidator, type: :validator do
let(:status) { double(errors: errors, local?: local, reblog?: reblog, text: disallowed_tags.map { |x| "##{x}" }.join(' ')) } let(:status) { double(errors: errors, local?: local, reblog?: reblog, text: disallowed_tags.map { |x| "##{x}" }.join(' ')) }
let(:errors) { double(add: nil) } let(:errors) { double(add: nil) }
context 'for a remote reblog' do context 'with a remote reblog' do
let(:local) { false } let(:local) { false }
let(:reblog) { true } let(:reblog) { true }
@ -23,7 +23,7 @@ RSpec.describe DisallowedHashtagsValidator, type: :validator do
end end
end end
context 'for a local original status' do context 'with a local original status' do
let(:local) { true } let(:local) { true }
let(:reblog) { false } let(:reblog) { false }

View File

@ -6,7 +6,7 @@ describe EmailMxValidator do
describe '#validate' do describe '#validate' do
let(:user) { double(email: 'foo@example.com', sign_up_ip: '1.2.3.4', errors: double(add: nil)) } let(:user) { double(email: 'foo@example.com', sign_up_ip: '1.2.3.4', errors: double(add: nil)) }
context 'for an e-mail domain that is explicitly allowed' do context 'with an e-mail domain that is explicitly allowed' do
around do |block| around do |block|
tmp = Rails.configuration.x.email_domains_whitelist tmp = Rails.configuration.x.email_domains_whitelist
Rails.configuration.x.email_domains_whitelist = 'example.com' Rails.configuration.x.email_domains_whitelist = 'example.com'

View File

@ -18,7 +18,7 @@ RSpec.describe FollowLimitValidator, type: :validator do
let(:_nil) { true } let(:_nil) { true }
let(:local) { false } let(:local) { false }
context 'follow.account.nil? || !follow.account.local?' do context 'with follow.account.nil? || !follow.account.local?' do
let(:_nil) { true } let(:_nil) { true }
it 'not calls errors.add' do it 'not calls errors.add' do
@ -26,11 +26,11 @@ RSpec.describe FollowLimitValidator, type: :validator do
end end
end end
context '!(follow.account.nil? || !follow.account.local?)' do context 'with !(follow.account.nil? || !follow.account.local?)' do
let(:_nil) { false } let(:_nil) { false }
let(:local) { true } let(:local) { true }
context 'limit_reached?' do context 'when limit_reached?' do
let(:limit_reached) { true } let(:limit_reached) { true }
it 'calls errors.add' do it 'calls errors.add' do
@ -39,7 +39,7 @@ RSpec.describe FollowLimitValidator, type: :validator do
end end
end end
context '!limit_reached?' do context 'with !limit_reached?' do
let(:limit_reached) { false } let(:limit_reached) { false }
it 'not calls errors.add' do it 'not calls errors.add' do

View File

@ -18,7 +18,7 @@ RSpec.describe PollValidator, type: :validator do
expect(errors).to_not have_received(:add) expect(errors).to_not have_received(:add)
end end
context 'expires just 5 min ago' do context 'when expires is just 5 min ago' do
let(:expires_at) { 5.minutes.from_now } let(:expires_at) { 5.minutes.from_now }
it 'not calls errors add' do it 'not calls errors add' do

Some files were not shown because too many files have changed in this diff Show More