factories: cleanup Administrateur, Instructeur and Expert factories
This changes: - avoids relying on application code to create mock objects, - allows to build Administrateur or Instructeurs without saving them.
This commit is contained in:
parent
0ff95df221
commit
a2b91c8ec6
9 changed files with 17 additions and 16 deletions
|
@ -61,7 +61,7 @@ describe Manager::UsersController, type: :controller do
|
|||
context 'and the old account belongs to an instructeur, expert and administrateur' do
|
||||
let!(:instructeur) { create(:instructeur, user: user) }
|
||||
let!(:expert) { create(:expert, user: user) }
|
||||
let!(:administrateur) { create(:administrateur, user: user) }
|
||||
let!(:administrateur) { create(:administrateur, user: user, instructeur: instructeur) }
|
||||
|
||||
it 'transfers instructeur account' do
|
||||
subject
|
||||
|
|
|
@ -40,7 +40,7 @@ describe WebhookController, type: :controller do
|
|||
|
||||
context 'when there are an associated Instructeur and Administrateur' do
|
||||
let!(:instructeur) { create(:instructeur, user: user) }
|
||||
let!(:admin) { create(:administrateur, user: user) }
|
||||
let!(:admin) { create(:administrateur, user: user, instructeur: instructeur) }
|
||||
|
||||
it 'returns a link to the Instructeur profile in the Manager' do
|
||||
expect(payload).to have_key('html')
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
FactoryBot.define do
|
||||
sequence(:administrateur_email) { |n| "admin#{n}@admin.com" }
|
||||
factory :administrateur do
|
||||
user { association :user, email: email, password: password }
|
||||
|
||||
transient do
|
||||
email { generate(:administrateur_email) }
|
||||
password { 'Mon [hien 4im3 {es banane$' }
|
||||
instructeur { build(:instructeur, user: user) }
|
||||
end
|
||||
|
||||
initialize_with do
|
||||
User.create_or_promote_to_administrateur(email, password).administrateur
|
||||
after(:build) do |administrateur, evaluator|
|
||||
if administrateur.user
|
||||
administrateur.user.instructeur = evaluator.instructeur
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,13 +2,11 @@ FactoryBot.define do
|
|||
sequence(:create_expert_email) { |n| "expert#{n}@expert.com" }
|
||||
|
||||
factory :expert do
|
||||
user { association :user, email: email, password: password }
|
||||
|
||||
transient do
|
||||
email { generate(:expert_email) }
|
||||
password { 'somethingverycomplated!' }
|
||||
end
|
||||
|
||||
initialize_with do
|
||||
User.create_or_promote_to_expert(email, password).expert
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,13 +2,11 @@ FactoryBot.define do
|
|||
sequence(:instructeur_email) { |n| "inst#{n}@inst.com" }
|
||||
|
||||
factory :instructeur do
|
||||
user { association :user, email: email, password: password }
|
||||
|
||||
transient do
|
||||
email { generate(:instructeur_email) }
|
||||
password { 'somethingverycomplated!' }
|
||||
end
|
||||
|
||||
initialize_with do
|
||||
User.create_or_promote_to_instructeur(email, password).instructeur
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe Administrateur, type: :model do
|
||||
let(:administration) { create(:administration) }
|
||||
|
||||
describe 'assocations' do
|
||||
describe 'associations' do
|
||||
it { is_expected.to have_and_belong_to_many(:instructeurs) }
|
||||
it { is_expected.to have_many(:procedures) }
|
||||
end
|
||||
|
|
|
@ -47,8 +47,8 @@ describe Commentaire do
|
|||
let(:dossier) { create(:dossier, procedure: procedure) }
|
||||
|
||||
context 'with a commentaire created by a instructeur' do
|
||||
let(:instructeur) { create :instructeur, email: 'some_user@exemple.fr' }
|
||||
let(:commentaire) { build :commentaire, instructeur: instructeur, dossier: dossier }
|
||||
let(:instructeur) { build :instructeur, email: 'some_user@exemple.fr' }
|
||||
|
||||
context 'when the procedure shows instructeurs email' do
|
||||
before { Flipper.disable(:hide_instructeur_email, procedure) }
|
||||
|
|
|
@ -372,7 +372,7 @@ describe User, type: :model do
|
|||
end
|
||||
|
||||
context 'for administrateurs' do
|
||||
let(:user) { build(:user, email: 'admin@exemple.fr', password: password, administrateur: build(:administrateur)) }
|
||||
let(:user) { build(:user, email: 'admin@exemple.fr', password: password, administrateur: create(:administrateur, user: nil)) }
|
||||
|
||||
context 'when the password is too short' do
|
||||
let(:password) { 's' * (PASSWORD_MIN_LENGTH - 1) }
|
||||
|
|
|
@ -52,7 +52,7 @@ describe ChampPolicy do
|
|||
end
|
||||
|
||||
context 'when the user also has instruction rights' do
|
||||
let(:instructeur) { create(:instructeur, email: signed_in_user.email, password: signed_in_user.password) }
|
||||
let(:instructeur) { create(:instructeur, user: signed_in_user) }
|
||||
let(:account) { { user: signed_in_user, instructeur: instructeur } }
|
||||
|
||||
context 'as the dossier instructeur and owner' do
|
||||
|
|
Loading…
Reference in a new issue