policies: refactor champ_policy_spec
Creating champs without attaching them to a procedure works only by chance.
This commit is contained in:
parent
533b16b6ea
commit
ac922c456e
1 changed files with 7 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
describe ChampPolicy do
|
||||
let(:champ) { create(:champ_text, private: private, dossier: dossier) }
|
||||
let(:dossier) { create(:dossier, user: dossier_owner) }
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure, user: dossier_owner) }
|
||||
let(:dossier_owner) { create(:user) }
|
||||
|
||||
let(:signed_in_user) { create(:user) }
|
||||
|
@ -8,24 +8,23 @@ describe ChampPolicy do
|
|||
|
||||
subject { Pundit.policy_scope(account, Champ) }
|
||||
|
||||
let(:champ) { dossier.champs.first }
|
||||
let(:champ_private) { dossier.champs_private.first }
|
||||
|
||||
shared_examples_for 'they can access a public champ' do
|
||||
let(:private) { false }
|
||||
it { expect(subject.find_by(id: champ.id)).to eq(champ) }
|
||||
end
|
||||
|
||||
shared_examples_for 'they can’t access a public champ' do
|
||||
let(:private) { false }
|
||||
it { expect(subject.find_by(id: champ.id)).to eq(nil) }
|
||||
end
|
||||
|
||||
shared_examples_for 'they can access a private champ' do
|
||||
let(:private) { true }
|
||||
it { expect(subject.find_by(id: champ.id)).to eq(champ) }
|
||||
it { expect(subject.find_by(id: champ_private.id)).to eq(champ_private) }
|
||||
end
|
||||
|
||||
shared_examples_for 'they can’t access a private champ' do
|
||||
let(:private) { true }
|
||||
it { expect(subject.find_by(id: champ.id)).to eq(nil) }
|
||||
it { expect(subject.find_by(id: champ_private.id)).to eq(nil) }
|
||||
end
|
||||
|
||||
context 'when an user only has user rights' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue