aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-09-08 14:25:58 +0200
committerTeddy Wing2017-09-11 12:49:45 +0200
commit70215298fcb592e52b0f3033a939a594f511e379 (patch)
treeed28fa484b6816fc7643257126c88d653a68213b
parent1b2976d7a63cc140304bd94b88b5ddc93e0aceb0 (diff)
downloadchouette-core-70215298fcb592e52b0f3033a939a594f511e379.tar.bz2
Import specs: Add tests to verify dependent-destroy of associations
When an import is destroyed, all: * child imports * associated `ImportReference`s * associated `ImportMessage`s must be destroyed. This is handled by a `dependent: :destory` on the associations. Here we add tests to validate that the records get properly destroyed. Refs #4412
-rw-r--r--spec/factories/import_messages.rb7
-rw-r--r--spec/models/import_spec.rb35
2 files changed, 36 insertions, 6 deletions
diff --git a/spec/factories/import_messages.rb b/spec/factories/import_messages.rb
new file mode 100644
index 000000000..75f80566c
--- /dev/null
+++ b/spec/factories/import_messages.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :import_message do
+ association :import
+ association :resource, factory: :import_resource
+ criticity :info
+ end
+end
diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb
index 477d269e0..cd5a30982 100644
--- a/spec/models/import_spec.rb
+++ b/spec/models/import_spec.rb
@@ -26,12 +26,35 @@ RSpec.describe Import, type: :model do
)
end
- # describe "#destroy" do
- # it "must call #destroy on imports children and then import_messages, import_resources linked" do
- # TODO
- #
- # end
- # end
+ describe "#destroy" do
+ it "must destroy all child imports" do
+ workbench_import = create(:workbench_import)
+ create(:netex_import, parent: workbench_import)
+
+ workbench_import.destroy
+
+ expect(workbench_import).to be_destroyed
+ expect(NetexImport.count).to eq(0)
+ end
+
+ it "must destroy all associated ImportMessages" do
+ import = create(:import)
+ create(:import_resource, import: import)
+
+ import.destroy
+
+ expect(ImportResource.count).to eq(0)
+ end
+
+ it "must destroy all associated ImportResources" do
+ import = create(:import)
+ create(:import_message, import: import)
+
+ import.destroy
+
+ expect(ImportMessage.count).to eq(0)
+ end
+ end
describe "#notify_parent" do
it "must call #child_change on its parent" do