diff options
| -rw-r--r-- | app/workers/compliance_control_set_cloning_worker.rb | 4 | ||||
| -rw-r--r-- | lib/compliance_control_set_cloner.rb | 12 | ||||
| -rw-r--r-- | spec/lib/compliance_control_set_cloner_spec.rb | 6 | ||||
| -rw-r--r-- | spec/workers/compliance_control_set_cloning_worker_spec.rb | 7 | 
4 files changed, 18 insertions, 11 deletions
| diff --git a/app/workers/compliance_control_set_cloning_worker.rb b/app/workers/compliance_control_set_cloning_worker.rb index 6194a06ad..9cbe5c81a 100644 --- a/app/workers/compliance_control_set_cloning_worker.rb +++ b/app/workers/compliance_control_set_cloning_worker.rb @@ -1,8 +1,8 @@  class ComplianceControlSetCloningWorker    include Sidekiq::Worker -  def perform id -    ComplianceControlSetCloner.new.copy id +  def perform id, organisation_id +    ComplianceControlSetCloner.new.copy id, organisation_id    end  end diff --git a/lib/compliance_control_set_cloner.rb b/lib/compliance_control_set_cloner.rb index 3856ce25e..1cf58a38d 100644 --- a/lib/compliance_control_set_cloner.rb +++ b/lib/compliance_control_set_cloner.rb @@ -4,10 +4,11 @@ class ComplianceControlSetCloner    #                    abbreviate compliance_control to cc and    #                    compliance_check to cck iff used as prefixes. -  attr_reader :source_set_id - -  def copy source_set_id +  attr_reader :organisation_id, :source_set_id +   +  def copy source_set_id, organisation_id      @source_set_id = source_set_id +    @organisation_id = organisation_id      copy_set    end @@ -71,12 +72,15 @@ class ComplianceControlSetCloner    # Lazy Values    # ----------- +  def organisation +    @__organisation__ ||= Organisation.find(organisation_id) +  end    def source_set      @__source_set__ ||= ComplianceControlSet.find(source_set_id)    end    def target_set      @__target_set__ ||= ComplianceControlSet.create!( -      organisation: source_set.organisation, +      organisation: organisation,        name: name_of_copy(:compliance_control_sets, source_set.name)      )    end diff --git a/spec/lib/compliance_control_set_cloner_spec.rb b/spec/lib/compliance_control_set_cloner_spec.rb index ca359536a..4305ec70b 100644 --- a/spec/lib/compliance_control_set_cloner_spec.rb +++ b/spec/lib/compliance_control_set_cloner_spec.rb @@ -2,6 +2,8 @@ RSpec.describe ComplianceControlSetCloner do    subject{ described_class.new } +  let( :new_organisation ){ create :organisation } +    let( :source_set ){ create :compliance_control_set }    let( :set_prefix ){ I18n.t('compliance_control_sets.clone.prefix') }    let( :block_prefix ){ I18n.t('compliance_control_blocks.clone.prefix') } @@ -80,11 +82,11 @@ RSpec.describe ComplianceControlSetCloner do            #            #  Execute copy and keep count            counts = object_counts -          subject.copy(source_set.id) +          subject.copy(source_set.id, new_organisation.id)            delta  = count_diff counts, object_counts            # Check correctly copied set -          expect(target_set.organisation).to eq(source_set.organisation) +          expect(target_set.organisation).to eq(new_organisation)            expect(target_set.name).to eq( [set_prefix, source_set.name].join(' ') )            # Check correctly copied controls diff --git a/spec/workers/compliance_control_set_cloning_worker_spec.rb b/spec/workers/compliance_control_set_cloning_worker_spec.rb index dee3e6dd5..3a2332f62 100644 --- a/spec/workers/compliance_control_set_cloning_worker_spec.rb +++ b/spec/workers/compliance_control_set_cloning_worker_spec.rb @@ -6,9 +6,10 @@ RSpec.describe ComplianceControlSetCloningWorker do    end    it 'delegates perform to the correct lib call' do -    id = random_int -    expect_any_instance_of(ComplianceControlSetCloner).to receive(:copy).with(id)  -    described_class.new.perform(id) +    id = double('id') +    organisation_id = double('organisation_id') +    expect_any_instance_of(ComplianceControlSetCloner).to receive(:copy).with(id, organisation_id)  +    described_class.new.perform(id, organisation_id)    end  end | 
