diff options
| author | Zog | 2018-01-03 16:31:33 +0100 |
|---|---|---|
| committer | Zog | 2018-01-08 08:18:57 +0100 |
| commit | 913d6935727ace3ac94c08adb4e1ec378741fb19 (patch) | |
| tree | 1c8f0c63693ef4fbe7e20f7af3e6731395c855ad /spec | |
| parent | fa63d6e3d51ccc0b3a38616747fcd91b5fdfbba5 (diff) | |
| download | chouette-core-913d6935727ace3ac94c08adb4e1ec378741fb19.tar.bz2 | |
Refs #5455 @6h; Add time and distance between stops in Journey Patterns
- Adds a `JSON` attribute in the model
- Adds the fields in the editor
Diffstat (limited to 'spec')
5 files changed, 82 insertions, 5 deletions
diff --git a/spec/controllers/journey_patterns_collections_controller_spec.rb b/spec/controllers/journey_patterns_collections_controller_spec.rb index a3efbc23f..e2adc59f4 100644 --- a/spec/controllers/journey_patterns_collections_controller_spec.rb +++ b/spec/controllers/journey_patterns_collections_controller_spec.rb @@ -25,4 +25,20 @@ RSpec.describe JourneyPatternsCollectionsController, :type => :controller do 'journey_patterns.update' => true }.to_json) end end + + context "get show" do + login_user + + let( :referential ){ Referential.first } + let( :line ){ create(:line) } + let( :route ){ create(:route, line: line) } + + let(:request){ + get :show, referential_id: referential.id, line_id: line.id, route_id: route.id, format: :json + } + it 'should be successful' do + request + expect(response).to be_success + end + end end diff --git a/spec/factories/chouette_journey_pattern.rb b/spec/factories/chouette_journey_pattern.rb index 05d8d536a..d96302e7f 100644 --- a/spec/factories/chouette_journey_pattern.rb +++ b/spec/factories/chouette_journey_pattern.rb @@ -13,6 +13,12 @@ FactoryGirl.define do j.stop_point_ids = j.route.stop_points.map(&:id) j.departure_stop_point_id = j.route.stop_points.first.id j.arrival_stop_point_id = j.route.stop_points.last.id + j.costs = { + "1-2": { + distance: 10, + time: 10 + } + } end end @@ -35,5 +41,3 @@ FactoryGirl.define do end end - - diff --git a/spec/javascript/journey_patterns/actions_spec.js b/spec/javascript/journey_patterns/actions_spec.js index 2542fa2f4..60d6d88bb 100644 --- a/spec/javascript/journey_patterns/actions_spec.js +++ b/spec/javascript/journey_patterns/actions_spec.js @@ -112,6 +112,22 @@ describe('when clicking on a journey pattern delete button', () => { expect(actions.deleteJourneyPattern(index)).toEqual(expectedAction) }) }) +describe('when changing on a journey pattern costs', () => { + it('should create an action to update journey pattern', () => { + const index = 1 + const costs = { + "1-2": { + distance: 1 + } + } + const expectedAction = { + type: 'UPDATE_JOURNEYPATTERN_COSTS', + index, + costs + } + expect(actions.updateJourneyPatternCosts(index, costs)).toEqual(expectedAction) + }) +}) describe('when clicking on validate button inside edit modal', () => { it('should create an action to save journey pattern modifications', () => { const index = 1 diff --git a/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js index 24780ab5a..bfa87d24a 100644 --- a/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js +++ b/spec/javascript/journey_patterns/reducers/journey_patterns_spec.js @@ -47,7 +47,10 @@ describe('journeyPatterns reducer', () => { object_id : 'o1', published_name: 'M1', registration_number: '', - stop_points: fakeStopPoints + stop_points: fakeStopPoints, + costs: { + + } }, { deletable: false, @@ -55,7 +58,13 @@ describe('journeyPatterns reducer', () => { object_id : 'o2', published_name: 'M2', registration_number: '', - stop_points: fakeStopPoints + stop_points: fakeStopPoints, + costs: { + "1-2": { + distance: 0, + time: 10, + } + } } ] }) @@ -83,7 +92,8 @@ describe('journeyPatterns reducer', () => { published_name: 'M3', registration_number: '', deletable: false, - stop_points: stopPoints + stop_points: stopPoints, + costs: {} }, ...state]) }) @@ -100,6 +110,28 @@ describe('journeyPatterns reducer', () => { ).toEqual([newState, state[1]]) }) + it('should handle UPDATE_JOURNEYPATTERN_COSTS', () => { + const costs = { + "1-2": { + distance: 1 + } + } + const new_costs = { + "1-2": { + distance: 1, + time: 10, + } + } + const new_state = Object.assign({}, state[1], {costs: new_costs}) + expect( + jpReducer(state, { + type: 'UPDATE_JOURNEYPATTERN_COSTS', + index: 1, + costs + }) + ).toEqual([state[0], new_state]) + }) + it('should handle DELETE_JOURNEYPATTERN', () => { expect( jpReducer(state, { diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb index ea7c2a2e9..077c85e85 100644 --- a/spec/models/chouette/journey_pattern_spec.rb +++ b/spec/models/chouette/journey_pattern_spec.rb @@ -39,6 +39,7 @@ describe Chouette::JourneyPattern, :type => :model do item['stop_points'] = jp.stop_points.map do |sp| { 'id' => sp.stop_area_id } end + item['costs'] = jp.costs end end @@ -72,6 +73,14 @@ describe Chouette::JourneyPattern, :type => :model do expect(new_state['new_record']).to be_truthy end + it 'should create journey_pattern with state_update' do + new_state = journey_pattern_to_state(build(:journey_pattern, objectid: nil, route: route)) + collection = [new_state] + expect { + Chouette::JourneyPattern.state_update route, collection + }.to change{Chouette::JourneyPattern.count}.by(1) + end + it 'should delete journey_pattern' do state['deletable'] = true collection = [state] |
