diff options
| author | Robert | 2017-04-18 20:05:06 +0200 | 
|---|---|---|
| committer | Robert | 2017-04-19 08:35:27 +0200 | 
| commit | efc4bda7c97299f259fb9f109fd370c623529cd9 (patch) | |
| tree | bce50a3fe1cf795967195af2442e4b9cb0f9ae56 /spec/workers | |
| parent | 2bcd11d80beb632f5204672bdbd9efc8b706ca12 (diff) | |
| download | chouette-core-efc4bda7c97299f259fb9f109fd370c623529cd9.tar.bz2 | |
removed obsolete migration 20170123131243_set_user_permissions.rb; Refs #3105
Diffstat (limited to 'spec/workers')
| -rw-r--r-- | spec/workers/referential_cloning_worker_spec.rb | 45 | 
1 files changed, 45 insertions, 0 deletions
| diff --git a/spec/workers/referential_cloning_worker_spec.rb b/spec/workers/referential_cloning_worker_spec.rb new file mode 100644 index 000000000..85d771742 --- /dev/null +++ b/spec/workers/referential_cloning_worker_spec.rb @@ -0,0 +1,45 @@ +require 'spec_helper' +require 'ostruct' + +RSpec.describe ReferentialCloningWorker do + +  context "given a refererntial cloning" do + +    let( :id ){ double } + +    let( :worker ){ described_class.new } + + +    let( :source_schema ){ "source_schema" } +    let( :target_schema ){ "#{source_schema}_tmp" } +    let( :referential_cloning ){ OpenStruct.new(source_referential: OpenStruct.new(slug: source_schema)) }  + +    before do +      expect( ReferentialCloning ).to receive(:find).with(id).and_return(referential_cloning) +      expect( StoredProcedures ) +        .to receive(:invoke_stored_procedure) +          .with(:clone_schema, source_schema, target_schema, true) + +      expect( worker ).to receive(:execute_sql).with( "DROP SCHEMA #{source_schema} CASCADE;" ) + +      expect( referential_cloning ).to receive(:run!) +    end + +    it "invokes the correct stored procedure, updates the database and the AASM" do +      expect( worker ).to receive(:execute_sql).with( "ALTER SCHEMA #{target_schema} RENAME TO #{source_schema};" ) +      expect( referential_cloning ).to receive(:successful!) +      worker.perform(id) +    end + +    it "handles failure correctly" do +      expect( worker ) +        .to receive(:execute_sql) +          .with( "ALTER SCHEMA #{target_schema} RENAME TO #{source_schema};" ) +          .and_raise(RuntimeError) +       +      expect( referential_cloning ).to receive(:failed!) +      worker.perform(id) +    end +  end +   +end | 
