mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-25 15:09:29 +00:00
More controller specs (#2561)
* Add render_views in more places * Delegate methods from account to user with allow nil true, so that admin accounts show view renders when missing a user * Use actual account instances in authorize follow controller spec
This commit is contained in:
parent
0e2589867f
commit
9566893cc9
|
@ -74,6 +74,14 @@ class Account < ApplicationRecord
|
||||||
scope :alphabetic, -> { order(domain: :asc, username: :asc) }
|
scope :alphabetic, -> { order(domain: :asc, username: :asc) }
|
||||||
scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') }
|
scope :by_domain_accounts, -> { group(:domain).select(:domain, 'COUNT(*) AS accounts_count').order('accounts_count desc') }
|
||||||
|
|
||||||
|
delegate :email,
|
||||||
|
:current_sign_in_ip,
|
||||||
|
:current_sign_in_at,
|
||||||
|
:confirmed?,
|
||||||
|
to: :user,
|
||||||
|
prefix: true,
|
||||||
|
allow_nil: true
|
||||||
|
|
||||||
def follow!(other_account)
|
def follow!(other_account)
|
||||||
active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
|
active_relationships.where(target_account: other_account).first_or_create!(target_account: other_account)
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,15 +16,15 @@
|
||||||
- if @account.local?
|
- if @account.local?
|
||||||
%tr
|
%tr
|
||||||
%th= t('admin.accounts.email')
|
%th= t('admin.accounts.email')
|
||||||
%td= @account.user.email
|
%td= @account.user_email
|
||||||
%tr
|
%tr
|
||||||
%th= t('admin.accounts.most_recent_ip')
|
%th= t('admin.accounts.most_recent_ip')
|
||||||
%td= @account.user.current_sign_in_ip
|
%td= @account.user_current_sign_in_ip
|
||||||
%tr
|
%tr
|
||||||
%th= t('admin.accounts.most_recent_activity')
|
%th= t('admin.accounts.most_recent_activity')
|
||||||
%td
|
%td
|
||||||
- if @account.user.current_sign_in_at
|
- if @account.user_current_sign_in_at
|
||||||
= l @account.user.current_sign_in_at
|
= l @account.user_current_sign_in_at
|
||||||
- else
|
- else
|
||||||
Never
|
Never
|
||||||
- else
|
- else
|
||||||
|
@ -78,7 +78,7 @@
|
||||||
= link_to t('admin.accounts.silence'), admin_account_silence_path(@account.id), method: :post, class: 'button'
|
= link_to t('admin.accounts.silence'), admin_account_silence_path(@account.id), method: :post, class: 'button'
|
||||||
|
|
||||||
- if @account.local?
|
- if @account.local?
|
||||||
- unless @account.user.confirmed?
|
- unless @account.user_confirmed?
|
||||||
= link_to t('admin.accounts.confirm'), admin_account_confirmation_path(@account.id), method: :post, class: 'button'
|
= link_to t('admin.accounts.confirm'), admin_account_confirmation_path(@account.id), method: :post, class: 'button'
|
||||||
|
|
||||||
- if @account.suspended?
|
- if @account.suspended?
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe AccountFollowController do
|
describe AccountFollowController do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe AccountUnfollowController do
|
describe AccountUnfollowController do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Admin::AccountsController, type: :controller do
|
RSpec.describe Admin::AccountsController, type: :controller do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user, admin: true), scope: :user
|
sign_in Fabricate(:user, admin: true), scope: :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Admin::DomainBlocksController, type: :controller do
|
RSpec.describe Admin::DomainBlocksController, type: :controller do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user, admin: true), scope: :user
|
sign_in Fabricate(:user, admin: true), scope: :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Admin::InstancesController, type: :controller do
|
RSpec.describe Admin::InstancesController, type: :controller do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user, admin: true), scope: :user
|
sign_in Fabricate(:user, admin: true), scope: :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Admin::PubsubhubbubController, type: :controller do
|
RSpec.describe Admin::PubsubhubbubController, type: :controller do
|
||||||
|
render_views
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user, admin: true), scope: :user
|
sign_in Fabricate(:user, admin: true), scope: :user
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Admin::ReportedStatusesController do
|
describe Admin::ReportedStatusesController do
|
||||||
|
render_views
|
||||||
|
|
||||||
let(:user) { Fabricate(:user, admin: true) }
|
let(:user) { Fabricate(:user, admin: true) }
|
||||||
before do
|
before do
|
||||||
sign_in user, scope: :user
|
sign_in user, scope: :user
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Admin::ResetsController do
|
describe Admin::ResetsController do
|
||||||
|
render_views
|
||||||
|
|
||||||
let(:account) { Fabricate(:account, user: Fabricate(:user)) }
|
let(:account) { Fabricate(:account, user: Fabricate(:user)) }
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user, admin: true), scope: :user
|
sign_in Fabricate(:user, admin: true), scope: :user
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Admin::SilencesController do
|
describe Admin::SilencesController do
|
||||||
|
render_views
|
||||||
|
|
||||||
let(:account) { Fabricate(:account) }
|
let(:account) { Fabricate(:account) }
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user, admin: true), scope: :user
|
sign_in Fabricate(:user, admin: true), scope: :user
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Admin::SuspensionsController do
|
describe Admin::SuspensionsController do
|
||||||
|
render_views
|
||||||
|
|
||||||
let(:account) { Fabricate(:account) }
|
let(:account) { Fabricate(:account) }
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user, admin: true), scope: :user
|
sign_in Fabricate(:user, admin: true), scope: :user
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe AuthorizeFollowsController do
|
describe AuthorizeFollowsController do
|
||||||
|
render_views
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
describe 'when signed out' do
|
describe 'when signed out' do
|
||||||
it 'redirects to sign in page' do
|
it 'redirects to sign in page' do
|
||||||
|
@ -38,7 +40,7 @@ describe AuthorizeFollowsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets account from url' do
|
it 'sets account from url' do
|
||||||
account = double
|
account = Account.new
|
||||||
service = double
|
service = double
|
||||||
allow(FetchRemoteAccountService).to receive(:new).and_return(service)
|
allow(FetchRemoteAccountService).to receive(:new).and_return(service)
|
||||||
allow(service).to receive(:call).with('http://example.com').and_return(account)
|
allow(service).to receive(:call).with('http://example.com').and_return(account)
|
||||||
|
@ -50,7 +52,7 @@ describe AuthorizeFollowsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets account from acct uri' do
|
it 'sets account from acct uri' do
|
||||||
account = double
|
account = Account.new
|
||||||
service = double
|
service = double
|
||||||
allow(FollowRemoteAccountService).to receive(:new).and_return(service)
|
allow(FollowRemoteAccountService).to receive(:new).and_return(service)
|
||||||
allow(service).to receive(:call).with('found@hostname').and_return(account)
|
allow(service).to receive(:call).with('found@hostname').and_return(account)
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe FollowerAccountsController do
|
describe FollowerAccountsController do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
|
|
|
@ -2,6 +2,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
describe FollowingAccountsController do
|
describe FollowingAccountsController do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe MediaController do
|
describe MediaController do
|
||||||
|
render_views
|
||||||
|
|
||||||
describe '#show' do
|
describe '#show' do
|
||||||
it 'redirects to the file url when attached to a status' do
|
it 'redirects to the file url when attached to a status' do
|
||||||
status = Fabricate(:status)
|
status = Fabricate(:status)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Oauth::AuthorizationsController, type: :controller do
|
RSpec.describe Oauth::AuthorizationsController, type: :controller do
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Settings::Exports::BlockedAccountsController do
|
describe Settings::Exports::BlockedAccountsController do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user), scope: :user
|
sign_in Fabricate(:user), scope: :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Settings::Exports::FollowingAccountsController do
|
describe Settings::Exports::FollowingAccountsController do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user), scope: :user
|
sign_in Fabricate(:user), scope: :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Settings::Exports::MutedAccountsController do
|
describe Settings::Exports::MutedAccountsController do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user), scope: :user
|
sign_in Fabricate(:user), scope: :user
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Settings::FollowerDomainsController do
|
describe Settings::FollowerDomainsController do
|
||||||
|
render_views
|
||||||
|
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Settings::ImportsController, type: :controller do
|
RSpec.describe Settings::ImportsController, type: :controller do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user), scope: :user
|
sign_in Fabricate(:user), scope: :user
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Settings::PreferencesController do
|
describe Settings::PreferencesController do
|
||||||
|
render_views
|
||||||
|
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Settings::ProfilesController, type: :controller do
|
RSpec.describe Settings::ProfilesController, type: :controller do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user), scope: :user
|
sign_in Fabricate(:user), scope: :user
|
||||||
|
|
Loading…
Reference in a new issue