diff options
| -rw-r--r-- | spec/lib/compliance_control_set_copier_spec.rb | 112 |
1 files changed, 64 insertions, 48 deletions
diff --git a/spec/lib/compliance_control_set_copier_spec.rb b/spec/lib/compliance_control_set_copier_spec.rb index 1b4a75634..b329018aa 100644 --- a/spec/lib/compliance_control_set_copier_spec.rb +++ b/spec/lib/compliance_control_set_copier_spec.rb @@ -4,7 +4,7 @@ RSpec.describe ComplianceControlSetCopier do let( :cc_set ){ create :compliance_control_set } - context 'Copying empty set' do + context 'Copying empty set' do context 'incorrect organisation' do # Assuring the organisation missmatch before { referential.organisation_id = cc_set.organisation_id.succ } @@ -18,53 +18,69 @@ RSpec.describe ComplianceControlSetCopier do end end - context 'correct organisation' do + 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}") + context 'Directed Acyclic Graph is copied correctly' do + 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 constrains 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 + + 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 constrains 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 + + context 'Node data is copied correctly' do + let( :cc_block ){ create :compliance_control_block, compliance_control_set: cc_set } + + let!( :control ){ create :compliance_control, + compliance_control_set: cc_set, + compliance_control_block: cc_block, + name: 'control' } + + it 'indeed' do + require 'pry'; binding.pry + + end end end @@ -80,9 +96,9 @@ RSpec.describe ComplianceControlSetCopier do cck_count: ComplianceCheck.count end - def mk_name name - [name, ref.name].join('-') - end + def mk_name name + [name, ref.name].join('-') + end end end |
