From 43541cf4d0a461ac76bec4ea9ae16163a105f76a Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Fri, 5 Jan 2018 10:22:26 +0100 Subject: Fixes ReferentialCloning specs. Refs #5299 --- spec/models/chouette/time_table_spec.rb | 2 +- spec/models/referential_cloning_spec.rb | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'spec/models') diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 23f26395e..d4a726740 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -1275,7 +1275,7 @@ end expected_ranges = [ Date.new(2017,12,1)..Date.new(2017,12,31), - Date.new(2018,2,2)..Date.new(2017,3,1) + Date.new(2018,2,2)..Date.new(2018,3,1) ] expect(time_table.periods.map(&:range)).to eq(expected_ranges) end diff --git a/spec/models/referential_cloning_spec.rb b/spec/models/referential_cloning_spec.rb index 4327c98aa..815e05a67 100644 --- a/spec/models/referential_cloning_spec.rb +++ b/spec/models/referential_cloning_spec.rb @@ -36,40 +36,50 @@ RSpec.describe ReferentialCloning, :type => :model do let(:cloner) { double } - before do - allow(AF83::SchemaCloner).to receive(:new).and_return cloner - allow(cloner).to receive(:clone_schema) - end - it 'creates a schema cloner with source and target schemas and clone schema' do expect(AF83::SchemaCloner).to receive(:new).with(source_referential.slug, target_referential.slug).and_return(cloner) expect(cloner).to receive(:clone_schema) referential_cloning.clone! end + end + + describe '#clone_with_status!' do + let(:referential_cloning) do + ReferentialCloning.new(target_referential: Referential.new(slug: "target")) + end + + before do + allow(referential_cloning).to receive(:clone!) + end + + it 'invokes clone! method' do + expect(referential_cloning).to receive(:clone!) + referential_cloning.clone_with_status! + end context 'when clone_schema is performed without error' do it "should have successful status" do - referential_cloning.clone! + referential_cloning.clone_with_status! expect(referential_cloning.status).to eq("successful") end end context 'when clone_schema raises an error' do it "should have failed status" do - expect(cloner).to receive(:clone_schema).and_raise("#fail") - referential_cloning.clone! + expect(referential_cloning).to receive(:clone!).and_raise("#fail") + referential_cloning.clone_with_status! expect(referential_cloning.status).to eq("failed") end end it "defines started_at" do - referential_cloning.clone! + referential_cloning.clone_with_status! expect(referential_cloning.started_at).not_to be_nil end it "defines ended_at" do - referential_cloning.clone! + referential_cloning.clone_with_status! expect(referential_cloning.ended_at).not_to be_nil end -- cgit v1.2.3