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(-) 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 557474c9bfeb60ba5234d022b92948a96babfc7b 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 --- app/models/chouette/time_table.rb | 21 ++++++++++++++++++++- spec/models/chouette/time_table_spec.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 7285e9716..fcdc525a9 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -54,7 +54,6 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord time_table_date = self.dates.find(date_id) if date_id next if !checked && !time_table_date - # Destroy date if no longer checked next if !checked && time_table_date.destroy @@ -67,9 +66,29 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord time_table_date.update_attributes({in_out: in_out}) end end + + self.state_update_periods state['time_table_periods'] self.save end + def state_update_periods state_periods + state_periods.each do |item| + period = self.periods.find(item['id']) if item['id'] + next if period && item['deleted'] && period.destroy + period ||= self.periods.build + + period.period_start = Date.parse(item['period_start']) + period.period_end = Date.parse(item['period_end']) + + if period.changed? + period.save + item['id'] = period.id + end + end + + state_periods.delete_if {|item| item['deleted']} + end + def self.state_permited_attributes item item.slice('comment').to_hash end 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 624a75890fbe7141a6f81452849f71d7f19ba9ae 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 --- app/models/chouette/time_table.rb | 2 +- spec/models/chouette/time_table_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index fcdc525a9..11e7293f1 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -90,7 +90,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord end def self.state_permited_attributes item - item.slice('comment').to_hash + item.slice('comment', 'color').to_hash end def presenter 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 8d936757a925e60d590dbda8d1f47d47a59912c8 Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 2 May 2017 13:04:54 +0200 Subject: Refs #3264: change shared boolean filter by select (to permit join) --- app/assets/stylesheets/components/_forms.sass | 2 +- app/controllers/calendars_controller.rb | 19 +++++++++++++++++-- app/views/calendars/_filters.html.slim | 9 ++++++--- app/views/calendars/index.html.slim | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index c24b7abda..46f40291a 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -159,7 +159,7 @@ input top: 0 bottom: 0 right: 60% - z-index: 2 + z-index: 5 width: auto > .btn diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index c33aa9373..d18e165d2 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -33,8 +33,12 @@ class CalendarsController < BreadcrumbController def collection return @calendars if @calendars + scope = Calendar.where('organisation_id = ?', current_organisation.id) + + scope = shared_scope(scope) + + @q = scope.ransack(params[:q]) - @q = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).search(params[:q]) calendars = @q.result calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction @calendars = calendars.paginate(page: params[:page]) @@ -51,5 +55,16 @@ class CalendarsController < BreadcrumbController params[:q]['contains_date'] = Date.parse(date.join('-')) end end -end + def shared_scope scope + return scope unless params[:q] + + if params[:q][:shared_true] == params[:q][:shared_false] + params[:q].delete(:shared_true) + params[:q].delete(:shared_false) + end + + scope + end + +end diff --git a/app/views/calendars/_filters.html.slim b/app/views/calendars/_filters.html.slim index d8707ba0f..4f625e4f0 100644 --- a/app/views/calendars/_filters.html.slim +++ b/app/views/calendars/_filters.html.slim @@ -7,13 +7,16 @@ span.fa.fa-search .ffg-row - .form-group.has_switch style='width: 260px' - = f.label Calendar.human_attribute_name(:shared), class: 'col-sm-4 control-label' - = f.input :shared_true, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, '', class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8' } + .form-group.togglable + = f.label Calendar.human_attribute_name(:shared), required: false, class: 'control-label' + .form-group.checkbox_list + = f.input :shared_true, as: :boolean, label: ("Oui").html_safe, wrapper_html: { class: 'checkbox-wrapper' } + = f.input :shared_false, as: :boolean, label: ("Non").html_safe, wrapper_html: { class: 'checkbox-wrapper' } .form-group = f.label Calendar.human_attribute_name(:date), class: 'control-label' = f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date' }, class: 'form-control', include_blank: true + .actions = link_to 'Effacer', calendars_path, class: 'btn btn-link' = f.submit 'Filtrer', id: 'filter_btn', class: 'btn btn-default' diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index 864d1e197..fbb9f889d 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -21,7 +21,7 @@ .row .col-lg-12 = table_builder @calendars, - { :name => 'name', :short_name => 'short_name', :shared => 'shared' }, + { :name => 'name', :short_name => 'short_name', :shared => Proc.new{|c| t("#{c.try(:shared)}") } }, [:show, :edit, :delete], [], 'table has-filter' -- cgit v1.2.3 From 7cbe0b90e9f696a0b43b3fd4be1fcba3c1c57623 Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 2 May 2017 13:42:02 +0200 Subject: Refs #3265: updating calendars#show layout --- app/views/calendars/show.html.slim | 68 ++++++++++++++------------------------ 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/app/views/calendars/show.html.slim b/app/views/calendars/show.html.slim index c0671fa94..3886cefaa 100644 --- a/app/views/calendars/show.html.slim +++ b/app/views/calendars/show.html.slim @@ -1,46 +1,26 @@ -= title_tag t('.title', calendar: @calendar.name) +/ PageHeader += pageheader 'map-marker', + @calendar.name, + '', + t('last_update', time: l(@calendar.updated_at, format: :short)), + (policy(@calendar).edit? ? link_to(t('actions.edit'), edit_calendar_path(@calendar), class: 'btn btn-default') : '') do -p - label => "#{Calendar.human_attribute_name('name')} : " - = @calendar.name -p - label => "#{Calendar.human_attribute_name('short_name')} : " - = @calendar.short_name + / Below is secondary actions & optional contents (filters, ...) + .row.mb-sm + .col-lg-12.text-right + - if policy(@calendar).destroy? + = link_to calendar_path(@calendar), method: :delete, data: { confirm: t('calendars.actions.destroy_confirm') }, class: 'btn btn-primary' do + span.fa.fa-trash + span = t('actions.destroy') -.row - .col-xs-4 - p - label => "#{Calendar.human_attribute_name('dates')} : " - table.table.table-condensed - tbody - - @calendar.dates.each do |date| - tr - td= l date - p - label => "#{Calendar.human_attribute_name('date_ranges')} : " - table.table.table-condensed - thead - th= t('simple_form.labels.calendar.ranges.begin') - th= t('simple_form.labels.calendar.ranges.end') - tbody - - @calendar.date_ranges.each do |date_range| - tr - td= l date_range.begin - td= l date_range.end - -p - label => "#{Calendar.human_attribute_name('shared')} : " - = @calendar.shared -p - label => "#{Organisation.model_name.human} : " - = @calendar.organisation.name - - -- content_for(:sidebar) do - ul.actions - - if policy(@calendar).edit? - li - = link_to t('calendars.actions.edit'), edit_calendar_path(@calendar), class: 'edit' - - if policy(@calendar).destroy? - li - = link_to t('calendars.actions.destroy'), calendar_path(@calendar), method: :delete, data: { confirm: t('calendars.actions.destroy_confirm') }, class: 'remove' +/ PageContent +.page_content + .container-fluid + .row + .col-lg-6.col-md-6.col-sm-12.col-xs-12 + = definition_list t('metadatas'), + { 'Nom court' => @calendar.try(:short_name), + Calendar.human_attribute_name(:shared) => t("#{@calendar.shared}"), + 'Organisation' => @calendar.organisation.name, + Calendar.human_attribute_name(:dates) => @calendar.dates.collect{|d| l(d, format: :short)}.join(', ').html_safe, + Calendar.human_attribute_name(:date_ranges) => @calendar.date_ranges.collect{|d| t('validity_range', debut: l(d.begin, format: :short), end: l(d.end, format: :short))}.join('
').html_safe } -- cgit v1.2.3 From c5cd58abb8fb460b08259dfb6e5e2186a2e139ec Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 2 May 2017 14:59:16 +0200 Subject: Refs #3265: refacto layout --- app/views/calendars/_date_value_fields.html.slim | 11 ++-- app/views/calendars/_form.html.slim | 74 ++++++++++++++++-------- app/views/calendars/_period_fields.html.slim | 15 +++-- app/views/calendars/edit.html.slim | 13 ++++- app/views/calendars/index.html.slim | 7 +-- app/views/calendars/new.html.slim | 13 ++++- 6 files changed, 85 insertions(+), 48 deletions(-) diff --git a/app/views/calendars/_date_value_fields.html.slim b/app/views/calendars/_date_value_fields.html.slim index 3a9cdb7bd..2d072fa0a 100644 --- a/app/views/calendars/_date_value_fields.html.slim +++ b/app/views/calendars/_date_value_fields.html.slim @@ -5,10 +5,9 @@ .alert.alert-danger - f.object.errors[:base].each do |message| p.small = message - .row - .col-xs-3 - = f.input :value, as: :date, html5: true, label: t('simple_form.labels.calendar.date_value') - .col-xs-1.end.text-right#delete-btn - = link_to_remove_association f, class: 'btn btn-danger', data: { confirm: t('are_you_sure') } do - span.fa.fa-trash + .wrapper + div + = f.input :value, as: :date, label: false, wrapper_html: { class: 'date' } + div + = link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete') diff --git a/app/views/calendars/_form.html.slim b/app/views/calendars/_form.html.slim index a97c16565..9aed9f7d8 100644 --- a/app/views/calendars/_form.html.slim +++ b/app/views/calendars/_form.html.slim @@ -1,27 +1,53 @@ -#calendar_form += simple_form_for @calendar, html: { class: 'form-horizontal', id: 'calendar_form' }, wrapper: :horizontal_form do |f| .row - .col-xs-8.col-xs-offset-2 - = simple_form_for @calendar, html: { class: 'form-horizontal' } do |f| - = f.input :name - = f.input :short_name - .form-group - = f.label :dates - .well - = f.simple_fields_for :date_values do |date_value| - = render 'date_value_fields', f: date_value - .links - = link_to_add_association t('simple_form.labels.calendar.add_a_date'), f, :date_values, class: 'btn btn-primary btn-xs' - .form-group - = f.label :date_ranges - .well - = f.simple_fields_for :periods do |period| - = render 'period_fields', f: period - .links - = link_to_add_association t('simple_form.labels.calendar.add_a_date_range'), f, :periods, class: 'btn btn-primary btn-xs' - - if policy(@calendar).share? - = f.input :shared - .form-actions - = f.button :submit, as: :button, class: 'btn btn-info' - = link_to t('cancel'), calendars_path, class: 'btn btn-default' + .col-lg-12 + = f.input :name + = f.input :short_name + - if policy(@calendar).share? + .form-group.has_switch + = f.label :shared, class: 'col-sm-4 control-label' + = f.input :shared, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, t("#{@calendar.shared}"), class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8'} + .separator + + .row + .col-lg-12 + .subform + .nested-head + .wrapper + div + .form-group + label.control-label + = Calendar.human_attribute_name(:date) + div + + = f.simple_fields_for :date_values do |date_value| + = render 'date_value_fields', f: date_value + + .links.nested-linker + = link_to_add_association t('simple_form.labels.calendar.add_a_date'), f, :date_values, class: 'btn btn-outline-primary' + + .separator + + .row + .col-lg-12 + .subform + .nested-head + .wrapper + div + .form-group + label.control-label + = t('simple_form.labels.calendar.ranges.begin') + div + .form-group + label.control-label + = t('simple_form.labels.calendar.ranges.end') + div + + = f.simple_fields_for :periods do |period| + = render 'period_fields', f: period + .links.nested-linker + = link_to_add_association t('simple_form.labels.calendar.add_a_date_range'), f, :periods, class: 'btn btn-outline-primary' + + = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'calendar_form' diff --git a/app/views/calendars/_period_fields.html.slim b/app/views/calendars/_period_fields.html.slim index 024d09de2..1e201a39f 100644 --- a/app/views/calendars/_period_fields.html.slim +++ b/app/views/calendars/_period_fields.html.slim @@ -5,12 +5,11 @@ .alert.alert-danger - f.object.errors[:base].each do |message| p.small = message - .row - .col-xs-4 - = f.input :begin, as: :date, html5: true, label: t('simple_form.labels.calendar.ranges.begin') - .col-xs-3 - = f.input :end, as: :date, html5: true, label: t('simple_form.labels.calendar.ranges.end') - .col-xs-1.text-right#delete-btn - = link_to_remove_association f, class: 'btn btn-danger', data: { confirm: t('are_you_sure') } do - span.fa.fa-trash + .wrapper + div + = f.input :begin, as: :date, label: false, wrapper_html: { class: 'date' } + div + = f.input :end, as: :date, label: false, wrapper_html: { class: 'date' } + div + = link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete') diff --git a/app/views/calendars/edit.html.slim b/app/views/calendars/edit.html.slim index 22645cf24..6668630e8 100644 --- a/app/views/calendars/edit.html.slim +++ b/app/views/calendars/edit.html.slim @@ -1,3 +1,12 @@ -= title_tag t('.title', calendar: @calendar.name) +/ PageHeader += pageheader 'map-marker', + t('.title', calendar: @calendar.name), + '', + t('last_update', time: l(@calendar.updated_at, format: :short)) -= render 'form' +/ PageContent +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form' diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index fbb9f889d..ec3893959 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -2,12 +2,7 @@ = pageheader 'map-marker', t('.title'), '', - '' do - - / Below is secundary actions & optional contents (filters, ...) - .row.mb-sm - .col-lg-12.text-right - = link_to t('actions.add'), new_calendar_path, class: 'btn btn-primary' + link_to(t('actions.add'), new_calendar_path, class: 'btn btn-default') do / PageContent .page_content diff --git a/app/views/calendars/new.html.slim b/app/views/calendars/new.html.slim index f827e2eb6..7faecf587 100644 --- a/app/views/calendars/new.html.slim +++ b/app/views/calendars/new.html.slim @@ -1,3 +1,12 @@ -= title_tag t('.title') +/ PageHeader += pageheader 'map-marker', + t('.title'), + '', + '' -= render 'form' +/ PageContent +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form' -- cgit v1.2.3 From e5aca3da960c4a52db2b6beef2b2157149e89fac 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(-) 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 19199e7119fb86f7f895d1c17dc6bfc742462063 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 2 May 2017 15:22:17 +0200 Subject: Refs #3267: Fix fetch vehicle_journey properly (company/idenfitier) Signed-off-by: Thomas Shawarma Haddad --- .../javascripts/es6_browserified/vehicle_journeys/actions/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js index 21aff1080..444d290ee 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js @@ -315,8 +315,8 @@ const actions = { deletable: false, selected: false, published_journey_name: val.published_journey_name || 'non renseigné', - published_journey_identifier: val.published_journey_name || 'non renseigné', - company_id: val.published_journey_name || 'non renseigné', + published_journey_identifier: val.published_journey_identifier || 'non renseigné', + company: val.company || 'non renseigné', transport_mode: val.route.line.transport_mode || 'non renseigné', transport_submode: val.route.line.transport_submode || 'non renseigné' }) -- cgit v1.2.3 From 006d7e0cc6ed5032e091e80b3997e8b501b28693 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 2 May 2017 15:43:18 +0200 Subject: Refs #3269: Fix required filed in create modal for jp Signed-off-by: Thomas Shawarma Haddad --- .../vehicle_journeys/components/tools/CreateModal.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js index 1273921e7..3d2251753 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js @@ -49,19 +49,18 @@ class CreateModal extends Component {
- + actions.resetValidation(e.currentTarget)} - required />
- + this.props.onSelect2Company(e)} -- cgit v1.2.3 From e63fd31c9675c95cb73e0faca7c8c521a8897835 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 2 May 2017 15:44:25 +0200 Subject: Duplicate TimeTable Refs #3188 --- app/controllers/time_tables_controller.rb | 16 ++++++++++++++-- app/models/chouette/time_table.rb | 2 ++ app/views/time_tables/_form.html.slim | 6 +++++- .../20170502130327_add_created_from_to_time_tables.rb | 5 +++++ db/schema.rb | 14 ++++++++------ 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20170502130327_add_created_from_to_time_tables.rb diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 3b8e390b6..8436dc020 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -37,7 +37,10 @@ class TimeTablesController < ChouetteController calendar = current_organisation.calendars.find_by_id(tt_params[:calendar_id]) tt_params[:calendar_id] = nil if tt_params.has_key?(:dates_attributes) || tt_params.has_key?(:periods_attributes) end - @time_table = Chouette::TimeTable.new(tt_params) + + created_from = duplicate_source + @time_table = created_from ? created_from.duplicate : Chouette::TimeTable.new(tt_params) + if calendar calendar.dates.each_with_index do |date, i| @time_table.dates << Chouette::TimeTableDate.new(date: date, position: i) @@ -48,7 +51,10 @@ class TimeTablesController < ChouetteController end create! do |success, failure| - success.html { redirect_to edit_referential_time_table_path(@referential, @time_table) } + success.html do + path = @time_table.created_from ? 'referential_time_table_path' : 'edit_referential_time_table_path' + redirect_to send(path, @referential, @time_table) + end failure.html { render :new } end end @@ -158,6 +164,11 @@ class TimeTablesController < ChouetteController %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' end + def duplicate_source + from_id = time_table_params['created_from_id'] + Chouette::TimeTable.find(from_id) if from_id + end + def time_table_params params.require(:time_table).permit( :objectid, @@ -175,6 +186,7 @@ class TimeTablesController < ChouetteController :sunday, :start_date, :end_date, + :created_from_id, { :dates_attributes => [:date, :in_out, :id, :_destroy] }, { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, {tag_list: []}, diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 11e7293f1..798fa81b4 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -18,6 +18,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord has_many :periods, -> {order(:period_start)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTablePeriod", :dependent => :destroy belongs_to :calendar + belongs_to :created_from, class_name: 'Chouette::TimeTable' after_save :save_shortcuts @@ -525,6 +526,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord def duplicate tt = self.deep_clone :include => [:periods, :dates], :except => :object_version tt.uniq_objectid + tt.created_from = self tt.comment = I18n.t("activerecord.copy", :name => self.comment) tt end diff --git a/app/views/time_tables/_form.html.slim b/app/views/time_tables/_form.html.slim index 8152e7f94..196682823 100644 --- a/app/views/time_tables/_form.html.slim +++ b/app/views/time_tables/_form.html.slim @@ -4,7 +4,11 @@ .col-lg-12 = form.input :comment, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.comment")} - - if @time_table.new_record? + - if @time_table.new_record? && !@time_table.created_from = form.input :calendar, as: :select, collection: current_organisation.calendars + - if @time_table.created_from + = form.input :created_from, disabled: true, input_html: { value: @time_table.created_from.comment } + .hidden = form.input :created_from_id, as: :hidden + = form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'timetable_form' diff --git a/db/migrate/20170502130327_add_created_from_to_time_tables.rb b/db/migrate/20170502130327_add_created_from_to_time_tables.rb new file mode 100644 index 000000000..6c0815eaf --- /dev/null +++ b/db/migrate/20170502130327_add_created_from_to_time_tables.rb @@ -0,0 +1,5 @@ +class AddCreatedFromToTimeTables < ActiveRecord::Migration + def change + add_reference :time_tables, :created_from, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3214c1e78..17df3c34f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170428133742) do +ActiveRecord::Schema.define(version: 20170502130327) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -696,21 +696,23 @@ ActiveRecord::Schema.define(version: 20170428133742) do add_index "time_table_periods", ["time_table_id"], name: "index_time_table_periods_on_time_table_id", using: :btree create_table "time_tables", id: :bigserial, force: :cascade do |t| - t.string "objectid", null: false - t.integer "object_version", limit: 8, default: 1 + t.string "objectid", null: false + t.integer "object_version", limit: 8, default: 1 t.string "creator_id" t.string "version" t.string "comment" - t.integer "int_day_types", default: 0 + t.integer "int_day_types", default: 0 t.date "start_date" t.date "end_date" - t.integer "calendar_id", limit: 8 + t.integer "calendar_id", limit: 8 t.datetime "created_at" t.datetime "updated_at" - t.string "color", limit: 255 + t.string "color", limit: 255 + t.integer "created_from_id" end add_index "time_tables", ["calendar_id"], name: "index_time_tables_on_calendar_id", using: :btree + add_index "time_tables", ["created_from_id"], name: "index_time_tables_on_created_from_id", using: :btree add_index "time_tables", ["objectid"], name: "time_tables_objectid_key", unique: true, using: :btree create_table "time_tables_vehicle_journeys", id: false, force: :cascade do |t| -- 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 --- app/controllers/referentials_controller.rb | 5 +- app/models/referential.rb | 4 +- app/models/rule_parameter_set.rb | 218 ++++++++++----------- config/initializers/apartment.rb | 2 + .../af83/stored_procedures/clone_schema_spec.rb | 5 +- spec/models/referential_spec.rb | 2 +- spec/spec_helper.rb | 7 +- 7 files changed, 126 insertions(+), 117 deletions(-) mode change 100755 => 100644 spec/lib/af83/stored_procedures/clone_schema_spec.rb diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index f46cd188d..437444f29 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -8,7 +8,10 @@ class ReferentialsController < BreadcrumbController respond_to :js, :only => :show def new - @referential = Referential.new_from(Referential.find(params[:from])) if params[:from] + if params[:from] + source_referential = Referential.find(params[:from]) + @referential = Referential.new_from(source_referential, organisation: current_organisation) + end new! do @referential.data_format = current_organisation.data_format diff --git a/app/models/referential.rb b/app/models/referential.rb index 50db32637..83d507320 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -126,14 +126,14 @@ class Referential < ActiveRecord::Base self end - def self.new_from from + def self.new_from(from, organisation:) Referential.new({ name: I18n.t("activerecord.copy", :name => from.name), slug: "#{from.slug}_clone", prefix: from.prefix, time_zone: from.time_zone, bounds: from.bounds, - organisation: from.organisation, + organisation: organisation, line_referential: from.line_referential, stop_area_referential: from.stop_area_referential, workbench: from.workbench, diff --git a/app/models/rule_parameter_set.rb b/app/models/rule_parameter_set.rb index ba13b6d27..db78a2f8a 100644 --- a/app/models/rule_parameter_set.rb +++ b/app/models/rule_parameter_set.rb @@ -165,22 +165,22 @@ class RuleParameterSet < ActiveRecord::Base end def self.default_params(mode=nil) - base = { :inter_stop_area_distance_min => 20, - :parent_stop_area_distance_max => 300, - :inter_access_point_distance_min => 20, - :inter_connection_link_distance_max => 400, - :walk_default_speed_max => 4, - :walk_occasional_traveller_speed_max => 2, - :walk_frequent_traveller_speed_max => 5, + base = { :inter_stop_area_distance_min => 20, + :parent_stop_area_distance_max => 300, + :inter_access_point_distance_min => 20, + :inter_connection_link_distance_max => 400, + :walk_default_speed_max => 4, + :walk_occasional_traveller_speed_max => 2, + :walk_frequent_traveller_speed_max => 5, :walk_mobility_restricted_traveller_speed_max => 1, - :inter_access_link_distance_max => 300, - :inter_stop_duration_max => 40, - :facility_stop_area_distance_max => 300, - :check_allowed_transport_modes => false, - :check_lines_in_groups => false, - :check_line_routes => false, - :check_stop_parent => false, - :check_connection_link_on_physical => false + :inter_access_link_distance_max => 300, + :inter_stop_duration_max => 40, + :facility_stop_area_distance_max => 300, + :check_allowed_transport_modes => false, + :check_lines_in_groups => false, + :check_line_routes => false, + :check_stop_parent => false, + :check_connection_link_on_physical => false } if mode && self.mode_default_params[ mode.to_sym] base.merge!( self.mode_default_params[ mode.to_sym]) @@ -190,145 +190,145 @@ class RuleParameterSet < ActiveRecord::Base def self.mode_default_params { :coach => { - :allowed_transport_mode_coach => false, - :inter_stop_area_distance_min_mode_coach => 500, - :inter_stop_area_distance_max_mode_coach => 10000, - :speed_max_mode_coach => 90, - :speed_min_mode_coach => 40, + :allowed_transport_mode_coach => false, + :inter_stop_area_distance_min_mode_coach => 500, + :inter_stop_area_distance_max_mode_coach => 10000, + :speed_max_mode_coach => 90, + :speed_min_mode_coach => 40, :inter_stop_duration_variation_max_mode_coach => 20}, :air => { - :allowed_transport_mode_air => false, - :inter_stop_area_distance_min_mode_air => 200, - :inter_stop_area_distance_max_mode_air => 10000, - :speed_max_mode_air => 800, - :speed_min_mode_air => 700, + :allowed_transport_mode_air => false, + :inter_stop_area_distance_min_mode_air => 200, + :inter_stop_area_distance_max_mode_air => 10000, + :speed_max_mode_air => 800, + :speed_min_mode_air => 700, :inter_stop_duration_variation_max_mode_air => 60}, :waterborne => { - :allowed_transport_mode_waterborne => false, - :inter_stop_area_distance_min_mode_waterborne => 200, - :inter_stop_area_distance_max_mode_waterborne => 10000, - :speed_max_mode_waterborne => 40, - :speed_min_mode_waterborne => 5, + :allowed_transport_mode_waterborne => false, + :inter_stop_area_distance_min_mode_waterborne => 200, + :inter_stop_area_distance_max_mode_waterborne => 10000, + :speed_max_mode_waterborne => 40, + :speed_min_mode_waterborne => 5, :inter_stop_duration_variation_max_mode_waterborne => 60}, :bus => { - :allowed_transport_mode_bus => false, - :inter_stop_area_distance_min_mode_bus => 100, - :inter_stop_area_distance_max_mode_bus => 10000, - :speed_max_mode_bus => 60, - :speed_min_mode_bus => 10, + :allowed_transport_mode_bus => false, + :inter_stop_area_distance_min_mode_bus => 100, + :inter_stop_area_distance_max_mode_bus => 10000, + :speed_max_mode_bus => 60, + :speed_min_mode_bus => 10, :inter_stop_duration_variation_max_mode_bus => 15}, :ferry => { - :allowed_transport_mode_ferry => false, - :inter_stop_area_distance_min_mode_ferry => 200, - :inter_stop_area_distance_max_mode_ferry => 10000, - :speed_max_mode_ferry => 40, - :speed_min_mode_ferry => 5, + :allowed_transport_mode_ferry => false, + :inter_stop_area_distance_min_mode_ferry => 200, + :inter_stop_area_distance_max_mode_ferry => 10000, + :speed_max_mode_ferry => 40, + :speed_min_mode_ferry => 5, :inter_stop_duration_variation_max_mode_ferry => 60}, :walk => { - :allowed_transport_mode_walk => false, - :inter_stop_area_distance_min_mode_walk => 1, - :inter_stop_area_distance_max_mode_walk => 10000, - :speed_max_mode_walk => 6, - :speed_min_mode_walk => 1, + :allowed_transport_mode_walk => false, + :inter_stop_area_distance_min_mode_walk => 1, + :inter_stop_area_distance_max_mode_walk => 10000, + :speed_max_mode_walk => 6, + :speed_min_mode_walk => 1, :inter_stop_duration_variation_max_mode_walk => 10}, :metro => { - :allowed_transport_mode_metro => false, - :inter_stop_area_distance_min_mode_metro => 300, - :inter_stop_area_distance_max_mode_metro => 2000, - :speed_max_mode_metro => 60, - :speed_min_mode_metro => 30, + :allowed_transport_mode_metro => false, + :inter_stop_area_distance_min_mode_metro => 300, + :inter_stop_area_distance_max_mode_metro => 2000, + :speed_max_mode_metro => 60, + :speed_min_mode_metro => 30, :inter_stop_duration_variation_max_mode_metro => 30}, :shuttle => { - :allowed_transport_mode_shuttle => false, - :inter_stop_area_distance_min_mode_shuttle => 500, - :inter_stop_area_distance_max_mode_shuttle => 10000, - :speed_max_mode_shuttle => 80, - :speed_min_mode_shuttle => 20, + :allowed_transport_mode_shuttle => false, + :inter_stop_area_distance_min_mode_shuttle => 500, + :inter_stop_area_distance_max_mode_shuttle => 10000, + :speed_max_mode_shuttle => 80, + :speed_min_mode_shuttle => 20, :inter_stop_duration_variation_max_mode_shuttle => 10}, :rapid_transit => { - :allowed_transport_mode_rapid_transit => false, - :inter_stop_area_distance_min_mode_rapid_transit => 2000, - :inter_stop_area_distance_max_mode_rapid_transit => 500000, - :speed_max_mode_rapid_transit => 300, - :speed_min_mode_rapid_transit => 20, + :allowed_transport_mode_rapid_transit => false, + :inter_stop_area_distance_min_mode_rapid_transit => 2000, + :inter_stop_area_distance_max_mode_rapid_transit => 500000, + :speed_max_mode_rapid_transit => 300, + :speed_min_mode_rapid_transit => 20, :inter_stop_duration_variation_max_mode_rapid_transit => 60}, :taxi => { - :allowed_transport_mode_taxi => false, - :inter_stop_area_distance_min_mode_taxi => 500, - :inter_stop_area_distance_max_mode_taxi => 300000, - :speed_max_mode_taxi => 130, - :speed_min_mode_taxi => 20, + :allowed_transport_mode_taxi => false, + :inter_stop_area_distance_min_mode_taxi => 500, + :inter_stop_area_distance_max_mode_taxi => 300000, + :speed_max_mode_taxi => 130, + :speed_min_mode_taxi => 20, :inter_stop_duration_variation_max_mode_taxi => 60}, :local_train => { - :allowed_transport_mode_local_train => false, - :inter_stop_area_distance_min_mode_local_train => 2000, - :inter_stop_area_distance_max_mode_local_train => 500000, - :speed_max_mode_local_train => 300, - :speed_min_mode_local_train => 20, + :allowed_transport_mode_local_train => false, + :inter_stop_area_distance_min_mode_local_train => 2000, + :inter_stop_area_distance_max_mode_local_train => 500000, + :speed_max_mode_local_train => 300, + :speed_min_mode_local_train => 20, :inter_stop_duration_variation_max_mode_local_train => 60}, :train => { - :allowed_transport_mode_train => false, - :inter_stop_area_distance_min_mode_train => 2000, - :inter_stop_area_distance_max_mode_train => 500000, - :speed_max_mode_train => 300, - :speed_min_mode_train => 20, + :allowed_transport_mode_train => false, + :inter_stop_area_distance_min_mode_train => 2000, + :inter_stop_area_distance_max_mode_train => 500000, + :speed_max_mode_train => 300, + :speed_min_mode_train => 20, :inter_stop_duration_variation_max_mode_train => 60}, :long_distance_train => { - :allowed_transport_mode_long_distance_train => false, - :inter_stop_area_distance_min_mode_long_distance_train => 2000, - :inter_stop_area_distance_max_mode_long_distance_train => 500000, - :speed_max_mode_long_distance_train => 300, - :speed_min_mode_long_distance_train => 20, + :allowed_transport_mode_long_distance_train => false, + :inter_stop_area_distance_min_mode_long_distance_train => 2000, + :inter_stop_area_distance_max_mode_long_distance_train => 500000, + :speed_max_mode_long_distance_train => 300, + :speed_min_mode_long_distance_train => 20, :inter_stop_duration_variation_max_mode_long_distance_train => 60}, :tramway => { - :allowed_transport_mode_tramway => false, - :inter_stop_area_distance_min_mode_tramway => 300, - :inter_stop_area_distance_max_mode_tramway => 2000, - :speed_max_mode_tramway => 50, - :speed_min_mode_tramway => 20, + :allowed_transport_mode_tramway => false, + :inter_stop_area_distance_min_mode_tramway => 300, + :inter_stop_area_distance_max_mode_tramway => 2000, + :speed_max_mode_tramway => 50, + :speed_min_mode_tramway => 20, :inter_stop_duration_variation_max_mode_tramway => 30}, :trolleybus => { - :allowed_transport_mode_trolleybus => false, - :inter_stop_area_distance_min_mode_trolleybus => 300, - :inter_stop_area_distance_max_mode_trolleybus => 2000, - :speed_max_mode_trolleybus => 50, - :speed_min_mode_trolleybus => 20, + :allowed_transport_mode_trolleybus => false, + :inter_stop_area_distance_min_mode_trolleybus => 300, + :inter_stop_area_distance_max_mode_trolleybus => 2000, + :speed_max_mode_trolleybus => 50, + :speed_min_mode_trolleybus => 20, :inter_stop_duration_variation_max_mode_trolleybus => 30}, :private_vehicle => { - :allowed_transport_mode_private_vehicle => false, - :inter_stop_area_distance_min_mode_private_vehicle => 500, - :inter_stop_area_distance_max_mode_private_vehicle => 300000, - :speed_max_mode_private_vehicle => 130, - :speed_min_mode_private_vehicle => 20, + :allowed_transport_mode_private_vehicle => false, + :inter_stop_area_distance_min_mode_private_vehicle => 500, + :inter_stop_area_distance_max_mode_private_vehicle => 300000, + :speed_max_mode_private_vehicle => 130, + :speed_min_mode_private_vehicle => 20, :inter_stop_duration_variation_max_mode_private_vehicle => 60}, :bicycle => { - :allowed_transport_mode_bicycle => false, - :inter_stop_area_distance_min_mode_bicycle => 300, - :inter_stop_area_distance_max_mode_bicycle => 30000, - :speed_max_mode_bicycle => 40, - :speed_min_mode_bicycle => 10, + :allowed_transport_mode_bicycle => false, + :inter_stop_area_distance_min_mode_bicycle => 300, + :inter_stop_area_distance_max_mode_bicycle => 30000, + :speed_max_mode_bicycle => 40, + :speed_min_mode_bicycle => 10, :inter_stop_duration_variation_max_mode_bicycle => 10}, :other => { - :allowed_transport_mode_other => false, - :inter_stop_area_distance_min_mode_other => 300, - :inter_stop_area_distance_max_mode_other => 30000, - :speed_max_mode_other => 40, - :speed_min_mode_other => 10, + :allowed_transport_mode_other => false, + :inter_stop_area_distance_min_mode_other => 300, + :inter_stop_area_distance_max_mode_other => 30000, + :speed_max_mode_other => 40, + :speed_min_mode_other => 10, :inter_stop_duration_variation_max_mode_other => 10}, } # :waterborne, :bus, :ferry, :walk, :metro, :shuttle, :rapidtransit, :taxi, :localtrain, :train, :longdistancetrain, :tramway, :trolleybus, :privatevehicle, :bicycle, :other end - def self.default( organisation) - self.default_for_all_modes( organisation).tap do |rps| + def self.default(organisation) + self.default_for_all_modes(organisation).tap do |rps| rps.name = "" end end - def self.default_for_all_modes( organisation) + def self.default_for_all_modes(organisation) mode_attributes = mode_default_params.values.inject(self.default_params){|memo, obj| memo.merge! obj} self.new( { :organisation_id => organisation.id, :name => "valeurs par defaut" - }.merge( mode_attributes)) + }.merge(mode_attributes)) end def allowed(mode) diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 2c2632f40..29ce6564f 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -25,10 +25,12 @@ Apartment.configure do |config| "Api::V1::ApiKey", "RuleParameterSet", "StopAreaReferential", + "StopAreaReferentialMembership", "StopAreaReferentialSync", "StopAreaReferentialSyncMessage", "Chouette::StopArea", "LineReferential", + "LineReferentialMembership", "LineReferentialSync", "LineReferentialSyncMessage", "Chouette::Line", 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 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 --- app/models/chouette/time_table.rb | 21 ++++++++++++++++++++- spec/models/chouette/time_table_spec.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 7285e9716..fcdc525a9 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -54,7 +54,6 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord time_table_date = self.dates.find(date_id) if date_id next if !checked && !time_table_date - # Destroy date if no longer checked next if !checked && time_table_date.destroy @@ -67,9 +66,29 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord time_table_date.update_attributes({in_out: in_out}) end end + + self.state_update_periods state['time_table_periods'] self.save end + def state_update_periods state_periods + state_periods.each do |item| + period = self.periods.find(item['id']) if item['id'] + next if period && item['deleted'] && period.destroy + period ||= self.periods.build + + period.period_start = Date.parse(item['period_start']) + period.period_end = Date.parse(item['period_end']) + + if period.changed? + period.save + item['id'] = period.id + end + end + + state_periods.delete_if {|item| item['deleted']} + end + def self.state_permited_attributes item item.slice('comment').to_hash end 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 --- app/models/chouette/time_table.rb | 2 +- spec/models/chouette/time_table_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index fcdc525a9..11e7293f1 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -90,7 +90,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord end def self.state_permited_attributes item - item.slice('comment').to_hash + item.slice('comment', 'color').to_hash end def presenter 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 e9a07b3d9208e4adba0947fd46c931472244ea9e Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 2 May 2017 13:04:54 +0200 Subject: Refs #3264: change shared boolean filter by select (to permit join) --- app/assets/stylesheets/components/_forms.sass | 2 +- app/controllers/calendars_controller.rb | 19 +++++++++++++++++-- app/views/calendars/_filters.html.slim | 9 ++++++--- app/views/calendars/index.html.slim | 2 +- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index c24b7abda..46f40291a 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -159,7 +159,7 @@ input top: 0 bottom: 0 right: 60% - z-index: 2 + z-index: 5 width: auto > .btn diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index c33aa9373..d18e165d2 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -33,8 +33,12 @@ class CalendarsController < BreadcrumbController def collection return @calendars if @calendars + scope = Calendar.where('organisation_id = ?', current_organisation.id) + + scope = shared_scope(scope) + + @q = scope.ransack(params[:q]) - @q = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).search(params[:q]) calendars = @q.result calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction @calendars = calendars.paginate(page: params[:page]) @@ -51,5 +55,16 @@ class CalendarsController < BreadcrumbController params[:q]['contains_date'] = Date.parse(date.join('-')) end end -end + def shared_scope scope + return scope unless params[:q] + + if params[:q][:shared_true] == params[:q][:shared_false] + params[:q].delete(:shared_true) + params[:q].delete(:shared_false) + end + + scope + end + +end diff --git a/app/views/calendars/_filters.html.slim b/app/views/calendars/_filters.html.slim index d8707ba0f..4f625e4f0 100644 --- a/app/views/calendars/_filters.html.slim +++ b/app/views/calendars/_filters.html.slim @@ -7,13 +7,16 @@ span.fa.fa-search .ffg-row - .form-group.has_switch style='width: 260px' - = f.label Calendar.human_attribute_name(:shared), class: 'col-sm-4 control-label' - = f.input :shared_true, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, '', class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8' } + .form-group.togglable + = f.label Calendar.human_attribute_name(:shared), required: false, class: 'control-label' + .form-group.checkbox_list + = f.input :shared_true, as: :boolean, label: ("Oui").html_safe, wrapper_html: { class: 'checkbox-wrapper' } + = f.input :shared_false, as: :boolean, label: ("Non").html_safe, wrapper_html: { class: 'checkbox-wrapper' } .form-group = f.label Calendar.human_attribute_name(:date), class: 'control-label' = f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date' }, class: 'form-control', include_blank: true + .actions = link_to 'Effacer', calendars_path, class: 'btn btn-link' = f.submit 'Filtrer', id: 'filter_btn', class: 'btn btn-default' diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index 864d1e197..fbb9f889d 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -21,7 +21,7 @@ .row .col-lg-12 = table_builder @calendars, - { :name => 'name', :short_name => 'short_name', :shared => 'shared' }, + { :name => 'name', :short_name => 'short_name', :shared => Proc.new{|c| t("#{c.try(:shared)}") } }, [:show, :edit, :delete], [], 'table has-filter' -- cgit v1.2.3 From 04f4b5f519a9c12e9f161fb2d86ad20a1e96302b Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 2 May 2017 13:42:02 +0200 Subject: Refs #3265: updating calendars#show layout --- app/views/calendars/show.html.slim | 68 ++++++++++++++------------------------ 1 file changed, 24 insertions(+), 44 deletions(-) diff --git a/app/views/calendars/show.html.slim b/app/views/calendars/show.html.slim index c0671fa94..3886cefaa 100644 --- a/app/views/calendars/show.html.slim +++ b/app/views/calendars/show.html.slim @@ -1,46 +1,26 @@ -= title_tag t('.title', calendar: @calendar.name) +/ PageHeader += pageheader 'map-marker', + @calendar.name, + '', + t('last_update', time: l(@calendar.updated_at, format: :short)), + (policy(@calendar).edit? ? link_to(t('actions.edit'), edit_calendar_path(@calendar), class: 'btn btn-default') : '') do -p - label => "#{Calendar.human_attribute_name('name')} : " - = @calendar.name -p - label => "#{Calendar.human_attribute_name('short_name')} : " - = @calendar.short_name + / Below is secondary actions & optional contents (filters, ...) + .row.mb-sm + .col-lg-12.text-right + - if policy(@calendar).destroy? + = link_to calendar_path(@calendar), method: :delete, data: { confirm: t('calendars.actions.destroy_confirm') }, class: 'btn btn-primary' do + span.fa.fa-trash + span = t('actions.destroy') -.row - .col-xs-4 - p - label => "#{Calendar.human_attribute_name('dates')} : " - table.table.table-condensed - tbody - - @calendar.dates.each do |date| - tr - td= l date - p - label => "#{Calendar.human_attribute_name('date_ranges')} : " - table.table.table-condensed - thead - th= t('simple_form.labels.calendar.ranges.begin') - th= t('simple_form.labels.calendar.ranges.end') - tbody - - @calendar.date_ranges.each do |date_range| - tr - td= l date_range.begin - td= l date_range.end - -p - label => "#{Calendar.human_attribute_name('shared')} : " - = @calendar.shared -p - label => "#{Organisation.model_name.human} : " - = @calendar.organisation.name - - -- content_for(:sidebar) do - ul.actions - - if policy(@calendar).edit? - li - = link_to t('calendars.actions.edit'), edit_calendar_path(@calendar), class: 'edit' - - if policy(@calendar).destroy? - li - = link_to t('calendars.actions.destroy'), calendar_path(@calendar), method: :delete, data: { confirm: t('calendars.actions.destroy_confirm') }, class: 'remove' +/ PageContent +.page_content + .container-fluid + .row + .col-lg-6.col-md-6.col-sm-12.col-xs-12 + = definition_list t('metadatas'), + { 'Nom court' => @calendar.try(:short_name), + Calendar.human_attribute_name(:shared) => t("#{@calendar.shared}"), + 'Organisation' => @calendar.organisation.name, + Calendar.human_attribute_name(:dates) => @calendar.dates.collect{|d| l(d, format: :short)}.join(', ').html_safe, + Calendar.human_attribute_name(:date_ranges) => @calendar.date_ranges.collect{|d| t('validity_range', debut: l(d.begin, format: :short), end: l(d.end, format: :short))}.join('
').html_safe } -- cgit v1.2.3 From 19036477ef4b876e5760aa2a2145a4fa12d676fb Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 2 May 2017 14:59:16 +0200 Subject: Refs #3265: refacto layout --- app/views/calendars/_date_value_fields.html.slim | 11 ++-- app/views/calendars/_form.html.slim | 74 ++++++++++++++++-------- app/views/calendars/_period_fields.html.slim | 15 +++-- app/views/calendars/edit.html.slim | 13 ++++- app/views/calendars/index.html.slim | 7 +-- app/views/calendars/new.html.slim | 13 ++++- 6 files changed, 85 insertions(+), 48 deletions(-) diff --git a/app/views/calendars/_date_value_fields.html.slim b/app/views/calendars/_date_value_fields.html.slim index 3a9cdb7bd..2d072fa0a 100644 --- a/app/views/calendars/_date_value_fields.html.slim +++ b/app/views/calendars/_date_value_fields.html.slim @@ -5,10 +5,9 @@ .alert.alert-danger - f.object.errors[:base].each do |message| p.small = message - .row - .col-xs-3 - = f.input :value, as: :date, html5: true, label: t('simple_form.labels.calendar.date_value') - .col-xs-1.end.text-right#delete-btn - = link_to_remove_association f, class: 'btn btn-danger', data: { confirm: t('are_you_sure') } do - span.fa.fa-trash + .wrapper + div + = f.input :value, as: :date, label: false, wrapper_html: { class: 'date' } + div + = link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete') diff --git a/app/views/calendars/_form.html.slim b/app/views/calendars/_form.html.slim index a97c16565..9aed9f7d8 100644 --- a/app/views/calendars/_form.html.slim +++ b/app/views/calendars/_form.html.slim @@ -1,27 +1,53 @@ -#calendar_form += simple_form_for @calendar, html: { class: 'form-horizontal', id: 'calendar_form' }, wrapper: :horizontal_form do |f| .row - .col-xs-8.col-xs-offset-2 - = simple_form_for @calendar, html: { class: 'form-horizontal' } do |f| - = f.input :name - = f.input :short_name - .form-group - = f.label :dates - .well - = f.simple_fields_for :date_values do |date_value| - = render 'date_value_fields', f: date_value - .links - = link_to_add_association t('simple_form.labels.calendar.add_a_date'), f, :date_values, class: 'btn btn-primary btn-xs' - .form-group - = f.label :date_ranges - .well - = f.simple_fields_for :periods do |period| - = render 'period_fields', f: period - .links - = link_to_add_association t('simple_form.labels.calendar.add_a_date_range'), f, :periods, class: 'btn btn-primary btn-xs' - - if policy(@calendar).share? - = f.input :shared - .form-actions - = f.button :submit, as: :button, class: 'btn btn-info' - = link_to t('cancel'), calendars_path, class: 'btn btn-default' + .col-lg-12 + = f.input :name + = f.input :short_name + - if policy(@calendar).share? + .form-group.has_switch + = f.label :shared, class: 'col-sm-4 control-label' + = f.input :shared, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, t("#{@calendar.shared}"), class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8'} + .separator + + .row + .col-lg-12 + .subform + .nested-head + .wrapper + div + .form-group + label.control-label + = Calendar.human_attribute_name(:date) + div + + = f.simple_fields_for :date_values do |date_value| + = render 'date_value_fields', f: date_value + + .links.nested-linker + = link_to_add_association t('simple_form.labels.calendar.add_a_date'), f, :date_values, class: 'btn btn-outline-primary' + + .separator + + .row + .col-lg-12 + .subform + .nested-head + .wrapper + div + .form-group + label.control-label + = t('simple_form.labels.calendar.ranges.begin') + div + .form-group + label.control-label + = t('simple_form.labels.calendar.ranges.end') + div + + = f.simple_fields_for :periods do |period| + = render 'period_fields', f: period + .links.nested-linker + = link_to_add_association t('simple_form.labels.calendar.add_a_date_range'), f, :periods, class: 'btn btn-outline-primary' + + = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'calendar_form' diff --git a/app/views/calendars/_period_fields.html.slim b/app/views/calendars/_period_fields.html.slim index 024d09de2..1e201a39f 100644 --- a/app/views/calendars/_period_fields.html.slim +++ b/app/views/calendars/_period_fields.html.slim @@ -5,12 +5,11 @@ .alert.alert-danger - f.object.errors[:base].each do |message| p.small = message - .row - .col-xs-4 - = f.input :begin, as: :date, html5: true, label: t('simple_form.labels.calendar.ranges.begin') - .col-xs-3 - = f.input :end, as: :date, html5: true, label: t('simple_form.labels.calendar.ranges.end') - .col-xs-1.text-right#delete-btn - = link_to_remove_association f, class: 'btn btn-danger', data: { confirm: t('are_you_sure') } do - span.fa.fa-trash + .wrapper + div + = f.input :begin, as: :date, label: false, wrapper_html: { class: 'date' } + div + = f.input :end, as: :date, label: false, wrapper_html: { class: 'date' } + div + = link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete') diff --git a/app/views/calendars/edit.html.slim b/app/views/calendars/edit.html.slim index 22645cf24..6668630e8 100644 --- a/app/views/calendars/edit.html.slim +++ b/app/views/calendars/edit.html.slim @@ -1,3 +1,12 @@ -= title_tag t('.title', calendar: @calendar.name) +/ PageHeader += pageheader 'map-marker', + t('.title', calendar: @calendar.name), + '', + t('last_update', time: l(@calendar.updated_at, format: :short)) -= render 'form' +/ PageContent +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form' diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index fbb9f889d..ec3893959 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -2,12 +2,7 @@ = pageheader 'map-marker', t('.title'), '', - '' do - - / Below is secundary actions & optional contents (filters, ...) - .row.mb-sm - .col-lg-12.text-right - = link_to t('actions.add'), new_calendar_path, class: 'btn btn-primary' + link_to(t('actions.add'), new_calendar_path, class: 'btn btn-default') do / PageContent .page_content diff --git a/app/views/calendars/new.html.slim b/app/views/calendars/new.html.slim index f827e2eb6..7faecf587 100644 --- a/app/views/calendars/new.html.slim +++ b/app/views/calendars/new.html.slim @@ -1,3 +1,12 @@ -= title_tag t('.title') +/ PageHeader += pageheader 'map-marker', + t('.title'), + '', + '' -= render 'form' +/ PageContent +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form' -- 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(-) 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 a1f7a72f013483df683f57aa9d8c4d38fcb347bc Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 2 May 2017 15:22:17 +0200 Subject: Refs #3267: Fix fetch vehicle_journey properly (company/idenfitier) Signed-off-by: Thomas Shawarma Haddad --- .../javascripts/es6_browserified/vehicle_journeys/actions/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js index 21aff1080..444d290ee 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js @@ -315,8 +315,8 @@ const actions = { deletable: false, selected: false, published_journey_name: val.published_journey_name || 'non renseigné', - published_journey_identifier: val.published_journey_name || 'non renseigné', - company_id: val.published_journey_name || 'non renseigné', + published_journey_identifier: val.published_journey_identifier || 'non renseigné', + company: val.company || 'non renseigné', transport_mode: val.route.line.transport_mode || 'non renseigné', transport_submode: val.route.line.transport_submode || 'non renseigné' }) -- cgit v1.2.3 From b8b4a59fdb1b6550c86d32fb7445ff83ab3e6d80 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 2 May 2017 15:43:18 +0200 Subject: Refs #3269: Fix required filed in create modal for jp Signed-off-by: Thomas Shawarma Haddad --- .../vehicle_journeys/components/tools/CreateModal.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js index 1273921e7..3d2251753 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js @@ -49,19 +49,18 @@ class CreateModal extends Component {
- + actions.resetValidation(e.currentTarget)} - required />
- + this.props.onSelect2Company(e)} -- cgit v1.2.3 From b6a0ea532f9c75da693ba1a012327807976a3e27 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 2 May 2017 15:44:25 +0200 Subject: Duplicate TimeTable Refs #3188 --- app/controllers/time_tables_controller.rb | 16 ++++++++++++++-- app/models/chouette/time_table.rb | 2 ++ app/views/time_tables/_form.html.slim | 6 +++++- .../20170502130327_add_created_from_to_time_tables.rb | 5 +++++ db/schema.rb | 14 ++++++++------ 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20170502130327_add_created_from_to_time_tables.rb diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 3b8e390b6..8436dc020 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -37,7 +37,10 @@ class TimeTablesController < ChouetteController calendar = current_organisation.calendars.find_by_id(tt_params[:calendar_id]) tt_params[:calendar_id] = nil if tt_params.has_key?(:dates_attributes) || tt_params.has_key?(:periods_attributes) end - @time_table = Chouette::TimeTable.new(tt_params) + + created_from = duplicate_source + @time_table = created_from ? created_from.duplicate : Chouette::TimeTable.new(tt_params) + if calendar calendar.dates.each_with_index do |date, i| @time_table.dates << Chouette::TimeTableDate.new(date: date, position: i) @@ -48,7 +51,10 @@ class TimeTablesController < ChouetteController end create! do |success, failure| - success.html { redirect_to edit_referential_time_table_path(@referential, @time_table) } + success.html do + path = @time_table.created_from ? 'referential_time_table_path' : 'edit_referential_time_table_path' + redirect_to send(path, @referential, @time_table) + end failure.html { render :new } end end @@ -158,6 +164,11 @@ class TimeTablesController < ChouetteController %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' end + def duplicate_source + from_id = time_table_params['created_from_id'] + Chouette::TimeTable.find(from_id) if from_id + end + def time_table_params params.require(:time_table).permit( :objectid, @@ -175,6 +186,7 @@ class TimeTablesController < ChouetteController :sunday, :start_date, :end_date, + :created_from_id, { :dates_attributes => [:date, :in_out, :id, :_destroy] }, { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, {tag_list: []}, diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 11e7293f1..798fa81b4 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -18,6 +18,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord has_many :periods, -> {order(:period_start)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTablePeriod", :dependent => :destroy belongs_to :calendar + belongs_to :created_from, class_name: 'Chouette::TimeTable' after_save :save_shortcuts @@ -525,6 +526,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord def duplicate tt = self.deep_clone :include => [:periods, :dates], :except => :object_version tt.uniq_objectid + tt.created_from = self tt.comment = I18n.t("activerecord.copy", :name => self.comment) tt end diff --git a/app/views/time_tables/_form.html.slim b/app/views/time_tables/_form.html.slim index 8152e7f94..196682823 100644 --- a/app/views/time_tables/_form.html.slim +++ b/app/views/time_tables/_form.html.slim @@ -4,7 +4,11 @@ .col-lg-12 = form.input :comment, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.comment")} - - if @time_table.new_record? + - if @time_table.new_record? && !@time_table.created_from = form.input :calendar, as: :select, collection: current_organisation.calendars + - if @time_table.created_from + = form.input :created_from, disabled: true, input_html: { value: @time_table.created_from.comment } + .hidden = form.input :created_from_id, as: :hidden + = form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'timetable_form' diff --git a/db/migrate/20170502130327_add_created_from_to_time_tables.rb b/db/migrate/20170502130327_add_created_from_to_time_tables.rb new file mode 100644 index 000000000..6c0815eaf --- /dev/null +++ b/db/migrate/20170502130327_add_created_from_to_time_tables.rb @@ -0,0 +1,5 @@ +class AddCreatedFromToTimeTables < ActiveRecord::Migration + def change + add_reference :time_tables, :created_from, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3214c1e78..17df3c34f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170428133742) do +ActiveRecord::Schema.define(version: 20170502130327) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -696,21 +696,23 @@ ActiveRecord::Schema.define(version: 20170428133742) do add_index "time_table_periods", ["time_table_id"], name: "index_time_table_periods_on_time_table_id", using: :btree create_table "time_tables", id: :bigserial, force: :cascade do |t| - t.string "objectid", null: false - t.integer "object_version", limit: 8, default: 1 + t.string "objectid", null: false + t.integer "object_version", limit: 8, default: 1 t.string "creator_id" t.string "version" t.string "comment" - t.integer "int_day_types", default: 0 + t.integer "int_day_types", default: 0 t.date "start_date" t.date "end_date" - t.integer "calendar_id", limit: 8 + t.integer "calendar_id", limit: 8 t.datetime "created_at" t.datetime "updated_at" - t.string "color", limit: 255 + t.string "color", limit: 255 + t.integer "created_from_id" end add_index "time_tables", ["calendar_id"], name: "index_time_tables_on_calendar_id", using: :btree + add_index "time_tables", ["created_from_id"], name: "index_time_tables_on_created_from_id", using: :btree add_index "time_tables", ["objectid"], name: "time_tables_objectid_key", unique: true, using: :btree create_table "time_tables_vehicle_journeys", id: false, force: :cascade do |t| -- 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 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 --- .rspec | 1 + spec/lib/range_ext_spec.rb | 17 +++++++++++++++++ spec/spec_helper.rb | 19 ++++++++++--------- 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 spec/lib/range_ext_spec.rb diff --git a/.rspec b/.rspec index 53607ea52..986f6f5c1 100644 --- a/.rspec +++ b/.rspec @@ -1 +1,2 @@ --colour +-r spec_helper 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 --- app/models/calendar.rb | 10 ---------- lib/range_ext.rb | 4 ++-- spec/lib/range_ext_spec.rb | 2 ++ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 641f97302..4890540b9 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -245,14 +245,4 @@ class Calendar < ActiveRecord::Base private :clear_date_values -### - -end - -class Range - def intersection(other) - return nil if (self.max < other.begin or other.max < self.begin) - [self.begin, other.begin].max..[self.max, other.max].min - end - alias_method :&, :intersection end diff --git a/lib/range_ext.rb b/lib/range_ext.rb index 5afb44dee..729cd1092 100644 --- a/lib/range_ext.rb +++ b/lib/range_ext.rb @@ -1,7 +1,7 @@ class Range def intersection(other) - return nil if (self.max < other.begin or other.max < self.begin) - [self.begin, other.begin].max..[self.max, other.max].min + return nil if (self.max < other.min or other.max < self.min) + [self.min, other.min].max..[self.max, other.max].min end alias_method :&, :intersection end 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(-) 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 --- app/models/calendar.rb | 1 + app/models/referential_metadata.rb | 9 +-------- config/application.rb | 2 +- lib/range_ext.rb | 1 + spec/lib/range_ext_spec.rb | 1 + 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 4890540b9..cd945a67f 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -1,3 +1,4 @@ +require 'range_ext' class Calendar < ActiveRecord::Base belongs_to :organisation has_many :time_tables diff --git a/app/models/referential_metadata.rb b/app/models/referential_metadata.rb index 3ec8398e0..357465c63 100644 --- a/app/models/referential_metadata.rb +++ b/app/models/referential_metadata.rb @@ -1,4 +1,5 @@ require 'activeattr_ext.rb' +require 'range_ext' class ReferentialMetadata < ActiveRecord::Base belongs_to :referential, touch: true @@ -160,11 +161,3 @@ class ReferentialMetadata < ActiveRecord::Base end end end - -class Range - def intersection(other) - return nil if (self.max < other.begin or other.max < self.begin) - [self.begin, other.begin].max..[self.max, other.max].min - end - alias_method :&, :intersection -end diff --git a/config/application.rb b/config/application.rb index 06f931765..8606a3156 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,7 +14,7 @@ module ChouetteIhm # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. - config.autoload_paths += %W(#{config.root}/lib) + config.autoload_paths << config.root.join("lib") # custom exception pages config.exceptions_app = self.routes diff --git a/lib/range_ext.rb b/lib/range_ext.rb index 729cd1092..f1df5e70d 100644 --- a/lib/range_ext.rb +++ b/lib/range_ext.rb @@ -1,4 +1,5 @@ class Range + def intersection(other) return nil if (self.max < other.min or other.max < self.min) [self.min, other.min].max..[self.max, other.max].min 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 bc45e4ccd5dc999efb2c49a91750e3493d07407a Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 3 May 2017 10:00:04 +0200 Subject: Add teaspoon in ci dependencies. Fixes #3275 --- lib/tasks/ci.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 85d1cbdf9..b4dc677c8 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -39,5 +39,5 @@ namespace :ci do end desc "Run continuous integration tasks (spec, ...)" -task :ci => ["ci:setup", "spec", "cucumber", "ci:deploy", "ci:clean"] +task :ci => ["ci:setup", "spec", "teaspoon", "cucumber", "ci:deploy", "ci:clean"] # task :ci => ["ci:setup", "spec", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] -- cgit v1.2.3 From 24fc29e3712fbfbfaaf5dba5924fa63fccdc4878 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 3 May 2017 10:02:04 +0200 Subject: Update rubyzip to 1.2.1. Fixes #3274 --- Gemfile | 2 +- Gemfile.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 4e0dd5426..202e05198 100644 --- a/Gemfile +++ b/Gemfile @@ -95,7 +95,7 @@ gem 'breadcrumbs_on_rails' # Format Output gem 'json' -gem 'rubyzip', '~> 1.1.7' +gem 'rubyzip' gem 'roo' # Controller diff --git a/Gemfile.lock b/Gemfile.lock index 3acf91cc5..d220788ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -445,7 +445,7 @@ GEM ruby-graphviz (1.2.3) rubycas-client (2.3.9) activesupport - rubyzip (1.1.7) + rubyzip (1.2.1) safe_yaml (1.0.4) sass (3.2.19) sass-rails (4.0.5) @@ -641,7 +641,7 @@ DEPENDENCIES rgeo (~> 0.5.2) roo rspec-rails (~> 3.5.0) - rubyzip (~> 1.1.7) + rubyzip sass-rails (~> 4.0.3) sawyer (~> 0.6.0) sdoc (~> 0.4.0) -- cgit v1.2.3 From bc55e06d948fc69d8639ae5dcfaa8adcc7a97926 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 3 May 2017 10:07:30 +0200 Subject: Restore ci:check_security in ci task. Fixes last warnings in Gemfile --- Gemfile | 16 ++++++++++------ Gemfile.lock | 56 +++++++++++++++++++++++++++---------------------------- lib/tasks/ci.rake | 3 +-- 3 files changed, 39 insertions(+), 36 deletions(-) diff --git a/Gemfile b/Gemfile index 202e05198..b7844cf28 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,9 @@ # coding: utf-8 -source 'http://rubygems.org' +source 'https://rubygems.org' + +# Use https for github +git_source(:github) { |name| "https://github.com/#{name}.git" } +git_source(:af83) { |name| "git@github.com:af83/#{name}.git" } # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 4.2.8' @@ -29,7 +33,7 @@ gem 'select2-rails', '~> 4.0', '>= 4.0.3' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring', group: :development # ActiveRecord associations on top of PostgreSQL arrays -gem 'has_array_of', git: 'git@github.com:AF83/has_array_of.git' +gem 'has_array_of', af83: 'has_array_of' gem 'rails-observers' @@ -60,9 +64,9 @@ gem 'activerecord-postgis-adapter', "~> 3.0.0" gem 'polylines' # Codifligne API -gem 'codifligne', git: 'git@github.com:AF83/stif-codifline-api.git' +gem 'codifligne', af83: 'stif-codifline-api' # Reflex API -gem 'reflex', git: 'git@github.com:AF83/stif-reflex-api.git' +gem 'reflex', af83: 'stif-reflex-api' # Authentication gem 'devise', '~> 3.5.4' @@ -105,7 +109,7 @@ gem 'google-analytics-rails' # Model gem 'will_paginate' gem 'ransack' -gem "squeel", :git => "git://github.com/activerecord-hackery/squeel.git" +gem "squeel", github: 'activerecord-hackery/squeel' gem 'active_attr' gem 'draper' @@ -194,7 +198,7 @@ gem 'devise-i18n' gem 'i18n-tasks' # Rails Assets -source 'http://rails-assets.org' do +source 'https://rails-assets.org' do gem 'rails-assets-footable', '~> 2.0.3' # Use twitter bootstrap resources diff --git a/Gemfile.lock b/Gemfile.lock index d220788ab..4e1337ec5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,28 +1,5 @@ GIT - remote: git://github.com/activerecord-hackery/squeel.git - revision: 5542266d502db8022e14105f9dfb455a79d6fc4a - specs: - squeel (1.2.3) - activerecord (>= 3.0) - activesupport (>= 3.0) - polyamorous (~> 1.1.0) - -GIT - remote: git://github.com/af83/language_engine.git - revision: c4d7d5af781b55c1df4806c3960caf3c22f1ee96 - specs: - language_engine (0.0.7) - rails (~> 4.2) - -GIT - remote: git://github.com/af83/whenever.git - revision: b7963381a11243affe4f35881c85be0710f434e3 - specs: - whenever (0.9.4) - chronic (>= 0.6.3) - -GIT - remote: git@github.com:AF83/has_array_of.git + remote: git@github.com:af83/has_array_of.git revision: a6439d93291c7a1ca224ea95a8d39ed101e2f05f specs: has_array_of (0.0.1) @@ -31,22 +8,45 @@ GIT railties (>= 4.0) GIT - remote: git@github.com:AF83/stif-codifline-api.git + remote: git@github.com:af83/stif-codifline-api.git revision: 02108a647514ca36e4377deecf3ffcce99359139 specs: codifligne (0.0.2) nokogiri (~> 1.6) GIT - remote: git@github.com:AF83/stif-reflex-api.git + remote: git@github.com:af83/stif-reflex-api.git revision: 7c517b98c3900c9bb0b81dd0ccab97f8e8f5f249 specs: reflex (0.0.1) nokogiri (~> 1.6) +GIT + remote: https://github.com/activerecord-hackery/squeel.git + revision: 5542266d502db8022e14105f9dfb455a79d6fc4a + specs: + squeel (1.2.3) + activerecord (>= 3.0) + activesupport (>= 3.0) + polyamorous (~> 1.1.0) + +GIT + remote: https://github.com/af83/language_engine.git + revision: c4d7d5af781b55c1df4806c3960caf3c22f1ee96 + specs: + language_engine (0.0.7) + rails (~> 4.2) + +GIT + remote: https://github.com/af83/whenever.git + revision: b7963381a11243affe4f35881c85be0710f434e3 + specs: + whenever (0.9.4) + chronic (>= 0.6.3) + GEM - remote: http://rubygems.org/ - remote: http://rails-assets.org/ + remote: https://rubygems.org/ + remote: https://rails-assets.org/ specs: RedCloth (4.3.2) SyslogLogger (2.0) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index b4dc677c8..926d10aca 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -39,5 +39,4 @@ namespace :ci do end desc "Run continuous integration tasks (spec, ...)" -task :ci => ["ci:setup", "spec", "teaspoon", "cucumber", "ci:deploy", "ci:clean"] -# task :ci => ["ci:setup", "spec", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] +task :ci => ["ci:setup", "spec", "teaspoon", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] -- cgit v1.2.3 From 3d234cd0d972ed91d3fb850681bf7f72695d42e4 Mon Sep 17 00:00:00 2001 From: jpl Date: Wed, 3 May 2017 11:02:03 +0200 Subject: Refs #3079: fix text overflow on notes --- app/assets/stylesheets/components/_panels.sass | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/assets/stylesheets/components/_panels.sass b/app/assets/stylesheets/components/_panels.sass index 675faf899..ff384faf9 100644 --- a/app/assets/stylesheets/components/_panels.sass +++ b/app/assets/stylesheets/components/_panels.sass @@ -25,3 +25,7 @@ background-color: transparent border-radius: 0 border: none + + p + hyphens: auto + word-wrap: break-word -- cgit v1.2.3 From ad80f005f8fcbffdfe3a146cdcf786e64741234d Mon Sep 17 00:00:00 2001 From: Xinhui Date: Wed, 3 May 2017 11:25:13 +0200 Subject: Referentials#Show display status Refs #3122 --- app/views/referentials/show.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index fd6ebf91a..45fffe6a1 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -32,7 +32,7 @@ .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { 'Statut' => (@referential.archived? ? 'Conservé' : '-'), + { 'Statut' => @referential.archived? ? "
Conservé
".html_safe : "
En préparation
".html_safe, @referential.human_attribute_name(:validity_period) => (@referential.validity_period.present? ? t('validity_range', debut: l(@referential.try(:validity_period).try(:begin), format: :short), end: l(@referential.try(:validity_period).try(:end), format: :short)) : '-'), @referential.human_attribute_name(:organisation) => @referential.organisation.name, @referential.human_attribute_name(:published_at) => '-' } -- cgit v1.2.3 From e4880ded62ee261a25a464073add6e202d62216c Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 3 May 2017 10:57:35 +0200 Subject: Remove timetables logger Signed-off-by: Thomas Shawarma Haddad --- .../javascripts/es6_browserified/time_tables/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/time_tables/index.js b/app/assets/javascripts/es6_browserified/time_tables/index.js index 3bf5a3b99..1fe6ee84b 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/index.js @@ -6,10 +6,10 @@ var timeTablesApp = require('./reducers') var App = require('./containers/App') // logger, DO NOT REMOVE -var applyMiddleware = require('redux').applyMiddleware -var createLogger = require('redux-logger') -var thunkMiddleware = require('redux-thunk').default -var promise = require('redux-promise') +// var applyMiddleware = require('redux').applyMiddleware +// var createLogger = require('redux-logger') +// var thunkMiddleware = require('redux-thunk').default +// var promise = require('redux-promise') var initialState = { status: { @@ -57,12 +57,12 @@ var initialState = { confirmModal: {} } } -const loggerMiddleware = createLogger() +// const loggerMiddleware = createLogger() let store = createStore( timeTablesApp, - initialState, - applyMiddleware(thunkMiddleware, promise, loggerMiddleware) + initialState + // applyMiddleware(thunkMiddleware, promise, loggerMiddleware) ) render( -- 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 --- .../javascripts/es6_browserified/itineraries/components/BSelect2.js | 3 ++- .../javascripts/es6_browserified/itineraries/components/OlMap.js | 4 ++++ app/assets/javascripts/es6_browserified/itineraries/index.js | 1 + .../javascripts/es6_browserified/itineraries/reducers/stopPoints.js | 1 + app/helpers/routes_helper.rb | 2 +- app/views/autocomplete_stop_areas/around.rabl | 3 ++- app/views/autocomplete_stop_areas/index.rabl | 3 ++- spec/javascripts/itineraries/reducers/stop_points_spec.js | 4 +++- 8 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/itineraries/components/BSelect2.js b/app/assets/javascripts/es6_browserified/itineraries/components/BSelect2.js index dae62d3e1..64c6d3ac7 100644 --- a/app/assets/javascripts/es6_browserified/itineraries/components/BSelect2.js +++ b/app/assets/javascripts/es6_browserified/itineraries/components/BSelect2.js @@ -24,7 +24,8 @@ class BSelect3 extends React.Component{ short_name: e.params.data.short_name, city_name: e.params.data.city_name, area_type: e.params.data.area_type, - zip_code: e.params.data.zip_code + zip_code: e.params.data.zip_code, + comment: e.params.data.comment }) } diff --git a/app/assets/javascripts/es6_browserified/itineraries/components/OlMap.js b/app/assets/javascripts/es6_browserified/itineraries/components/OlMap.js index 0eca5f3ff..b9e106c1a 100644 --- a/app/assets/javascripts/es6_browserified/itineraries/components/OlMap.js +++ b/app/assets/javascripts/es6_browserified/itineraries/components/OlMap.js @@ -142,6 +142,10 @@ class OlMap extends Component{ Commune : {this.props.value.olMap.json.city_name}

