aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
authorTeddy Wing2017-08-01 20:47:15 +0200
committerTeddy Wing2017-08-01 20:47:15 +0200
commit985f22e3d4c7c503c4f830f00692a1219ade9612 (patch)
tree5e8eb9d99d1ab9950c5eeceeff80947c51e9e9a0 /spec/models
parentf189c4331d4f6f1ed10b7545d90a92dc2b7ca9b1 (diff)
downloadchouette-core-985f22e3d4c7c503c4f830f00692a1219ade9612.tar.bz2
Import: Make #child_change work
The `#child_change` method should update the current import (the parent) with a 'failed' or 'successful' status depending on the status of the child passed in. If the child has a failure status, the parent import should be updated to failed. If the import is `#ready?`, that tells us that all children have called `#child_change` without any problems, and we can update the parent's status to be successful. THAT PARAGRAPH IS WRONG. We could have `#ready?` with failed children. NEED TO UPDATE TO SUPPORT THAT. Add a method that describes the possible "failing" statuses. These are the ones that will cause 'failed' to be set on the parent. Refs #3509, #3511
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/import_spec.rb60
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb
index 1b8fe72c2..c97cfcaa2 100644
--- a/spec/models/import_spec.rb
+++ b/spec/models/import_spec.rb
@@ -24,6 +24,66 @@ RSpec.describe Import, :type => :model do
end
end
+ describe "#child_change" do
+ def updates_status_to_failed_when_child_status_indicates_failure(
+ failure_status
+ )
+ workbench_import = build_stubbed(:workbench_import)
+ allow(workbench_import).to receive(:update)
+
+ netex_import = build_stubbed(
+ :netex_import,
+ parent: workbench_import,
+ status: failure_status
+ )
+
+ expect(workbench_import).to receive(:update).with(status: 'failed')
+
+ workbench_import.child_change(netex_import)
+ end
+
+ it "updates :status to failed when child status indicates failure" do
+ updates_status_to_failed_when_child_status_indicates_failure('failed')
+ updates_status_to_failed_when_child_status_indicates_failure('aborted')
+ updates_status_to_failed_when_child_status_indicates_failure('canceled')
+ end
+
+ it "updates :status to successful when #ready?" do
+ workbench_import = build_stubbed(
+ :workbench_import,
+ total_steps: 2,
+ current_step: 2
+ )
+ netex_import = build_stubbed(
+ :netex_import,
+ parent: workbench_import
+ )
+
+ expect(workbench_import).to receive(:update).with(status: 'successful')
+
+ workbench_import.child_change(netex_import)
+ end
+
+ it "updates :status to failed when #ready? and child is failed" do
+ workbench_import = build_stubbed(
+ :workbench_import,
+ total_steps: 2,
+ current_step: 2
+ )
+ netex_import = build_stubbed(
+ :netex_import,
+ parent: workbench_import,
+ status: :failed
+ )
+
+ expect(workbench_import).to receive(:update).with(status: 'failed')
+
+ workbench_import.child_change(netex_import)
+ end
+ # when status is failed, update status to failed
+ # else when ready? update status to successful
+ end
+
describe "#ready?" do
it "returns true if #current_step == #total_steps" do
import = build_stubbed(