0
0
Fork 0

Refactor and improve tests (#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.
This commit is contained in:
Claire 2022-01-28 00:46:42 +01:00 committed by GitHub
parent 03d59340da
commit e38fc319dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
95 changed files with 187 additions and 185 deletions

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe AccountModerationNotePolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :create? do
context 'staff' do
@ -42,7 +42,7 @@ RSpec.describe AccountModerationNotePolicy do
end
context 'neither admin nor owner' do
let(:kevin) { Fabricate(:user).account }
let(:kevin) { Fabricate(:account) }
it 'denies to destroy' do
expect(subject).to_not permit(kevin, account_moderation_note)

View file

@ -6,8 +6,8 @@ require 'pundit/rspec'
RSpec.describe AccountPolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:alice) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
let(:alice) { Fabricate(:account) }
permissions :index? do
context 'staff' do

View file

@ -5,7 +5,7 @@ require 'pundit/rspec'
RSpec.describe BackupPolicy do
let(:subject) { described_class }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :create? do
context 'not user_signed_in?' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe CustomEmojiPolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :index?, :enable?, :disable? do
context 'staff' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe DomainBlockPolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :index?, :show?, :create?, :destroy? do
context 'admin' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe EmailDomainBlockPolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :index?, :create?, :destroy? do
context 'admin' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe InstancePolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :index?, :show?, :destroy? do
context 'admin' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe InvitePolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :index? do
context 'staff?' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe RelayPolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :update? do
context 'admin?' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe ReportNotePolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :create? do
context 'staff?' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe ReportPolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :update?, :index?, :show? do
context 'staff?' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe SettingsPolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :update?, :show? do
context 'admin?' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe TagPolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :index?, :show?, :update? do
context 'staff?' do

View file

@ -6,7 +6,7 @@ require 'pundit/rspec'
RSpec.describe UserPolicy do
let(:subject) { described_class }
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
let(:john) { Fabricate(:account) }
permissions :reset_password?, :change_email? do
context 'staff?' do