+

+ Commentaire : + {this.props.value.olMap.json.comment} +

{(this.props.value.stoparea_id != this.props.value.olMap.json.stoparea_id) &&(
{this.props.onUpdateViaOlMap(this.props.index, this.props.value.olMap.json)}} diff --git a/app/assets/javascripts/es6_browserified/itineraries/index.js b/app/assets/javascripts/es6_browserified/itineraries/index.js index 57c63a97b..12a44e376 100644 --- a/app/assets/javascripts/es6_browserified/itineraries/index.js +++ b/app/assets/javascripts/es6_browserified/itineraries/index.js @@ -38,6 +38,7 @@ const getInitialState = () => { for_alighting: v.for_alighting || "normal", longitude: v.longitude || 0, latitude: v.latitude || 0, + comment: v.comment, olMap: { isOpened: false, json: {} diff --git a/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js b/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js index 79b9648a6..a1be73cd9 100644 --- a/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js +++ b/app/assets/javascripts/es6_browserified/itineraries/reducers/stopPoints.js @@ -75,6 +75,7 @@ const stopPoints = (state = [], action) => { short_name: action.text.short_name, area_type: action.text.area_type, city_name: action.text.city_name, + comment: action.text.comment, registration_number: action.text.registration_number } ) diff --git a/app/helpers/routes_helper.rb b/app/helpers/routes_helper.rb index 4a9215653..a8c9a1f0c 100644 --- a/app/helpers/routes_helper.rb +++ b/app/helpers/routes_helper.rb @@ -21,7 +21,7 @@ module RoutesHelper def route_json_for_edit(route) route.stop_points.includes(:stop_area).order(:position).map do |stop_point| - stop_area_attributes = stop_point.stop_area.attributes.slice("name","city_name", "zip_code", "registration_number", "longitude", "latitude", "area_type") + stop_area_attributes = stop_point.stop_area.attributes.slice("name","city_name", "zip_code", "registration_number", "longitude", "latitude", "area_type", "comment") stop_area_attributes["short_name"] = truncate(stop_area_attributes["name"], :length => 30) || "" stop_point_attributes = stop_point.attributes.slice("for_boarding","for_alighting") stop_area_attributes.merge(stop_point_attributes).merge(stoppoint_id: stop_point.id, stoparea_id: stop_point.stop_area.id).merge(user_objectid: stop_point.stop_area.user_objectid) diff --git a/app/views/autocomplete_stop_areas/around.rabl b/app/views/autocomplete_stop_areas/around.rabl index da4e92552..bc8f06054 100644 --- a/app/views/autocomplete_stop_areas/around.rabl +++ b/app/views/autocomplete_stop_areas/around.rabl @@ -19,7 +19,8 @@ child @stop_areas, root: :features, object_root: false do user_objectid: s.user_objectid, zip_code: s.zip_code, latitude: s.latitude, - longitude: s.longitude + longitude: s.longitude, + comment: s.comment } end end diff --git a/app/views/autocomplete_stop_areas/index.rabl b/app/views/autocomplete_stop_areas/index.rabl index 5b7f71565..5a9f76a47 100644 --- a/app/views/autocomplete_stop_areas/index.rabl +++ b/app/views/autocomplete_stop_areas/index.rabl @@ -13,7 +13,8 @@ node do |stop_area| :user_objectid => stop_area.user_objectid, :longitude => stop_area.longitude, :latitude => stop_area.latitude, - :area_type => stop_area.area_type + :area_type => stop_area.area_type, + :comment => stop_area.comment } end 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 c415af8d04de007e117fe6992f79c7937342139f Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 3 May 2017 15:06:22 +0200 Subject: some typos and formatting --- app/models/chouette/active_record.rb | 3 ++- app/models/chouette/stop_area.rb | 2 +- app/models/chouette/trident_active_record.rb | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/chouette/active_record.rb b/app/models/chouette/active_record.rb index 59052075e..1862319af 100644 --- a/app/models/chouette/active_record.rb +++ b/app/models/chouette/active_record.rb @@ -7,7 +7,7 @@ module Chouette before_save :nil_if_blank - # to be overrided to set nullable attrs when empty + # to be overridden to set nullable attrs when empty def self.nullable_attributes [] end @@ -21,6 +21,7 @@ module Chouette self.class.human_attribute_name(*args) end + # TODO: Can we remove this? # class << self # alias_method :create_reflection_without_chouette_naming, :create_reflection diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 7441e5f6f..4d98027d6 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -30,7 +30,7 @@ class Chouette::StopArea < Chouette::ActiveRecord belongs_to :stop_area_referential validates_presence_of :stop_area_referential_id - acts_as_tree :foreign_key => 'parent_id',:order => "name" + acts_as_tree :foreign_key => 'parent_id', :order => "name" attr_accessor :stop_area_type attr_accessor :children_ids diff --git a/app/models/chouette/trident_active_record.rb b/app/models/chouette/trident_active_record.rb index cf7a59c0c..c1bc0172b 100644 --- a/app/models/chouette/trident_active_record.rb +++ b/app/models/chouette/trident_active_record.rb @@ -12,8 +12,7 @@ class Chouette::TridentActiveRecord < Chouette::ActiveRecord end def prefix - self.referential.prefix + referential.prefix end - end -- cgit v1.2.3 From e665b02375e9b3a9c028a7b8b43c6cb61ad4fca6 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 3 May 2017 15:15:45 +0200 Subject: Refs #3269: Fix fields not being required anymore + wording Signed-off-by: Thomas Shawarma Haddad --- .../vehicle_journeys/components/tools/CreateModal.js | 2 +- .../vehicle_journeys/components/tools/EditVehicleJourney.js | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js index 3d2251753..1e121b473 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/CreateModal.js @@ -69,7 +69,7 @@ class CreateModal extends Component {
- +
- + actions.resetValidation(e.currentTarget)} - required />
@@ -81,14 +80,13 @@ class EditVehicleJourney extends Component {
- + actions.resetValidation(e.currentTarget)} - required />
-- cgit v1.2.3 From 06db1209afed8bb4d42552c40f9f635ff0d25e4c Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 3 May 2017 14:22:58 +0200 Subject: Disable teaspoon (#mybad). Refs #3275 --- lib/tasks/ci.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 926d10aca..79cf35db9 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -39,4 +39,4 @@ namespace :ci do end desc "Run continuous integration tasks (spec, ...)" -task :ci => ["ci:setup", "spec", "teaspoon", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] +task :ci => ["ci:setup", "spec", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] -- cgit v1.2.3 From a0cf16f9ce054335757280e0798a5b112fdfb499 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 3 May 2017 15:32:27 +0200 Subject: Fixes (a little) devise sessions new style. Refs #3038 --- app/views/devise/sessions/new.html.slim | 70 +++++++++++----------- app/views/layouts/devise.html.slim | 41 ------------- .../layouts/navigation/_main_nav_top.html.slim | 19 +++--- config/initializers/devise.rb | 9 --- 4 files changed, 46 insertions(+), 93 deletions(-) delete mode 100644 app/views/layouts/devise.html.slim diff --git a/app/views/devise/sessions/new.html.slim b/app/views/devise/sessions/new.html.slim index 5f4fec741..0ed17e24a 100644 --- a/app/views/devise/sessions/new.html.slim +++ b/app/views/devise/sessions/new.html.slim @@ -1,34 +1,36 @@ -#sessions_new.row - = render 'devise/shared/intro' - - .col-md-4.login - .panel.panel-default - .panel-body - = simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: { :class => 'form-horizontal session_new' } ) do |form| - - = form.input :email, :label => false, input_html: { :class => "form-control" } - - .row - .col-md-6 - = form.input :password, :as => :password, :label => false, input_html: { :class => "form-control" } - - .col-md-6 - = form.button :submit, t("devise.sessions.new.commit"), :class => "btn-primary" - - .row.options - .col-md-6 - - if devise_mapping.rememberable? - = form.input :remember_me, :as => :boolean if devise_mapping.rememberable? - - .col-md-6.new_password - = link_to t("devise.links.new_password"), new_password_path(resource_name) - - / FIXME ref #819 - - if false - - if devise_mapping.confirmable? && controller_name != 'confirmations' - br - = link_to t("devise.links.new_confirmation"), new_confirmation_path(resource_name) - - / FIXME ref #819 - - if false - = render partial: 'devise/shared/form_registration', locals: { organisation: (resource.organisation || Organisation.new) } +.page_content#devise + .container-fluid + #sessions_new.row + = render 'devise/shared/intro' + + .col-md-4.login + .panel.panel-default + .panel-body + = simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: { :class => 'form-horizontal session_new' } ) do |form| + + = form.input :email, :label => false, input_html: { :class => "form-control" } + + .row + .col-md-6 + = form.input :password, :as => :password, :label => false, input_html: { :class => "form-control" } + + .col-md-6 + = form.button :submit, t("devise.sessions.new.commit"), :class => "btn-primary" + + .row.options + .col-md-6 + - if devise_mapping.rememberable? + = form.input :remember_me, :as => :boolean if devise_mapping.rememberable? + + .col-md-6.new_password + = link_to t("devise.links.new_password"), new_password_path(resource_name) + + / FIXME ref #819 + - if false + - if devise_mapping.confirmable? && controller_name != 'confirmations' + br + = link_to t("devise.links.new_confirmation"), new_confirmation_path(resource_name) + + / FIXME ref #819 + - if false + = render partial: 'devise/shared/form_registration', locals: { organisation: (resource.organisation || Organisation.new) } diff --git a/app/views/layouts/devise.html.slim b/app/views/layouts/devise.html.slim deleted file mode 100644 index e72748d10..000000000 --- a/app/views/layouts/devise.html.slim +++ /dev/null @@ -1,41 +0,0 @@ -doctype html -html lang=I18n.locale - head - meta charset="utf-8" - meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" - meta content="IE=EmulateIE7" http-equiv="X-UA-Compatible" - - title = "STIF BOIV - #{title}" - - = favicon_link_tag "logo_chouette_small.ico" - = favicon_link_tag 'logo_chouette_small.png', rel: 'apple-touch-icon', type: 'image/png' - - = stylesheet_link_tag :application - = javascript_include_tag :application - - - if defined?(@map) - = javascript_include_tag "http://maps.google.com/maps/api/js?v=3.2&sensor=false" - = javascript_include_tag "http://openlayers.org/api/OpenLayers.js" - - / Todo from @jpl: check if it works... - - - = analytics_init if Rails.env.production? - = csrf_meta_tag - - body#devise - #header - = render partial: "shared/header" - - .front_bg - #devise_middle.container - .row - div class=("#{content_for?(:sidebar) ? 'col-md-9' : 'col-md-12'}") - #workspace class=("#{controller_name} #{action_name}") - = render partial: "shared/flash_messages", flash: flash - = render partial: "shared/breadcrumb" - = yield - #footer - = render partial: "shared/footer" \ No newline at end of file diff --git a/app/views/layouts/navigation/_main_nav_top.html.slim b/app/views/layouts/navigation/_main_nav_top.html.slim index 095fbca0b..4cdd5f053 100644 --- a/app/views/layouts/navigation/_main_nav_top.html.slim +++ b/app/views/layouts/navigation/_main_nav_top.html.slim @@ -5,17 +5,18 @@ .menu-item = render 'layouts/navigation/breadcrumb' - .menu-item-group.pull-right - = link_to '#', class: 'menu-item', data: { panel: 'toggle', target: '#operations_panel' }, title: 'Opérations' do - span.fa.fa-lg.fa-tasks + - if user_signed_in? + .menu-item-group.pull-right + = link_to '#', class: 'menu-item', data: { panel: 'toggle', target: '#operations_panel' }, title: 'Opérations' do + span.fa.fa-lg.fa-tasks - = link_to '#', class: 'menu-item', data: { panel: 'toggle', target: '#profile_panel' }, title: 'Profil' do - span = current_user.username - span.fa.fa-lg.fa-user + = link_to '#', class: 'menu-item', data: { panel: 'toggle', target: '#profile_panel' }, title: 'Profil' do + span = current_user.username + span.fa.fa-lg.fa-user - = link_to destroy_user_session_path, method: :delete, class: 'menu-item', title: 'Se déconnecter' do - span.fa.fa-lg.fa-sign-out + = link_to destroy_user_session_path, method: :delete, class: 'menu-item', title: 'Se déconnecter' do + span.fa.fa-lg.fa-sign-out = render 'layouts/navigation/nav_panel_operations' - = render 'layouts/navigation/nav_panel_profile' + = render 'layouts/navigation/nav_panel_profile' if user_signed_in? diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 057d4b215..ccce16f5f 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -327,12 +327,3 @@ Devise.setup do |config| # logger: Rails.logger # } end - -Rails.application.config.to_prepare do - Devise::SessionsController.layout "devise" - Devise::RegistrationsController.layout proc{ |controller| ( action_name == "edit" || action_name == "update") ? "application" : "devise" } - Devise::InvitationsController.layout proc{ |controller| ( action_name == "new") ? "application" : "devise" } - Devise::ConfirmationsController.layout "devise" - Devise::UnlocksController.layout "devise" - Devise::PasswordsController.layout "devise" -end -- cgit v1.2.3 From 434ebbc37848384b28c0aedc3ca90cd56e34e08e Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 3 May 2017 15:39:49 +0200 Subject: Use test env for teaspoon (#mybad). Refs #3275 --- lib/tasks/ci.rake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 79cf35db9..658e4e04e 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -27,6 +27,11 @@ namespace :ci do sh "bundle exec bundle-audit check --update" end + task :teaspoon do + sh "RAILS_ENV=test bundle exec rake teaspoon" + end + + desc "Deploy after CI" task :deploy do sh "cap #{deploy_env} deploy:migrations" @@ -39,4 +44,4 @@ namespace :ci do end desc "Run continuous integration tasks (spec, ...)" -task :ci => ["ci:setup", "spec", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] +task :ci => ["ci:setup", "spec", "ci:teaspoon", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] -- 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(-) 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 fdff8db191dbda598406392ccfdde251318d7140 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Wed, 3 May 2017 17:28:42 +0200 Subject: Refs #3284: use I18n for transport_(sub)mode in vj edit Signed-off-by: Thomas Shawarma Haddad --- .../javascripts/es6_browserified/vehicle_journeys/actions/index.js | 4 ++-- .../vehicle_journeys/components/tools/EditVehicleJourney.js | 4 ++-- app/views/vehicle_journeys/index.html.slim | 3 ++- config/locales/enumerize.fr.yml | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js index 444d290ee..ea03694bd 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js @@ -317,8 +317,8 @@ const actions = { published_journey_name: val.published_journey_name || 'non renseigné', published_journey_identifier: val.published_journey_identifier || 'non renseigné', company: val.company || 'non renseigné', - transport_mode: val.route.line.transport_mode || 'non renseigné', - transport_submode: val.route.line.transport_submode || 'non renseigné' + transport_mode: val.route.line.transport_mode || 'undefined', + transport_submode: val.route.line.transport_submode || 'undefined' }) } window.currentItemsLength = vehicleJourneys.length diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/EditVehicleJourney.js index 3ccc8b4d8..932c56532 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/EditVehicleJourney.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/tools/EditVehicleJourney.js @@ -108,7 +108,7 @@ class EditVehicleJourney extends Component {
@@ -119,7 +119,7 @@ class EditVehicleJourney extends Component {
diff --git a/app/views/vehicle_journeys/index.html.slim b/app/views/vehicle_journeys/index.html.slim index 92bc3951a..38e07ad82 100644 --- a/app/views/vehicle_journeys/index.html.slim +++ b/app/views/vehicle_journeys/index.html.slim @@ -19,6 +19,7 @@ | window.vehicleJourneysLength = #{@vehicle_journeys.total_entries()}; | window.vehicleJourneysPerPage = #{@ppage}; | window.line_footnotes = #{raw @footnotes}; - | window.perms = #{raw @perms} + | window.perms = #{raw @perms}; + | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe}; = javascript_include_tag 'es6_browserified/vehicle_journeys/index.js' diff --git a/config/locales/enumerize.fr.yml b/config/locales/enumerize.fr.yml index 6ce7fd1cc..8b6c8092d 100644 --- a/config/locales/enumerize.fr.yml +++ b/config/locales/enumerize.fr.yml @@ -108,6 +108,7 @@ fr: transport_mode: interchange: Interconnection unknown: Inconnu + undefined: 'Non défini' air: Air train: Train long_distance_train: Train Grande Ligne -- 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(-) 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 dc3afdd13ee5e58bfd8645cb92f85f8767db83a7 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 3 May 2017 19:20:41 +0200 Subject: Fixes seed by adding user permissions and organisation functionnal_scope. Refs #3291 --- app/models/user.rb | 6 ++++++ db/seeds.rb | 18 +++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 8e73aa1d5..1230a64a1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,4 @@ +# coding: utf-8 class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable, :database_authenticatable @@ -32,6 +33,11 @@ class User < ActiveRecord::Base 'vehicle_journeys.create', 'vehicle_journeys.edit', 'vehicle_journeys.destroy', 'time_tables.create', 'time_tables.edit', 'time_tables.destroy', 'footnotes.edit', 'footnotes.create', 'footnotes.destroy', 'routing_constraint_zones.create', 'routing_constraint_zones.edit', 'routing_constraint_zones.destroy', 'referentials.create', 'referentials.edit', 'referentials.destroy'] + mattr_reader :edit_offer_permissions + + def self.all_permissions + edit_offer_permissions + end def cas_extra_attributes=(extra_attributes) extra = extra_attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} diff --git a/db/seeds.rb b/db/seeds.rb index e3fa4c69d..6e7f59c54 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -7,17 +7,19 @@ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name => 'Emanuel', :city => cities.first) -stif = Organisation.find_or_create_by!(name: "STIF") do |org| - org.code = 'STIF' +Organisation.where(code: nil).destroy_all + +stif = Organisation.find_or_create_by!(code: "STIF") do |org| + org.name = 'STIF' end stif.users.find_or_create_by!(username: "admin") do |user| user.email = 'stif-boiv@af83.com' user.password = "secret" user.name = "STIF Administrateur" + user.permissions = User.all_permissions end - operator = Organisation.find_or_create_by!(code: 'transporteur-a') do |organisation| organisation.name = "Transporteur A" end @@ -26,6 +28,7 @@ operator.users.find_or_create_by!(username: "transporteur") do |user| user.email = 'stif-boiv+transporteur@af83.com' user.password = "secret" user.name = "Martin Lejeune" + user.permissions = User.all_permissions end stop_area_referential = StopAreaReferential.find_or_create_by!(name: "Reflex") do |referential| @@ -42,15 +45,16 @@ line_referential = LineReferential.find_or_create_by!(name: "CodifLigne") do |re referential.add_member operator end -LineReferentialSync.find_or_create_by!(line_referential: line_referential) -StopAreaReferentialSync.find_or_create_by!(stop_area_referential: stop_area_referential) - 10.times do |n| - line_referential.lines.find_or_create_by name: "Test #{n}" do |l| + line_referential.lines.find_or_create_by! name: "Test #{n}" do |l| l.objectid = "Chouette:Dummy:Line:00" + n.to_s end end +# Include all Lines in organisation functional_scope +stif.update sso_attributes: { functional_scope: line_referential.lines.pluck(:objectid) } +operator.update sso_attributes: { functional_scope: line_referential.lines.limit(3).pluck(:objectid) } + workbench = Workbench.find_by(name: "Gestion de l'offre") workbench.update_attributes(line_referential: line_referential, stop_area_referential: stop_area_referential) -- cgit v1.2.3 From 1dd229532976f628270900fa76183fad4be67f19 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 3 May 2017 19:21:18 +0200 Subject: Improve referential:create task. Refs #3291 * use a single transaction * use by default workbench 1 * use a random line found in workbench lines --- lib/tasks/referential.rake | 101 +++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/lib/tasks/referential.rake b/lib/tasks/referential.rake index c89cd3f7a..76f1b4c00 100644 --- a/lib/tasks/referential.rake +++ b/lib/tasks/referential.rake @@ -3,60 +3,61 @@ namespace :referential do desc 'Create a referential and accompanying data' - task :create, [:workbench_id, :line_id, :start_date, :end_date] => [:environment] do |t, args| - args.with_defaults(start_date: Date.today.strftime, end_date: (Date.today + 30).strftime) - - workbench = Workbench.find_by!(id: args[:workbench_id]) - line = workbench.line_referential.lines.find_by!(id: args[:line_id]) - name = "Referential #{Faker::Name.unique.name}" - - referential = workbench.referentials.create!(name: name, slug: name.downcase.parameterize.underscore, organisation: workbench.organisation, - prefix: Faker::Lorem.unique.characters(10)) - ReferentialMetadata.create!(referential: referential, line_ids: [args[:line_id]], periodes: [Date.parse(args[:start_date])..Date.parse(args[:end_date])]) - referential.switch - - - print "✓ Created Referential ".green, name, "(#{referential.id})".blue, " switched to schema: ", referential.slug.yellow, "\n" - puts " For inspection of data in the console, do a: `Referential.last.switch'".blueish - - stop_areas = workbench.stop_area_referential.stop_areas.last(10) - - 4.times do |i| - route_attrs = { line_id: args[:line_id].to_i, name: "Route #{Faker::Name.unique.name}" } - if i.even? - route_attrs[:wayback] = :straight_forward - route = Chouette::Route.create!(route_attrs) - route.stop_areas = stop_areas - else - route_attrs[:wayback] = :backward - route_attrs[:opposite_route] = Chouette::Route.last if i == 3 - route = Chouette::Route.create!(route_attrs) - route.stop_areas = stop_areas.reverse - end - route.save! - print " ✓ Created Route ".green, route.name, "(#{route.id}), ".blue, "Line (#{line.id}) has #{line.routes.count} routes\n" - - journey_pattern = Chouette::JourneyPattern.create!(route: route, name: "Journey Pattern #{Faker::Name.unique.name}") - journey_pattern.stop_points = stop_areas.inject([]) { |stop_points, stop_area| stop_points += stop_area.stop_points } - - time_tables = [] - 2.times do |j| - name = "Test #{Faker::Name.unique.name}" - time_table = Chouette::TimeTable.create!(comment: name, start_date: Date.parse(args[:start_date]) + j.days, - end_date: Date.parse(args[:end_date]) - j.days) - time_tables << time_table - end + task :create, [:workbench_id, :start_date, :end_date] => [:environment] do |t, args| + args.with_defaults(workbench_id: 1, start_date: Date.today.strftime, end_date: (Date.today + 30).strftime) + + Referential.transaction do + workbench = Workbench.find_by!(id: args[:workbench_id]) + line = workbench.line_referential.lines.order("random()").first + name = "Referential #{Faker::Name.unique.name}" + + referential = workbench.referentials.create!(name: name, slug: name.downcase.parameterize.underscore, organisation: workbench.organisation, + prefix: Faker::Lorem.unique.characters(10)) + ReferentialMetadata.create!(referential: referential, line_ids: [line.id], periodes: [Date.parse(args[:start_date])..Date.parse(args[:end_date])]) + referential.switch + + print "✓ Created Referential ".green, name, "(#{referential.id})".blue, "\n" + puts " For inspection of data in the console, do a: `Referential.last.switch'".blueish + + stop_areas = workbench.stop_area_referential.stop_areas.last(10) + + 4.times do |i| + route_attrs = { line: line, name: "Route #{Faker::Name.unique.name}" } + if i.even? + route_attrs[:wayback] = :straight_forward + route = Chouette::Route.create!(route_attrs) + route.stop_areas = stop_areas + else + route_attrs[:wayback] = :backward + route_attrs[:opposite_route] = Chouette::Route.last if i == 3 + route = Chouette::Route.create!(route_attrs) + route.stop_areas = stop_areas.reverse + end + route.save! + print " ✓ Created Route ".green, route.name, "(#{route.id}), ".blue, "Line (#{line.id}) has #{line.routes.count} routes\n" + + journey_pattern = Chouette::JourneyPattern.create!(route: route, name: "Journey Pattern #{Faker::Name.unique.name}") + journey_pattern.stop_points = stop_areas.inject([]) { |stop_points, stop_area| stop_points += stop_area.stop_points } + + time_tables = [] + 2.times do |j| + name = "Test #{Faker::Name.unique.name}" + time_table = Chouette::TimeTable.create!(comment: name, start_date: Date.parse(args[:start_date]) + j.days, + end_date: Date.parse(args[:end_date]) - j.days) + time_tables << time_table + end - 25.times do |j| - vehicle_journey = Chouette::VehicleJourney.create!(journey_pattern: journey_pattern, route: route, number: Faker::Number.unique.number(4), time_tables: time_tables) - time = Time.current.at_noon + j.minutes - journey_pattern.stop_points.each_with_index do |stop_point, k| - vehicle_journey.vehicle_journey_at_stops.create!(stop_point: stop_point, arrival_time: time + k.minutes, departure_time: time + k.minutes + 30.seconds) + 25.times do |j| + vehicle_journey = Chouette::VehicleJourney.create!(journey_pattern: journey_pattern, route: route, number: Faker::Number.unique.number(4), time_tables: time_tables) + time = Time.current.at_noon + j.minutes + journey_pattern.stop_points.each_with_index do |stop_point, k| + vehicle_journey.vehicle_journey_at_stops.create!(stop_point: stop_point, arrival_time: time + k.minutes, departure_time: time + k.minutes + 30.seconds) + end end + end + referential.update(ready: true) end - - referential.update(ready: true) end end -- cgit v1.2.3 From c697909ed7acedf020c695440cdf44b0332dbb35 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 3 May 2017 19:24:48 +0200 Subject: Complete INSTALL.md. Refs #3291 --- INSTALL.md | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 7bfcb7074..4e052a0db 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -27,7 +27,7 @@ Go into your local repro and install the gems bundle config build.libv8 --with-system-v8 bundle -or +or gem install libv8 -v '' -- --with-system-v8 bundle @@ -65,16 +65,33 @@ When promted for the password enter the highly secure string `chouette`. bundle exec rake npm:install -### SSO Configuration +### Authentication -Get yourself an invitation to [Stif Portail](http://stif-portail-dev.af83.priv/) and be sure to update your information -on your [profile page](http://stif-portail-dev.af83.priv/users/edit) - - -# Troubleshouting +See `config.chouette_authentication_settings`. -If PG complains about illegal type `hstore` in your tests that is probably because the shared extension is not installed, here is waht to do: - - bundle exec rake db:test:purge +Use the database authentication or get an invitation to [STIF Portail](http://stif-portail-dev.af83.priv/). + +### Run seed + +Run : + + bundle exec rake db:seed + +Two users are created : stif-boiv@af83.com/secret and stif-boiv+transporteur@af83.com/secret + +If you have access to STIF CodifLigne and Reflex : + + bundle exec rake codifligne:sync + bundle exec rake reflex:sync + +To create Referential with some data (Route, JourneyPattern, VehicleJourney, etc) : + + bundle exec rake referential:create + +# Troubleshooting + +If PG complains about illegal type `hstore` in your tests that is probably because the shared extension is not installed, here is what to do: + + bundle exec rake db:test:purge Thanks to `lib/tasks/extensions.rake`. -- cgit v1.2.3 From a75b51bc9b4112d851a38f0e569565ce2c4602c6 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 4 May 2017 14:36:25 +0200 Subject: easy change locale for testing and developping translations --- app/controllers/application_controller.rb | 5 ++++- app/views/line_referentials/show.html.slim | 9 ++++++--- config/application.rb | 2 +- config/locales/line_referentials.en.yml | 3 +++ config/locales/line_referentials.fr.yml | 3 +++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f2c9b4c6f..42b7c2a25 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,7 +12,10 @@ class ApplicationController < ActionController::Base helper LanguageEngine::Engine.helpers def set_locale - I18n.locale = session[:language] || I18n.default_locale + # I18n.locale = session[:language] || I18n.default_locale + # For testing different locales w/o restarting the server + I18n.locale = (params['lang'] || session[:language] || I18n.default_locale).to_sym + logger.info "locale set to #{I18n.locale.inspect}" end def pundit_user diff --git a/app/views/line_referentials/show.html.slim b/app/views/line_referentials/show.html.slim index 5c0df1a71..7d4067202 100644 --- a/app/views/line_referentials/show.html.slim +++ b/app/views/line_referentials/show.html.slim @@ -27,9 +27,12 @@ table.table thead tr - th Synchronisé - th Statut - th Message + / th Synchronisé + th = t('.synchronized') + / th Statut + th = t('.status') + / th Message + th = t('.message') tbody - @line_referential.line_referential_syncs.each_with_index do |sync, i| diff --git a/config/application.rb b/config/application.rb index 8606a3156..6c8de781d 100644 --- a/config/application.rb +++ b/config/application.rb @@ -25,7 +25,7 @@ module ChouetteIhm # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - config.i18n.default_locale = :fr + config.i18n.default_locale = ENV.fetch('RAILS_LOCALE', 'fr').to_sym # Configure Browserify to use babelify to compile ES6 config.browserify_rails.commandline_options = "-t [ babelify --presets [ react es2015 ] ]" diff --git a/config/locales/line_referentials.en.yml b/config/locales/line_referentials.en.yml index 7d84a24f8..78083912d 100644 --- a/config/locales/line_referentials.en.yml +++ b/config/locales/line_referentials.en.yml @@ -8,6 +8,9 @@ en: title: "Edit %{line_referential} referential" show: title: "iLICO synchronization" + synchronized: Synchronized + status: Status + message: Message activerecord: models: line_referential: diff --git a/config/locales/line_referentials.fr.yml b/config/locales/line_referentials.fr.yml index fe8496d99..c8dfbd640 100644 --- a/config/locales/line_referentials.fr.yml +++ b/config/locales/line_referentials.fr.yml @@ -8,6 +8,9 @@ fr: title: "Editer le référentiel %{line_referential}" show: title: 'Synchronisation iLICO' + synchronized: Synchronisé + status: Statut + message: Message activerecord: models: line_referential: -- cgit v1.2.3 From 990cc5b907076793ce52c956a57e294b9730c379 Mon Sep 17 00:00:00 2001 From: jpl Date: Thu, 4 May 2017 14:52:27 +0200 Subject: Refs #3271: adding periods correct dates display on tt#edit --- .../es6_browserified/time_tables/actions/index.js | 4 ++++ .../time_tables/components/PeriodManager.js | 22 +++++++++++++++++++++- .../time_tables/components/PeriodsInDay.js | 3 ++- app/assets/stylesheets/modules/_timetables.sass | 18 ++++++++++++++++-- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js index cef9bc75d..69ee0661b 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js @@ -140,6 +140,10 @@ const actions = { return (D + ' ' + M + ' ' + Y) }, + getLocaleDate(strDate) { + let date = new Date(strDate) + return date.toLocaleDateString() + }, updateSynthesis: (state, daytypes) => { let periods = state.time_table_periods diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodManager.js b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodManager.js index de3f31ee0..cf4cbfb32 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodManager.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodManager.js @@ -8,14 +8,33 @@ class PeriodManager extends Component { super(props) } + toEndPeriod(curr, end) { + let diff + + let startCurrM = curr.split('-')[1] + let endPeriodM = end.split('-')[1] + + let lastDayInM = new Date(curr.split('-')[2], startCurrM + 1, 0) + lastDayInM = lastDayInM.toJSON().substr(0, 10).split('-')[2] + + if(startCurrM === endPeriodM) { + diff = (end.split('-')[2] - curr.split('-')[2]) + } else { + diff = (lastDayInM - curr.split('-')[2]) + } + + return diff + } + render() { return (

- {actions.getHumanDate(this.props.value.period_start, 3).substr(0, 7) + ' > ' + actions.getHumanDate(this.props.value.period_end, 3)} + {actions.getLocaleDate(this.props.value.period_start) + ' > ' + actions.getLocaleDate(this.props.value.period_end)}

@@ -58,6 +77,7 @@ class PeriodManager extends Component { PeriodManager.propTypes = { value: PropTypes.object.isRequired, + currentDate: PropTypes.object.isRequired, onDeletePeriod: PropTypes.func.isRequired, onOpenEditPeriodForm: PropTypes.func.isRequired } diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js index 93a8fe433..ca44d3a07 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/PeriodsInDay.js @@ -50,9 +50,10 @@ class PeriodsInDay extends Component { key={i} index={i} value={p} + metas={this.props.metas} + currentDate={this.props.currentDate} onDeletePeriod={this.props.onDeletePeriod} onOpenEditPeriodForm={this.props.onOpenEditPeriodForm} - metas={this.props.metas} /> ) } else { diff --git a/app/assets/stylesheets/modules/_timetables.sass b/app/assets/stylesheets/modules/_timetables.sass index 03dba3e23..84f1af043 100644 --- a/app/assets/stylesheets/modules/_timetables.sass +++ b/app/assets/stylesheets/modules/_timetables.sass @@ -125,21 +125,35 @@ display: block height: auto word-wrap: normal - white-space: nowrap + white-space: normal position: absolute - left: 8px + left: 0 top: 50% transform: translateY(-50%) z-index: 5 + padding: 0 8px + + @for $i from 0 through 31 + &[data-toendperiod='#{$i}'] + width: 40px * ($i + 1) > * display: inline-block vertical-align: middle margin: 0 + max-width: calc(100% - 30px) &.dropdown margin-left: 5px + &[data-toendperiod='0'], &[data-toendperiod='1'], &[data-toendperiod='2'] + max-width: none + > * + display: none + + &.dropdown + display: inline-block + .btn.dropdown-toggle color: $blue background-color: rgba(#fff, 0) -- 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 --- .../es6_browserified/time_tables/actions/index.js | 2 +- .../time_tables/components/Navigate.js | 2 +- spec/javascripts/time_table/actions_spec.js | 158 ++++++++++++++++++++- 3 files changed, 159 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js index 69ee0661b..48d3a585f 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js @@ -45,7 +45,7 @@ const actions = { pagination, nextPage : true }), - changePage : (dispatch, pagination, val) => ({ + changePage : (dispatch, val) => ({ type: 'CHANGE_PAGE', dispatch, page: val diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/Navigate.js b/app/assets/javascripts/es6_browserified/time_tables/components/Navigate.js index c43cd025a..74ca36ea6 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/Navigate.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/Navigate.js @@ -39,7 +39,7 @@ let Navigate = ({ dispatch, metas, timetable, pagination, status, filters}) => { value={month} onClick={e => { e.preventDefault() - dispatch(actions.checkConfirmModal(e, actions.changePage(dispatch, pagination, e.currentTarget.value), pagination.stateChanged, dispatch)) + dispatch(actions.checkConfirmModal(e, actions.changePage(dispatch, e.currentTarget.value), pagination.stateChanged, dispatch)) }} > {actions.monthName(month) + ' ' + new Date(month).getFullYear()} 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 b54ab0a2321bbd0c5c6162a0d313800bb586a98d Mon Sep 17 00:00:00 2001 From: Xinhui Date: Thu, 4 May 2017 15:22:57 +0200 Subject: Fix can't edit or create calendar due to 3 parts date_select Refs #3298 --- app/controllers/calendars_controller.rb | 7 +++---- app/models/calendar.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index d18e165d2..5370d9cbb 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -45,14 +45,13 @@ class CalendarsController < BreadcrumbController end def ransack_contains_date - # 3 parts to date object, in order to use in ransackable_scopes + date =[] if params[:q] && !params[:q]['contains_date(1i)'].empty? - date =[] ['contains_date(1i)', 'contains_date(2i)', 'contains_date(3i)'].each do |key| - date << params[:q][key] + date << params[:q][key].to_i params[:q].delete(key) end - params[:q]['contains_date'] = Date.parse(date.join('-')) + params[:q]['contains_date'] = Date.new(*date) end end diff --git a/app/models/calendar.rb b/app/models/calendar.rb index cd945a67f..91a17e853 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -118,9 +118,18 @@ class Calendar < ActiveRecord::Base end end + def flatten_date_array attributes, key + date_int = %w(1 2 3).map {|e| attributes["#{key}(#{e}i)"].to_i } + Date.new(*date_int) + end + def periods_attributes=(attributes = {}) @periods = [] attributes.each do |index, period_attribute| + # Convert date_select to date + ['begin', 'end'].map do |attr| + period_attribute[attr] = flatten_date_array(period_attribute, attr) + end period = Period.new(period_attribute.merge(id: index)) @periods << period unless period.marked_for_destruction? end @@ -223,6 +232,7 @@ class Calendar < ActiveRecord::Base def date_values_attributes=(attributes = {}) @date_values = [] attributes.each do |index, date_value_attribute| + date_value_attribute['value'] = flatten_date_array(date_value_attribute, 'value') date_value = DateValue.new(date_value_attribute.merge(id: index)) @date_values << date_value unless date_value.marked_for_destruction? end -- cgit v1.2.3 From fb29c762d084e6f707adcf77dce88745fda09cff Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 4 May 2017 16:20:54 +0200 Subject: schema update --- db/schema.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 17df3c34f..a45181687 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -283,7 +283,7 @@ ActiveRecord::Schema.define(version: 20170502130327) do t.datetime "started_at" t.datetime "ended_at" t.string "token_download" - t.string "type", limit: 255 + t.string "type" end add_index "imports", ["referential_id"], name: "index_imports_on_referential_id", using: :btree @@ -601,7 +601,7 @@ ActiveRecord::Schema.define(version: 20170502130327) do create_table "stop_areas", id: :bigserial, force: :cascade do |t| t.integer "parent_id", limit: 8 - t.string "objectid", null: false + t.string "objectid", null: false t.integer "object_version", limit: 8 t.string "creator_id" t.string "name" @@ -610,8 +610,8 @@ ActiveRecord::Schema.define(version: 20170502130327) do t.string "registration_number" t.string "nearest_topic_name" t.integer "fare_code" - t.decimal "longitude", precision: 19, scale: 16 - t.decimal "latitude", precision: 19, scale: 16 + t.decimal "longitude", precision: 19, scale: 16 + t.decimal "latitude", precision: 19, scale: 16 t.string "long_lat_type" t.string "country_code" t.string "street_name" @@ -629,7 +629,7 @@ ActiveRecord::Schema.define(version: 20170502130327) do t.datetime "deleted_at" t.datetime "created_at" t.datetime "updated_at" - t.string "stif_type", limit: 255 + t.string "stif_type" end add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree @@ -696,18 +696,18 @@ ActiveRecord::Schema.define(version: 20170502130327) do add_index "time_table_periods", ["time_table_id"], name: "index_time_table_periods_on_time_table_id", using: :btree create_table "time_tables", id: :bigserial, force: :cascade do |t| - t.string "objectid", null: false - t.integer "object_version", limit: 8, default: 1 + t.string "objectid", null: false + t.integer "object_version", limit: 8, default: 1 t.string "creator_id" t.string "version" t.string "comment" - t.integer "int_day_types", default: 0 + t.integer "int_day_types", default: 0 t.date "start_date" t.date "end_date" t.integer "calendar_id", limit: 8 t.datetime "created_at" t.datetime "updated_at" - t.string "color", limit: 255 + t.string "color" t.integer "created_from_id" end -- cgit v1.2.3 From 4c12a6632907d5d24b654791db994bfb830c7e37 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 4 May 2017 15:14:44 +0200 Subject: VehicleJourneysCtl#collection: Sort journeys by departure time ascending Correctly sort journeys. They used to be sorted correctly this way, but after d7c6d5ce602219b9bfa47686542dd575f1fe2e50 or c3d207301d17538b65d2a1239ce0acf642942ce9, the sorting got messed up because of the join. Here we leverage `journey_patterns.departure_stop_point_id` in order to get the first stop and sort by that stop's departure time. Query solution thanks to Luc and Alban, who remembered that a reference to the first stop point is stored so we can leverage that for complex things like this. Refs #3268 --- app/controllers/vehicle_journeys_controller.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index c084b592a..f692f3628 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -77,14 +77,22 @@ class VehicleJourneysController < ChouetteController protected def collection - scope = route.vehicle_journeys.joins(:journey_pattern).joins('LEFT JOIN "vehicle_journey_at_stops" ON "vehicle_journey_at_stops"."vehicle_journey_id" = "vehicle_journeys"."id"') + scope = route.vehicle_journeys + .joins(:journey_pattern) + .joins(' + LEFT JOIN "vehicle_journey_at_stops" + ON "vehicle_journey_at_stops"."vehicle_journey_id" = "vehicle_journeys"."id" + AND "vehicle_journey_at_stops"."stop_point_id" = + "journey_patterns"."departure_stop_point_id" + ') + .order("vehicle_journey_at_stops.departure_time") @q = scope.search filtered_ransack_params grouping = ransack_periode_filter @q.build_grouping(grouping) if grouping @ppage = 20 - @vehicle_journeys = @q.result(distinct: true).paginate(:page => params[:page], :per_page => @ppage) + @vehicle_journeys = @q.result.paginate(:page => params[:page], :per_page => @ppage) @footnotes = route.line.footnotes.to_json @matrix = resource_class.matrix(@vehicle_journeys) @vehicle_journeys -- 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 --- app/models/chouette/vehicle_journey.rb | 13 +++++++++ spec/models/chouette/vehicle_journey_spec.rb | 41 ++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index 4d7d596d8..297e462f0 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -209,5 +209,18 @@ module Chouette end end + def self.with_stops + self + .joins(:journey_pattern) + .joins(' + LEFT JOIN "vehicle_journey_at_stops" + ON "vehicle_journey_at_stops"."vehicle_journey_id" = + "vehicle_journeys"."id" + AND "vehicle_journey_at_stops"."stop_point_id" = + "journey_patterns"."departure_stop_point_id" + ') + .order("vehicle_journey_at_stops.departure_time") + end + end end 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(+) 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(-) 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(-) 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 76abc55ed7aeb07cf65ed2a027ad2cdc694c5751 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 4 May 2017 17:18:05 +0200 Subject: VehicleJourneysCtl#collection: Use VehicleJourney.with_stops Use the class method to get the vehicle journeys in the proper order of departure time ascending. The `.with_stops` method replicates this same SQL sequence of joins and order. Refs #3268 --- app/controllers/vehicle_journeys_controller.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index f692f3628..316652ca2 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -77,15 +77,7 @@ class VehicleJourneysController < ChouetteController protected def collection - scope = route.vehicle_journeys - .joins(:journey_pattern) - .joins(' - LEFT JOIN "vehicle_journey_at_stops" - ON "vehicle_journey_at_stops"."vehicle_journey_id" = "vehicle_journeys"."id" - AND "vehicle_journey_at_stops"."stop_point_id" = - "journey_patterns"."departure_stop_point_id" - ') - .order("vehicle_journey_at_stops.departure_time") + scope = route.vehicle_journeys.with_stops @q = scope.search filtered_ransack_params grouping = ransack_periode_filter -- cgit v1.2.3 From 7f2c15f363b1c16590ec2859a9b672cf52ef1ca3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 4 May 2017 18:01:09 +0200 Subject: _vj_collection.sass: Remove z-index from .has-error:before When an error occurred when modifying a time in a journey pattern, it would be surrounded by a red box. The trouble is, you wouldn't be able to click inside that box to focus the inputs and change times once the box was added. The problem happens on this page: http://stif-boiv.dev:3000/referentials/4/lines/158/routes/1/vehicle_journeys This was due to the z-index placing the box on a layer closer to the front than the inputs, eating click events and preventing them from being clicked on. Originally I thought about using `pointer-events: none;` but according to http://caniuse.com/#search=pointer-events it isn't supported in IE < 11. Eliminated the `z-index` instead which has the same effect and doesn't appear to cause any visual problems, at least on the page I mentioned. Only tested in Opera TBH. Refs #3301 --- app/assets/stylesheets/modules/_vj_collection.sass | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/stylesheets/modules/_vj_collection.sass b/app/assets/stylesheets/modules/_vj_collection.sass index 50ad1cd54..46ebda776 100644 --- a/app/assets/stylesheets/modules/_vj_collection.sass +++ b/app/assets/stylesheets/modules/_vj_collection.sass @@ -92,7 +92,6 @@ left: 0 right: 0 bottom: 0 - z-index: 5 border: 2px solid $red > .th -- 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 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 08f9856e606ac6ab092be50bccf6da0975c25e02 Mon Sep 17 00:00:00 2001 From: Robert Dober Date: Fri, 5 May 2017 07:08:56 +0200 Subject: Update INSTALL.md --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 4e052a0db..31de0bd4c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -9,7 +9,7 @@ and install that version. Example with [rvm](https://rvm.io/): - rvm install 2.3.0 + rvm install 2.3.1 Add the bundler gem -- cgit v1.2.3 From 52d7caa0c824c319b8427e6e66778b407cc7bfc4 Mon Sep 17 00:00:00 2001 From: Robert Dober Date: Fri, 5 May 2017 07:12:13 +0200 Subject: Update INSTALL.md --- INSTALL.md | 1 + 1 file changed, 1 insertion(+) diff --git a/INSTALL.md b/INSTALL.md index 31de0bd4c..d471ec057 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -28,6 +28,7 @@ Go into your local repro and install the gems bundle or + gem install libv8 -v '' -- --with-system-v8 bundle -- cgit v1.2.3 From de12174819c0cb9383e99f4e32cef6f815ab09f7 Mon Sep 17 00:00:00 2001 From: Robert Dober Date: Fri, 5 May 2017 07:20:39 +0200 Subject: Update INSTALL.md --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index d471ec057..5fdd30e43 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -91,7 +91,7 @@ To create Referential with some data (Route, JourneyPattern, VehicleJourney, etc # Troubleshooting -If PG complains about illegal type `hstore` in your tests that is probably because the shared extension is not installed, here is what to do: +If Postgres complains about illegal type `hstore` in your tests that is probably because the shared extension is not installed, here is what to do: bundle exec rake db:test:purge -- cgit v1.2.3 From 2df84619b9b5950a3bbbb5550d3cc03ba1489df2 Mon Sep 17 00:00:00 2001 From: Robert Dober Date: Fri, 5 May 2017 07:23:02 +0200 Subject: Update INSTALL.md --- INSTALL.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 5fdd30e43..f5ec6418b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -64,7 +64,18 @@ When promted for the password enter the highly secure string `chouette`. #### Install node.js packages - bundle exec rake npm:install + bundle exec rake npm:installndle + +#### Check installation + +* Run tests + + bundle exec rake spec + bundle exec rake teaspoon + +* Start local server + + bundle exec rails server ### Authentication -- 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(-) 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 1fe77ca170e8dc017bf3ee16fa6392284c710407 Mon Sep 17 00:00:00 2001 From: jpl Date: Fri, 5 May 2017 15:28:11 +0200 Subject: Refs #3287: adding time to date of sync, to sync pages --- app/views/line_referentials/show.html.slim | 8 +++----- app/views/stop_area_referentials/show.html.slim | 5 +++-- config/locales/en.yml | 2 ++ config/locales/fr.yml | 2 ++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/views/line_referentials/show.html.slim b/app/views/line_referentials/show.html.slim index 7d4067202..95c2c02b0 100644 --- a/app/views/line_referentials/show.html.slim +++ b/app/views/line_referentials/show.html.slim @@ -27,11 +27,8 @@ table.table thead tr - / th Synchronisé th = t('.synchronized') - / th Statut th = t('.status') - / th Message th = t('.message') tbody @@ -42,8 +39,9 @@ - sync.line_referential_sync_messages.last.tap do |log| - if log.criticity = log.criticity tr - td = l(log.created_at, format: :short) - td + td style='width: 150px' + = l(log.created_at, format: :short_with_time) + td.text-center .fa.fa-circle class="text-#{criticity_class(log.criticity)}" td - data = log.message_attributs.symbolize_keys! diff --git a/app/views/stop_area_referentials/show.html.slim b/app/views/stop_area_referentials/show.html.slim index 24428eea4..56ecbf6da 100644 --- a/app/views/stop_area_referentials/show.html.slim +++ b/app/views/stop_area_referentials/show.html.slim @@ -32,8 +32,9 @@ - sync.stop_area_referential_sync_messages.last.tap do |log| - if log.criticity = log.criticity tr - td = l(log.created_at, format: :short) - td + td style='width:150px' + = l(log.created_at, format: :short_with_time) + td.text-center .fa.fa-circle class="text-#{criticity_class(log.criticity)}" td - data = log.message_attributs.symbolize_keys! diff --git a/config/locales/en.yml b/config/locales/en.yml index 5ed0b9ec5..3f6a68f8d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -8,10 +8,12 @@ en: hour: "%Hh%M" minute: "%M min" short: "%Y/%m/%d" + short_with_time: "%Y/%m/%d at %Hh%M" date: formats: short: "%Y/%m/%d" + short_with_time: "%Y/%m/%d at %Hh%M" last_update: 'Last update on
%{time}' last_sync: 'Last sync on %{time}' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index db8a3608d..49d1c5bb7 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -8,10 +8,12 @@ fr: hour: "%Hh%M" minute: "%M min" short: "%d/%m/%Y" + short_with_time: "%d/%m/%Y à %Hh%M" date: formats: short: "%d/%m/%Y" + short_with_time: "%d/%m/%Y à %Hh%M" last_update: 'Dernière mise à jour
le %{time}' last_sync: 'Dernière mise à jour le %{time}' -- 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 --- .../javascripts/es6_browserified/time_tables/actions/index.js | 6 ++---- .../es6_browserified/time_tables/components/ExceptionsInDay.js | 4 ++-- .../es6_browserified/time_tables/containers/Timetable.js | 8 ++++---- spec/javascripts/time_table/actions_spec.js | 6 ++---- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js index 48d3a585f..3f15b7f01 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js @@ -104,16 +104,14 @@ const actions = { timeTablePeriods, metas }), - includeDateInPeriod: (index, day, dayTypes) => ({ + includeDateInPeriod: (index, dayTypes) => ({ type: 'INCLUDE_DATE_IN_PERIOD', index, - day, dayTypes }), - excludeDateFromPeriod: (index, day, dayTypes) => ({ + excludeDateFromPeriod: (index, dayTypes) => ({ type: 'EXCLUDE_DATE_FROM_PERIOD', index, - day, dayTypes }), openConfirmModal : (callback) => ({ diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js b/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js index 13615a6ef..e90099283 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/ExceptionsInDay.js @@ -21,7 +21,7 @@ class ExceptionsInDay extends Component { data-actiontype='remove' onClick={(e) => { $(e.currentTarget).toggleClass('active') - this.props.onExcludeDateFromPeriod(this.props.index, this.props.value.current_month[this.props.index], this.props.metas.day_types) + this.props.onExcludeDateFromPeriod(this.props.index, this.props.metas.day_types) }} > @@ -37,7 +37,7 @@ class ExceptionsInDay extends Component { data-actiontype='add' onClick={(e) => { $(e.currentTarget).toggleClass('active') - this.props.onIncludeDateInPeriod(this.props.index, this.props.value.current_month[this.props.index], this.props.metas.day_types) + this.props.onIncludeDateInPeriod(this.props.index, this.props.metas.day_types) }} > diff --git a/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js b/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js index 2a17d3dea..c6b5fcc6b 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js +++ b/app/assets/javascripts/es6_browserified/time_tables/containers/Timetable.js @@ -15,11 +15,11 @@ const mapDispatchToProps = (dispatch) => { onDeletePeriod: (index, dayTypes) =>{ dispatch(actions.deletePeriod(index, dayTypes)) }, - onExcludeDateFromPeriod: (index, day, dayTypes) => { - dispatch(actions.excludeDateFromPeriod(index, day, dayTypes)) + onExcludeDateFromPeriod: (index, dayTypes) => { + dispatch(actions.excludeDateFromPeriod(index, dayTypes)) }, - onIncludeDateInPeriod: (index, day, dayTypes) => { - dispatch(actions.includeDateInPeriod(index, day, dayTypes)) + onIncludeDateInPeriod: (index, dayTypes) => { + dispatch(actions.includeDateInPeriod(index, dayTypes)) }, onOpenEditPeriodForm: (period, index) => { dispatch(actions.openEditPeriodForm(period, index)) 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 e5a1a2cb94fc2f2c4bab56a594df7db254a527ce Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 May 2017 15:44:29 +0200 Subject: Spourious characters (from vim misshandling) removed --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index b45c0bf7b..a9ec7969d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -64,7 +64,7 @@ When promted for the password enter the highly secure string `chouette`. #### Install node.js packages - bundle exec rake npm:installndle + bundle exec rake npm:install #### Check installation -- cgit v1.2.3 From 2851898700264605b1ede654e09e6e7c85003f28 Mon Sep 17 00:00:00 2001 From: jpl Date: Fri, 5 May 2017 16:36:01 +0200 Subject: Refs #3159: updating styles on stop_areas lists --- app/assets/stylesheets/modules/_jp_collection.sass | 16 ++++++++++++++++ .../stylesheets/modules/_routes_stopoints.sass | 18 +++++++++++++++++- app/assets/stylesheets/modules/_vj_collection.sass | 21 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/modules/_jp_collection.sass b/app/assets/stylesheets/modules/_jp_collection.sass index d1f864e5c..c109fc71a 100644 --- a/app/assets/stylesheets/modules/_jp_collection.sass +++ b/app/assets/stylesheets/modules/_jp_collection.sass @@ -82,3 +82,19 @@ .t2e-head > .td:last-child > div > span &:after bottom: 50% + + .t2e-head > .td:nth-child(2) > div, + .t2e-head > .td:last-child > div + > span:before + content: '•' + color: $blue + text-align: center + font-size: 28px + letter-spacing: 0 + text-indent: -0.01em + line-height: 12px + width: 15px + height: 15px + left: -23px + top: 50% + margin-top: -8px diff --git a/app/assets/stylesheets/modules/_routes_stopoints.sass b/app/assets/stylesheets/modules/_routes_stopoints.sass index 735e91df7..88e662849 100644 --- a/app/assets/stylesheets/modules/_routes_stopoints.sass +++ b/app/assets/stylesheets/modules/_routes_stopoints.sass @@ -12,7 +12,7 @@ height: 100% > div:first-child position: relative - padding-left: 20px /* intial value is 10 */ + padding-left: 25px /* intial value is 10 */ overflow: hidden span @@ -70,3 +70,19 @@ .nested-head + .nested-fields > .wrapper > div:first-child span:after top: 5px + + .nested-head + .nested-fields > .wrapper > div:first-child, + .nested-fields:last-child > .wrapper:last-child > div:first-child + span:before + content: '•' + color: $blue + text-align: center + font-size: 28px + letter-spacing: 0 + text-indent: -0.01em + line-height: 12px + width: 15px + height: 15px + left: -23px + top: 50% + margin-top: -8px diff --git a/app/assets/stylesheets/modules/_vj_collection.sass b/app/assets/stylesheets/modules/_vj_collection.sass index 46ebda776..8ff983310 100644 --- a/app/assets/stylesheets/modules/_vj_collection.sass +++ b/app/assets/stylesheets/modules/_vj_collection.sass @@ -79,6 +79,27 @@ &:after bottom: -6px + .t2e-head > .td:last-child > div > span + &:after + bottom: 50% + + .table-2entries .t2e-head > .td:nth-child(2) > div, + .table-2entries .t2e-head > .td:last-child > div, + .table-2entries.no_result .t2e-head > .td:last-child > div + > span:before + content: '•' + color: $blue + text-align: center + font-size: 28px + letter-spacing: 0 + text-indent: -0.01em + line-height: 12px + width: 15px + height: 15px + left: -23px + top: 50% + margin-top: -8px + // Errors .table-2entries .t2e-item-list .t2e-item -- 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(-) 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 --- app/models/chouette/route.rb | 2 +- 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 --------------------- 6 files changed, 228 insertions(+), 174 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 diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 429189ff5..9f6344055 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -105,7 +105,7 @@ class Chouette::Route < Chouette::TridentActiveRecord end def time_tables - self.vehicle_journeys.joins(:time_tables).map(&:"time_tables").flatten.uniq + vehicle_journeys.joins(:time_tables).map(&:"time_tables").flatten.uniq end def sorted_vehicle_journeys(journey_category_model) 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) --- app/models/route_observer.rb | 2 +- spec/models/chouette/route/route_delete_spec.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/route_observer.rb b/app/models/route_observer.rb index 71578c6da..e2217a75e 100644 --- a/app/models/route_observer.rb +++ b/app/models/route_observer.rb @@ -16,6 +16,6 @@ class RouteObserver < ActiveRecord::Observer def after_destroy(route) Rails.logger.debug "after_destroy(#{route.inspect})" - line.routes.where(opposite_route: route).update_all(opposite_route: nil) + route.line.routes.where(opposite_route: route).update_all(opposite_route_id: nil) end end 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 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 6e925a3a2516aa11682cb178fcb903a7aa169ed0 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 May 2017 12:20:43 +0200 Subject: Refs: #3297 removed patch of inherited_resources in RoutesController --- app/controllers/routes_controller.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index a1aadf883..f914a102b 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -46,11 +46,6 @@ class RoutesController < ChouetteController end end - # overwrite inherited resources to use delete instead of destroy - # foreign keys will propagate deletion) - def destroy_resource(object) - object.delete - end def destroy destroy! do |success, failure| -- 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 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(-) 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 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 41b9b5decf022e748c6577baf9756bd785149e6f Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 May 2017 16:52:32 +0200 Subject: Refs #3297 Nullification of foreign keys in delete route moved from an `after_destroy' to a `before_destroy' hook. (Motivation: Seemed like a good idea) --- app/controllers/routes_controller.rb | 2 ++ app/models/route_observer.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index f914a102b..5a73d397c 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -46,6 +46,8 @@ class RoutesController < ChouetteController end end + # overwrite inherited resources to use delete instead of destroy + # foreign keys will propagate deletion) def destroy destroy! do |success, failure| diff --git a/app/models/route_observer.rb b/app/models/route_observer.rb index e2217a75e..1848bbc85 100644 --- a/app/models/route_observer.rb +++ b/app/models/route_observer.rb @@ -14,7 +14,7 @@ class RouteObserver < ActiveRecord::Observer end end - def after_destroy(route) + def before_destroy(route) Rails.logger.debug "after_destroy(#{route.inspect})" route.line.routes.where(opposite_route: route).update_all(opposite_route_id: nil) end -- cgit v1.2.3 From 41d215e737a3a025435a796ccc7cb45b1cc59a9f Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 6 May 2017 06:03:19 +0200 Subject: removed left over comment --- app/controllers/routes_controller.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 5a73d397c..73febc4b9 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -46,9 +46,6 @@ class RoutesController < ChouetteController end end - # overwrite inherited resources to use delete instead of destroy - # foreign keys will propagate deletion) - def destroy destroy! do |success, failure| success.html { redirect_to referential_line_path(@referential,@line) } -- cgit v1.2.3 From 95776acb5113d3a44044e74c06b1dbf9df0e1ec8 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 6 May 2017 06:03:19 +0200 Subject: minor esthetic correction --- app/controllers/routes_controller.rb | 3 --- lib/stif/codif_line_synchronization.rb | 10 +++++----- lib/stif/reflex_synchronization.rb | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 5a73d397c..73febc4b9 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -46,9 +46,6 @@ class RoutesController < ChouetteController end end - # overwrite inherited resources to use delete instead of destroy - # foreign keys will propagate deletion) - def destroy destroy! do |success, failure| success.html { redirect_to referential_line_path(@referential,@line) } diff --git a/lib/stif/codif_line_synchronization.rb b/lib/stif/codif_line_synchronization.rb index feb313f45..2bb4d8778 100644 --- a/lib/stif/codif_line_synchronization.rb +++ b/lib/stif/codif_line_synchronization.rb @@ -11,18 +11,18 @@ module Stif def processed_counts { - imported: self.imported_count, - updated: self.updated_count, - deleted: self.deleted_count + imported: imported_count, + updated: updated_count, + deleted: deleted_count } end def increment_counts prop_name, value - self.send("#{prop_name}=", self.send(prop_name) + value) + send("#{prop_name}=", self.send(prop_name) + value) end def synchronize - self.reset_counts + reset_counts start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) # Fetch Codifline data client = Codifligne::API.new diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index 6d8497bce..675486265 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -35,7 +35,7 @@ module Stif end def synchronize - self.reset_counts + reset_counts ['getOR', 'getOP'].each do |method| start = Time.now results = Reflex::API.new().process(method) -- cgit v1.2.3 From 04018a2857e5277ab1c180666169e86e64837619 Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 9 May 2017 14:54:19 +0200 Subject: Refs #3323: using I18n correctly on refs#show --- app/views/referentials/show.html.slim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index 45fffe6a1..befa851ab 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -50,8 +50,8 @@ { 'ID Codif' => Proc.new { |n| n.objectid.local_id }, :number => 'number', :name => 'name', - :deactivated => Proc.new{|n| n.deactivated? ? t('false') : t('true')}, - :transport_mode => 'transport_mode', + :deactivated => Proc.new{ |n| n.deactivated? ? t('false') : t('true') }, + :transport_mode => Proc.new{ |n| n.transport_mode ? t("enumerize.line.transport_mode.#{n.transport_mode}") : '' }, 'networks.name' => Proc.new { |n| n.try(:network).try(:name) }, 'companies.name' => Proc.new { |n| n.try(:company).try(:name) } }, [:show], -- cgit v1.2.3 From 2b9e9414d03727d671e2e9cebb45b58ca8313aaa Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 9 May 2017 15:29:59 +0200 Subject: Refs #3325: adding oid on tt#index --- app/views/time_tables/index.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim index 01b65653c..c17f96c85 100644 --- a/app/views/time_tables/index.html.slim +++ b/app/views/time_tables/index.html.slim @@ -15,7 +15,7 @@ .row .col-lg-12 = table_builder @time_tables, - { :color => Proc.new{|tt| tt.color ? content_tag(:span, '', class: 'fa fa-circle', style: "color:#{tt.color}") : '-' }, :comment => 'comment', + { 'OiD' => Proc.new { |n| n.objectid.local_id }, :color => Proc.new{|tt| tt.color ? content_tag(:span, '', class: 'fa fa-circle', style: "color:#{tt.color}") : '-' }, :comment => 'comment', "Période englobante" => Proc.new{ |tt| tt.bounding_dates.empty? ? '-' : t('bounding_dates', debut: l(tt.bounding_dates.min), end: l(tt.bounding_dates.max)) }, "Nombre de courses associées" => Proc.new{ |tt| tt.vehicle_journeys.count }, "Journées d'application" => Proc.new{ |tt| (%w(monday tuesday wednesday thursday friday saturday sunday).collect{|d| tt.send(d) ? t("calendars.days.#{d}") : '' }).reject{|a| a.empty?}.join(', ').html_safe }, -- cgit v1.2.3 From 68143d532ec98f1f7518a2b567193bcdd50ea1b7 Mon Sep 17 00:00:00 2001 From: Thomas Haddad Date: Tue, 9 May 2017 15:40:26 +0200 Subject: Refs #3327: Fix no data attr for turbolinks not used Signed-off-by: Thomas Shawarma Haddad --- .../es6_browserified/journey_patterns/components/JourneyPattern.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js b/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js index d9f6d5550..dcc044c56 100644 --- a/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js +++ b/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js @@ -14,7 +14,7 @@ class JourneyPattern extends Component{ let vjURL = routeURL + '/vehicle_journeys?jp=' + jpOid return ( - Horaires des courses + Horaires des courses ) } -- 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 --- app/models/chouette/time_table.rb | 13 ++++++++++ app/models/time_table_combination.rb | 40 +++++++++++++++--------------- spec/models/time_table_combination_spec.rb | 17 ++++++++++++- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 798fa81b4..0a99f6df6 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -33,6 +33,19 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord validates_associated :dates validates_associated :periods + def continuous_dates + chunk = {} + group = nil + + self.dates.each_with_index do |date, index| + group ||= index + group = (date.date == dates[index - 1].date + 1.day) ? group : group + 1 + chunk[group] ||= [] + chunk[group] << date + end + chunk + end + def state_update state update_attributes(self.class.state_permited_attributes(state)) self.tag_list = state['tags'].collect{|t| t['name']}.join(', ') diff --git a/app/models/time_table_combination.rb b/app/models/time_table_combination.rb index 783ef53ef..519c02f2b 100644 --- a/app/models/time_table_combination.rb +++ b/app/models/time_table_combination.rb @@ -1,33 +1,33 @@ class TimeTableCombination - include ActiveModel::Validations - include ActiveModel::Conversion + include ActiveModel::Validations + include ActiveModel::Conversion extend ActiveModel::Naming - - attr_accessor :source_id, :combined_id, :operation - - validates_presence_of :source_id, :combined_id, :operation + + attr_accessor :source_id, :combined_id, :operation + + validates_presence_of :source_id, :combined_id, :operation validates_inclusion_of :operation, :in => %w( union intersection disjunction), :allow_nil => true - + def clean self.source_id = nil self.combined_id = nil self.operation = nil self.errors.clear - end - + end + def self.operations %w( union intersection disjunction) end - def initialize(attributes = {}) - attributes.each do |name, value| - send("#{name}=", value) - end - end - - def persisted? - false - end + def initialize(attributes = {}) + attributes.each do |name, value| + send("#{name}=", value) + end + end + + def persisted? + false + end def combine source = Chouette::TimeTable.find( source_id) @@ -38,10 +38,10 @@ class TimeTableCombination source.intersect! combined elsif operation == "disjunction" source.disjoin! combined - else + else raise "unknown operation" end source end - + end 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 c5b39e62fc79fa2fb4d57904273dbc75d9cb698e Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 9 May 2017 15:53:09 +0200 Subject: Refs #3328: updating objectid with shorten version on VJ and JP --- .../javascripts/es6_browserified/journey_patterns/actions/index.js | 4 ++++ .../es6_browserified/journey_patterns/components/JourneyPattern.js | 2 +- .../javascripts/es6_browserified/vehicle_journeys/actions/index.js | 4 ++++ .../es6_browserified/vehicle_journeys/components/VehicleJourney.js | 5 +++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js b/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js index 54d62f999..0ed961f44 100644 --- a/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js +++ b/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js @@ -84,6 +84,10 @@ const actions = { resetValidation: (target) => { $(target).parent().removeClass('has-error').children('.help-block').remove() }, + humanOID : (oid) => { + var a = oid.split(':') + return a[a.length - 1] + }, validateFields : (fields) => { const test = [] diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js b/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js index dcc044c56..14ddf2b99 100644 --- a/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js +++ b/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js @@ -62,7 +62,7 @@ class JourneyPattern extends Component{ )}
-
{this.props.value.object_id ? this.props.value.object_id : '-'}
+
{this.props.value.object_id ? actions.humanOID(this.props.value.object_id) : '-'}
{this.props.value.registration_number}
{actions.getChecked(this.props.value.stop_points).length} arrêt(s)
diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js index ea03694bd..0e6f5ed12 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js @@ -248,6 +248,10 @@ const actions = { type: 'RECEIVE_TOTAL_COUNT', total }), + humanOID : (oid) => { + var a = oid.split(':') + return a[a.length - 1] + }, fetchVehicleJourneys : (dispatch, currentPage, nextPage, queryString) => { if(currentPage == undefined){ currentPage = 1 diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourney.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourney.js index d795d76e3..6f338f747 100644 --- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourney.js +++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourney.js @@ -1,6 +1,7 @@ var React = require('react') var Component = require('react').Component var PropTypes = require('react').PropTypes +var actions = require('../actions') class VehicleJourney extends Component { constructor(props) { @@ -48,8 +49,8 @@ class VehicleJourney extends Component { return (
-
{this.props.value.objectid ? this.props.value.objectid : '-'}
-
{this.props.value.journey_pattern.objectid}
+
{this.props.value.objectid ? actions.humanOID(this.props.value.objectid) : '-'}
+
{actions.humanOID(this.props.value.journey_pattern.objectid)}
{this.props.value.time_tables.map((tt, i)=>
{this.timeTableURL(tt)}
)} -- 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 --- app/models/chouette/time_table.rb | 18 +++++++++++++++--- spec/models/time_table_combination_spec.rb | 25 ++++++++++++++++++++----- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 0a99f6df6..37f609163 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -36,14 +36,26 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord def continuous_dates chunk = {} group = nil - - self.dates.each_with_index do |date, index| + self.dates.where(in_out: true).each_with_index do |date, index| group ||= index group = (date.date == dates[index - 1].date + 1.day) ? group : group + 1 chunk[group] ||= [] chunk[group] << date end - chunk + chunk.values + end + + def convert_continuous_dates_to_periods + chunks = self.continuous_dates + # Remove less than 3 continuous day chunk + chunks.delete_if {|chunk| chunk.count < 3} + + transaction do + chunks.each do |chunk| + self.periods.create!(period_start: chunk.first.date, period_end: chunk.last.date) + chunk.map(&:destroy) + end + end end def state_update state 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