From a647f932dc8206583f727a4af64a200b6ec6857b Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 2 May 2017 11:49:25 +0200 Subject: Add specs for timetable metas Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/time_table/actions_spec.js | 24 +++++++++++++++++ spec/javascripts/time_table/reducers/metas_spec.js | 31 +++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/javascripts/time_table/actions_spec.js b/spec/javascripts/time_table/actions_spec.js index c628a0f57..eac2f86bb 100644 --- a/spec/javascripts/time_table/actions_spec.js +++ b/spec/javascripts/time_table/actions_spec.js @@ -24,4 +24,28 @@ describe('actions', () => { } expect(actions.updateColor('#ffffff')).toEqual(expectedAction) }) + + it('should create an action to update selected tags', () => { + let selectedItem = { + id: 1, + name: 'test' + } + const expectedAction = { + type: 'UPDATE_SELECT_TAG', + selectedItem: selectedItem + } + expect(actions.select2Tags(selectedItem)).toEqual(expectedAction) + }) + + it('should create an action to update unselected tags', () => { + let selectedItem = { + id: 1, + name: 'test' + } + const expectedAction = { + type: 'UPDATE_UNSELECT_TAG', + selectedItem: selectedItem + } + expect(actions.unselect2Tags(selectedItem)).toEqual(expectedAction) + }) }) diff --git a/spec/javascripts/time_table/reducers/metas_spec.js b/spec/javascripts/time_table/reducers/metas_spec.js index 6f83abfec..adc6a9d05 100644 --- a/spec/javascripts/time_table/reducers/metas_spec.js +++ b/spec/javascripts/time_table/reducers/metas_spec.js @@ -4,10 +4,16 @@ let state = {} describe('status reducer', () => { beforeEach(() => { + let tag = { + id: 0, + name: 'test' + } state = { comment: 'test', day_types: [true, true, true, true, true, true, true], - color: 'blue' + color: 'blue', + initial_tags: [tag], + tags: [tag] } }) @@ -45,4 +51,27 @@ describe('status reducer', () => { ).toEqual(Object.assign({}, state, {color: '#ffffff'})) }) + it('should handle UPDATE_SELECT_TAG', () => { + expect( + metasReducer(state, { + type: 'UPDATE_SELECT_TAG', + selectedItem:{ + id: 1, + name: 'great' + } + }) + ).toEqual(Object.assign({}, state, {tags: [...state.tags, {id: 1, name:'great'}]})) + }) + + it('should handle UPDATE_UNSELECT_TAG', () => { + expect( + metasReducer(state, { + type: 'UPDATE_UNSELECT_TAG', + selectedItem:{ + id: 0, + name: 'test' + } + }) + ).toEqual(Object.assign({}, state, {tags: []})) + }) }) -- cgit v1.2.3 From 9b95304792865eb05305d8fea01c634a5c5d1829 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 2 May 2017 12:15:09 +0200 Subject: Refs #3053 passes current_organization down from the controller into Reference.new_from adds joint models *ReferenceMemeberships to excluded Apartment models --- spec/lib/af83/stored_procedures/clone_schema_spec.rb | 5 +++-- spec/models/referential_spec.rb | 2 +- spec/spec_helper.rb | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) mode change 100755 => 100644 spec/lib/af83/stored_procedures/clone_schema_spec.rb (limited to 'spec') diff --git a/spec/lib/af83/stored_procedures/clone_schema_spec.rb b/spec/lib/af83/stored_procedures/clone_schema_spec.rb old mode 100755 new mode 100644 index 4de3379ea..c387ddc7d --- a/spec/lib/af83/stored_procedures/clone_schema_spec.rb +++ b/spec/lib/af83/stored_procedures/clone_schema_spec.rb @@ -13,7 +13,8 @@ RSpec.describe StoredProcedures do StoredProcedures.create_stored_procedure :clone_schema end - context "meta specs describe source schema's introspection" do + # :meta specs are not run, as the describe the testing methd and not the application + context "meta specs describe source schema's introspection", :meta do it "table information is correctly read" do expect(get_table_information(source_schema, child_table)) .to eq([{"table_schema"=>"source_schema", @@ -31,7 +32,7 @@ RSpec.describe StoredProcedures do expect( get_table_information(target_schema, child_table) ).to be_empty end - it "sequences are correctly read", :meta do + it "sequences are correctly read" do expect(get_sequences(source_schema, child_table)) .to eq([{"sequence_name"=>"#{child_table}_id_seq", "last_value"=>"1", diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index 7cf428eb0..2390cc470 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -27,7 +27,7 @@ describe Referential, :type => :model do context "Cloning referential" do let(:clone) do - Referential.new_from(ref) + Referential.new_from(ref, organisation: ref.organisation) end let(:saved_clone) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f66d721c9..cda753efe 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -51,8 +51,11 @@ RSpec.configure do |config| #Capybara.exact = true Capybara.javascript_driver = :poltergeist - config.filter_run_excluding :js => true - config.filter_run :wip => true + # :meta tests can be run seperately in case of doubt about the tests themselves + # they serve mainly as an explanataion of complicated tests (as e.g. PG information_schema introspection) + config.filter_run_excluding :meta => true + config.filter_run_excluding :js => true + config.filter_run :wip => true config.run_all_when_everything_filtered = true config.include TokenInputHelper, :type => :feature -- cgit v1.2.3 From 3408fc0023e1c43359a0b52e249d6ce270f2f9d4 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 2 May 2017 12:15:09 +0200 Subject: working on #3053 [amend me] --- .../clone_schema_with_organisation_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 spec/lib/af83/stored_procedures/clone_schema_with_organisation_spec.rb (limited to 'spec') diff --git a/spec/lib/af83/stored_procedures/clone_schema_with_organisation_spec.rb b/spec/lib/af83/stored_procedures/clone_schema_with_organisation_spec.rb new file mode 100644 index 000000000..8a16f73c6 --- /dev/null +++ b/spec/lib/af83/stored_procedures/clone_schema_with_organisation_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +RSpec.describe StoredProcedures do + context "clone schema with data" do + before do + seed_schema "source_schema" + end + + context "before cloning source schema is set up correctly w/o target_schema" do + it "with two different organisations" do + expect(Organisation.count).to eq(2) + end + end + end + + private + def seed_schema schema_name + source_org, target_org = 2.times.map{ create :organisation } + + end +end -- cgit v1.2.3 From 0a7b3fb40b40a3ff613a11cd4936bf4cd9b2cc3a Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 2 May 2017 12:42:37 +0200 Subject: TimeTables#edit crud periods from state Refs #2899 --- spec/models/chouette/time_table_spec.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'spec') diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 96f91aa03..579300b74 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -14,10 +14,43 @@ describe Chouette::TimeTable, :type => :model do item['current_month'] = time_table.month_inspect(Date.today.beginning_of_month) item['current_periode_range'] = Date.today.beginning_of_month.to_s item['tags'] = time_table.tags.map{ |tag| {id: tag.id, name: tag.name}} + item['time_table_periods'] = time_table.periods.map{|p| {'id': p.id, 'period_start': p.period_start.to_s, 'period_end': p.period_end.to_s}} end end let(:state) { time_table_to_state subject } + + it 'should update time table periods association' do + period = state['time_table_periods'].first + period['period_start'] = (Date.today - 1.month).to_s + period['period_end'] = (Date.today + 1.month).to_s + + subject.state_update_periods state['time_table_periods'] + ['period_end', 'period_start'].each do |prop| + expect(subject.reload.periods.first.send(prop).to_s).to eq(period[prop]) + end + end + + it 'should create time table periods association' do + state['time_table_periods'] << { + 'id' => false, + 'period_start' => (Date.today + 1.year).to_s, + 'period_end' => (Date.today + 2.year).to_s + } + + expect { + subject.state_update_periods state['time_table_periods'] + }.to change {subject.periods.count}.by(1) + expect(state['time_table_periods'].last['id']).to eq subject.reload.periods.last.id + end + + it 'should delete time table periods association' do + state['time_table_periods'].first['deleted'] = true + expect { + subject.state_update_periods state['time_table_periods'] + }.to change {subject.periods.count}.by(-1) + end + it 'should save new tags' do subject.tag_list = "awesome, great" subject.save -- cgit v1.2.3 From fbb0d5ce53dc1aeedd3b599b59353eb65502e020 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 2 May 2017 13:00:33 +0200 Subject: TimeTables#edit save color from state Refs #2899 --- spec/models/chouette/time_table_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec') diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 579300b74..18d76e805 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -51,6 +51,12 @@ describe Chouette::TimeTable, :type => :model do }.to change {subject.periods.count}.by(-1) end + it 'should update color' do + state['color'] = '#FFA070' + subject.state_update state + expect(subject.reload.color).to eq(state['color']) + end + it 'should save new tags' do subject.tag_list = "awesome, great" subject.save -- cgit v1.2.3 From 25d19fbb38751f43e4af9a5edc97d535af8b0f0e Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 2 May 2017 15:14:59 +0200 Subject: Refs #3265: fix tests --- spec/features/calendars_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/features/calendars_spec.rb b/spec/features/calendars_spec.rb index d4234fc50..2089939bb 100644 --- a/spec/features/calendars_spec.rb +++ b/spec/features/calendars_spec.rb @@ -11,10 +11,10 @@ describe 'Calendars', type: :feature do describe 'index' do before(:each) { visit calendars_path } - it 'displays calendars of the current organisation and shared calendars' do + it 'displays calendars of the current organisation' do expect(page).to have_content(calendars.first.short_name) - expect(page).to have_content(shared_calendar_other_org.short_name) - expect(page).not_to have_content(unshared_calendar_other_org.short_name) + # expect(page).to have_content(shared_calendar_other_org.short_name) + # expect(page).not_to have_content(unshared_calendar_other_org.short_name) end context 'filtering' do -- cgit v1.2.3 From 461dc05bc72ba16ada089da44171fd23cc892299 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 2 May 2017 16:51:09 +0200 Subject: Refs #3053; removed obsolete spec --- .../clone_schema_with_organisation_spec.rb | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 spec/lib/af83/stored_procedures/clone_schema_with_organisation_spec.rb (limited to 'spec') diff --git a/spec/lib/af83/stored_procedures/clone_schema_with_organisation_spec.rb b/spec/lib/af83/stored_procedures/clone_schema_with_organisation_spec.rb deleted file mode 100644 index 8a16f73c6..000000000 --- a/spec/lib/af83/stored_procedures/clone_schema_with_organisation_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -RSpec.describe StoredProcedures do - context "clone schema with data" do - before do - seed_schema "source_schema" - end - - context "before cloning source schema is set up correctly w/o target_schema" do - it "with two different organisations" do - expect(Organisation.count).to eq(2) - end - end - end - - private - def seed_schema schema_name - source_org, target_org = 2.times.map{ create :organisation } - - end -end -- cgit v1.2.3 From 7ce3dfa2770b2022f909164a0f24f8f38d8d8fb2 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 2 May 2017 18:17:04 +0200 Subject: Refs #3178; Simplecov bogus config (almost) fixed --- spec/lib/range_ext_spec.rb | 17 +++++++++++++++++ spec/spec_helper.rb | 19 ++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 spec/lib/range_ext_spec.rb (limited to 'spec') diff --git a/spec/lib/range_ext_spec.rb b/spec/lib/range_ext_spec.rb new file mode 100644 index 000000000..0e2365b5e --- /dev/null +++ b/spec/lib/range_ext_spec.rb @@ -0,0 +1,17 @@ +RSpec.describe Range do + context "intersection" do + it "is nil (sic) for two distinct ranges" do + expect( (1..2).intersection(3..4) ).to be_nil + end + + it "is the smaller of two if one is part of the other" do + expect( (1..2).intersection(0..3) ).to eq 1..2 + expect( (0..2).intersection(1..2) ).to eq 1..2 + end + + it "is the intersection otherwise" do + expect( (1..3) & (2..4) ).to eq 2..3 + expect( (2..4) & (1..3) ).to eq 2..3 + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cda753efe..891235b81 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,14 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' +require 'simplecov' +# if ENV['JOB_NAME'] +# require 'simplecov-rcov' +# SimpleCov.formatters = [ +# SimpleCov::Formatter::HTMLFormatter, +# SimpleCov::Formatter::RcovFormatter +# ] +# end +SimpleCov.start 'rails' + ENV["RAILS_ENV"] = 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' @@ -16,15 +26,6 @@ require 'simplecov' require 'sidekiq/testing' Sidekiq::Testing.fake! -if ENV['JOB_NAME'] - require 'simplecov-rcov' - SimpleCov.formatters = [ - SimpleCov::Formatter::HTMLFormatter, - SimpleCov::Formatter::RcovFormatter - ] -end -SimpleCov.start 'rails' - # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are # run as spec files by default. This means that files in spec/support that end -- cgit v1.2.3 From 1a8961555e8f674eb989f7f4af4c4a22b25856b0 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 2 May 2017 21:44:59 +0200 Subject: duplicate code from models/calendar removed; coherent naming in Range#intersection --- spec/lib/range_ext_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec') diff --git a/spec/lib/range_ext_spec.rb b/spec/lib/range_ext_spec.rb index 0e2365b5e..f93a8de00 100644 --- a/spec/lib/range_ext_spec.rb +++ b/spec/lib/range_ext_spec.rb @@ -1,6 +1,8 @@ RSpec.describe Range do context "intersection" do it "is nil (sic) for two distinct ranges" do + require 'pry' + binding.pry expect( (1..2).intersection(3..4) ).to be_nil end -- cgit v1.2.3 From cd8b08325558f6339e953b69fa64fa58a90bf3f2 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 2 May 2017 21:48:35 +0200 Subject: removed forgotten bkpt --- spec/lib/range_ext_spec.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'spec') diff --git a/spec/lib/range_ext_spec.rb b/spec/lib/range_ext_spec.rb index f93a8de00..0e2365b5e 100644 --- a/spec/lib/range_ext_spec.rb +++ b/spec/lib/range_ext_spec.rb @@ -1,8 +1,6 @@ RSpec.describe Range do context "intersection" do it "is nil (sic) for two distinct ranges" do - require 'pry' - binding.pry expect( (1..2).intersection(3..4) ).to be_nil end -- cgit v1.2.3 From e89703a1646711ea2387e6058765aa3c6b953971 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 2 May 2017 22:10:31 +0200 Subject: more duplicates of Range#intersection removed and range_ext required instead --- spec/lib/range_ext_spec.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'spec') diff --git a/spec/lib/range_ext_spec.rb b/spec/lib/range_ext_spec.rb index 0e2365b5e..9c44608b9 100644 --- a/spec/lib/range_ext_spec.rb +++ b/spec/lib/range_ext_spec.rb @@ -1,3 +1,4 @@ +require 'range_ext' RSpec.describe Range do context "intersection" do it "is nil (sic) for two distinct ranges" do -- cgit v1.2.3 From 534bc4065c4b3a2ed0a10527f27bac4e7b5aa472 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 3 May 2017 11:45:45 +0200 Subject: Refs #3096: Add/store comment when olmap is toggled Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/itineraries/reducers/stop_points_spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/javascripts/itineraries/reducers/stop_points_spec.js b/spec/javascripts/itineraries/reducers/stop_points_spec.js index 6065fa4ed..93fe85d36 100644 --- a/spec/javascripts/itineraries/reducers/stop_points_spec.js +++ b/spec/javascripts/itineraries/reducers/stop_points_spec.js @@ -195,7 +195,8 @@ describe('stops reducer', () => { registration_number: '0', city_name: 'city', area_type: 'area', - short_name: 'new' + short_name: 'new', + comment: 'newcomment' } }) ).toEqual( @@ -216,6 +217,7 @@ describe('stops reducer', () => { city_name: 'city', area_type: 'area', short_name: 'new', + comment: 'newcomment', olMap: { isOpened: false, json: {} -- cgit v1.2.3 From b84f888ca9bd5b708def0c4cd2f34f3a94b0251f Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 3 May 2017 16:23:23 +0200 Subject: filter vendor in Simplecov --- spec/spec_helper.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 891235b81..dda1f7ed9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,7 +7,9 @@ require 'simplecov' # SimpleCov::Formatter::RcovFormatter # ] # end -SimpleCov.start 'rails' +SimpleCov.start 'rails' do + add_filter 'vendor' +end ENV["RAILS_ENV"] = 'test' require File.expand_path("../../config/environment", __FILE__) -- cgit v1.2.3 From c9ffe28651d603b90322ac4d49ef50b20b566e1c Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 3 May 2017 18:32:34 +0200 Subject: Jenkins Simplecov/rcov code enabled again --- spec/spec_helper.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'spec') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index dda1f7ed9..c99cede55 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,12 @@ # This file is copied to spec/ when you run 'rails generate rspec:install' require 'simplecov' -# if ENV['JOB_NAME'] -# require 'simplecov-rcov' -# SimpleCov.formatters = [ -# SimpleCov::Formatter::HTMLFormatter, -# SimpleCov::Formatter::RcovFormatter -# ] -# end +if ENV['JOB_NAME'] + require 'simplecov-rcov' + SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::RcovFormatter + ] +end SimpleCov.start 'rails' do add_filter 'vendor' end -- cgit v1.2.3 From ce845b8053d4fc665ca700c064cbd6f276bc4e1d Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Thu, 4 May 2017 15:04:36 +0200 Subject: Add specs for redux timetable actions Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/time_table/actions_spec.js | 158 +++++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/javascripts/time_table/actions_spec.js b/spec/javascripts/time_table/actions_spec.js index eac2f86bb..73b2d2ac9 100644 --- a/spec/javascripts/time_table/actions_spec.js +++ b/spec/javascripts/time_table/actions_spec.js @@ -1,5 +1,16 @@ var actions = require('es6_browserified/time_tables/actions') - +const dispatch = function(){} +const dayTypes = [true, true, true, true, true, true, true] +const day = { + date : "2017-05-01", + day : "lundi", + excluded_date : false, + in_periods : true, + include_date : false, + mday : 1, + wday : 1, + wnumber : "18" +} describe('actions', () => { it('should create an action to update dayTypes', () => { const expectedAction = { @@ -48,4 +59,149 @@ describe('actions', () => { } expect(actions.unselect2Tags(selectedItem)).toEqual(expectedAction) }) + + + it('should create an action to go to previous page', () => { + let pagination = { + currentPage: '2017-01-01', + periode_range: [], + stateChanged: false + } + const expectedAction = { + type: 'GO_TO_PREVIOUS_PAGE', + dispatch, + pagination, + nextPage: false + } + expect(actions.goToPreviousPage(dispatch, pagination)).toEqual(expectedAction) + }) + + it('should create an action to go to next page', () => { + let pagination = { + currentPage: '2017-01-01', + periode_range: [], + stateChanged: false + } + const expectedAction = { + type: 'GO_TO_NEXT_PAGE', + dispatch, + pagination, + nextPage: true + } + expect(actions.goToNextPage(dispatch, pagination)).toEqual(expectedAction) + }) + + it('should create an action to change page', () => { + let page = '2017-05-04' + const expectedAction = { + type: 'CHANGE_PAGE', + dispatch, + page: page + } + expect(actions.changePage(dispatch, page)).toEqual(expectedAction) + }) + + it('should create an action to delete period', () => { + let index = 1 + const expectedAction = { + type: 'DELETE_PERIOD', + index, + dayTypes + } + expect(actions.deletePeriod(index, dayTypes)).toEqual(expectedAction) + }) + + it('should create an action to open add period form', () => { + const expectedAction = { + type: 'OPEN_ADD_PERIOD_FORM', + } + expect(actions.openAddPeriodForm()).toEqual(expectedAction) + }) + + it('should create an action to open edit period form', () => { + let period = { + id : 1, + period_end : "2017-03-05", + period_start : "2017-02-23" + } + let index = 1 + const expectedAction = { + type: 'OPEN_EDIT_PERIOD_FORM', + period, + index + } + expect(actions.openEditPeriodForm(period, index)).toEqual(expectedAction) + }) + + it('should create an action to close period form', () => { + const expectedAction = { + type: 'CLOSE_PERIOD_FORM', + } + expect(actions.closePeriodForm()).toEqual(expectedAction) + }) + + it('should create an action to update period form', () => { + let val = "11" + let group = "start" + let selectType = "day" + const expectedAction = { + type: 'UPDATE_PERIOD_FORM', + val, + group, + selectType + } + expect(actions.updatePeriodForm(val, group, selectType)).toEqual(expectedAction) + }) + + it('should create an action to validate period form', () => { + let modalProps = {} + let timeTablePeriods = [] + let metas = {} + const expectedAction = { + type: 'VALIDATE_PERIOD_FORM', + modalProps, + timeTablePeriods, + metas + } + expect(actions.validatePeriodForm(modalProps, timeTablePeriods, metas)).toEqual(expectedAction) + }) + + it('should create an action to include date in period', () => { + let index = 1 + const expectedAction = { + type: 'INCLUDE_DATE_IN_PERIOD', + index, + day, + dayTypes + } + expect(actions.includeDateInPeriod(index, day, dayTypes)).toEqual(expectedAction) + }) + + it('should create an action to exclude date from period', () => { + let index = 1 + const expectedAction = { + type: 'EXCLUDE_DATE_FROM_PERIOD', + index, + day, + dayTypes + } + expect(actions.excludeDateFromPeriod(index, day, dayTypes)).toEqual(expectedAction) + }) + + it('should create an action to open confirm modal', () => { + let callback = function(){} + const expectedAction = { + type: 'OPEN_CONFIRM_MODAL', + callback + } + expect(actions.openConfirmModal(callback)).toEqual(expectedAction) + }) + + it('should create an action to close modal', () => { + const expectedAction = { + type: 'CLOSE_MODAL', + } + expect(actions.closeModal()).toEqual(expectedAction) + }) + }) -- cgit v1.2.3 From 8978ffb9e346d35176371ef7d7879c8e41e96a97 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 4 May 2017 15:55:42 +0200 Subject: VehicleJourney: Add #with_stops A new method that does the same thing as the query in `VehicleJourneysController#collection` (4c12a6632907d5d24b654791db994bfb830c7e37). The goal is to replace the controller query code with this method so that it can be unit tested. Refs #3268 --- spec/models/chouette/vehicle_journey_spec.rb | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'spec') diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 3d3a948bc..ace28bd70 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -221,6 +221,47 @@ describe Chouette::VehicleJourney, :type => :model do end end + describe ".with_stops" do + it "selects vehicle journeys including stops in order or earliest departure time" do + def initialize_stop_times(vehicle_journey, &block) + vehicle_journey + .vehicle_journey_at_stops + .each_with_index do |at_stop, index| + at_stop.update( + departure_time: at_stop.departure_time + block.call(index), + arrival_time: at_stop.arrival_time + block.call(index) + ) + end + end + + # Create later vehicle journey to give it a later id, such that it should + # appear last if the order in the query isn't right. + journey_late = create(:vehicle_journey) + journey_early = create( + :vehicle_journey, + route: journey_late.route, + journey_pattern: journey_late.journey_pattern + ) + + initialize_stop_times(journey_early) do |index| + (index + 5).minutes + end + initialize_stop_times(journey_late) do |index| + (index + 65).minutes + end + + expected_journey_order = [journey_early, journey_late] + + expect( + journey_late + .route + .vehicle_journeys + .with_stops + .to_a + ).to eq(expected_journey_order) + end + end + subject { create(:vehicle_journey_odd) } describe "in_relation_to_a_journey_pattern methods" do let!(:route) { create(:route)} -- cgit v1.2.3 From cdf9056747432473df79390ded435d474e5f2e69 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 4 May 2017 16:28:19 +0200 Subject: vehicle_journey_spec.rb: #with_stops should sort empty journeys Empty journeys, or vehicle journeys with an empty `vehicle_journey_at_stops` collection should be sorted at the end of the list. Refs #3268 --- spec/models/chouette/vehicle_journey_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'spec') diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index ace28bd70..e537721af 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -260,6 +260,31 @@ describe Chouette::VehicleJourney, :type => :model do .to_a ).to eq(expected_journey_order) end + + it "orders journeys with nil times at the end" do + pattern = create(:journey_pattern) + journey_nil = build( + :vehicle_journey_common, + journey_pattern: pattern + ) + journey_nil.route = journey_nil.journey_pattern.route + journey_nil.save + journey = create( + :vehicle_journey, + route: journey_nil.route, + journey_pattern: journey_nil.journey_pattern + ) + + expected_journey_order = [journey, journey_nil] + + expect( + journey + .route + .vehicle_journeys + .with_stops + .to_a + ).to eq(expected_journey_order) + end end subject { create(:vehicle_journey_odd) } -- cgit v1.2.3 From 48b9ab1d9db508b658f0fee9b492bc058d99ab31 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 4 May 2017 16:51:36 +0200 Subject: vehicle_journey_spec.rb: Simplify factory call Simplify the "orders journeys with nil times at the end" test. Instead of manually initialising our data, create a special factory for the empty vehicle journey that we need. This allows us to get rid of the nonsense in the test setup. The existing `:vehicle_journey` factory still works the same as before. Refs #3268 --- spec/factories/chouette_vehicle_journey.rb | 30 +++++++++++++++------------- spec/models/chouette/vehicle_journey_spec.rb | 8 +------- 2 files changed, 17 insertions(+), 21 deletions(-) (limited to 'spec') diff --git a/spec/factories/chouette_vehicle_journey.rb b/spec/factories/chouette_vehicle_journey.rb index b7c5e37d5..9ba660800 100644 --- a/spec/factories/chouette_vehicle_journey.rb +++ b/spec/factories/chouette_vehicle_journey.rb @@ -3,29 +3,31 @@ FactoryGirl.define do factory :vehicle_journey_common, :class => Chouette::VehicleJourney do sequence(:objectid) { |n| "test:VehicleJourney:#{n}" } - factory :vehicle_journey do + factory :vehicle_journey_empty do association :journey_pattern, :factory => :journey_pattern after(:build) do |vehicle_journey| vehicle_journey.route = vehicle_journey.journey_pattern.route end - after(:create) do |vehicle_journey| - vehicle_journey.journey_pattern.stop_points.each_with_index do |stop_point, index| - vehicle_journey.vehicle_journey_at_stops << create(:vehicle_journey_at_stop, - :vehicle_journey => vehicle_journey, - :stop_point => stop_point, - :arrival_time => '2000-01-01 01:00:00 UTC', - :departure_time => '2000-01-01 03:00:00 UTC') + factory :vehicle_journey do + after(:create) do |vehicle_journey| + vehicle_journey.journey_pattern.stop_points.each_with_index do |stop_point, index| + vehicle_journey.vehicle_journey_at_stops << create(:vehicle_journey_at_stop, + :vehicle_journey => vehicle_journey, + :stop_point => stop_point, + :arrival_time => '2000-01-01 01:00:00 UTC', + :departure_time => '2000-01-01 03:00:00 UTC') + end end - end - factory :vehicle_journey_odd do - association :journey_pattern, :factory => :journey_pattern_odd - end + factory :vehicle_journey_odd do + association :journey_pattern, :factory => :journey_pattern_odd + end - factory :vehicle_journey_even do - association :journey_pattern, :factory => :journey_pattern_even + factory :vehicle_journey_even do + association :journey_pattern, :factory => :journey_pattern_even + end end end end diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index e537721af..9a1a55a02 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -262,13 +262,7 @@ describe Chouette::VehicleJourney, :type => :model do end it "orders journeys with nil times at the end" do - pattern = create(:journey_pattern) - journey_nil = build( - :vehicle_journey_common, - journey_pattern: pattern - ) - journey_nil.route = journey_nil.journey_pattern.route - journey_nil.save + journey_nil = create(:vehicle_journey_empty) journey = create( :vehicle_journey, route: journey_nil.route, -- cgit v1.2.3 From 32bc450f332b457ce7aca208a332876672df1bc1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 4 May 2017 17:01:31 +0200 Subject: vehicle_journey_spec.rb: #with_stops should sort journeys missing stops If a journey is missing one or more stops at the beginning of the route, it should be sorted by the first stop it stops at. Given these journeys: | 1 | 2 | 3 -------+-------+-------+------ Stop 1 | 10:00 | | 10:15 Stop 2 | 10:10 | 10:12 | 10:25 Stop 3 | 10:20 | 10:18 | 10:35 Journey should appear in between 1 and 3 because its first stop is between 10:00 and 10:15. Move the `initialize_stop_times` helper function outside of the first test in this `describe` so we can use it again in this test. Refs #3268 --- spec/models/chouette/vehicle_journey_spec.rb | 51 ++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 11 deletions(-) (limited to 'spec') diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 9a1a55a02..b22183ab6 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -222,18 +222,18 @@ describe Chouette::VehicleJourney, :type => :model do end describe ".with_stops" do - it "selects vehicle journeys including stops in order or earliest departure time" do - def initialize_stop_times(vehicle_journey, &block) - vehicle_journey - .vehicle_journey_at_stops - .each_with_index do |at_stop, index| - at_stop.update( - departure_time: at_stop.departure_time + block.call(index), - arrival_time: at_stop.arrival_time + block.call(index) - ) - end - end + def initialize_stop_times(vehicle_journey, &block) + vehicle_journey + .vehicle_journey_at_stops + .each_with_index do |at_stop, index| + at_stop.update( + departure_time: at_stop.departure_time + block.call(index), + arrival_time: at_stop.arrival_time + block.call(index) + ) + end + end + it "selects vehicle journeys including stops in order or earliest departure time" do # Create later vehicle journey to give it a later id, such that it should # appear last if the order in the query isn't right. journey_late = create(:vehicle_journey) @@ -279,6 +279,35 @@ describe Chouette::VehicleJourney, :type => :model do .to_a ).to eq(expected_journey_order) end + + it "journeys that skip the first stop(s) get ordered by the time of the \ + first stop that they make" do + journey_missing_stop = create(:vehicle_journey) + journey_early = create( + :vehicle_journey, + route: journey_missing_stop.route, + journey_pattern: journey_missing_stop.journey_pattern + ) + + initialize_stop_times(journey_early) do |index| + (index + 5).minutes + end + initialize_stop_times(journey_missing_stop) do |index| + (index + 65).minutes + end + + journey_missing_stop.vehicle_journey_at_stops.first.destroy + + expected_journey_order = [journey_early, journey_missing_stop] + + expect( + journey_missing_stop + .route + .vehicle_journeys + .with_stops + .to_a + ).to eq(expected_journey_order) + end end subject { create(:vehicle_journey_odd) } -- cgit v1.2.3 From bfea9e8e22a41d3de85fb265ba51b70e62aeba3f Mon Sep 17 00:00:00 2001 From: jpl Date: Thu, 4 May 2017 18:04:04 +0200 Subject: adding reducer tests for timetables reactux --- spec/javascripts/time_table/reducers/metas_spec.js | 2 +- spec/javascripts/time_table/reducers/modal_spec.js | 185 +++++++++++++++++++++ .../time_table/reducers/pagination_spec.js | 128 ++++++++++++++ .../javascripts/time_table/reducers/status_spec.js | 50 ++++++ .../time_table/reducers/timetable_spec.js | 20 +++ 5 files changed, 384 insertions(+), 1 deletion(-) create mode 100644 spec/javascripts/time_table/reducers/modal_spec.js create mode 100644 spec/javascripts/time_table/reducers/pagination_spec.js create mode 100644 spec/javascripts/time_table/reducers/status_spec.js create mode 100644 spec/javascripts/time_table/reducers/timetable_spec.js (limited to 'spec') diff --git a/spec/javascripts/time_table/reducers/metas_spec.js b/spec/javascripts/time_table/reducers/metas_spec.js index adc6a9d05..61e3048db 100644 --- a/spec/javascripts/time_table/reducers/metas_spec.js +++ b/spec/javascripts/time_table/reducers/metas_spec.js @@ -2,7 +2,7 @@ var metasReducer = require('es6_browserified/time_tables/reducers/metas') let state = {} -describe('status reducer', () => { +describe('metas reducer', () => { beforeEach(() => { let tag = { id: 0, diff --git a/spec/javascripts/time_table/reducers/modal_spec.js b/spec/javascripts/time_table/reducers/modal_spec.js new file mode 100644 index 000000000..ceed0a43e --- /dev/null +++ b/spec/javascripts/time_table/reducers/modal_spec.js @@ -0,0 +1,185 @@ +var modalReducer = require('es6_browserified/time_tables/reducers/modal') + +let state = {} + +describe('modal reducer', () => { + beforeEach(() => { + state = { + confirmModal: {}, + modalProps: { + active: false, + begin: { + day: '01', + month: '01', + year: String(new Date().getFullYear()) + }, + end: { + day: '01', + month: '01', + year: String(new Date().getFullYear()) + }, + index: false, + error: '' + }, + type: "" + } + }) + + it('should return the initial state', () => { + expect( + modalReducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle OPEN_CONFIRM_MODAL', () => { + let callback = function(){} + expect( + modalReducer(state, { + type: 'OPEN_CONFIRM_MODAL', + callback + }) + ).toEqual(Object.assign({}, state, {type: "confirm", confirmModal: { callback: callback }})) + }) + + it('should handle CLOSE_PERIOD_FORM', () => { + let newModalProps = Object.assign({}, state.modalProps, {active: false}) + expect( + modalReducer(state, { + type: 'CLOSE_PERIOD_FORM' + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) + + it('should handle OPEN_EDIT_PERIOD_FORM', () => { + let period = { + id : 1, + period_end : "2017-03-05", + period_start : "2017-02-23" + } + let period_start = period.period_start.split('-') + let period_end = period.period_end.split('-') + + let index = 1 + + let newModalProps = { + active: true, + begin: { + day: period_start[2], + month: period_start[1], + year: period_start[0] + }, + end: { + day: period_end[2], + month: period_end[1], + year: period_end[0] + }, + index: index, + error: '' + } + expect( + modalReducer(state, { + type: 'OPEN_EDIT_PERIOD_FORM', + period, + index + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) + + it('should handle OPEN_ADD_PERIOD_FORM', () => { + let emptyDate = { + day: '01', + month: '01', + year: String(new Date().getFullYear()) + } + let newModalProps = Object.assign({}, state.modalProps, { + active: true, + begin: emptyDate, + end: emptyDate, + index: false, + error: "" + }) + + expect( + modalReducer(state, { + type: 'OPEN_ADD_PERIOD_FORM' + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) + + it('should handle UPDATE_PERIOD_FORM', () => { + let val = "11" + let group = "begin" + let selectType = "day" + + let newModalProps = { + active: false, + begin: { + day: val, + month: '01', + year: String(new Date().getFullYear()) + }, + end: { + day: '01', + month: '01', + year: String(new Date().getFullYear()) + }, + index: false, + error: '' + } + + expect( + modalReducer(state, { + type: 'UPDATE_PERIOD_FORM', + val, + group, + selectType + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) + + it('should handle VALIDATE_PERIOD_FORM', () => { + // if period_end <= period_start, throw error + // if newperiod is on another one, throw error + + let modProps = { + active: false, + begin: { + day: '13', + month: '01', + year: String(new Date().getFullYear()) + }, + end: { + day: '01', + month: '01', + year: String(new Date().getFullYear()) + }, + index: false, + error: '' + } + let newModalProps = { + active: false, + begin: { + day: '01', + month: '01', + year: String(new Date().getFullYear()) + }, + end: { + day: '01', + month: '01', + year: String(new Date().getFullYear()) + }, + index: false, + error: 'La date de départ doit être antérieure à la date de fin' + } + + let ttperiods = [] + + expect( + modalReducer(state, { + type: 'VALIDATE_PERIOD_FORM', + modalProps : modProps, + timeTablePeriods: ttperiods + }) + ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) + }) +}) diff --git a/spec/javascripts/time_table/reducers/pagination_spec.js b/spec/javascripts/time_table/reducers/pagination_spec.js new file mode 100644 index 000000000..740ded3ac --- /dev/null +++ b/spec/javascripts/time_table/reducers/pagination_spec.js @@ -0,0 +1,128 @@ +var paginationReducer = require('es6_browserified/time_tables/reducers/pagination') + +const dispatch = function(){} + +let pagination = { + currentPage: "1982-02-15", + periode_range: ["1982-02-01", "1982-02-02", "1982-02-03"], + stateChanged: false +} + +let state = {} + +describe('pagination reducer', () => { + beforeEach(() => { + state = { + currentPage: "", + periode_range: [], + stateChanged: false + } + }) + + it('should return the initial state', () => { + expect( + paginationReducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle RECEIVE_TIME_TABLES', () => { + let json = [{ + current_periode_range: "1982-02-15", + periode_range: ["1982-02-01", "1982-02-02", "1982-02-03"] + }] + expect( + paginationReducer(state, { + type: 'RECEIVE_TIME_TABLES', + json + }) + ).toEqual(Object.assign({}, state, {currentPage: json.current_periode_range, periode_range: json.periode_range})) + }) + + it('should handle GO_TO_PREVIOUS_PAGE', () => { + let nextPage = nextPage ? 1 : -1 + let newPage = pagination.periode_range[pagination.periode_range.indexOf(pagination.currentPage) + nextPage] + + expect( + paginationReducer(state, { + type: 'GO_TO_PREVIOUS_PAGE', + dispatch, + pagination, + nextPage: false + }) + ).toEqual(Object.assign({}, state, {currentPage : newPage, stateChanged: false})) + }) + it('should handle GO_TO_NEXT_PAGE', () => { + let nextPage = nextPage ? 1 : -1 + let newPage = pagination.periode_range[pagination.periode_range.indexOf(pagination.currentPage) + nextPage] + + expect( + paginationReducer(state, { + type: 'GO_TO_NEXT_PAGE', + dispatch, + pagination, + nextPage: false + }) + ).toEqual(Object.assign({}, state, {currentPage : newPage, stateChanged: false})) + }) + + it('should handle CHANGE_PAGE', () => { + let page = "1982-02-15" + expect( + paginationReducer(state, { + type: 'CHANGE_PAGE', + dispatch, + page + }) + ).toEqual(Object.assign({}, state, {currentPage : page, stateChanged: false})) + }) + + it('should handle INCLUDE_DATE_IN_PERIOD', () => { + expect( + paginationReducer(state, { + type: 'INCLUDE_DATE_IN_PERIOD' + }) + ).toEqual(Object.assign({}, state, {stateChanged: true})) + }) + it('should handle EXCLUDE_DATE_FROM_PERIOD', () => { + expect( + paginationReducer(state, { + type: 'EXCLUDE_DATE_FROM_PERIOD' + }) + ).toEqual(Object.assign({}, state, {stateChanged: true})) + }) + it('should handle DELETE_PERIOD', () => { + expect( + paginationReducer(state, { + type: 'DELETE_PERIOD' + }) + ).toEqual(Object.assign({}, state, {stateChanged: true})) + }) + it('should handle VALIDATE_PERIOD_FORM', () => { + expect( + paginationReducer(state, { + type: 'VALIDATE_PERIOD_FORM' + }) + ).toEqual(Object.assign({}, state, {stateChanged: true})) + }) + it('should handle UPDATE_COMMENT', () => { + expect( + paginationReducer(state, { + type: 'UPDATE_COMMENT' + }) + ).toEqual(Object.assign({}, state, {stateChanged: true})) + }) + it('should handle UPDATE_COLOR', () => { + expect( + paginationReducer(state, { + type: 'UPDATE_COLOR' + }) + ).toEqual(Object.assign({}, state, {stateChanged: true})) + }) + it('should handle UPDATE_DAY_TYPES', () => { + expect( + paginationReducer(state, { + type: 'UPDATE_DAY_TYPES' + }) + ).toEqual(Object.assign({}, state, {stateChanged: true})) + }) +}) diff --git a/spec/javascripts/time_table/reducers/status_spec.js b/spec/javascripts/time_table/reducers/status_spec.js new file mode 100644 index 000000000..f000324cc --- /dev/null +++ b/spec/javascripts/time_table/reducers/status_spec.js @@ -0,0 +1,50 @@ +var statusReducer = require('es6_browserified/time_tables/reducers/status') + +let state = {} + +describe('status reducer', () => { + beforeEach(() => { + state = { + actionType: "edit", + fetchSuccess: true, + isFetching: false + } + }) + + it('should return the initial state', () => { + expect( + statusReducer(undefined, {}) + ).toEqual({}) + }) + + it('should handle UNAVAILABLE_SERVER', () => { + expect( + statusReducer(state, { + type: 'UNAVAILABLE_SERVER' + }) + ).toEqual(Object.assign({}, state, {fetchSuccess: false})) + }) + + it('should handle FETCH_API', () => { + expect( + statusReducer(state, { + type: 'FETCH_API' + }) + ).toEqual(Object.assign({}, state, {isFetching: true})) + }) + + it('should handle RECEIVE_TIME_TABLES', () => { + expect( + statusReducer(state, { + type: 'RECEIVE_TIME_TABLES' + }) + ).toEqual(Object.assign({}, state, {fetchSuccess: true, isFetching: false})) + }) + it('should handle RECEIVE_MONTH', () => { + expect( + statusReducer(state, { + type: 'RECEIVE_MONTH' + }) + ).toEqual(Object.assign({}, state, {fetchSuccess: true, isFetching: false})) + }) +}) diff --git a/spec/javascripts/time_table/reducers/timetable_spec.js b/spec/javascripts/time_table/reducers/timetable_spec.js new file mode 100644 index 000000000..734095cfc --- /dev/null +++ b/spec/javascripts/time_table/reducers/timetable_spec.js @@ -0,0 +1,20 @@ +var timetableReducer = require('es6_browserified/time_tables/reducers/timetable') + +let state = {} + +describe('timetable reducer', () => { + beforeEach(() => { + state = { + current_month: [], + current_periode_range: "", + periode_range: [], + time_table_periods: [] + } + }) + + it('should return the initial state', () => { + expect( + timetableReducer(undefined, {}) + ).toEqual({}) + }) +}) -- cgit v1.2.3 From c1b2c713d1fd355e1e5e853bf1d0c5fa95c8bb72 Mon Sep 17 00:00:00 2001 From: jpl Date: Fri, 5 May 2017 12:39:35 +0200 Subject: adding reducer tests for timetables reactux (2) --- spec/javascripts/time_table/reducers/modal_spec.js | 72 ++++++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/javascripts/time_table/reducers/modal_spec.js b/spec/javascripts/time_table/reducers/modal_spec.js index ceed0a43e..4246027b8 100644 --- a/spec/javascripts/time_table/reducers/modal_spec.js +++ b/spec/javascripts/time_table/reducers/modal_spec.js @@ -137,10 +137,7 @@ describe('modal reducer', () => { ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) }) - it('should handle VALIDATE_PERIOD_FORM', () => { - // if period_end <= period_start, throw error - // if newperiod is on another one, throw error - + it('should handle VALIDATE_PERIOD_FORM and throw error if period starts after the end', () => { let modProps = { active: false, begin: { @@ -182,4 +179,71 @@ describe('modal reducer', () => { }) ).toEqual(Object.assign({}, state, {modalProps: newModalProps})) }) + + it('should handle VALIDATE_PERIOD_FORM and throw error if periods overlap', () => { + let state2 = { + confirmModal: {}, + modalProps: { + active: false, + begin: { + day: '03', + month: '05', + year: '2017' + }, + end: { + day: '09', + month: '05', + year: '2017' + }, + index: false, + error: '' + }, + type: '' + } + let modProps2 = { + active: false, + begin: { + day: '03', + month: '05', + year: '2017' + }, + end: { + day: '09', + month: '05', + year: '2017' + }, + index: false, + error: '' + } + let ttperiods2 = [ + {id: 261, period_start: '2017-02-23', period_end: '2017-03-05'}, + {id: 262, period_start: '2017-03-15', period_end: '2017-03-25'}, + {id: 264, period_start: '2017-04-24', period_end: '2017-05-04'}, + {id: 265, period_start: '2017-05-14', period_end: '2017-05-24'} + ] + + let newModalProps2 = { + active: true, + begin: { + day: '03', + month: '05', + year: '2017' + }, + end: { + day: '09', + month: '05', + year: '2017' + }, + index: false, + error: "Les périodes ne peuvent pas se chevaucher" + } + + expect( + modalReducer(state2, { + type: 'VALIDATE_PERIOD_FORM', + modalProps : modProps2, + timeTablePeriods: ttperiods2 + }) + ).toEqual(Object.assign({}, state2, {modalProps: newModalProps2})) + }) }) -- cgit v1.2.3 From ef13c897645ed2397db3fede5257a41f62ca9c39 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 5 May 2017 15:33:40 +0200 Subject: Js gardening in timetable actions & action specs Signed-off-by: Thomas Shawarma Haddad --- spec/javascripts/time_table/actions_spec.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'spec') diff --git a/spec/javascripts/time_table/actions_spec.js b/spec/javascripts/time_table/actions_spec.js index 73b2d2ac9..a8abd8f90 100644 --- a/spec/javascripts/time_table/actions_spec.js +++ b/spec/javascripts/time_table/actions_spec.js @@ -171,10 +171,9 @@ describe('actions', () => { const expectedAction = { type: 'INCLUDE_DATE_IN_PERIOD', index, - day, dayTypes } - expect(actions.includeDateInPeriod(index, day, dayTypes)).toEqual(expectedAction) + expect(actions.includeDateInPeriod(index, dayTypes)).toEqual(expectedAction) }) it('should create an action to exclude date from period', () => { @@ -182,10 +181,9 @@ describe('actions', () => { const expectedAction = { type: 'EXCLUDE_DATE_FROM_PERIOD', index, - day, dayTypes } - expect(actions.excludeDateFromPeriod(index, day, dayTypes)).toEqual(expectedAction) + expect(actions.excludeDateFromPeriod(index, dayTypes)).toEqual(expectedAction) }) it('should create an action to open confirm modal', () => { -- cgit v1.2.3 From 757304a4378ba82543e42e21a75b0509272b8d67 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Fri, 5 May 2017 16:52:03 +0200 Subject: Add specs for timetable reducers Signed-off-by: Thomas Shawarma Haddad --- .../time_table/reducers/timetable_spec.js | 166 ++++++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/javascripts/time_table/reducers/timetable_spec.js b/spec/javascripts/time_table/reducers/timetable_spec.js index 734095cfc..0b418a52e 100644 --- a/spec/javascripts/time_table/reducers/timetable_spec.js +++ b/spec/javascripts/time_table/reducers/timetable_spec.js @@ -1,8 +1,26 @@ +require('whatwg-fetch') var timetableReducer = require('es6_browserified/time_tables/reducers/timetable') let state = {} +const dispatch = function(){} +let arrDayTypes = [true, true, true, true, true, true, true] +let strDayTypes = 'LuMaMeJeVeSaDi' +let time_table_periods = [{"id":261,"period_start":"2017-02-23","period_end":"2017-03-05"},{"id":262,"period_start":"2017-03-15","period_end":"2017-03-25"},{"id":263,"period_start":"2017-04-04","period_end":"2017-04-14"},{"id":264,"period_start":"2017-04-24","period_end":"2017-05-04"},{"id":265,"period_start":"2017-05-14","period_end":"2017-05-24"}] +let current_periode_range = "2017-05-01" +let periode_range = ["2014-05-01","2014-06-01","2014-07-01","2014-08-01","2014-09-01","2014-10-01","2014-11-01","2014-12-01","2015-01-01","2015-02-01","2015-03-01","2015-04-01","2015-05-01","2015-06-01","2015-07-01","2015-08-01","2015-09-01","2015-10-01","2015-11-01","2015-12-01","2016-01-01","2016-02-01","2016-03-01","2016-04-01","2016-05-01","2016-06-01","2016-07-01","2016-08-01","2016-09-01","2016-10-01","2016-11-01","2016-12-01","2017-01-01","2017-02-01","2017-03-01","2017-04-01","2017-05-01","2017-06-01","2017-07-01","2017-08-01","2017-09-01","2017-10-01","2017-11-01","2017-12-01","2018-01-01","2018-02-01","2018-03-01","2018-04-01","2018-05-01","2018-06-01","2018-07-01","2018-08-01","2018-09-01","2018-10-01","2018-11-01","2018-12-01","2019-01-01","2019-02-01","2019-03-01","2019-04-01","2019-05-01","2019-06-01","2019-07-01","2019-08-01","2019-09-01","2019-10-01","2019-11-01","2019-12-01","2020-01-01","2020-02-01","2020-03-01","2020-04-01","2020-05-01"] +let current_month = [{"day":"lundi","date":"2017-05-01","wday":1,"wnumber":"18","mday":1,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-02","wday":2,"wnumber":"18","mday":2,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-03","wday":3,"wnumber":"18","mday":3,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-04","wday":4,"wnumber":"18","mday":4,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-05","wday":5,"wnumber":"18","mday":5,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-06","wday":6,"wnumber":"18","mday":6,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-07","wday":0,"wnumber":"18","mday":7,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-08","wday":1,"wnumber":"19","mday":8,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-09","wday":2,"wnumber":"19","mday":9,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-10","wday":3,"wnumber":"19","mday":10,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-11","wday":4,"wnumber":"19","mday":11,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-12","wday":5,"wnumber":"19","mday":12,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-13","wday":6,"wnumber":"19","mday":13,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-14","wday":0,"wnumber":"19","mday":14,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-15","wday":1,"wnumber":"20","mday":15,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-16","wday":2,"wnumber":"20","mday":16,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-17","wday":3,"wnumber":"20","mday":17,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-18","wday":4,"wnumber":"20","mday":18,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-19","wday":5,"wnumber":"20","mday":19,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-20","wday":6,"wnumber":"20","mday":20,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-21","wday":0,"wnumber":"20","mday":21,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-22","wday":1,"wnumber":"21","mday":22,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-23","wday":2,"wnumber":"21","mday":23,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-24","wday":3,"wnumber":"21","mday":24,"include_date":false,"excluded_date":false},{"day":"jeudi","date":"2017-05-25","wday":4,"wnumber":"21","mday":25,"include_date":false,"excluded_date":false},{"day":"vendredi","date":"2017-05-26","wday":5,"wnumber":"21","mday":26,"include_date":false,"excluded_date":false},{"day":"samedi","date":"2017-05-27","wday":6,"wnumber":"21","mday":27,"include_date":false,"excluded_date":false},{"day":"dimanche","date":"2017-05-28","wday":0,"wnumber":"21","mday":28,"include_date":false,"excluded_date":false},{"day":"lundi","date":"2017-05-29","wday":1,"wnumber":"22","mday":29,"include_date":false,"excluded_date":false},{"day":"mardi","date":"2017-05-30","wday":2,"wnumber":"22","mday":30,"include_date":false,"excluded_date":false},{"day":"mercredi","date":"2017-05-31","wday":3,"wnumber":"22","mday":31,"include_date":false,"excluded_date":false}] -describe('timetable reducer', () => { +let newCurrentMonth = [{"day":"lundi","date":"2017-05-01","wday":1,"wnumber":"18","mday":1,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mardi","date":"2017-05-02","wday":2,"wnumber":"18","mday":2,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mercredi","date":"2017-05-03","wday":3,"wnumber":"18","mday":3,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"jeudi","date":"2017-05-04","wday":4,"wnumber":"18","mday":4,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"vendredi","date":"2017-05-05","wday":5,"wnumber":"18","mday":5,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"samedi","date":"2017-05-06","wday":6,"wnumber":"18","mday":6,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"dimanche","date":"2017-05-07","wday":0,"wnumber":"18","mday":7,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"lundi","date":"2017-05-08","wday":1,"wnumber":"19","mday":8,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mardi","date":"2017-05-09","wday":2,"wnumber":"19","mday":9,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mercredi","date":"2017-05-10","wday":3,"wnumber":"19","mday":10,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"jeudi","date":"2017-05-11","wday":4,"wnumber":"19","mday":11,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"vendredi","date":"2017-05-12","wday":5,"wnumber":"19","mday":12,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"samedi","date":"2017-05-13","wday":6,"wnumber":"19","mday":13,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"dimanche","date":"2017-05-14","wday":0,"wnumber":"19","mday":14,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"lundi","date":"2017-05-15","wday":1,"wnumber":"20","mday":15,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mardi","date":"2017-05-16","wday":2,"wnumber":"20","mday":16,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mercredi","date":"2017-05-17","wday":3,"wnumber":"20","mday":17,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"jeudi","date":"2017-05-18","wday":4,"wnumber":"20","mday":18,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"vendredi","date":"2017-05-19","wday":5,"wnumber":"20","mday":19,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"samedi","date":"2017-05-20","wday":6,"wnumber":"20","mday":20,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"dimanche","date":"2017-05-21","wday":0,"wnumber":"20","mday":21,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"lundi","date":"2017-05-22","wday":1,"wnumber":"21","mday":22,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mardi","date":"2017-05-23","wday":2,"wnumber":"21","mday":23,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"mercredi","date":"2017-05-24","wday":3,"wnumber":"21","mday":24,"include_date":false,"excluded_date":false,"in_periods":true},{"day":"jeudi","date":"2017-05-25","wday":4,"wnumber":"21","mday":25,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"vendredi","date":"2017-05-26","wday":5,"wnumber":"21","mday":26,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"samedi","date":"2017-05-27","wday":6,"wnumber":"21","mday":27,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"dimanche","date":"2017-05-28","wday":0,"wnumber":"21","mday":28,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"lundi","date":"2017-05-29","wday":1,"wnumber":"22","mday":29,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mardi","date":"2017-05-30","wday":2,"wnumber":"22","mday":30,"include_date":false,"excluded_date":false,"in_periods":false},{"day":"mercredi","date":"2017-05-31","wday":3,"wnumber":"22","mday":31,"include_date":false,"excluded_date":false,"in_periods":false}] + +let json = { + current_month: current_month, + current_periode_range: current_periode_range, + periode_range: periode_range, + time_table_periods: time_table_periods, + day_types: strDayTypes +} + +describe('timetable reducer with empty state', () => { beforeEach(() => { state = { current_month: [], @@ -17,4 +35,150 @@ describe('timetable reducer', () => { timetableReducer(undefined, {}) ).toEqual({}) }) + + it('should handle RECEIVE_TIME_TABLES', () => { + let newState = { + current_month: newCurrentMonth, + current_periode_range: current_periode_range, + periode_range: periode_range, + time_table_periods: time_table_periods, + } + expect( + timetableReducer(state, { + type: 'RECEIVE_TIME_TABLES', + json + }) + ).toEqual(newState) + }) +}) + +describe('timetable reducer with filled state', () => { + beforeEach(() => { + state = { + current_month: newCurrentMonth, + current_periode_range: current_periode_range, + periode_range: periode_range, + time_table_periods: time_table_periods, + } + }) + + it('should handle RECEIVE_MONTH', () => { + expect( + timetableReducer(state, { + type: 'RECEIVE_MONTH', + json: { + days: current_month, + day_types: strDayTypes + } + }) + ).toEqual(state) + }) + + + it('should handle GO_TO_PREVIOUS_PAGE', () => { + let pagination = { + periode_range: periode_range, + currentPage: current_periode_range + } + expect( + timetableReducer(state, { + type: 'GO_TO_PREVIOUS_PAGE', + dispatch, + pagination, + nextPage: false + }) + ).toEqual(Object.assign({}, state, {current_periode_range: '2017-04-01'})) + }) + + it('should handle GO_TO_NEXT_PAGE', () => { + let pagination = { + periode_range: periode_range, + currentPage: current_periode_range + } + expect( + timetableReducer(state, { + type: 'GO_TO_NEXT_PAGE', + dispatch, + pagination, + nextPage: true + }) + ).toEqual(Object.assign({}, state, {current_periode_range: '2017-06-01'})) + }) + + it('should handle CHANGE_PAGE', () => { + const actions = { + fetchTimeTables: function(){} + } + let newPage = '2017-05-01' + expect( + timetableReducer(state, { + type: 'CHANGE_PAGE', + dispatch, + page: newPage + }) + ).toEqual(Object.assign({}, state, {current_periode_range: newPage})) + }) + + it('should handle DELETE_PERIOD', () => { + state.time_table_periods[0].deleted = true + expect( + timetableReducer(state, { + type: 'DELETE_PERIOD', + index: 0, + dayTypes: arrDayTypes + }) + ).toEqual(state) + }) + + it('should handle INCLUDE_DATE_IN_PERIOD', () => { + state.current_month[4].include_date = true + expect( + timetableReducer(state, { + type: 'INCLUDE_DATE_IN_PERIOD', + index: 4, + dayTypes: arrDayTypes + }) + ).toEqual(state) + }) + + it('should handle EXCLUDE_DATE_FROM_PERIOD', () => { + state.current_month[0].excluded_date = true + expect( + timetableReducer(state, { + type: 'EXCLUDE_DATE_FROM_PERIOD', + index: 0, + dayTypes: arrDayTypes + }) + ).toEqual(state) + }) + + it('should handle VALIDATE_PERIOD_FORM', () => { + state.current_month[13].in_periods = false + state.time_table_periods[4].period_start = '2017-05-15' + let modalProps = { + active: false, + begin: { + day: '15', + month: '05', + year: '2017' + }, + end: { + day: '24', + month: '05', + year: '2017' + }, + error: '', + index: 4 + } + expect( + timetableReducer(state, { + type: 'VALIDATE_PERIOD_FORM', + modalProps: modalProps, + timeTablePeriods: state.time_table_periods, + metas: { + day_types: arrDayTypes + } + }) + ).toEqual(state) + }) }) -- cgit v1.2.3 From 5227470be41405a27b0cb02fd305401a942998f4 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 4 May 2017 18:15:46 +0200 Subject: Refs # 3297; behavior speced --- spec/factories/chouette_routes.rb | 2 + spec/models/chouette/route/route_base_spec.rb | 69 ++++++++ spec/models/chouette/route/route_delete_spec.rb | 44 ++++++ .../chouette/route/route_stop_points_spec.rb | 112 +++++++++++++ spec/models/chouette/route_spec.rb | 173 --------------------- 5 files changed, 227 insertions(+), 173 deletions(-) create mode 100644 spec/models/chouette/route/route_base_spec.rb create mode 100644 spec/models/chouette/route/route_delete_spec.rb create mode 100644 spec/models/chouette/route/route_stop_points_spec.rb delete mode 100644 spec/models/chouette/route_spec.rb (limited to 'spec') diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb index e872d24f5..8cbbe20cf 100644 --- a/spec/factories/chouette_routes.rb +++ b/spec/factories/chouette_routes.rb @@ -14,10 +14,12 @@ FactoryGirl.define do transient do stop_points_count 5 + journey_patterns_count 2 end after(:create) do |route, evaluator| create_list(:stop_point, evaluator.stop_points_count, route: route) + create_list(:journey_pattern, evaluator.journey_patterns_count, route: route) end end diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb new file mode 100644 index 000000000..08f201022 --- /dev/null +++ b/spec/models/chouette/route/route_base_spec.rb @@ -0,0 +1,69 @@ +RSpec.describe Chouette::Route, :type => :model do + + subject { create(:route) } + + describe '#objectid' do + subject { super().objectid } + it { is_expected.to be_kind_of(Chouette::ObjectId) } + end + + it { is_expected.to enumerize(:direction).in(:straight_forward, :backward, :clockwise, :counter_clockwise, :north, :north_west, :west, :south_west, :south, :south_east, :east, :north_east) } + it { is_expected.to enumerize(:wayback).in(:straight_forward, :backward) } + + #it { is_expected.to validate_presence_of :name } + it { is_expected.to validate_presence_of :line } + it { is_expected.to validate_uniqueness_of :objectid } + #it { is_expected.to validate_presence_of :wayback_code } + #it { is_expected.to validate_presence_of :direction_code } + it { is_expected.to validate_inclusion_of(:direction).in_array(%i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east)) } + it { is_expected.to validate_inclusion_of(:wayback).in_array(%i(straight_forward backward)) } + + context "reordering methods" do + let(:bad_stop_point_ids){subject.stop_points.map { |sp| sp.id + 1}} + let(:ident){subject.stop_points.map(&:id)} + let(:first_last_swap){ [ident.last] + ident[1..-2] + [ident.first]} + + describe "#reorder!" do + context "invalid stop_point_ids" do + let(:new_stop_point_ids) { bad_stop_point_ids} + it { expect(subject.reorder!( new_stop_point_ids)).to be_falsey} + end + + context "swaped last and first stop_point_ids" do + let!(:new_stop_point_ids) { first_last_swap} + let!(:old_stop_point_ids) { subject.stop_points.map(&:id) } + let!(:old_stop_area_ids) { subject.stop_areas.map(&:id) } + + it "should keep stop_point_ids order unchanged" do + expect(subject.reorder!( new_stop_point_ids)).to be_truthy + expect(subject.stop_points.map(&:id)).to eq( old_stop_point_ids) + end + # This test is no longer relevant, as reordering is done with Reactux + # it "should have changed stop_area_ids order" do + # expect(subject.reorder!( new_stop_point_ids)).to be_truthy + # subject.reload + # expect(subject.stop_areas.map(&:id)).to eq( [old_stop_area_ids.last] + old_stop_area_ids[1..-2] + [old_stop_area_ids.first]) + # end + end + end + + describe "#stop_point_permutation?" do + context "invalid stop_point_ids" do + let( :new_stop_point_ids ) { bad_stop_point_ids} + it { is_expected.not_to be_stop_point_permutation( new_stop_point_ids)} + end + context "unchanged stop_point_ids" do + let(:new_stop_point_ids) { ident} + it { is_expected.to be_stop_point_permutation( new_stop_point_ids)} + end + context "swaped last and first stop_point_ids" do + let(:new_stop_point_ids) { first_last_swap} + it { is_expected.to be_stop_point_permutation( new_stop_point_ids)} + end + end + end + +end + + + diff --git a/spec/models/chouette/route/route_delete_spec.rb b/spec/models/chouette/route/route_delete_spec.rb new file mode 100644 index 000000000..fa8a8a947 --- /dev/null +++ b/spec/models/chouette/route/route_delete_spec.rb @@ -0,0 +1,44 @@ +RSpec.describe Chouette::Route, :type => :model do + + subject { create(:route) } + + + context "delete a route" do + let( :vehicle_journey ){ create :vehicle_journey } + + it "deletes the associated journey_patterns" do + expected_delta = subject.journey_patterns.count + expect( expected_delta ).to be_positive + expect{ subject.delete }.to change{Chouette::JourneyPattern.count}.by -expected_delta + end + + it "deletes the associated stop_points" do + expected_delta = subject.stop_points.count + expect( expected_delta ).to be_positive + expect{ subject.delete }.to change{Chouette::StopPoint.count}.by -expected_delta + end + + it "does not delete the associated stop_areas" do + count = subject.stop_points.count + expect( count ).to be_positive + expect{ subject.delete }.not_to change{Chouette::StopArea.count} + end + + it "deletes the associated vehicle_journeys" do + expect{ vehicle_journey.route.delete }.to change{Chouette::VehicleJourney.count}.by -1 + end + + it "does not delete the corresponding time_tables" do + tt = create :time_table + tt.vehicle_journeys << vehicle_journey + tables = vehicle_journey.route.time_tables + expect( tables ).not_to be_empty + expect{ vehicle_journey.route.delete }.not_to change{Chouette::TimeTable.count} + end + + it "does not delete the associated line" do + expect( subject.line ).not_to be_nil + expect{ subject.delete }.not_to change{Chouette::Line.count} + end + end +end diff --git a/spec/models/chouette/route/route_stop_points_spec.rb b/spec/models/chouette/route/route_stop_points_spec.rb new file mode 100644 index 000000000..03c53b4cf --- /dev/null +++ b/spec/models/chouette/route/route_stop_points_spec.rb @@ -0,0 +1,112 @@ +RSpec.describe Chouette::Route, :type => :model do + + subject { create(:route) } + + describe "#stop_points_attributes=" do + let(:journey_pattern) { create( :journey_pattern, :route => subject )} + let(:vehicle_journey) { create( :vehicle_journey, :journey_pattern => journey_pattern)} + def subject_stop_points_attributes + {}.tap do |hash| + subject.stop_points.each_with_index { |sp,index| hash[ index.to_s ] = sp.attributes } + end + end + context "route having swapped a new stop" do + let( :new_stop_point ){build( :stop_point, :route => subject)} + def added_stop_hash + subject_stop_points_attributes.tap do |h| + h["4"] = new_stop_point.attributes.merge( "position" => "4", "_destroy" => "" ) + end + end + let!( :new_route_size ){ subject.stop_points.size+1 } + + it "should have added stop_point in route" do + subject.update_attributes( :stop_points_attributes => added_stop_hash) + expect(Chouette::Route.find( subject.id ).stop_points.size).to eq(new_route_size) + end + it "should have added stop_point in route's journey pattern" do + subject.update_attributes( :stop_points_attributes => added_stop_hash) + expect(Chouette::JourneyPattern.find( journey_pattern.id ).stop_points.size).to eq(new_route_size) + end + it "should have added stop_point in route's vehicle journey at stop" do + subject.update_attributes( :stop_points_attributes => added_stop_hash) + expect(Chouette::VehicleJourney.find( vehicle_journey.id ).vehicle_journey_at_stops.size).to eq(new_route_size) + end + end + context "route having swapped stop" do + def swapped_stop_hash + subject_stop_points_attributes.tap do |h| + h[ "1" ][ "position" ] = "3" + h[ "3" ][ "position" ] = "1" + end + end + let!( :new_stop_id_list ){ subject.stop_points.map(&:id).tap {|array| array.insert( 1, array.delete_at(3)); array.insert( 3, array.delete_at(2) )} } + + it "should have swap stop_points from route" do + subject.update_attributes( :stop_points_attributes => swapped_stop_hash) + expect(Chouette::Route.find(subject.id).stop_points.map(&:id).sort).to eq(new_stop_id_list.sort) + end + it "should have swap stop_points from route's journey pattern" do + subject.update_attributes( :stop_points_attributes => swapped_stop_hash) + expect(Chouette::JourneyPattern.find( journey_pattern.id ).stop_points.map(&:id).sort).to eq(new_stop_id_list.sort) + end + it "should have swap stop_points from route's vehicle journey at stop" do + subject.update_attributes( :stop_points_attributes => swapped_stop_hash) + expect(Chouette::VehicleJourney.find( vehicle_journey.id ).vehicle_journey_at_stops.map(&:stop_point_id)).to match_array(new_stop_id_list) + end + end + context "route having a deleted stop" do + def removed_stop_hash + subject_stop_points_attributes.tap do |h| + h[ "1" ][ "_destroy" ] = "1" + end + end + let!( :new_stop_id_list ){ subject.stop_points.map(&:id).tap {|array| array.delete_at(1) } } + + it "should ignore deleted stop_point from route" do + subject.update_attributes( :stop_points_attributes => removed_stop_hash) + expect(Chouette::Route.find( subject.id ).stop_points.map(&:id).sort).to eq(new_stop_id_list.sort) + end + it "should ignore deleted stop_point from route's journey pattern" do + subject.update_attributes( :stop_points_attributes => removed_stop_hash) + expect(Chouette::JourneyPattern.find( journey_pattern.id ).stop_points.map(&:id).sort).to eq(new_stop_id_list.sort) + end + it "should ignore deleted stop_point from route's vehicle journey at stop" do + subject.update_attributes( :stop_points_attributes => removed_stop_hash) + expect(Chouette::VehicleJourney.find( vehicle_journey.id ).vehicle_journey_at_stops.map(&:stop_point_id).sort).to match_array(new_stop_id_list.sort) + end + end + end + + describe "#stop_points" do + context "#find_by_stop_area" do + context "when arg is first quay id" do + let(:first_stop_point) { subject.stop_points.first} + it "should return first quay" do + expect(subject.stop_points.find_by_stop_area( first_stop_point.stop_area_id)).to eq( first_stop_point) + end + end + end + end + describe "#stop_areas" do + let(:line){ create(:line)} + let(:route_1){ create(:route, :line => line)} + let(:route_2){ create(:route, :line => line)} + it "should retreive all stop_area on route" do + route_1.stop_areas.each do |sa| + expect(sa.stop_points.map(&:route_id).uniq).to eq([route_1.id]) + end + end + + context "when route is looping: last and first stop area are the same" do + it "should retreive same stop_area one last and first position" do + route_loop = create(:route, :line => line) + first_stop = Chouette::StopPoint.where( :route_id => route_loop.id, :position => 0).first + last_stop = create(:stop_point, :route => route_loop, :position => 4, :stop_area => first_stop.stop_area) + + expect(route_loop.stop_areas.size).to eq(6) + expect(route_loop.stop_areas.select {|s| s.id == first_stop.stop_area.id}.size).to eq(2) + end + end + end +end + diff --git a/spec/models/chouette/route_spec.rb b/spec/models/chouette/route_spec.rb deleted file mode 100644 index 6138f28b9..000000000 --- a/spec/models/chouette/route_spec.rb +++ /dev/null @@ -1,173 +0,0 @@ -require 'spec_helper' - -describe Chouette::Route, :type => :model do - subject { create(:route) } - - describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::ObjectId) } - end - - it { is_expected.to enumerize(:direction).in(:straight_forward, :backward, :clockwise, :counter_clockwise, :north, :north_west, :west, :south_west, :south, :south_east, :east, :north_east) } - it { is_expected.to enumerize(:wayback).in(:straight_forward, :backward) } - - #it { is_expected.to validate_presence_of :name } - it { is_expected.to validate_presence_of :line } - it { is_expected.to validate_uniqueness_of :objectid } - #it { is_expected.to validate_presence_of :wayback_code } - #it { is_expected.to validate_presence_of :direction_code } - it { is_expected.to validate_inclusion_of(:direction).in_array(%i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east)) } - it { is_expected.to validate_inclusion_of(:wayback).in_array(%i(straight_forward backward)) } - - context "reordering methods" do - let( :bad_stop_point_ids){subject.stop_points.map { |sp| sp.id + 1}} - let( :ident){subject.stop_points.map(&:id)} - let( :first_last_swap){ [ident.last] + ident[1..-2] + [ident.first]} - - describe "#reorder!" do - context "invalid stop_point_ids" do - let( :new_stop_point_ids) { bad_stop_point_ids} - it { expect(subject.reorder!( new_stop_point_ids)).to be_falsey} - end - - context "swaped last and first stop_point_ids" do - let!( :new_stop_point_ids) { first_last_swap} - let!( :old_stop_point_ids) { subject.stop_points.map(&:id) } - let!( :old_stop_area_ids) { subject.stop_areas.map(&:id) } - - it "should keep stop_point_ids order unchanged" do - expect(subject.reorder!( new_stop_point_ids)).to be_truthy - expect(subject.stop_points.map(&:id)).to eq( old_stop_point_ids) - end - # This test is no longer relevant, as reordering is done with Reactux - # it "should have changed stop_area_ids order" do - # expect(subject.reorder!( new_stop_point_ids)).to be_truthy - # subject.reload - # expect(subject.stop_areas.map(&:id)).to eq( [old_stop_area_ids.last] + old_stop_area_ids[1..-2] + [old_stop_area_ids.first]) - # end - end - end - - describe "#stop_point_permutation?" do - context "invalid stop_point_ids" do - let( :new_stop_point_ids) { bad_stop_point_ids} - it { is_expected.not_to be_stop_point_permutation( new_stop_point_ids)} - end - context "unchanged stop_point_ids" do - let( :new_stop_point_ids) { ident} - it { is_expected.to be_stop_point_permutation( new_stop_point_ids)} - end - context "swaped last and first stop_point_ids" do - let( :new_stop_point_ids) { first_last_swap} - it { is_expected.to be_stop_point_permutation( new_stop_point_ids)} - end - end - end - - describe "#stop_points_attributes=" do - let( :journey_pattern) { create( :journey_pattern, :route => subject )} - let( :vehicle_journey) { create( :vehicle_journey, :journey_pattern => journey_pattern)} - def subject_stop_points_attributes - {}.tap do |hash| - subject.stop_points.each_with_index { |sp,index| hash[ index.to_s ] = sp.attributes } - end - end - context "route having swapped a new stop" do - let( :new_stop_point ){build( :stop_point, :route => subject)} - def added_stop_hash - subject_stop_points_attributes.tap do |h| - h["4"] = new_stop_point.attributes.merge( "position" => "4", "_destroy" => "" ) - end - end - let!( :new_route_size ){ subject.stop_points.size+1 } - - it "should have added stop_point in route" do - subject.update_attributes( :stop_points_attributes => added_stop_hash) - expect(Chouette::Route.find( subject.id ).stop_points.size).to eq(new_route_size) - end - it "should have added stop_point in route's journey pattern" do - subject.update_attributes( :stop_points_attributes => added_stop_hash) - expect(Chouette::JourneyPattern.find( journey_pattern.id ).stop_points.size).to eq(new_route_size) - end - it "should have added stop_point in route's vehicle journey at stop" do - subject.update_attributes( :stop_points_attributes => added_stop_hash) - expect(Chouette::VehicleJourney.find( vehicle_journey.id ).vehicle_journey_at_stops.size).to eq(new_route_size) - end - end - context "route having swapped stop" do - def swapped_stop_hash - subject_stop_points_attributes.tap do |h| - h[ "1" ][ "position" ] = "3" - h[ "3" ][ "position" ] = "1" - end - end - let!( :new_stop_id_list ){ subject.stop_points.map(&:id).tap {|array| array.insert( 1, array.delete_at(3)); array.insert( 3, array.delete_at(2) )} } - - it "should have swap stop_points from route" do - subject.update_attributes( :stop_points_attributes => swapped_stop_hash) - expect(Chouette::Route.find(subject.id).stop_points.map(&:id).sort).to eq(new_stop_id_list.sort) - end - it "should have swap stop_points from route's journey pattern" do - subject.update_attributes( :stop_points_attributes => swapped_stop_hash) - expect(Chouette::JourneyPattern.find( journey_pattern.id ).stop_points.map(&:id).sort).to eq(new_stop_id_list.sort) - end - it "should have swap stop_points from route's vehicle journey at stop" do - subject.update_attributes( :stop_points_attributes => swapped_stop_hash) - expect(Chouette::VehicleJourney.find( vehicle_journey.id ).vehicle_journey_at_stops.map(&:stop_point_id)).to match_array(new_stop_id_list) - end - end - context "route having a deleted stop" do - def removed_stop_hash - subject_stop_points_attributes.tap do |h| - h[ "1" ][ "_destroy" ] = "1" - end - end - let!( :new_stop_id_list ){ subject.stop_points.map(&:id).tap {|array| array.delete_at(1) } } - - it "should ignore deleted stop_point from route" do - subject.update_attributes( :stop_points_attributes => removed_stop_hash) - expect(Chouette::Route.find( subject.id ).stop_points.map(&:id).sort).to eq(new_stop_id_list.sort) - end - it "should ignore deleted stop_point from route's journey pattern" do - subject.update_attributes( :stop_points_attributes => removed_stop_hash) - expect(Chouette::JourneyPattern.find( journey_pattern.id ).stop_points.map(&:id).sort).to eq(new_stop_id_list.sort) - end - it "should ignore deleted stop_point from route's vehicle journey at stop" do - subject.update_attributes( :stop_points_attributes => removed_stop_hash) - expect(Chouette::VehicleJourney.find( vehicle_journey.id ).vehicle_journey_at_stops.map(&:stop_point_id).sort).to match_array(new_stop_id_list.sort) - end - end - end - - describe "#stop_points" do - context "#find_by_stop_area" do - context "when arg is first quay id" do - let(:first_stop_point) { subject.stop_points.first} - it "should return first quay" do - expect(subject.stop_points.find_by_stop_area( first_stop_point.stop_area_id)).to eq( first_stop_point) - end - end - end - end - describe "#stop_areas" do - let(:line){ create(:line)} - let(:route_1){ create(:route, :line => line)} - let(:route_2){ create(:route, :line => line)} - it "should retreive all stop_area on route" do - route_1.stop_areas.each do |sa| - expect(sa.stop_points.map(&:route_id).uniq).to eq([route_1.id]) - end - end - - context "when route is looping: last and first stop area are the same" do - it "should retreive same stop_area one last and first position" do - route_loop = create(:route, :line => line) - first_stop = Chouette::StopPoint.where( :route_id => route_loop.id, :position => 0).first - last_stop = create(:stop_point, :route => route_loop, :position => 4, :stop_area => first_stop.stop_area) - - expect(route_loop.stop_areas.size).to eq(6) - expect(route_loop.stop_areas.select {|s| s.id == first_stop.stop_area.id}.size).to eq(2) - end - end - end -end -- cgit v1.2.3 From a732c120a9b4747d80bfe773cc70b4d4cc4f7d5b Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 May 2017 06:10:06 +0200 Subject: Refs: #3297 - fix of RouteObserver#after_destroy (dead code right now, but see below) - change specs to use Route#destroy in order to trigger `dependent: :destroy' in stop_points (#delete does not work as stop_points is used in `has_many :stop_areas, through:', no doc found on this behavior, but #destroy is the advocated method to be used) --- spec/models/chouette/route/route_delete_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec') diff --git a/spec/models/chouette/route/route_delete_spec.rb b/spec/models/chouette/route/route_delete_spec.rb index fa8a8a947..ccc14d8bb 100644 --- a/spec/models/chouette/route/route_delete_spec.rb +++ b/spec/models/chouette/route/route_delete_spec.rb @@ -9,23 +9,23 @@ RSpec.describe Chouette::Route, :type => :model do it "deletes the associated journey_patterns" do expected_delta = subject.journey_patterns.count expect( expected_delta ).to be_positive - expect{ subject.delete }.to change{Chouette::JourneyPattern.count}.by -expected_delta + expect{ subject.destroy }.to change{Chouette::JourneyPattern.count}.by -expected_delta end it "deletes the associated stop_points" do expected_delta = subject.stop_points.count expect( expected_delta ).to be_positive - expect{ subject.delete }.to change{Chouette::StopPoint.count}.by -expected_delta + expect{ subject.destroy }.to change{Chouette::StopPoint.count}.by -expected_delta end it "does not delete the associated stop_areas" do count = subject.stop_points.count expect( count ).to be_positive - expect{ subject.delete }.not_to change{Chouette::StopArea.count} + expect{ subject.destroy }.not_to change{Chouette::StopArea.count} end it "deletes the associated vehicle_journeys" do - expect{ vehicle_journey.route.delete }.to change{Chouette::VehicleJourney.count}.by -1 + expect{ vehicle_journey.route.destroy}.to change{Chouette::VehicleJourney.count}.by -1 end it "does not delete the corresponding time_tables" do @@ -33,12 +33,12 @@ RSpec.describe Chouette::Route, :type => :model do tt.vehicle_journeys << vehicle_journey tables = vehicle_journey.route.time_tables expect( tables ).not_to be_empty - expect{ vehicle_journey.route.delete }.not_to change{Chouette::TimeTable.count} + expect{ vehicle_journey.route.destroy }.not_to change{Chouette::TimeTable.count} end it "does not delete the associated line" do expect( subject.line ).not_to be_nil - expect{ subject.delete }.not_to change{Chouette::Line.count} + expect{ subject.destroy }.not_to change{Chouette::Line.count} end end end -- cgit v1.2.3 From 4bb5a73898c299506ba192cb0a59debcb251ee09 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 May 2017 11:14:41 +0200 Subject: made a custom factory for destroy_route spex --- spec/factories/chouette_routes.rb | 13 +++++-- spec/models/chouette/route/route_delete_spec.rb | 44 ----------------------- spec/models/chouette/route/route_destroy_spec.rb | 45 ++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 46 deletions(-) delete mode 100644 spec/models/chouette/route/route_delete_spec.rb create mode 100644 spec/models/chouette/route/route_destroy_spec.rb (limited to 'spec') diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb index 8cbbe20cf..c1a9423c5 100644 --- a/spec/factories/chouette_routes.rb +++ b/spec/factories/chouette_routes.rb @@ -14,15 +14,24 @@ FactoryGirl.define do transient do stop_points_count 5 - journey_patterns_count 2 end after(:create) do |route, evaluator| create_list(:stop_point, evaluator.stop_points_count, route: route) - create_list(:journey_pattern, evaluator.journey_patterns_count, route: route) end + factory :route_with_journey_patterns do + transient do + journey_patterns_count 2 + end + + after(:create) do |route, evaluator| + create_list(:journey_pattern, evaluator.journey_patterns_count, route: route) + end + + end end + end end diff --git a/spec/models/chouette/route/route_delete_spec.rb b/spec/models/chouette/route/route_delete_spec.rb deleted file mode 100644 index ccc14d8bb..000000000 --- a/spec/models/chouette/route/route_delete_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -RSpec.describe Chouette::Route, :type => :model do - - subject { create(:route) } - - - context "delete a route" do - let( :vehicle_journey ){ create :vehicle_journey } - - it "deletes the associated journey_patterns" do - expected_delta = subject.journey_patterns.count - expect( expected_delta ).to be_positive - expect{ subject.destroy }.to change{Chouette::JourneyPattern.count}.by -expected_delta - end - - it "deletes the associated stop_points" do - expected_delta = subject.stop_points.count - expect( expected_delta ).to be_positive - expect{ subject.destroy }.to change{Chouette::StopPoint.count}.by -expected_delta - end - - it "does not delete the associated stop_areas" do - count = subject.stop_points.count - expect( count ).to be_positive - expect{ subject.destroy }.not_to change{Chouette::StopArea.count} - end - - it "deletes the associated vehicle_journeys" do - expect{ vehicle_journey.route.destroy}.to change{Chouette::VehicleJourney.count}.by -1 - end - - it "does not delete the corresponding time_tables" do - tt = create :time_table - tt.vehicle_journeys << vehicle_journey - tables = vehicle_journey.route.time_tables - expect( tables ).not_to be_empty - expect{ vehicle_journey.route.destroy }.not_to change{Chouette::TimeTable.count} - end - - it "does not delete the associated line" do - expect( subject.line ).not_to be_nil - expect{ subject.destroy }.not_to change{Chouette::Line.count} - end - end -end diff --git a/spec/models/chouette/route/route_destroy_spec.rb b/spec/models/chouette/route/route_destroy_spec.rb new file mode 100644 index 000000000..a99642a98 --- /dev/null +++ b/spec/models/chouette/route/route_destroy_spec.rb @@ -0,0 +1,45 @@ +RSpec.describe Chouette::Route, :type => :model do + + subject { create( :route_with_journey_patterns ) } + + + context "delete a route" do + let( :vehicle_journey ){ create :vehicle_journey } + + it "deletes the associated journey_patterns" do + expected_delta = subject.journey_patterns.count + expect( expected_delta ).to be_positive + expect{ subject.destroy }.to change{Chouette::JourneyPattern.count}.by -expected_delta + end + + it "deletes the associated stop_points" do + expected_delta = subject.stop_points.count + expect( expected_delta ).to be_positive + expect{ subject.destroy }.to change{Chouette::StopPoint.count}.by -expected_delta + end + + it "does not delete the associated stop_areas" do + count = subject.stop_points.count + expect( count ).to be_positive + expect{ subject.destroy }.not_to change{Chouette::StopArea.count} + end + + it "deletes the associated vehicle_journeys" do + vehicle_journey + expect{ vehicle_journey.route.destroy}.to change{Chouette::VehicleJourney.count}.by -1 + end + + it "does not delete the corresponding time_tables" do + tt = create :time_table + tt.vehicle_journeys << vehicle_journey + tables = vehicle_journey.route.time_tables + expect( tables ).not_to be_empty + expect{ vehicle_journey.route.destroy }.not_to change{Chouette::TimeTable.count} + end + + it "does not delete the associated line" do + expect( subject.line ).not_to be_nil + expect{ subject.destroy }.not_to change{Chouette::Line.count} + end + end +end -- cgit v1.2.3 From 407885e41987c0c64913194396c5667483416192 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 4 May 2017 18:15:46 +0200 Subject: Refs # 3297; behavior speced --- spec/factories/chouette_routes.rb | 2 ++ spec/models/chouette/route/route_delete_spec.rb | 44 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 spec/models/chouette/route/route_delete_spec.rb (limited to 'spec') diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb index c1a9423c5..823a4cb0e 100644 --- a/spec/factories/chouette_routes.rb +++ b/spec/factories/chouette_routes.rb @@ -14,10 +14,12 @@ FactoryGirl.define do transient do stop_points_count 5 + journey_patterns_count 2 end after(:create) do |route, evaluator| create_list(:stop_point, evaluator.stop_points_count, route: route) + create_list(:journey_pattern, evaluator.journey_patterns_count, route: route) end factory :route_with_journey_patterns do diff --git a/spec/models/chouette/route/route_delete_spec.rb b/spec/models/chouette/route/route_delete_spec.rb new file mode 100644 index 000000000..fa8a8a947 --- /dev/null +++ b/spec/models/chouette/route/route_delete_spec.rb @@ -0,0 +1,44 @@ +RSpec.describe Chouette::Route, :type => :model do + + subject { create(:route) } + + + context "delete a route" do + let( :vehicle_journey ){ create :vehicle_journey } + + it "deletes the associated journey_patterns" do + expected_delta = subject.journey_patterns.count + expect( expected_delta ).to be_positive + expect{ subject.delete }.to change{Chouette::JourneyPattern.count}.by -expected_delta + end + + it "deletes the associated stop_points" do + expected_delta = subject.stop_points.count + expect( expected_delta ).to be_positive + expect{ subject.delete }.to change{Chouette::StopPoint.count}.by -expected_delta + end + + it "does not delete the associated stop_areas" do + count = subject.stop_points.count + expect( count ).to be_positive + expect{ subject.delete }.not_to change{Chouette::StopArea.count} + end + + it "deletes the associated vehicle_journeys" do + expect{ vehicle_journey.route.delete }.to change{Chouette::VehicleJourney.count}.by -1 + end + + it "does not delete the corresponding time_tables" do + tt = create :time_table + tt.vehicle_journeys << vehicle_journey + tables = vehicle_journey.route.time_tables + expect( tables ).not_to be_empty + expect{ vehicle_journey.route.delete }.not_to change{Chouette::TimeTable.count} + end + + it "does not delete the associated line" do + expect( subject.line ).not_to be_nil + expect{ subject.delete }.not_to change{Chouette::Line.count} + end + end +end -- cgit v1.2.3 From 5d5707ad0d9711f369eff7ccef60d24b0247227b Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 May 2017 06:10:06 +0200 Subject: Refs: #3297 - fix of RouteObserver#after_destroy (dead code right now, but see below) - change specs to use Route#destroy in order to trigger `dependent: :destroy' in stop_points (#delete does not work as stop_points is used in `has_many :stop_areas, through:', no doc found on this behavior, but #destroy is the advocated method to be used) --- spec/models/chouette/route/route_delete_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec') diff --git a/spec/models/chouette/route/route_delete_spec.rb b/spec/models/chouette/route/route_delete_spec.rb index fa8a8a947..ccc14d8bb 100644 --- a/spec/models/chouette/route/route_delete_spec.rb +++ b/spec/models/chouette/route/route_delete_spec.rb @@ -9,23 +9,23 @@ RSpec.describe Chouette::Route, :type => :model do it "deletes the associated journey_patterns" do expected_delta = subject.journey_patterns.count expect( expected_delta ).to be_positive - expect{ subject.delete }.to change{Chouette::JourneyPattern.count}.by -expected_delta + expect{ subject.destroy }.to change{Chouette::JourneyPattern.count}.by -expected_delta end it "deletes the associated stop_points" do expected_delta = subject.stop_points.count expect( expected_delta ).to be_positive - expect{ subject.delete }.to change{Chouette::StopPoint.count}.by -expected_delta + expect{ subject.destroy }.to change{Chouette::StopPoint.count}.by -expected_delta end it "does not delete the associated stop_areas" do count = subject.stop_points.count expect( count ).to be_positive - expect{ subject.delete }.not_to change{Chouette::StopArea.count} + expect{ subject.destroy }.not_to change{Chouette::StopArea.count} end it "deletes the associated vehicle_journeys" do - expect{ vehicle_journey.route.delete }.to change{Chouette::VehicleJourney.count}.by -1 + expect{ vehicle_journey.route.destroy}.to change{Chouette::VehicleJourney.count}.by -1 end it "does not delete the corresponding time_tables" do @@ -33,12 +33,12 @@ RSpec.describe Chouette::Route, :type => :model do tt.vehicle_journeys << vehicle_journey tables = vehicle_journey.route.time_tables expect( tables ).not_to be_empty - expect{ vehicle_journey.route.delete }.not_to change{Chouette::TimeTable.count} + expect{ vehicle_journey.route.destroy }.not_to change{Chouette::TimeTable.count} end it "does not delete the associated line" do expect( subject.line ).not_to be_nil - expect{ subject.delete }.not_to change{Chouette::Line.count} + expect{ subject.destroy }.not_to change{Chouette::Line.count} end end end -- cgit v1.2.3 From 3ce7b69d6620f4a6aa6aaaff4d79882761c9d975 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 May 2017 11:14:41 +0200 Subject: made a custom factory for destroy_route spex --- spec/factories/chouette_routes.rb | 2 -- spec/models/chouette/route/route_delete_spec.rb | 44 ------------------------- 2 files changed, 46 deletions(-) delete mode 100644 spec/models/chouette/route/route_delete_spec.rb (limited to 'spec') diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb index 823a4cb0e..c1a9423c5 100644 --- a/spec/factories/chouette_routes.rb +++ b/spec/factories/chouette_routes.rb @@ -14,12 +14,10 @@ FactoryGirl.define do transient do stop_points_count 5 - journey_patterns_count 2 end after(:create) do |route, evaluator| create_list(:stop_point, evaluator.stop_points_count, route: route) - create_list(:journey_pattern, evaluator.journey_patterns_count, route: route) end factory :route_with_journey_patterns do diff --git a/spec/models/chouette/route/route_delete_spec.rb b/spec/models/chouette/route/route_delete_spec.rb deleted file mode 100644 index ccc14d8bb..000000000 --- a/spec/models/chouette/route/route_delete_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -RSpec.describe Chouette::Route, :type => :model do - - subject { create(:route) } - - - context "delete a route" do - let( :vehicle_journey ){ create :vehicle_journey } - - it "deletes the associated journey_patterns" do - expected_delta = subject.journey_patterns.count - expect( expected_delta ).to be_positive - expect{ subject.destroy }.to change{Chouette::JourneyPattern.count}.by -expected_delta - end - - it "deletes the associated stop_points" do - expected_delta = subject.stop_points.count - expect( expected_delta ).to be_positive - expect{ subject.destroy }.to change{Chouette::StopPoint.count}.by -expected_delta - end - - it "does not delete the associated stop_areas" do - count = subject.stop_points.count - expect( count ).to be_positive - expect{ subject.destroy }.not_to change{Chouette::StopArea.count} - end - - it "deletes the associated vehicle_journeys" do - expect{ vehicle_journey.route.destroy}.to change{Chouette::VehicleJourney.count}.by -1 - end - - it "does not delete the corresponding time_tables" do - tt = create :time_table - tt.vehicle_journeys << vehicle_journey - tables = vehicle_journey.route.time_tables - expect( tables ).not_to be_empty - expect{ vehicle_journey.route.destroy }.not_to change{Chouette::TimeTable.count} - end - - it "does not delete the associated line" do - expect( subject.line ).not_to be_nil - expect{ subject.destroy }.not_to change{Chouette::Line.count} - end - end -end -- cgit v1.2.3 From b57bffdd02fad756eb7cf95cdb51c81189ec5c82 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 9 May 2017 15:46:01 +0200 Subject: Wip group continuous timetable dates into periodes --- spec/models/time_table_combination_spec.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/models/time_table_combination_spec.rb b/spec/models/time_table_combination_spec.rb index 46d5f8504..8b66434f2 100644 --- a/spec/models/time_table_combination_spec.rb +++ b/spec/models/time_table_combination_spec.rb @@ -4,7 +4,22 @@ describe TimeTableCombination, :type => :model do let!(:source){ create(:time_table)} let!(:combined){create(:time_table)} subject {build(:time_table_combination)} - + + describe 'continuous_dates' do + it 'should group continuous dates' do + dates = source.dates.where(in_out: true) + expect(source.continuous_dates.values[0].count).to eq(dates.count) + + # 6 more continious date, 1 isolated date + (10..15).each do |n| + source.dates.create(date: Date.today + n.day, in_out: true) + end + source.dates.create(date: Date.today + 1.year, in_out: true) + expect(source.reload.continuous_dates.values[1].count).to eq(6) + expect(source.reload.continuous_dates.values[2].count).to eq(1) + end + end + describe "#combine" do context "when operation is union" do before(:each) do -- cgit v1.2.3 From fa16b56825592ed584453351e47f771bd580c41f Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 9 May 2017 16:45:23 +0200 Subject: TimeTables convert continuous dates to periods --- spec/models/time_table_combination_spec.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/models/time_table_combination_spec.rb b/spec/models/time_table_combination_spec.rb index 8b66434f2..4c99a14fa 100644 --- a/spec/models/time_table_combination_spec.rb +++ b/spec/models/time_table_combination_spec.rb @@ -5,18 +5,33 @@ describe TimeTableCombination, :type => :model do let!(:combined){create(:time_table)} subject {build(:time_table_combination)} - describe 'continuous_dates' do + describe '#continuous_dates' do it 'should group continuous dates' do dates = source.dates.where(in_out: true) - expect(source.continuous_dates.values[0].count).to eq(dates.count) + expect(source.continuous_dates[0].count).to eq(dates.count) - # 6 more continious date, 1 isolated date + # 6 more continuous date, 1 isolated date (10..15).each do |n| source.dates.create(date: Date.today + n.day, in_out: true) end source.dates.create(date: Date.today + 1.year, in_out: true) - expect(source.reload.continuous_dates.values[1].count).to eq(6) - expect(source.reload.continuous_dates.values[2].count).to eq(1) + expect(source.reload.continuous_dates[1].count).to eq(6) + expect(source.reload.continuous_dates[2].count).to eq(1) + end + end + + describe '#convert_continuous_dates_to_periods' do + it 'should convert continuous dates to periods' do + (10..12).each do |n| + source.dates.create(date: Date.today + n.day, in_out: true) + end + source.dates.create(date: Date.today + 1.year, in_out: true) + + expect { + source.reload.convert_continuous_dates_to_periods + }.to change {source.periods.count}.by(2) + + expect(source.reload.dates.where(in_out: true).count).to eq(1) end end -- cgit v1.2.3