diff options
| author | teddywing | 2017-09-11 13:11:51 +0200 | 
|---|---|---|
| committer | GitHub | 2017-09-11 13:11:51 +0200 | 
| commit | ecef9d98cbe08e42434753477da4886dcfcb02bb (patch) | |
| tree | 5e8f19e9cab501452044438e07bab3052a2e158d | |
| parent | 1b2976d7a63cc140304bd94b88b5ddc93e0aceb0 (diff) | |
| parent | 7ff60302d391afd850733d7ddade238bef502d70 (diff) | |
| download | chouette-core-ecef9d98cbe08e42434753477da4886dcfcb02bb.tar.bz2 | |
Merge pull request #62 from af83/4412-add-tests-for-Import#destroy--v2--rb201709111249
4412 add tests for import#destroy  v2  rb201709111249
| -rw-r--r-- | app/models/import_message.rb | 2 | ||||
| -rw-r--r-- | spec/factories/import_messages.rb | 7 | ||||
| -rw-r--r-- | spec/models/import_spec.rb | 35 | 
3 files changed, 37 insertions, 7 deletions
| diff --git a/app/models/import_message.rb b/app/models/import_message.rb index 913f6fd41..5d0f5c862 100644 --- a/app/models/import_message.rb +++ b/app/models/import_message.rb @@ -1,6 +1,6 @@  class ImportMessage < ActiveRecord::Base    belongs_to :import -  belongs_to :resource, class_name: ImportResource, dependent: :destroy +  belongs_to :resource, class_name: ImportResource    enum criticity: [:info, :warning, :error]    validates :criticity, presence: true 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 | 
