aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2018-01-31 14:15:19 +0100
committerGitHub2018-01-31 14:15:19 +0100
commit7f483236325d54acc6499a82e8a98b8e8d744d41 (patch)
treec35b9353f5617bc661f063ef186e7606ad711e86
parentc100b5ae399d3c092801a13c26e8f28ea1a1797f (diff)
parent9c322a5ea47f0badb0ba7e91de6df42d25e591c5 (diff)
downloadchouette-core-7f483236325d54acc6499a82e8a98b8e8d744d41.tar.bz2
Merge pull request #269 from af83/5574-vehicle-journeys--fix-transporter-deletion-in-modal--rb
5574 vehicle journeys fix transporter deletion in modal rb
-rw-r--r--app/javascript/vehicle_journeys/components/tools/CreateModal.js1
-rw-r--r--app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js2
-rw-r--r--app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js3
-rw-r--r--app/models/chouette/vehicle_journey.rb22
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb8
5 files changed, 31 insertions, 5 deletions
diff --git a/app/javascript/vehicle_journeys/components/tools/CreateModal.js b/app/javascript/vehicle_journeys/components/tools/CreateModal.js
index 90328458b..8536f66e6 100644
--- a/app/javascript/vehicle_journeys/components/tools/CreateModal.js
+++ b/app/javascript/vehicle_journeys/components/tools/CreateModal.js
@@ -66,6 +66,7 @@ export default class CreateModal extends Component {
<CompanySelect2
company = {this.props.modal.modalProps.vehicleJourney && this.props.modal.modalProps.vehicleJourney.company || undefined}
onSelect2Company = {(e) => this.props.onSelect2Company(e)}
+ onUnselect2Company = {() => this.props.onUnselect2Company()}
/>
</div>
</div>
diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js
index 28a092945..5c7f75d99 100644
--- a/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js
+++ b/app/javascript/vehicle_journeys/components/tools/select2s/CompanySelect2.js
@@ -26,7 +26,7 @@ export default class BSelect4 extends Component {
multiple={false}
ref='company_id'
options={{
- allowClear: this.props.editMode,
+ allowClear: true,
theme: 'bootstrap',
width: '100%',
placeholder: 'Filtrer par transporteur...',
diff --git a/app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js b/app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js
index 0db7628be..d982f5a5f 100644
--- a/app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js
+++ b/app/javascript/vehicle_journeys/containers/tools/AddVehicleJourney.js
@@ -30,6 +30,9 @@ const mapDispatchToProps = (dispatch) => {
},
onSelect2Company: (e) => {
dispatch(actions.select2Company(e.params.data))
+ },
+ onUnselect2Company: () => {
+ dispatch(actions.unselect2Company())
}
}
}
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 8a704d8c0..d94b69271 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -220,11 +220,25 @@ module Chouette
end
def self.state_permited_attributes item
- attrs = item.slice('published_journey_identifier', 'published_journey_name', 'journey_pattern_id', 'company_id').to_hash
- ['company', 'journey_pattern'].map do |association|
- attrs["#{association}_id"] = item[association]['id'] if item[association]
+ attrs = item.slice(
+ 'published_journey_identifier',
+ 'published_journey_name',
+ 'journey_pattern_id',
+ 'company_id'
+ ).to_hash
+
+ if item['journey_pattern']
+ attrs['journey_pattern_id'] = item['journey_pattern']['id']
end
- attrs["custom_field_values"] = Hash[*(item["custom_fields"] || {}).map{|k, v| [k, v["value"]]}.flatten]
+
+ attrs['company_id'] = item['company'] ? item['company']['id'] : nil
+
+ attrs["custom_field_values"] = Hash[
+ *(item["custom_fields"] || {})
+ .map { |k, v| [k, v["value"]] }
+ .flatten
+ ]
+
attrs
end
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 2a88ac3ce..21bbc1ba8 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -231,6 +231,14 @@ describe Chouette::VehicleJourney, :type => :model do
expect(vehicle_journey.reload.company_id).to eq state['company']['id']
end
+ it "handles vehicle journey company deletion" do
+ vehicle_journey.update(company: create(:company))
+ state.delete('company')
+ Chouette::VehicleJourney.state_update(route, collection)
+
+ expect(vehicle_journey.reload.company_id).to be_nil
+ end
+
it 'should update vj attributes from state' do
state['published_journey_name'] = 'edited_name'
state['published_journey_identifier'] = 'edited_identifier'