forbid to create champ with same type_de_champ and same row
This commit is contained in:
parent
0538da3fad
commit
5b6044803b
2 changed files with 12 additions and 0 deletions
|
@ -21,6 +21,8 @@ class Champ < ApplicationRecord
|
|||
|
||||
before_create :set_dossier_id, if: :needs_dossier_id?
|
||||
|
||||
validates :type_de_champ_id, uniqueness: { scope: [:dossier_id, :row] }
|
||||
|
||||
def public?
|
||||
!private?
|
||||
end
|
||||
|
|
|
@ -3,6 +3,16 @@ describe Champ do
|
|||
|
||||
it_should_behave_like "champ_spec"
|
||||
|
||||
describe "validations" do
|
||||
let(:row) { 1 }
|
||||
let(:champ) { create(:champ, type_de_champ: create(:type_de_champ), row: row) }
|
||||
let(:champ2) { build(:champ, type_de_champ: champ.type_de_champ, row: champ.row, dossier: champ.dossier) }
|
||||
|
||||
it "returns false when champ with same type_de_champ and row already exist" do
|
||||
expect(champ2).not_to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe '#public?' do
|
||||
let(:type_de_champ) { build(:type_de_champ) }
|
||||
let(:champ) { type_de_champ.champ.build }
|
||||
|
|
Loading…
Reference in a new issue