diff options
| author | Robert | 2017-10-04 14:46:42 +0200 |
|---|---|---|
| committer | Robert | 2017-10-09 15:04:22 +0200 |
| commit | 158c8d1062151cf26461af97e533b6acac09b6d4 (patch) | |
| tree | 681c73b84ce353e61e941db1116f1efbc401428f /spec | |
| parent | 2f68a7e9ea109c4667a64ee183c052eaa6b3d5e8 (diff) | |
| download | chouette-core-158c8d1062151cf26461af97e533b6acac09b6d4.tar.bz2 | |
Fixes: #4629@4.5h; Implemented copy
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/lib/af83/cloning/compliance_control_set_copier_spec.rb | 88 | ||||
| -rw-r--r-- | spec/models/compliance_check_block_spec.rb | 1 | ||||
| -rw-r--r-- | spec/models/compliance_check_set_spec.rb | 3 | ||||
| -rw-r--r-- | spec/models/compliance_control_set_spec.rb | 1 |
4 files changed, 93 insertions, 0 deletions
diff --git a/spec/lib/af83/cloning/compliance_control_set_copier_spec.rb b/spec/lib/af83/cloning/compliance_control_set_copier_spec.rb new file mode 100644 index 000000000..aacd9d7c9 --- /dev/null +++ b/spec/lib/af83/cloning/compliance_control_set_copier_spec.rb @@ -0,0 +1,88 @@ +RSpec.describe AF83::ComplianceControlSetCopier do + + subject{ described_class.new } + + let( :cc_set ){ create :compliance_control_set } + + context 'Copying empty set' do + context 'incorrect organisation' do + # Assuring the organisation missmatch + before { referential.organisation_id = cc_set.organisation_id.succ } + it 'fails' do + expect{ subject.copy(cc_set.id, referential.id) }.to raise_error(ArgumentError) + end + it 'does not create any objects in the database' do + expect{ subject.copy(cc_set.id, referential.id) rescue nil }.to_not change{ComplianceCheckSet.count} + expect{ subject.copy(cc_set.id, referential.id) rescue nil }.to_not change{ComplianceCheckBlock.count} + expect{ subject.copy(cc_set.id, referential.id) rescue nil }.to_not change{ComplianceCheck.count} + end + end + + context 'correct organisation' do + let(:ref){ create :referential, organisation_id: cc_set.organisation_id } + + let(:cc_blox){ + 3.times.map{ |_| create :compliance_control_block, compliance_control_set: cc_set } + } + let!(:direct_ccs){ + 3.times.map{ |n| create :compliance_control, compliance_control_set: cc_set, name: "direct #{n.succ}" } + } + # Needed to check we do not dulicate a node (compliance_control) twice + let!(:indirect_ccs){ + # Create 1 child for each block and also associate first of the direct ccs to the first block + # seconf of the direct css to the second block + cc_blox.take(2).zip(direct_ccs.take(2)).each do | cc_block, cc | + cc.update compliance_control_block_id: cc_block.id + end + cc_blox.each_with_index.map{ | cc_block, n | + create(:compliance_control, compliance_control_set: cc_set, compliance_control_block: cc_block, name: "indirect #{n.succ}") + } + } + + let( :cck_set ){ ComplianceCheckSet.last } + let( :cck_blox ){ cck_set.compliance_check_blocks } + let( :ccks ){ cck_set.compliance_checks } + + it 'correctly creates a cck_set for a complete DAG' do + # Slowness of tests constrain us to create a minimum of objects in the DB, + # hence only one example :( + counts = object_counts + subject.copy(cc_set.id, ref.id) + + # Did not change the original objects + # Correct numbers + expect( ComplianceControlSet.count).to eq(counts.cc_set_count) + expect( ComplianceControlBlock.count).to eq(counts.cc_block_count) + expect( ComplianceControl.count).to eq(counts.cc_count) + + expect( ComplianceCheckSet.count ).to eq(counts.cck_set_count + 1) + expect( cck_blox.count ).to eq(counts.cck_block_count + cc_blox.size) + expect( ccks.count ).to eq(counts.cck_count + direct_ccs.size + indirect_ccs.size) + + # Correcly associated + expect( cck_blox.map(&:compliance_checks).map(&:size) ) + .to eq([2, 2, 1]) + expect( ComplianceCheck.where(name: mk_name('direct 1')).first.compliance_check_block_id ) + .to eq( cck_blox.first.id ) + expect( ComplianceCheck.where(name: mk_name('direct 3')).first.compliance_check_block_id ).to be_nil + end + + end + + + def object_counts + OpenStruct.new \ + cc_set_count: ComplianceControlSet.count, + cc_block_count: ComplianceControlBlock.count, + cc_count: ComplianceControl.count, + cck_set_count: ComplianceCheckSet.count, + cck_block_count: ComplianceCheckBlock.count, + cck_count: ComplianceCheck.count + end + + def mk_name name + [name, ref.name].join('-') + end + end + +end diff --git a/spec/models/compliance_check_block_spec.rb b/spec/models/compliance_check_block_spec.rb index f581d5085..a3d98d459 100644 --- a/spec/models/compliance_check_block_spec.rb +++ b/spec/models/compliance_check_block_spec.rb @@ -6,4 +6,5 @@ RSpec.describe ComplianceCheckBlock, type: :model do end it { should belong_to :compliance_check_set } + it { should have_many :compliance_checks } end diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb index 6e53c9def..8afea5b3e 100644 --- a/spec/models/compliance_check_set_spec.rb +++ b/spec/models/compliance_check_set_spec.rb @@ -9,4 +9,7 @@ RSpec.describe ComplianceCheckSet, type: :model do it { should belong_to :workbench } it { should belong_to :compliance_control_set } it { should belong_to :parent } + + it { should have_many :compliance_checks } + it { should have_many :compliance_check_blocks } end diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb index edc684bbc..04d1c418c 100644 --- a/spec/models/compliance_control_set_spec.rb +++ b/spec/models/compliance_control_set_spec.rb @@ -7,6 +7,7 @@ RSpec.describe ComplianceControlSet, type: :model do it { should belong_to :organisation } it { should have_many(:compliance_controls).dependent(:destroy) } + it { should have_many(:compliance_control_blocks).dependent(:destroy) } it { should validate_presence_of :name } end |
