aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorTeddy Wing2017-11-13 18:27:48 +0100
committerTeddy Wing2017-11-13 18:27:48 +0100
commit51a0898506e9c6bcc379ed8db01d3f14a1dbe110 (patch)
tree27351c2fec102efec73daff5b320ad4661f23d97 /spec
parent336dab9900aee831e73113e400609ec2ebd40c20 (diff)
downloadchouette-core-51a0898506e9c6bcc379ed8db01d3f14a1dbe110.tar.bz2
NetexImport: Destroy referential on destroy if ready:false
If the `NetexImport`'s associated `Referential` has `ready: false`, when the `NetexImport` is destroyed, also destroy the `Referential`. This prevents a case where users get an invalid `Referential` as a result of an import, but because of the `ready: false`, it doesn't display on the website, so they can't see what the problem is. Refs #4962
Diffstat (limited to 'spec')
-rw-r--r--spec/models/import_spec.rb18
-rw-r--r--spec/models/netex_import_spec.rb28
2 files changed, 28 insertions, 18 deletions
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb
index dfb947711..7be05908a 100644
--- a/spec/models/import_spec.rb
+++ b/spec/models/import_spec.rb
@@ -57,24 +57,6 @@ RSpec.describe Import, type: :model do
expect(ImportMessage.count).to eq(0)
end
-
- it "must destroy its associated Referential if ready: false" do
- referential = create(:referential, ready: false)
- import = create(:import, referential: referential)
-
- import.destroy
-
- expect(referential).to be_destroyed
- end
-
- it "must not destroy its associated Referential if ready: true" do
- referential = create(:referential, ready: true)
- import = create(:import, referential: referential)
-
- import.destroy
-
- expect(referential).not_to be_destroyed
- end
end
describe "#notify_parent" do
diff --git a/spec/models/netex_import_spec.rb b/spec/models/netex_import_spec.rb
new file mode 100644
index 000000000..d52d475cc
--- /dev/null
+++ b/spec/models/netex_import_spec.rb
@@ -0,0 +1,28 @@
+RSpec.describe NetexImport, type: :model do
+ describe "#destroy" do
+ it "must destroy its associated Referential if ready: false" do
+ workbench_import = create(:workbench_import)
+ referential_ready_false = create(:referential, ready: false)
+ referential_ready_true = create(:referential, ready: true)
+ create(
+ :netex_import,
+ parent: workbench_import,
+ referential: referential_ready_false
+ )
+ create(
+ :netex_import,
+ parent: workbench_import,
+ referential: referential_ready_true
+ )
+
+ workbench_import.destroy
+
+ expect(
+ Referential.where(id: referential_ready_false.id).exists?
+ ).to be false
+ expect(
+ Referential.where(id: referential_ready_true.id).exists?
+ ).to be true
+ end
+ end
+end