diff options
| author | Zog | 2018-01-30 20:49:24 +0100 |
|---|---|---|
| committer | Johan Van Ryseghem | 2018-02-20 09:50:28 +0100 |
| commit | beadf103e66f752706e9bf16931e80dc1629c1db (patch) | |
| tree | e4e50ed8617c919ab97230cf5429835aeeda7128 /spec | |
| parent | 51e08724766bf2ca4837436178984c33d22cf16a (diff) | |
| download | chouette-core-beadf103e66f752706e9bf16931e80dc1629c1db.tar.bz2 | |
Refs #5765; Add new task to import in a given referential
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/models/simple_importer_spec.rb | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/spec/models/simple_importer_spec.rb b/spec/models/simple_importer_spec.rb index 50958970c..6b2889d59 100644 --- a/spec/models/simple_importer_spec.rb +++ b/spec/models/simple_importer_spec.rb @@ -26,6 +26,9 @@ RSpec.describe SimpleImporter do end describe "#import" do + let(:importer){ importer = SimpleImporter.new(configuration_name: :test, filepath: filepath) } + let(:filepath){ Rails.root + "spec/fixtures/simple_importer/#{filename}" } + let(:filename){ "stop_area.csv" } before(:each) do SimpleImporter.define :test do |config| config.model = Chouette::StopArea @@ -41,7 +44,6 @@ RSpec.describe SimpleImporter do end it "should import the given file" do - importer = SimpleImporter.new(configuration_name: :test, filepath: Rails.root + "spec/fixtures/simple_importer/stop_area.csv") expect{importer.import}.to change{Chouette::StopArea.count}.by 1 expect(importer.status).to eq "success" stop = Chouette::StopArea.last @@ -52,12 +54,30 @@ RSpec.describe SimpleImporter do expect(importer.reload.journal.last["event"]).to eq("creation") end + context "when overriding configuration" do + before(:each){ + importer.configure do |config| + config.add_value :latitude, 88 + end + } + + it "should import the given file and not mess with the global configuration" do + expect{importer.import}.to change{Chouette::StopArea.count}.by 1 + expect(importer.status).to eq "success" + stop = Chouette::StopArea.last + expect(stop.latitude).to eq 88 + importer = SimpleImporter.new(configuration_name: :test, filepath: filepath) + expect{importer.import}.to change{Chouette::StopArea.count}.by 0 + expect(stop.reload.latitude).to eq 45 + end + end + context "with an already existing record" do + let(:filename){ "stop_area.csv" } before(:each){ create :stop_area, name: "Nom du Stop" } it "should only update the record" do - importer = SimpleImporter.new(configuration_name: :test, filepath: Rails.root + "spec/fixtures/simple_importer/stop_area.csv") expect{importer.import}.to change{Chouette::StopArea.count}.by 0 expect(importer.status).to eq "success" stop = Chouette::StopArea.last @@ -70,8 +90,8 @@ RSpec.describe SimpleImporter do end context "with a missing column" do + let(:filename){ "stop_area_missing_street_name.csv" } it "should set an error message" do - importer = SimpleImporter.new(configuration_name: :test, filepath: Rails.root + "spec/fixtures/simple_importer/stop_area_missing_street_name.csv") expect{importer.import}.to_not raise_error expect(importer.status).to eq "success_with_warnings" expect(importer.reload.journal.first["event"]).to eq("column_not_found") @@ -79,8 +99,8 @@ RSpec.describe SimpleImporter do end context "with a incomplete dataset" do + let(:filename){ "stop_area_incomplete.csv" } it "should create a StopArea" do - importer = SimpleImporter.new(configuration_name: :test, filepath: Rails.root + "spec/fixtures/simple_importer/stop_area_incomplete.csv") expect{importer.import}.to_not raise_error expect(importer.status).to eq "failed" expect(importer.reload.journal.first["message"]).to eq({"name" => ["doit ĂȘtre rempli(e)"]}) @@ -88,8 +108,8 @@ RSpec.describe SimpleImporter do end context "with a wrong filepath" do + let(:filename){ "not_found.csv" } it "should create a StopArea" do - importer = SimpleImporter.new(configuration_name: :test, filepath: Rails.root + "spec/fixtures/simple_importer/not_found.csv") expect{importer.import}.to_not raise_error expect(importer.status).to eq "failed" expect(importer.reload.journal.first["message"]).to eq "File not found: #{importer.filepath}" @@ -97,6 +117,7 @@ RSpec.describe SimpleImporter do end context "with a full file" do + let(:filename){ "stop_area_full.csv" } before(:each) do SimpleImporter.define :test do |config| config.model = Chouette::StopArea @@ -121,7 +142,6 @@ RSpec.describe SimpleImporter do end it "should import the given file" do - importer = SimpleImporter.new(configuration_name: :test, filepath: Rails.root + "spec/fixtures/simple_importer/stop_area_full.csv") expect{importer.import}.to change{Chouette::StopArea.count}.by 2 expect(importer.status).to eq "success" first = Chouette::StopArea.find_by registration_number: "PAR" @@ -134,8 +154,9 @@ RSpec.describe SimpleImporter do end context "with a relation in reverse order" do + let(:filename){ "stop_area_full_reverse.csv" } + it "should import the given file" do - importer = SimpleImporter.new(configuration_name: :test, filepath: Rails.root + "spec/fixtures/simple_importer/stop_area_full_reverse.csv") expect{importer.import}.to change{Chouette::StopArea.count}.by 2 expect(importer.status).to eq "success" first = Chouette::StopArea.find_by registration_number: "XED" |
