diff options
| author | Luc Donnet | 2018-04-13 15:01:01 +0200 | 
|---|---|---|
| committer | GitHub | 2018-04-13 15:01:01 +0200 | 
| commit | fa780b81676f7d7f75f3a8b683d830a34d1c713d (patch) | |
| tree | 530f9cca1642fedc0c8a3ece201357ba6c4762b7 | |
| parent | 94090e82bfb5f875f70aa1e8bffb8a51724eb760 (diff) | |
| parent | 13087614ceb0e9e3a604cd08a023f11cd0567bea (diff) | |
| download | chouette-core-fa780b81676f7d7f75f3a8b683d830a34d1c713d.tar.bz2 | |
Merge pull request #476 from af83/6536-fix-lines-form
6536 Cleanup value passed for secondary_company_ids by the lines form
| -rw-r--r-- | app/controllers/lines_controller.rb | 4 | ||||
| -rw-r--r-- | db/migrate/20180413082929_clean_lines_secondary_companies.rb | 5 | ||||
| -rw-r--r-- | spec/controllers/lines_controller_spec.rb | 29 | 
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 } | 
