This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and improve tests (mastodon#17386)
* Change account and user fabricators to simplify and improve tests - `Fabricate(:account)` implicitly fabricates an associated `user` if no `domain` attribute is given (an account with `domain: nil` is considered a local account, but no user record was created), unless `user: nil` is passed - `Fabricate(:account, user: Fabricate(:user))` should still be possible but is discouraged. * Fix and refactor tests - avoid passing unneeded attributes to `Fabricate(:user)` or `Fabricate(:account)` - avoid embedding `Fabricate(:user)` into a `Fabricate(:account)` or the other way around - prefer `Fabricate(:user, account_attributes: …)` to `Fabricate(:user, account: Fabricate(:account, …)` - also, some tests were using remote accounts with local user records, which is not representative of production code.
- Loading branch information
1 parent
03d5934
commit e38fc31
Showing
95 changed files
with
187 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,10 +11,9 @@ | |
|
||
describe "GET #show" do | ||
it "returns http success" do | ||
account = Fabricate(:account) | ||
user = Fabricate(:user, account: account) | ||
user = Fabricate(:user) | ||
|
||
get :show, params: { account_id: account.id } | ||
get :show, params: { account_id: user.account.id } | ||
|
||
expect(response).to have_http_status(200) | ||
end | ||
|
@@ -26,12 +25,11 @@ | |
end | ||
|
||
it "returns http success" do | ||
account = Fabricate(:account) | ||
user = Fabricate(:user, account: account) | ||
user = Fabricate(:user) | ||
|
||
previous_email = user.email | ||
|
||
post :update, params: { account_id: account.id, user: { unconfirmed_email: '[email protected]' } } | ||
post :update, params: { account_id: user.account.id, user: { unconfirmed_email: '[email protected]' } } | ||
|
||
user.reload | ||
|
||
|
@@ -41,7 +39,7 @@ | |
|
||
expect(UserMailer).to have_received(:confirmation_instructions).with(user, user.confirmation_token, { to: '[email protected]' }) | ||
|
||
expect(response).to redirect_to(admin_account_path(account.id)) | ||
expect(response).to redirect_to(admin_account_path(user.account.id)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,16 @@ | |
describe Api::V1::Accounts::RelationshipsController do | ||
render_views | ||
|
||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } | ||
let(:user) { Fabricate(:user) } | ||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'read:follows') } | ||
|
||
before do | ||
allow(controller).to receive(:doorkeeper_token) { token } | ||
end | ||
|
||
describe 'GET #index' do | ||
let(:simon) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'simon')).account } | ||
let(:lewis) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'lewis')).account } | ||
let(:simon) { Fabricate(:account) } | ||
let(:lewis) { Fabricate(:account) } | ||
|
||
before do | ||
user.account.follow!(simon) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
RSpec.describe Api::V1::AccountsController, type: :controller do | ||
render_views | ||
|
||
let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) } | ||
let(:user) { Fabricate(:user) } | ||
let(:scopes) { '' } | ||
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) } | ||
|
||
|
@@ -69,7 +69,7 @@ | |
|
||
describe 'POST #follow' do | ||
let(:scopes) { 'write:follows' } | ||
let(:other_account) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'bob', locked: locked)).account } | ||
let(:other_account) { Fabricate(:account, username: 'bob', locked: locked) } | ||
|
||
context do | ||
before do | ||
|
@@ -150,7 +150,7 @@ | |
|
||
describe 'POST #unfollow' do | ||
let(:scopes) { 'write:follows' } | ||
let(:other_account) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'bob')).account } | ||
let(:other_account) { Fabricate(:account, username: 'bob') } | ||
|
||
before do | ||
user.account.follow!(other_account) | ||
|
@@ -170,7 +170,7 @@ | |
|
||
describe 'POST #remove_from_followers' do | ||
let(:scopes) { 'write:follows' } | ||
let(:other_account) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'bob')).account } | ||
let(:other_account) { Fabricate(:account, username: 'bob') } | ||
|
||
before do | ||
other_account.follow!(user.account) | ||
|
@@ -190,7 +190,7 @@ | |
|
||
describe 'POST #block' do | ||
let(:scopes) { 'write:blocks' } | ||
let(:other_account) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'bob')).account } | ||
let(:other_account) { Fabricate(:account, username: 'bob') } | ||
|
||
before do | ||
user.account.follow!(other_account) | ||
|
@@ -214,7 +214,7 @@ | |
|
||
describe 'POST #unblock' do | ||
let(:scopes) { 'write:blocks' } | ||
let(:other_account) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'bob')).account } | ||
let(:other_account) { Fabricate(:account, username: 'bob') } | ||
|
||
before do | ||
user.account.block!(other_account) | ||
|
@@ -234,7 +234,7 @@ | |
|
||
describe 'POST #mute' do | ||
let(:scopes) { 'write:mutes' } | ||
let(:other_account) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'bob')).account } | ||
let(:other_account) { Fabricate(:account, username: 'bob') } | ||
|
||
before do | ||
user.account.follow!(other_account) | ||
|
@@ -262,7 +262,7 @@ | |
|
||
describe 'POST #mute with notifications set to false' do | ||
let(:scopes) { 'write:mutes' } | ||
let(:other_account) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'bob')).account } | ||
let(:other_account) { Fabricate(:account, username: 'bob') } | ||
|
||
before do | ||
user.account.follow!(other_account) | ||
|
@@ -290,7 +290,7 @@ | |
|
||
describe 'POST #mute with nonzero duration set' do | ||
let(:scopes) { 'write:mutes' } | ||
let(:other_account) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'bob')).account } | ||
let(:other_account) { Fabricate(:account, username: 'bob') } | ||
|
||
before do | ||
user.account.follow!(other_account) | ||
|
@@ -318,7 +318,7 @@ | |
|
||
describe 'POST #unmute' do | ||
let(:scopes) { 'write:mutes' } | ||
let(:other_account) { Fabricate(:user, email: '[email protected]', account: Fabricate(:account, username: 'bob')).account } | ||
let(:other_account) { Fabricate(:account, username: 'bob') } | ||
|
||
before do | ||
user.account.mute!(other_account) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.