aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/lines_controller.rb4
-rw-r--r--db/migrate/20180413082929_clean_lines_secondary_companies.rb5
-rw-r--r--spec/controllers/lines_controller_spec.rb29
3 files changed, 36 insertions, 2 deletions
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index ae8c9ed0c..cd8091252 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -122,7 +122,7 @@ class LinesController < ChouetteController
end
def line_params
- params.require(:line).permit(
+ out = params.require(:line).permit(
:transport_mode,
:network_id,
:company_id,
@@ -148,6 +148,8 @@ class LinesController < ChouetteController
:secondary_company_ids => [],
footnotes_attributes: [:code, :label, :_destroy, :id]
)
+ out[:secondary_company_ids] = (out[:secondary_company_ids] || []).select(&:present?)
+ out
end
# Fake ransack filter
diff --git a/db/migrate/20180413082929_clean_lines_secondary_companies.rb b/db/migrate/20180413082929_clean_lines_secondary_companies.rb
new file mode 100644
index 000000000..4c5659e8f
--- /dev/null
+++ b/db/migrate/20180413082929_clean_lines_secondary_companies.rb
@@ -0,0 +1,5 @@
+class CleanLinesSecondaryCompanies < ActiveRecord::Migration
+ def up
+ Chouette::Line.where("secondary_company_ids = '{NULL}'").update_all secondary_company_ids: nil
+ end
+end
diff --git a/spec/controllers/lines_controller_spec.rb b/spec/controllers/lines_controller_spec.rb
index 96f49bb36..78020484b 100644
--- a/spec/controllers/lines_controller_spec.rb
+++ b/spec/controllers/lines_controller_spec.rb
@@ -1,9 +1,36 @@
RSpec.describe LinesController, :type => :controller do
login_user
- let(:line_referential) { create :line_referential, member: @user.organisation }
+ let(:line_referential) { create :line_referential, member: @user.organisation, objectid_format: :netex }
let(:line) { create :line, line_referential: line_referential }
+ describe 'POST create' do
+ let(:line_attrs){{
+ name: "test",
+ transport_mode: "bus"
+ }}
+ let(:request){ post :create, line_referential_id: line_referential.id, line: line_attrs }
+
+ with_permission "lines.create" do
+ it "should create a new line" do
+ expect{request}.to change{ line_referential.lines.count }.by 1
+ end
+
+ context "with an empty value in secondary_company_ids" do
+ let(:line_attrs){{
+ name: "test",
+ transport_mode: "bus",
+ secondary_company_ids: [""]
+ }}
+
+ it "should cleanup secondary_company_ids" do
+ expect{request}.to change{ line_referential.lines.count }.by 1
+ expect(line_referential.lines.last.secondary_company_ids).to eq []
+ end
+ end
+ end
+ end
+
describe 'PUT deactivate' do
let(:request){ put :deactivate, id: line.id, line_referential_id: line_referential.id }