diff options
| author | Robert Dober | 2017-11-03 14:58:11 +0100 |
|---|---|---|
| committer | GitHub | 2017-11-03 14:58:11 +0100 |
| commit | 75988d4b5d821266131aec86e33c67eda0c38dcb (patch) | |
| tree | 35e4f1cfcd3589c069717aa7385d90ed7ce431d4 | |
| parent | 13553712a18435f16f449a6d0c6a2ade24038797 (diff) | |
| parent | 213c2ac6702718486f10b999948a8e5e3190c749 (diff) | |
| download | chouette-core-75988d4b5d821266131aec86e33c67eda0c38dcb.tar.bz2 | |
Merge pull request #106 from af83/4782-create-worker-for-compliance-check-copy--rb201710301748
4782 create worker for compliance check copy rb201710301748
| -rw-r--r-- | app/workers/compliance_control_set_copy_worker.rb | 14 | ||||
| -rw-r--r-- | config/environments/test.rb | 3 | ||||
| -rw-r--r-- | lib/compliance_control_set_copier.rb | 2 | ||||
| -rw-r--r-- | spec/lib/compliance_control_set_copier_spec.rb | 4 | ||||
| -rw-r--r-- | spec/workers/compliance_control_set_copy_worker_spec.rb | 35 |
5 files changed, 58 insertions, 0 deletions
diff --git a/app/workers/compliance_control_set_copy_worker.rb b/app/workers/compliance_control_set_copy_worker.rb new file mode 100644 index 000000000..d18bb0c88 --- /dev/null +++ b/app/workers/compliance_control_set_copy_worker.rb @@ -0,0 +1,14 @@ +class ComplianceControlSetCopyWorker + include Sidekiq::Worker + + def perform(control_set_id, referential_id) + check_set = ComplianceControlSetCopier.new.copy(control_set_id, referential_id) + + begin + Net::HTTP.get(URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/validator/new?id=#{check_set.id}")) + rescue Exception => e + logger.error "IEV server error : #{e.message}" + logger.error e.backtrace.inspect + end + end +end diff --git a/config/environments/test.rb b/config/environments/test.rb index b3312be4a..8bf94f5da 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -62,6 +62,9 @@ Rails.application.configure do # Reflex api url config.reflex_api_url = "https://195.46.215.128/ws/reflex/V1/service=getData" + # IEV url + config.iev_url = ENV.fetch('IEV_URL', 'http://localhost:8080') + config.rails_host = "http://www.example.com" # file to data for demo config.demo_data = "tmp/demo.zip" diff --git a/lib/compliance_control_set_copier.rb b/lib/compliance_control_set_copier.rb index 20518ee0e..58d40cdbf 100644 --- a/lib/compliance_control_set_copier.rb +++ b/lib/compliance_control_set_copier.rb @@ -11,6 +11,8 @@ class ComplianceControlSetCopier @referential_id = referential_id check_organisation_coherence! copy_set + + cck_set end diff --git a/spec/lib/compliance_control_set_copier_spec.rb b/spec/lib/compliance_control_set_copier_spec.rb index a9e576cf7..0f15d86d0 100644 --- a/spec/lib/compliance_control_set_copier_spec.rb +++ b/spec/lib/compliance_control_set_copier_spec.rb @@ -99,6 +99,10 @@ RSpec.describe ComplianceControlSetCopier do expect( actual ).to eq( expected ) end + + it 'returns the newly-created ComplianceCheckSet' do + expect(subject.copy(cc_set.id, ref.id)).to eq(cck_set) + end end end diff --git a/spec/workers/compliance_control_set_copy_worker_spec.rb b/spec/workers/compliance_control_set_copy_worker_spec.rb new file mode 100644 index 000000000..0ff721e75 --- /dev/null +++ b/spec/workers/compliance_control_set_copy_worker_spec.rb @@ -0,0 +1,35 @@ +RSpec.describe ComplianceControlSetCopyWorker do + let(:control_set_id) { 55 } + let(:referential_id) { 99 } + let(:check_set) { double(ComplianceCheckSet, id: 888) } + let(:stub_validation_request) do + stub_request( + :get, + "#{Rails.configuration.iev_url}/boiv_iev/referentials/validator/new?id=#{check_set.id}" + ) + end + + before(:each) do + allow_any_instance_of( + ComplianceControlSetCopier + ).to receive(:copy).and_return(check_set) + + stub_validation_request + end + + it "calls ComplianceControlSetCopier" do + expect_any_instance_of( + ComplianceControlSetCopier + ).to receive(:copy) + .with(control_set_id, referential_id) + .and_return(check_set) + + ComplianceControlSetCopyWorker.new.perform(control_set_id, referential_id) + end + + it "calls the Java API to launch validation" do + ComplianceControlSetCopyWorker.new.perform(control_set_id, referential_id) + + expect(stub_validation_request).to have_been_requested + end +end |
