diff options
| author | Luc Donnet | 2017-09-27 21:57:22 +0200 |
|---|---|---|
| committer | Luc Donnet | 2017-09-27 21:57:22 +0200 |
| commit | c86a9c0bd4e8cb7bc677051e44e1e33d1419a409 (patch) | |
| tree | 045a6a1172b31c950e824450e349015790a9889f /spec/models | |
| parent | 16fc6a184311c0ab5e1463398b91f8a716bcf4db (diff) | |
| parent | 55779bdf1737eea5e5ae79bacfebabbc249643af (diff) | |
| download | chouette-core-c86a9c0bd4e8cb7bc677051e44e1e33d1419a409.tar.bz2 | |
Merge branch 'master' of github.com:AF83/stif-boiv
Diffstat (limited to 'spec/models')
| -rw-r--r-- | spec/models/compliance_control_block_spec.rb | 3 | ||||
| -rw-r--r-- | spec/models/compliance_control_set_spec.rb | 2 | ||||
| -rw-r--r-- | spec/models/compliance_control_spec.rb | 37 | ||||
| -rw-r--r-- | spec/models/workbench_spec.rb | 24 |
4 files changed, 60 insertions, 6 deletions
diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb index 248049b0c..f45ec3d42 100644 --- a/spec/models/compliance_control_block_spec.rb +++ b/spec/models/compliance_control_block_spec.rb @@ -1,9 +1,12 @@ require 'rails_helper' RSpec.describe ComplianceControlBlock, type: :model do + subject { create(:compliance_control_block) } + it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_control_block)).to be_valid end it { should belong_to :compliance_control_set } + it { should belong_to :compliance_control } end diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb index ededec5e0..edc684bbc 100644 --- a/spec/models/compliance_control_set_spec.rb +++ b/spec/models/compliance_control_set_spec.rb @@ -6,7 +6,7 @@ RSpec.describe ComplianceControlSet, type: :model do end it { should belong_to :organisation } - it { should have_many :compliance_controls } + it { should have_many(:compliance_controls).dependent(:destroy) } it { should validate_presence_of :name } end diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb index b00ff4c5a..d7bffb0b2 100644 --- a/spec/models/compliance_control_spec.rb +++ b/spec/models/compliance_control_spec.rb @@ -1,14 +1,41 @@ require 'rails_helper' RSpec.describe ComplianceControl, type: :model do + + let(:compliance_control) { create :compliance_control } + it 'should have a valid factory' do - expect(FactoryGirl.build(:compliance_control)).to be_valid + expect(compliance_control).to be_valid end it { should belong_to :compliance_control_set } - it { should belong_to :compliance_control_block } + it { should have_one(:compliance_control_block).dependent(:destroy) } + + it 'should validate_presence_of criticity' do + compliance_control.criticity = nil + expect(compliance_control).not_to be_valid + end + + it 'should validate_presence_of name' do + compliance_control.name = nil + expect(compliance_control).not_to be_valid + end + + it 'should validate_presence_of code' do + compliance_control.code = nil + expect(compliance_control).not_to be_valid + end + + it 'should validate_presence_of origin_code' do + compliance_control.origin_code = nil + expect(compliance_control).not_to be_valid + end - it { should validate_presence_of :criticity } - it { should validate_presence_of :name } - it { should validate_presence_of :code } + #TODO dont know why the 'shortcuts' below to validates presence dont work + # That's why we dont it 'manually' + # it { should validate_presence_of :criticity } + # it { should validate_presence_of :name } + # it { should validate_presence_of :code } + # it { should validate_presence_of :origin_code } + end diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb index 84149ddb0..037537b60 100644 --- a/spec/models/workbench_spec.rb +++ b/spec/models/workbench_spec.rb @@ -11,6 +11,7 @@ RSpec.describe Workbench, :type => :model do it { should belong_to(:organisation) } it { should belong_to(:line_referential) } it { should belong_to(:stop_area_referential) } + it { should belong_to(:output).class_name('ReferentialSuite') } it { should have_many(:lines).through(:line_referential) } it { should have_many(:networks).through(:line_referential) } @@ -19,6 +20,15 @@ RSpec.describe Workbench, :type => :model do it { should have_many(:stop_areas).through(:stop_area_referential) } + it do + # This callback interferes with the validation test + Workbench.skip_callback(:validation, :before, :initialize_output) + + should validate_presence_of(:output) + + Workbench.set_callback(:validation, :before, :initialize_output) + end + context '.lines' do let!(:ids) { ['STIF:CODIFLIGNE:Line:C00840', 'STIF:CODIFLIGNE:Line:C00086'] } let!(:organisation) { create :organisation, sso_attributes: { functional_scope: ids.to_json } } @@ -33,4 +43,18 @@ RSpec.describe Workbench, :type => :model do expect(lines.map(&:objectid)).to include(*ids) end end + + describe ".create" do + it "must automatically create a ReferentialSuite when being created" do + workbench = Workbench.create + expect(workbench.output).to be_an_instance_of(ReferentialSuite) + end + + it "must not overwrite a given ReferentialSuite" do + referential_suite = create(:referential_suite) + workbench = create(:workbench, output: referential_suite) + + expect(workbench.output).to eq(referential_suite) + end + end end |
