From 0f59b9c1d0133393f68194a366aafc27ca23392b Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Tue, 23 Jan 2018 22:46:16 -0800 Subject: First draft for including calendars into workgroup for having appropriate scoping --- app/controllers/calendars_controller.rb | 4 +++- app/decorators/calendar_decorator.rb | 2 +- app/helpers/table_builder_helper.rb | 8 +++++++- app/helpers/table_builder_helper/custom_links.rb | 7 ++++--- app/helpers/table_builder_helper/url.rb | 5 +++-- app/models/calendar.rb | 1 + app/models/workgroup.rb | 1 + app/views/calendars/_filters.html.slim | 4 ++-- app/views/calendars/index.html.slim | 4 ++-- app/views/dashboards/_dashboard.html.slim | 6 +++--- .../layouts/navigation/_main_nav_left_content_stif.html.slim | 2 +- app/views/stif/dashboards/_dashboard.html.slim | 4 ++-- config/routes.rb | 7 ++++--- db/migrate/20180123174450_add_workgroup_id_to_calendars.rb | 6 ++++++ db/schema.rb | 6 ++++-- lib/stif/dashboard.rb | 2 +- 16 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 db/migrate/20180123174450_add_workgroup_id_to_calendars.rb diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 4a752f2b9..72d213953 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -7,7 +7,9 @@ class CalendarsController < ChouetteController def index index! do - @calendars = ModelDecorator.decorate(@calendars, with: CalendarDecorator) + @calendars = ModelDecorator.decorate(@calendars, with: CalendarDecorator, context: { + workgroup: current_workgroup + }) end end diff --git a/app/decorators/calendar_decorator.rb b/app/decorators/calendar_decorator.rb index 37e2cfe80..ce2c1a2dd 100644 --- a/app/decorators/calendar_decorator.rb +++ b/app/decorators/calendar_decorator.rb @@ -7,7 +7,7 @@ class CalendarDecorator < Draper::Decorator if h.policy(object).destroy? links << Link.new( content: h.destroy_link_content, - href: h.calendar_path(object), + href: h.workgroup_calendar_path(context[:workgroup], object), method: :delete, data: { confirm: h.t('calendars.actions.destroy_confirm') } ) diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index dede51920..9ead7180a 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -308,7 +308,7 @@ module TableBuilderHelper menu = content_tag :ul, class: 'dropdown-menu' do ( - CustomLinks.new(item, pundit_user, links, referential).links + + CustomLinks.new(item, pundit_user, links, referential, workgroup).links + item.action_links.select { |link| link.is_a?(Link) } ).map do |link| gear_menu_link(link) @@ -391,4 +391,10 @@ module TableBuilderHelper # cases, avoid a `NoMethodError`. @__referential__ ||= try(:current_referential) end + + def workgroup + # Certain controllers don't define a `#current_referential`. In these + # cases, avoid a `NoMethodError`. + @__workgroup__ ||= try(:current_workgroup) + end end diff --git a/app/helpers/table_builder_helper/custom_links.rb b/app/helpers/table_builder_helper/custom_links.rb index b1bb11f10..e09078be0 100644 --- a/app/helpers/table_builder_helper/custom_links.rb +++ b/app/helpers/table_builder_helper/custom_links.rb @@ -8,13 +8,14 @@ module TableBuilderHelper unarchive: :put } - attr_reader :actions, :object, :user_context, :referential + attr_reader :actions, :object, :user_context, :referential, :workgroup - def initialize(object, user_context, actions, referential = nil) + def initialize(object, user_context, actions, referential = nil, workgroup = nil) @object = object @user_context = user_context @actions = actions @referential = referential + @workgroup = workgroup end def links @@ -34,7 +35,7 @@ module TableBuilderHelper polymorph_url << action end - polymorph_url += URL.polymorphic_url_parts(object, referential) + polymorph_url += URL.polymorphic_url_parts(object, referential, workgroup) end def method_for_action(action) diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb index 28f1ade76..40e1f839f 100644 --- a/app/helpers/table_builder_helper/url.rb +++ b/app/helpers/table_builder_helper/url.rb @@ -1,9 +1,9 @@ module TableBuilderHelper class URL - def self.polymorphic_url_parts(item, referential) + def self.polymorphic_url_parts(item, referential, workgroup) polymorph_url = [] - unless item.is_a?(Calendar) || item.is_a?(Referential) || item.is_a?(ComplianceControlSet) + unless item.is_a?(Referential) || item.is_a?(ComplianceControlSet) if referential polymorph_url << referential polymorph_url << item.line if item.respond_to? :line @@ -20,6 +20,7 @@ module TableBuilderHelper end end else + polymorph_url << item.workgroup if item.is_a?(Calendar) polymorph_url << item end diff --git a/app/models/calendar.rb b/app/models/calendar.rb index a7fd9220c..236223892 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -8,6 +8,7 @@ class Calendar < ActiveRecord::Base has_paper_trail class_name: 'PublicVersion' belongs_to :organisation + belongs_to :workgroup validates_presence_of :name, :short_name, :organisation validates_uniqueness_of :short_name diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb index 3d761e81f..3af20ae23 100644 --- a/app/models/workgroup.rb +++ b/app/models/workgroup.rb @@ -3,6 +3,7 @@ class Workgroup < ActiveRecord::Base belongs_to :stop_area_referential has_many :workbenches + has_many :calendars has_many :organisations, through: :workbenches has_many :referentials, through: :workbenches diff --git a/app/views/calendars/_filters.html.slim b/app/views/calendars/_filters.html.slim index b5283c1e8..c1d8c47f7 100644 --- a/app/views/calendars/_filters.html.slim +++ b/app/views/calendars/_filters.html.slim @@ -1,4 +1,4 @@ -= search_form_for @q, url: calendars_path, builder: SimpleForm::FormBuilder, html: { method: :get, class: 'form form-filter' } do |f| += search_form_for @q, url: workgroup_calendars_path(current_workgroup), builder: SimpleForm::FormBuilder, html: { method: :get, class: 'form form-filter' } do |f| .ffg-row .input-group.search_bar = f.search_field :name_or_short_name_cont, class: 'form-control', placeholder: 'Indiquez un nom/nom court de calendrier...' @@ -18,5 +18,5 @@ = f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date smart_date' }, class: 'form-control', include_blank: true .actions - = link_to 'Effacer', calendars_path, class: 'btn btn-link' + = link_to 'Effacer', workgroup_calendars_path(current_workgroup), class: 'btn btn-link' = f.submit 'Filtrer', id: 'calendar_filter_btn', class: 'btn btn-default' diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index 77478a624..d0544856d 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -1,7 +1,7 @@ - breadcrumb :calendars - content_for :page_header_actions do - if policy(Calendar).create? - = link_to(t('actions.add'), new_calendar_path, class: 'btn btn-default') + = link_to(t('actions.add'), new_workgroup_calendar_path(current_workgroup), class: 'btn btn-default') .page_content .container-fluid @@ -19,7 +19,7 @@ key: :name, \ attribute: 'name', \ link_to: lambda do |calendar| \ - calendar_path(calendar) \ + workgroup_calendar_path(current_workgroup, calendar) \ end \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/dashboards/_dashboard.html.slim b/app/views/dashboards/_dashboard.html.slim index 075b94ddc..58cfcc542 100644 --- a/app/views/dashboards/_dashboard.html.slim +++ b/app/views/dashboards/_dashboard.html.slim @@ -22,13 +22,13 @@ .panel.panel-default .panel-heading h3.panel-title.with_actions - = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), calendars_path + = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), workgroup_calendars_path(current_workgroup) div - = link_to '', calendars_path, class: ' fa fa-chevron-right pull-right' + = link_to '', workgroup_calendars_path(current_workgroup), class: ' fa fa-chevron-right pull-right' - if @dashboard.current_organisation.calendars.present? .list-group - @dashboard.current_organisation.calendars.order("updated_at desc").limit(5).each do |calendar| - = link_to calendar.name, calendar_path(calendar), class: 'list-group-item' + = link_to calendar.name, workgroup_calendars_path(current_workgroup, calendar), class: 'list-group-item' - else .panel-body em.small.text-muted diff --git a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim index 3963d4cd4..1b7293d21 100644 --- a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim +++ b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim @@ -29,7 +29,7 @@ span Jeux de données = link_to workbench_imports_path(current_offer_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do span Import - = link_to calendars_path, class: 'list-group-item' do + = link_to workgroup_calendars_path(current_workgroup), class: 'list-group-item' do span Modèles de calendrier = link_to workbench_compliance_check_sets_path(current_offer_workbench), class: 'list-group-item' do span Rapport de contrôle diff --git a/app/views/stif/dashboards/_dashboard.html.slim b/app/views/stif/dashboards/_dashboard.html.slim index 64e7d4f96..c28696a94 100644 --- a/app/views/stif/dashboards/_dashboard.html.slim +++ b/app/views/stif/dashboards/_dashboard.html.slim @@ -60,12 +60,12 @@ span.badge.ml-xs = @dashboard.calendars.count if @dashboard.calendars.present? div - = link_to '', calendars_path, class: ' fa fa-chevron-right pull-right', title: t('.see') + = link_to '', workgroup_calendars_path(current_workgroup), class: ' fa fa-chevron-right pull-right', title: t('.see') - if @dashboard.calendars.present? .list-group - @dashboard.calendars.first(5).each_with_index do |calendar, i| - = link_to calendar.name, calendar_path(calendar), class: 'list-group-item' if i < 6 + = link_to calendar.name, workgroup_calendar_path(current_workgroup, calendar), class: 'list-group-item' if i < 6 - else .panel-body diff --git a/config/routes.rb b/config/routes.rb index 0f60733af..6a6a7cb07 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -111,9 +111,10 @@ ChouetteIhm::Application.routes.draw do resources :companies resources :networks end - - resources :calendars do - get :autocomplete, on: :collection, controller: 'autocomplete_calendars' + resources :workgroups do + resources :calendars do + get :autocomplete, on: :collection, controller: 'autocomplete_calendars' + end end resources :referentials, except: :index do diff --git a/db/migrate/20180123174450_add_workgroup_id_to_calendars.rb b/db/migrate/20180123174450_add_workgroup_id_to_calendars.rb new file mode 100644 index 000000000..64ad1a752 --- /dev/null +++ b/db/migrate/20180123174450_add_workgroup_id_to_calendars.rb @@ -0,0 +1,6 @@ +class AddWorkgroupIdToCalendars < ActiveRecord::Migration + def change + add_column :calendars, :workgroup_id, :integer, limit: 8 + add_index :calendars, :workgroup_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c5520110..11fb96ee3 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: 20180111200406) do +ActiveRecord::Schema.define(version: 20180123174450) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -90,10 +90,12 @@ ActiveRecord::Schema.define(version: 20180111200406) do t.integer "organisation_id", limit: 8 t.datetime "created_at" t.datetime "updated_at" + t.integer "workgroup_id", limit: 8 end add_index "calendars", ["organisation_id"], name: "index_calendars_on_organisation_id", using: :btree add_index "calendars", ["short_name"], name: "index_calendars_on_short_name", unique: true, using: :btree + add_index "calendars", ["workgroup_id"], name: "index_calendars_on_workgroup_id", using: :btree create_table "clean_up_results", id: :bigserial, force: :cascade do |t| t.string "message_key" @@ -416,9 +418,9 @@ ActiveRecord::Schema.define(version: 20180111200406) do t.string "type" t.integer "parent_id", limit: 8 t.string "parent_type" - t.datetime "notified_parent_at" t.integer "current_step", default: 0 t.integer "total_steps", default: 0 + t.datetime "notified_parent_at" t.string "creator" end diff --git a/lib/stif/dashboard.rb b/lib/stif/dashboard.rb index b6b6b8284..7dd83efbc 100644 --- a/lib/stif/dashboard.rb +++ b/lib/stif/dashboard.rb @@ -9,7 +9,7 @@ module Stif end def calendars - @calendars ||= Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true) + @calendars ||= Calendar.where('workgroup_id = ? OR shared = ?', @workbench.workgroup_id, true) end end end -- cgit v1.2.3 From f32d869cc3f34a939764cc3fa4d612a5d6544d08 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 24 Jan 2018 19:55:56 -0800 Subject: update calendar build_links for table builder --- app/controllers/calendars_controller.rb | 25 +++++++++++++++++++------ app/controllers/concerns/workgroup_support.rb | 12 ++++++++++++ app/helpers/table_builder_helper/url.rb | 4 ++-- app/models/calendar.rb | 2 +- app/views/calendars/_form.html.slim | 2 +- app/views/calendars/edit.html.slim | 2 +- app/views/calendars/index.html.slim | 2 +- app/views/calendars/new.html.slim | 2 +- app/views/calendars/show.html.slim | 4 ++-- config/breadcrumbs.rb | 10 +++++----- lib/stif/dashboard.rb | 6 +++++- 11 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 app/controllers/concerns/workgroup_support.rb diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 72d213953..27c944f5f 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -1,4 +1,5 @@ class CalendarsController < ChouetteController + include WorkgroupSupport include PolicyChecker defaults resource_class: Calendar before_action :ransack_contains_date, only: [:index] @@ -7,19 +8,30 @@ class CalendarsController < ChouetteController def index index! do - @calendars = ModelDecorator.decorate(@calendars, with: CalendarDecorator, context: { - workgroup: current_workgroup - }) + @calendars = decorate_calendars(@calendars) end end def show show! do - @calendar = @calendar.decorate + @calendar = @calendar.decorate(context: { + workgroup: current_workgroup + }) end end private + + def decorate_calendars(calendars) + ModelDecorator.decorate( + calendars, + with: CalendarDecorator, + context: { + workgroup: current_workgroup + } + ) + end + def calendar_params permitted_params = [:id, :name, :short_name, :shared, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]] permitted_params << :shared if policy(Calendar).share? @@ -36,18 +48,19 @@ class CalendarsController < ChouetteController protected def resource - @calendar = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).find_by_id(params[:id]) + @calendar = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id).find_by_id(params[:id], true, @workgroup.id) end def build_resource super.tap do |calendar| + calendar.workgroup = current_workgroup calendar.organisation = current_organisation end end def collection return @calendars if @calendars - scope = Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true) + scope = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, @workgroup.id) scope = shared_scope(scope) @q = scope.ransack(params[:q]) diff --git a/app/controllers/concerns/workgroup_support.rb b/app/controllers/concerns/workgroup_support.rb new file mode 100644 index 000000000..a3b49bb12 --- /dev/null +++ b/app/controllers/concerns/workgroup_support.rb @@ -0,0 +1,12 @@ +module WorkgroupSupport + extend ActiveSupport::Concern + + included do + before_action :find_workgroup + end + + def find_workgroup + @workgroup ||= Workgroup.find params[:workgroup_id] + end + +end diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb index 40e1f839f..0e3dce0aa 100644 --- a/app/helpers/table_builder_helper/url.rb +++ b/app/helpers/table_builder_helper/url.rb @@ -3,7 +3,7 @@ module TableBuilderHelper def self.polymorphic_url_parts(item, referential, workgroup) polymorph_url = [] - unless item.is_a?(Referential) || item.is_a?(ComplianceControlSet) + unless item.is_a?(Calendar) || item.is_a?(Referential) || item.is_a?(ComplianceControlSet) if referential polymorph_url << referential polymorph_url << item.line if item.respond_to? :line @@ -20,7 +20,7 @@ module TableBuilderHelper end end else - polymorph_url << item.workgroup if item.is_a?(Calendar) + polymorph_url << item.workgroup if item.respond_to? :workgroup polymorph_url << item end diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 236223892..d93532908 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -10,7 +10,7 @@ class Calendar < ActiveRecord::Base belongs_to :organisation belongs_to :workgroup - validates_presence_of :name, :short_name, :organisation + validates_presence_of :name, :short_name, :organisation, :workgroup validates_uniqueness_of :short_name has_many :time_tables diff --git a/app/views/calendars/_form.html.slim b/app/views/calendars/_form.html.slim index 3c152c61d..bf9f4f3a7 100644 --- a/app/views/calendars/_form.html.slim +++ b/app/views/calendars/_form.html.slim @@ -1,4 +1,4 @@ -= simple_form_for @calendar, html: { class: 'form-horizontal', id: 'calendar_form' }, wrapper: :horizontal_form do |f| += simple_form_for [@workgroup, @calendar], html: { class: 'form-horizontal', id: 'calendar_form' }, wrapper: :horizontal_form do |f| .row .col-lg-12 = f.input :name diff --git a/app/views/calendars/edit.html.slim b/app/views/calendars/edit.html.slim index e806fc94b..a1af5e257 100644 --- a/app/views/calendars/edit.html.slim +++ b/app/views/calendars/edit.html.slim @@ -1,4 +1,4 @@ -- breadcrumb :calendar, @calendar +- breadcrumb :calendar, @workgroup, @calendar - page_header_content_for @calendar .page_content .container-fluid diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index d0544856d..60bc9793d 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -1,4 +1,4 @@ -- breadcrumb :calendars +- breadcrumb :calendars, current_workgroup - content_for :page_header_actions do - if policy(Calendar).create? = link_to(t('actions.add'), new_workgroup_calendar_path(current_workgroup), class: 'btn btn-default') diff --git a/app/views/calendars/new.html.slim b/app/views/calendars/new.html.slim index ce8b6a036..c1e084913 100644 --- a/app/views/calendars/new.html.slim +++ b/app/views/calendars/new.html.slim @@ -1,4 +1,4 @@ -- breadcrumb :calendars +- breadcrumb :calendars, @workgroup .page_content .container-fluid .row diff --git a/app/views/calendars/show.html.slim b/app/views/calendars/show.html.slim index da4afa3e6..9f7512173 100644 --- a/app/views/calendars/show.html.slim +++ b/app/views/calendars/show.html.slim @@ -1,4 +1,4 @@ -- breadcrumb :calendar, @calendar +- breadcrumb :calendar, @workgroup, @calendar - page_header_content_for @calendar - content_for :page_header_content do .row.mb-sm @@ -11,7 +11,7 @@ = link.content - if policy(@calendar).edit? - content_for :page_header_actions do - = link_to(t('actions.edit'), edit_calendar_path(@calendar), class: 'btn btn-default') + = link_to(t('actions.edit'), edit_workgroup_calendar_path(@workgroup, @calendar), class: 'btn btn-default') .page_content .container-fluid diff --git a/config/breadcrumbs.rb b/config/breadcrumbs.rb index 6da96d73a..2772895fe 100644 --- a/config/breadcrumbs.rb +++ b/config/breadcrumbs.rb @@ -202,13 +202,13 @@ crumb :purchase_window do |referential, purchase_window| parent :purchase_windows, referential end -crumb :calendars do - link I18n.t('calendars.index.title'), calendars_path +crumb :calendars do |workgroup| + link I18n.t('calendars.index.title'), workgroup_calendars_path(workgroup) end -crumb :calendar do |calendar| - link breadcrumb_name(calendar), calendar_path(calendar) - parent :calendars +crumb :calendar do |workgroup, calendar| + link breadcrumb_name(calendar), workgroup_calendar_path(workgroup, calendar) + parent :calendars, workgroup end crumb :referential_line do |referential, line| diff --git a/lib/stif/dashboard.rb b/lib/stif/dashboard.rb index 7dd83efbc..46c635091 100644 --- a/lib/stif/dashboard.rb +++ b/lib/stif/dashboard.rb @@ -4,12 +4,16 @@ module Stif @workbench ||= current_organisation.workbenches.find_by(name: "Gestion de l'offre") end + def workgroup + workbench.workgroup + end + def referentials @referentials ||= self.workbench.all_referentials end def calendars - @calendars ||= Calendar.where('workgroup_id = ? OR shared = ?', @workbench.workgroup_id, true) + @calendars ||= Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, workgroup.id) end end end -- cgit v1.2.3 From 4023ea52097a47458ac2fcad36d343aba0c8e68b Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Tue, 30 Jan 2018 23:07:07 -0800 Subject: Make some changes to avoid unnacessaty lines of code --- app/controllers/calendars_controller.rb | 33 +++++++++++++++++------------ app/views/calendars/index.html.slim | 4 ++-- spec/factories/calendars.rb | 1 + spec/features/calendars_permissions_spec.rb | 7 +++--- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 27c944f5f..193680342 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -1,10 +1,11 @@ class CalendarsController < ChouetteController - include WorkgroupSupport include PolicyChecker defaults resource_class: Calendar before_action :ransack_contains_date, only: [:index] respond_to :html respond_to :js, only: :index + + belongs_to :workgroup def index index! do @@ -15,7 +16,7 @@ class CalendarsController < ChouetteController def show show! do @calendar = @calendar.decorate(context: { - workgroup: current_workgroup + workgroup: workgroup }) end end @@ -27,7 +28,7 @@ class CalendarsController < ChouetteController calendars, with: CalendarDecorator, context: { - workgroup: current_workgroup + workgroup: workgroup } ) end @@ -47,26 +48,30 @@ class CalendarsController < ChouetteController end protected + + alias_method :workgroup, :parent + helper_method :workgroup + def resource - @calendar = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id).find_by_id(params[:id], true, @workgroup.id) + @calendar ||= workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true).find_by_id(params[:id]) end def build_resource super.tap do |calendar| - calendar.workgroup = current_workgroup + calendar.workgroup = workgroup calendar.organisation = current_organisation end end def collection - return @calendars if @calendars - scope = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, @workgroup.id) - scope = shared_scope(scope) - @q = scope.ransack(params[:q]) - - calendars = @q.result - calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction - @calendars = calendars.paginate(page: params[:page]) + @calendars ||= begin + scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true) + scope = shared_scope(scope) + @q = scope.ransack(params[:q]) + calendars = @q.result + calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction + calendars = calendars.paginate(page: params[:page]) + end end def ransack_contains_date @@ -91,4 +96,4 @@ class CalendarsController < ChouetteController scope end -end +end \ No newline at end of file diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index 309f0e6f9..0b58c0c72 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -1,4 +1,4 @@ -- breadcrumb :calendars, current_workgroup +- breadcrumb :calendars, workgroup .page_content .container-fluid @@ -16,7 +16,7 @@ key: :name, \ attribute: 'name', \ link_to: lambda do |calendar| \ - workgroup_calendar_path(current_workgroup, calendar) \ + workgroup_calendar_path(workgroup, calendar) \ end \ ), \ TableBuilderHelper::Column.new( \ diff --git a/spec/factories/calendars.rb b/spec/factories/calendars.rb index 5f3188bee..d9fd242d1 100644 --- a/spec/factories/calendars.rb +++ b/spec/factories/calendars.rb @@ -6,6 +6,7 @@ FactoryGirl.define do sequence(:dates) { |n| [ Date.yesterday - n, Date.yesterday - 2*n ] } shared false organisation + workgroup end sequence :date_range do |n| diff --git a/spec/features/calendars_permissions_spec.rb b/spec/features/calendars_permissions_spec.rb index 9b47ab2bb..4857592d5 100644 --- a/spec/features/calendars_permissions_spec.rb +++ b/spec/features/calendars_permissions_spec.rb @@ -2,6 +2,7 @@ RSpec.describe 'Calendars', type: :feature do login_user let(:calendar) { create :calendar, organisation_id: 1 } + let(:workgroup) { calendar.workgroup } describe 'permissions' do before do @@ -13,7 +14,7 @@ RSpec.describe 'Calendars', type: :feature do end context 'on show view' do - let( :path ){ calendar_path(calendar) } + let( :path ){ workgroup_calendar_path(workgroup, calendar) } context 'if present → ' do let( :permission ){ true } @@ -33,7 +34,7 @@ RSpec.describe 'Calendars', type: :feature do end context 'on edit view' do - let( :path ){ edit_calendar_path(calendar) } + let( :path ){ edit_workgroup_calendar_path(workgroup, calendar) } context 'if present → ' do let( :permission ){ true } @@ -51,7 +52,7 @@ RSpec.describe 'Calendars', type: :feature do end context 'on index view' do - let( :path ){ calendars_path } + let( :path ){ workgroup_calendars_path(workgroup) } context 'if present → ' do let( :permission ){ true } -- cgit v1.2.3 From fe7915ffac359db41c7737a3847f31a728f502e6 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 31 Jan 2018 11:39:39 +0100 Subject: Refs #5683 @2H; Fix specs and refactor action_links Note: Did not fix the missing workgroup in the calendar mailer --- app/controllers/calendars_controller.rb | 21 ++++---- app/decorators/calendar_decorator.rb | 2 + app/decorators/company_decorator.rb | 19 ++----- app/decorators/compliance_control_decorator.rb | 18 ++----- app/decorators/import_decorator.rb | 7 ++- app/decorators/line_decorator.rb | 10 ++-- app/decorators/network_decorator.rb | 14 +---- app/decorators/purchase_window_decorator.rb | 18 ++----- app/decorators/referential_line_decorator.rb | 10 ++-- app/decorators/referential_network_decorator.rb | 21 ++------ app/decorators/route_decorator.rb | 29 ++-------- .../routing_constraint_zone_decorator.rb | 39 ++------------ app/decorators/stop_area_decorator.rb | 22 +------- app/helpers/table_builder_helper.rb | 1 - lib/af83/decorator.rb | 63 ++++++++++++---------- lib/af83/decorator/enhanced_decorator.rb | 22 ++++++-- lib/af83/decorator/link.rb | 3 +- spec/support/pundit/pundit_view_policy.rb | 5 +- spec/support/referential.rb | 4 +- spec/views/referentials/show.html.erb_spec.rb | 6 ++- 20 files changed, 114 insertions(+), 220 deletions(-) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 193680342..6f1522428 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -4,7 +4,7 @@ class CalendarsController < ChouetteController before_action :ransack_contains_date, only: [:index] respond_to :html respond_to :js, only: :index - + belongs_to :workgroup def index @@ -24,9 +24,8 @@ class CalendarsController < ChouetteController private def decorate_calendars(calendars) - ModelDecorator.decorate( + CalendarDecorator.decorate( calendars, - with: CalendarDecorator, context: { workgroup: workgroup } @@ -65,13 +64,13 @@ class CalendarsController < ChouetteController def collection @calendars ||= begin - scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true) - scope = shared_scope(scope) - @q = scope.ransack(params[:q]) - calendars = @q.result - calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction - calendars = calendars.paginate(page: params[:page]) - end + scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true) + scope = shared_scope(scope) + @q = scope.ransack(params[:q]) + calendars = @q.result + calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction + calendars = calendars.paginate(page: params[:page]) + end end def ransack_contains_date @@ -96,4 +95,4 @@ class CalendarsController < ChouetteController scope end -end \ No newline at end of file +end diff --git a/app/decorators/calendar_decorator.rb b/app/decorators/calendar_decorator.rb index be1f9e3bf..0a7cbc312 100644 --- a/app/decorators/calendar_decorator.rb +++ b/app/decorators/calendar_decorator.rb @@ -1,6 +1,8 @@ class CalendarDecorator < AF83::Decorator decorates Calendar + set_scope { context[:workgroup] } + create_action_link with_instance_decorator do |instance_decorator| diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb index aadce68bb..5580e0d4a 100644 --- a/app/decorators/company_decorator.rb +++ b/app/decorators/company_decorator.rb @@ -1,34 +1,21 @@ class CompanyDecorator < AF83::Decorator decorates Chouette::Company + set_scope { context[:referential] } + create_action_link do |l| l.content { h.t('companies.actions.new') } - l.href { [:new, context[:referential], :company] } end with_instance_decorator do |instance_decorator| - instance_decorator.show_action_link do |l| - l.href { [context[:referential], object] } - end + instance_decorator.show_action_link instance_decorator.edit_action_link do |l| l.content {|l| l.action == "show" ? h.t('actions.edit') : h.t('companies.actions.edit') } - l.href { - h.edit_line_referential_company_path( - context[:referential], - object - ) - } end instance_decorator.destroy_action_link do |l| l.content { h.destroy_link_content('companies.actions.destroy') } - l.href { - h.edit_line_referential_company_path( - context[:referential], - object - ) - } l.data {{ confirm: h.t('companies.actions.destroy_confirm') }} end end diff --git a/app/decorators/compliance_control_decorator.rb b/app/decorators/compliance_control_decorator.rb index c57a7ccc7..fd2dbd9ce 100644 --- a/app/decorators/compliance_control_decorator.rb +++ b/app/decorators/compliance_control_decorator.rb @@ -1,6 +1,8 @@ class ComplianceControlDecorator < AF83::Decorator decorates ComplianceControl + set_scope { object.compliance_control_set } + with_instance_decorator do |instance_decorator| instance_decorator.show_action_link do |l| l.content h.t('compliance_control_sets.actions.show') @@ -12,23 +14,9 @@ class ComplianceControlDecorator < AF83::Decorator end end - instance_decorator.edit_action_link do |l| - l.href do - h.edit_compliance_control_set_compliance_control_path( - object.compliance_control_set_id, - object.id - ) - end - end + instance_decorator.edit_action_link instance_decorator.destroy_action_link do |l| - l.content h.destroy_link_content - l.href do - h.compliance_control_set_compliance_control_path( - object.compliance_control_set.id, - object.id - ) - end l.data confirm: h.t('compliance_controls.actions.destroy_confirm') end end diff --git a/app/decorators/import_decorator.rb b/app/decorators/import_decorator.rb index c6b1f2349..1964365ae 100644 --- a/app/decorators/import_decorator.rb +++ b/app/decorators/import_decorator.rb @@ -1,6 +1,8 @@ class ImportDecorator < AF83::Decorator decorates Import + set_scope { context[:workbench] } + define_instance_method :import_status_css_class do cls ='' cls = 'overheaded-success' if object.status == 'successful' @@ -11,13 +13,10 @@ class ImportDecorator < AF83::Decorator create_action_link do |l| l.content t('imports.actions.new') - l.href { h.new_workbench_import_path(workbench_id: context[:workbench]) } end with_instance_decorator do |instance_decorator| - instance_decorator.show_action_link do |l| - l.href { h.workbench_import_path(context[:workbench], object) } - end + instance_decorator.show_action_link instance_decorator.action_link secondary: :show do |l| l.content t('imports.actions.download') diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb index 9171a6310..039ad90a3 100644 --- a/app/decorators/line_decorator.rb +++ b/app/decorators/line_decorator.rb @@ -1,9 +1,10 @@ class LineDecorator < AF83::Decorator decorates Chouette::Line + set_scope { context[:line_referential] } + create_action_link do |l| l.content t('lines.actions.new') - l.href { h.new_line_referential_line_path(context[:line_referential]) } end with_instance_decorator do |instance_decorator| @@ -14,17 +15,16 @@ class LineDecorator < AF83::Decorator instance_decorator.show_action_link do |l| l.content t('lines.actions.show') - l.href { [context[:line_referential], object] } end instance_decorator.action_link secondary: :show do |l| l.content t('lines.actions.show_network') - l.href { [context[:line_referential], object.network] } + l.href { [scope, object.network] } end instance_decorator.action_link secondary: :show do |l| l.content t('lines.actions.show_company') - l.href { [context[:line_referential], object.company] } + l.href { [scope, object.company] } l.disabled { object.company.nil? } end @@ -33,7 +33,6 @@ class LineDecorator < AF83::Decorator instance_decorator.with_condition can_edit_line do edit_action_link do |l| l.content {|l| l.primary? ? h.t('actions.edit') : h.t('lines.actions.edit') } - l.href { h.edit_line_referential_line_path(context[:line_referential], object.id) } end action_link on: :index, secondary: :index do |l| @@ -63,7 +62,6 @@ class LineDecorator < AF83::Decorator instance_decorator.destroy_action_link do |l| l.content { h.destroy_link_content('lines.actions.destroy') } - l.href { h.line_referential_line_path(context[:line_referential], object) } l.data confirm: h.t('lines.actions.destroy_confirm') l.add_class "delete-action" end diff --git a/app/decorators/network_decorator.rb b/app/decorators/network_decorator.rb index 90f0d0e82..ea0f73dc2 100644 --- a/app/decorators/network_decorator.rb +++ b/app/decorators/network_decorator.rb @@ -1,6 +1,7 @@ class NetworkDecorator < AF83::Decorator decorates Chouette::Network + set_scope { context[:line_referential] } # Action links require: # context: { # line_referential: , @@ -8,15 +9,10 @@ class NetworkDecorator < AF83::Decorator create_action_link do |l| l.content t('networks.actions.new') - l.href { h.new_line_referential_network_path(context[:line_referential]) } end with_instance_decorator do |instance_decorator| - instance_decorator.show_action_link do |l| - l.href do - h.line_referential_network_path(context[:line_referential], object) - end - end + instance_decorator.show_action_link instance_decorator.action_link secondary: true, policy: :edit do |l| l.content t('networks.actions.edit') @@ -30,12 +26,6 @@ class NetworkDecorator < AF83::Decorator instance_decorator.destroy_action_link do |l| l.content h.destroy_link_content('networks.actions.destroy') - l.href do - h.line_referential_network_path( - context[:line_referential], - object - ) - end l.data confirm: h.t('networks.actions.destroy_confirm') end end diff --git a/app/decorators/purchase_window_decorator.rb b/app/decorators/purchase_window_decorator.rb index 54b241173..9b58577b2 100644 --- a/app/decorators/purchase_window_decorator.rb +++ b/app/decorators/purchase_window_decorator.rb @@ -1,32 +1,20 @@ class PurchaseWindowDecorator < AF83::Decorator decorates Chouette::PurchaseWindow + set_scope { context[:referential] } + create_action_link do |l| l.content t('purchase_windows.actions.new') - l.href { h.new_referential_purchase_window_path(context[:referential]) } end with_instance_decorator do |instance_decorator| instance_decorator.show_action_link do |l| l.content t('purchase_windows.actions.show') - l.href do - h.referential_purchase_window_path( - context[:referential], - object - ) - end end - instance_decorator.edit_action_link do |l| - l.href do - h.edit_referential_purchase_window_path(context[:referential].id, object) - end - end + instance_decorator.edit_action_link instance_decorator.destroy_action_link do |l| - l.href do - h.referential_purchase_window_path(context[:referential].id, object) - end l.data confirm: h.t('purchase_windows.actions.destroy_confirm') end end diff --git a/app/decorators/referential_line_decorator.rb b/app/decorators/referential_line_decorator.rb index 8f884a8e0..3ac846d76 100644 --- a/app/decorators/referential_line_decorator.rb +++ b/app/decorators/referential_line_decorator.rb @@ -1,6 +1,8 @@ class ReferentialLineDecorator < AF83::Decorator decorates Chouette::Line + set_scope { context[:referential] } + # Action links require: # context: { # referential: , @@ -8,9 +10,7 @@ class ReferentialLineDecorator < AF83::Decorator # } with_instance_decorator do |instance_decorator| - instance_decorator.show_action_link do |l| - l.href { h.referential_line_path(context[:referential], object) } - end + instance_decorator.show_action_link instance_decorator.action_link secondary: true do |l| l.content Chouette::Line.human_attribute_name(:footnotes) @@ -21,7 +21,7 @@ class ReferentialLineDecorator < AF83::Decorator l.content h.t('routing_constraint_zones.index.title') l.href do h.referential_line_routing_constraint_zones_path( - context[:referential], + scope, object ) end @@ -37,7 +37,7 @@ class ReferentialLineDecorator < AF83::Decorator secondary: true ) do |l| l.content h.t('routes.actions.new') - l.href { h.new_referential_line_route_path(context[:referential], object) } + l.href { h.new_referential_line_route_path(scope, object) } end end end diff --git a/app/decorators/referential_network_decorator.rb b/app/decorators/referential_network_decorator.rb index ff3467188..c508452c0 100644 --- a/app/decorators/referential_network_decorator.rb +++ b/app/decorators/referential_network_decorator.rb @@ -1,6 +1,8 @@ class ReferentialNetworkDecorator < AF83::Decorator decorates Chouette::Network + set_scope { context[:referential] } + # Action links require: # context: { # referential: , @@ -8,33 +10,18 @@ class ReferentialNetworkDecorator < AF83::Decorator create_action_link do |l| l.content t('networks.actions.new') - l.href { h.new_referential_network_path(context[:referential]) } end with_instance_decorator do |instance_decorator| - instance_decorator.show_action_link do |l| - l.href { h.referential_network_path(context[:referential], object) } - end + instance_decorator.show_action_link instance_decorator.edit_action_link do |l| l.content t('networks.actions.edit') - l.href do - h.edit_referential_network_path( - context[:referential], - object - ) - end end instance_decorator.destroy_action_link do |l| l.content h.destroy_link_content('networks.actions.destroy') - l.href do - h.referential_network_path( - context[:referential], - object - ) - end l.data confirm: h.t('networks.actions.destroy_confirm') end end -end \ No newline at end of file +end diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb index 7e3ea889f..75ef20d63 100644 --- a/app/decorators/route_decorator.rb +++ b/app/decorators/route_decorator.rb @@ -7,26 +7,12 @@ class RouteDecorator < AF83::Decorator # line: # } + set_scope { [context[:referential], context[:line]] } + with_instance_decorator do |instance_decorator| - instance_decorator.show_action_link do |l| - l.href do - h.referential_line_route_path( - context[:referential], - context[:line], - object - ) - end - end + instance_decorator.show_action_link - instance_decorator.edit_action_link do |l| - l.href do - h.edit_referential_line_route_path( - context[:referential], - context[:line], - object - ) - end - end + instance_decorator.edit_action_link instance_decorator.action_link( if: ->() { object.stop_points.any? }, @@ -85,13 +71,6 @@ class RouteDecorator < AF83::Decorator end instance_decorator.destroy_action_link do |l| - l.href do - h.referential_line_route_path( - context[:referential], - context[:line], - object - ) - end l.data confirm: h.t('routes.actions.destroy_confirm') end end diff --git a/app/decorators/routing_constraint_zone_decorator.rb b/app/decorators/routing_constraint_zone_decorator.rb index 962625fa7..de73068be 100644 --- a/app/decorators/routing_constraint_zone_decorator.rb +++ b/app/decorators/routing_constraint_zone_decorator.rb @@ -1,6 +1,8 @@ class RoutingConstraintZoneDecorator < AF83::Decorator decorates Chouette::RoutingConstraintZone + set_scope { [context[:referential], context[:line]] } + # Action links require: # context: { # referential: , @@ -12,44 +14,13 @@ class RoutingConstraintZoneDecorator < AF83::Decorator h.policy(Chouette::RoutingConstraintZone).create? && context[:referential].organisation == h.current_organisation } - ) do |l| - l.href do - h.new_referential_line_routing_constraint_zone_path( - context[:referential], - context[:line] - ) - end - end + ) with_instance_decorator do |instance_decorator| - instance_decorator.show_action_link do |l| - l.href do - h.referential_line_routing_constraint_zone_path( - context[:referential], - context[:line], - object - ) - end - end - - instance_decorator.edit_action_link do |l| - l.href do - h.edit_referential_line_routing_constraint_zone_path( - context[:referential], - context[:line], - object - ) - end - end + instance_decorator.show_action_link + instance_decorator.edit_action_link instance_decorator.destroy_action_link do |l| - l.href do - h.referential_line_routing_constraint_zone_path( - context[:referential], - context[:line], - object - ) - end l.data confirm: h.t('routing_constraint_zones.actions.destroy_confirm') end end diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb index 2e57da0e4..525681971 100644 --- a/app/decorators/stop_area_decorator.rb +++ b/app/decorators/stop_area_decorator.rb @@ -7,23 +7,11 @@ class StopAreaDecorator < AF83::Decorator end with_instance_decorator do |instance_decorator| - instance_decorator.show_action_link do |l| - l.href do - h.stop_area_referential_stop_area_path( - object.stop_area_referential, - object - ) - end - end + set_scope { object.stop_area_referential } + instance_decorator.show_action_link instance_decorator.edit_action_link do |l| l.content h.t('stop_areas.actions.edit') - l.href do - h.edit_stop_area_referential_stop_area_path( - object.stop_area_referential, - object - ) - end end instance_decorator.action_link policy: :deactivate, secondary: true do |l| @@ -54,12 +42,6 @@ class StopAreaDecorator < AF83::Decorator instance_decorator.destroy_action_link do |l| l.content h.destroy_link_content('stop_areas.actions.destroy') - l.href do - h.stop_area_referential_stop_area_path( - object.stop_area_referential, - object - ) - end l.data confirm: h.t('stop_areas.actions.destroy_confirm') end end diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index f48075ed9..2068dd23c 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -395,7 +395,6 @@ module TableBuilderHelper klass << link.extra_class if link.extra_class klass << 'delete-action' if link.method == :delete klass << 'disabled' if link.disabled - content_tag( :li, link_to( diff --git a/lib/af83/decorator.rb b/lib/af83/decorator.rb index f990555fe..71cf1170d 100644 --- a/lib/af83/decorator.rb +++ b/lib/af83/decorator.rb @@ -2,40 +2,49 @@ class AF83::Decorator < ModelDecorator include AF83::Decorator::EnhancedDecorator extend AF83::Decorator::EnhancedDecorator::ClassMethods - def self.decorates klass - instance_decorator.decorates klass - end + class << self + def decorates klass + instance_decorator.decorates klass + end - def self.instance_decorator - @instance_decorator ||= begin - klass = Class.new(AF83::Decorator::InstanceDecorator) - klass.delegate_all - klass + def instance_decorator + @instance_decorator ||= begin + klass = Class.new(AF83::Decorator::InstanceDecorator) + klass.delegate_all + klass + end end - end - def self.with_instance_decorator - @_with_instance_decorator = true - yield instance_decorator - @_with_instance_decorator = false - end + def with_instance_decorator + @_with_instance_decorator = true + yield instance_decorator + @_with_instance_decorator = false + end + + def decorate object, options = {} + if object.is_a?(ActiveRecord::Base) + return instance_decorator.decorate object, options + else + self.new object, options.update(with: instance_decorator) + end + end - def self.decorate object, options = {} - if object.is_a?(ActiveRecord::Base) - return instance_decorator.decorate object, options - else - self.new object, options.update(with: instance_decorator) + def define_instance_method method_name, &block + instance_decorator.send(:define_method, method_name, &block) end - end - def self.define_instance_method method_name, &block - instance_decorator.send(:define_method, method_name, &block) - end + # Defines a class method on the decorated object's class. These + # can be called like `object.class.my_method`. + def define_instance_class_method method_name, &block + instance_decorator.send(:define_singleton_method, method_name, &block) + end + + def set_scope_with_instance_decorator value=nil, &block + set_scope_without_instance_decorator value, &block + instance_decorator.set_scope value, &block + end - # Defines a class method on the decorated object's class. These - # can be called like `object.class.my_method`. - def self.define_instance_class_method method_name, &block - instance_decorator.send(:define_singleton_method, method_name, &block) + alias_method_chain :set_scope, :instance_decorator end class ActionLinks diff --git a/lib/af83/decorator/enhanced_decorator.rb b/lib/af83/decorator/enhanced_decorator.rb index 904d1b2da..fff8bb8b3 100644 --- a/lib/af83/decorator/enhanced_decorator.rb +++ b/lib/af83/decorator/enhanced_decorator.rb @@ -25,7 +25,7 @@ module AF83::Decorator::EnhancedDecorator policy: :create, before_block: -> (l){ l.content { h.t('actions.add') } - l.href { [:new, object.klass.name.underscore.singularize] } + l.href { [:new, scope, object.klass.model_name.singular] } } } action_link opts.update(args), &block @@ -37,7 +37,7 @@ module AF83::Decorator::EnhancedDecorator primary: :index, before_block: -> (l){ l.content { h.t('actions.show') } - l.href { [object] } + l.href { [scope, object] } } } action_link opts.update(args), &block @@ -49,7 +49,7 @@ module AF83::Decorator::EnhancedDecorator policy: :edit, before_block: -> (l){ l.content { h.t('actions.edit') } - l.href { [:edit, object] } + l.href { [:edit, scope, object] } } } action_link opts.update(args), &block @@ -62,7 +62,7 @@ module AF83::Decorator::EnhancedDecorator secondary: :show, before_block: -> (l){ l.content { h.destroy_link_content } - l.href { [object] } + l.href { [scope, object] } l.method :delete l.data {{ confirm: h.t('actions.destroy_confirm') }} } @@ -70,6 +70,14 @@ module AF83::Decorator::EnhancedDecorator action_link opts.update(args), &block end + def set_scope value=nil, &block + @scope = value || block + end + + def scope + @scope + end + def t key eval "-> (l){ h.t('#{key}') }" end @@ -142,4 +150,10 @@ module AF83::Decorator::EnhancedDecorator def check_feature feature h.has_feature? feature end + + def scope + scope = self.class.scope + scope = instance_exec &scope if scope.is_a? Proc + scope + end end diff --git a/lib/af83/decorator/link.rb b/lib/af83/decorator/link.rb index 7d2896e6a..de7106740 100644 --- a/lib/af83/decorator/link.rb +++ b/lib/af83/decorator/link.rb @@ -30,7 +30,8 @@ class AF83::Decorator::Link @options[name] = block elsif args.size == 0 out = @options[name] - out = context.instance_exec(self, &out) if out.is_a?(Proc) + out = context.instance_exec(self, &out) if out.is_a?(Proc) + out = out.flatten.compact if name.to_s == "href" && out.is_a?(Array) out else # we can use l.foo("bar") or l.foo = "bar" diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index 91be0624c..330209049 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -2,9 +2,8 @@ module Pundit module PunditViewPolicy def self.included into into.let(:permissions){ nil } - into.let(:organisation){ referential.try(:organisation) } - into.let(:current_referential){ referential || build_stubbed(:referential) } - into.let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation } + into.let(:current_referential){ referential || build_stubbed(:referential, organisation: organisation) } + into.let(:current_user){ create :user, permissions: permissions, organisation: organisation } into.let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } into.before do allow(view).to receive(:pundit_user) { pundit_user } diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 497ff47a8..9acdce73a 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -11,8 +11,8 @@ module ReferentialHelper def self.included(base) base.class_eval do extend ClassMethods - alias_method :referential, :first_referential - alias_method :organisation, :first_organisation + base.let(:referential){ first_referential } + base.let(:organisation){ first_organisation } end end diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb index 4a2afe2ca..6fd51949a 100644 --- a/spec/views/referentials/show.html.erb_spec.rb +++ b/spec/views/referentials/show.html.erb_spec.rb @@ -3,20 +3,22 @@ require 'spec_helper' describe "referentials/show", type: :view do let!(:referential) do - referential = create(:referential) + referential = create(:referential, organisation: organisation) assign :referential, referential.decorate(context: { current_organisation: referential.organisation }) end let(:permissions){ [] } let(:current_organisation) { organisation } - let(:current_offer_workbench) { create :workbench, organisation: current_organisation} + let(:current_offer_workbench) { create :workbench, organisation: organisation} + let(:current_workgroup) { current_offer_workbench.workgroup } let(:readonly){ false } before :each do assign :reflines, [] allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench) allow(view).to receive(:current_organisation).and_return(current_organisation) + allow(view).to receive(:current_workgroup).and_return(current_workgroup) allow(view).to receive(:current_user).and_return(current_user) allow(view).to receive(:resource).and_return(referential) -- cgit v1.2.3 From d56aed95bcd9970bdc49477c2d5c59befbaeeefd Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 22 Jan 2018 11:05:09 +0100 Subject: Refs #5647; Scope CustomField validations on workgroup --- app/models/custom_field.rb | 5 +++-- spec/models/custom_field_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 3f79ec62c..774c8b0f6 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -1,8 +1,9 @@ class CustomField < ActiveRecord::Base extend Enumerize + belongs_to :workgroup enumerize :field_type, in: %i{list} - validates :name, uniqueness: {scope: :resource_type} - validates :code, uniqueness: {scope: :resource_type, case_sensitive: false} + validates :name, uniqueness: {scope: [:resource_type, :workgroup_id]} + validates :code, uniqueness: {scope: [:resource_type, :workgroup_id], case_sensitive: false} end diff --git a/spec/models/custom_field_spec.rb b/spec/models/custom_field_spec.rb index 8a6d0cb41..51128b0a2 100644 --- a/spec/models/custom_field_spec.rb +++ b/spec/models/custom_field_spec.rb @@ -4,8 +4,8 @@ RSpec.describe CustomField, type: :model do let( :vj ){ create :vehicle_journey, custom_field_values: {energy: 99} } context "validates" do - it { should validate_uniqueness_of(:name).scoped_to(:resource_type) } - it { should validate_uniqueness_of(:code).scoped_to(:resource_type).case_insensitive } + it { should validate_uniqueness_of(:name).scoped_to(:resource_type, :workgroup_id) } + it { should validate_uniqueness_of(:code).scoped_to(:resource_type, :workgroup_id).case_insensitive } end context "field access" do -- cgit v1.2.3 From 87e0ea06cbc6bdfb281da8805b0221868341fee2 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 24 Jan 2018 08:58:28 +0100 Subject: Add a toolbar for devs to easily manage permissions and features --- .gitignore | 1 + app/assets/stylesheets/components/_toolbar.sass | 47 +++++++++++++++++++++ app/controllers/development_toolbar_controller.rb | 11 +++++ app/views/layouts/application.html.slim | 3 ++ .../layouts/navigation/_main_nav_top.html.slim | 4 ++ app/views/shared/_development_toolbar.html.slim | 48 ++++++++++++++++++++++ config/environments/development.rb | 7 ++++ config/routes.rb | 4 ++ 8 files changed, 125 insertions(+) create mode 100644 app/assets/stylesheets/components/_toolbar.sass create mode 100644 app/controllers/development_toolbar_controller.rb create mode 100644 app/views/shared/_development_toolbar.html.slim diff --git a/.gitignore b/.gitignore index ddd5fdda3..acdb5e230 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ coverage /bin/spring spec/fixtures/target_* +config/development_toolbar.rb diff --git a/app/assets/stylesheets/components/_toolbar.sass b/app/assets/stylesheets/components/_toolbar.sass new file mode 100644 index 000000000..47ae2ac0c --- /dev/null +++ b/app/assets/stylesheets/components/_toolbar.sass @@ -0,0 +1,47 @@ +#development-toolbar + .inner + overflow: scroll + padding: 10px + max-height: 70vh + display: flex + flex-direction: row + .toggles + font-size: 0.7em + float: right + a:first-child + padding-right: 3px + margin-right: 3px + border-right: 1px solid $lightgrey + + .col + flex: 1 1 + padding-right: 10px + padding-left: 10px + border-right: 1px solid $lightgrey + &:last-child + padding-right: 0 + border-right: none + + ul + padding: 0 + li + list-style-type: none + label + padding-left: 5px + font-weight: normal + h5 + font-weight: bold + &.permissions + ul + overflow: hidden + li + float: left + width: 33% + label + font-size: 0.8em + max-width: calc(100% - 15px) + text-overflow: ellipsis + overflow: hidden + padding-top: 3px + input + vertical-align: top diff --git a/app/controllers/development_toolbar_controller.rb b/app/controllers/development_toolbar_controller.rb new file mode 100644 index 000000000..20349f7b8 --- /dev/null +++ b/app/controllers/development_toolbar_controller.rb @@ -0,0 +1,11 @@ +class DevelopmentToolbarController < ApplicationController + def update_settings + return unless Rails.application.config.development_toolbar.present? + organisation = current_user.organisation + organisation.features = params[:features].keys.select{|k| params[:features][k] == "true"} + organisation.save + current_user.permissions = params[:permissions].keys.select{|k| params[:permissions][k] == "true"} + current_user.save + redirect_to request.referrer || "/" + end +end diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 567e14ef0..34b373295 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -21,3 +21,6 @@ html lang=I18n.locale = yield #sidebar = yield :sidebar + + = render 'shared/development_toolbar' + = yield :javascript diff --git a/app/views/layouts/navigation/_main_nav_top.html.slim b/app/views/layouts/navigation/_main_nav_top.html.slim index 278249e09..f664d5416 100644 --- a/app/views/layouts/navigation/_main_nav_top.html.slim +++ b/app/views/layouts/navigation/_main_nav_top.html.slim @@ -14,9 +14,13 @@ span = current_user.name span.fa.fa-lg.fa-user + - if Rails.application.config.development_toolbar + = link_to '#', data: { toggle: 'modal', target: '#development-toolbar' }, class: "toolbar-button menu-item" do + .fa.fa-cog = 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' if user_signed_in? diff --git a/app/views/shared/_development_toolbar.html.slim b/app/views/shared/_development_toolbar.html.slim new file mode 100644 index 000000000..b51bb3de6 --- /dev/null +++ b/app/views/shared/_development_toolbar.html.slim @@ -0,0 +1,48 @@ +- if Rails.application.config.development_toolbar + = modalbox 'development-toolbar' do + = form_tag development_toolbar_update_settings_path, authenticity_token: true do + .modal-header + h3= "Toolbar" + + .inner + .col.features + h4 + = "Features" + .toggles + = link_to 'all', '#', data: {mask: 'features', val: true} + = link_to 'none', '#', data: {mask: 'features', val: false} + ul + - Rails.application.config.development_toolbar.available_features.sort.each do |feature| + li + = hidden_field_tag "features[#{feature}]", false, id: "" + = check_box_tag "features[#{feature}]", true, has_feature?(feature) + = label :features, feature + .col.permissions + h4 + = "Permissions" + .toggles + = link_to 'all', '#', data: {mask: 'permissions', val: true} + = link_to 'none', '#', data: {mask: 'permissions', val: false} + - model = "" + - Rails.application.config.development_toolbar.available_permissions.sort.each do |permission| + - if permission.split('.').first != model + - model = permission.split('.').first + + h5 + = model + .toggles + = link_to 'all', '#', data: {mask: "permissions[#{model}", val: true} + = link_to 'none', '#', data: {mask: "permissions[#{model}", val: false} + - {actions.getSelected(vehicleJourneys).length} course(s) sélectionnée(s) - + {I18n.t('vehicle_journeys.vehicle_journeys_matrix.selected_journeys', {count: actions.getSelected(vehicleJourneys).length})} + ) } diff --git a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js index bcfd4eb41..d3c01f154 100644 --- a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js @@ -59,7 +59,7 @@ export default class EditVehicleJourney extends Component {
-

Informations

+

{I18n.t('vehicle_journeys.form.infos')}

×
@@ -69,7 +69,7 @@ export default class EditVehicleJourney extends Component {
- +
- +
- +
- +
- +
- +
- + +
- +
) } } diff --git a/config/locales/vehicle_journeys.en.yml b/config/locales/vehicle_journeys.en.yml index a1f20a7e8..0c8a75b0c 100644 --- a/config/locales/vehicle_journeys.en.yml +++ b/config/locales/vehicle_journeys.en.yml @@ -1,11 +1,14 @@ en: vehicle_journeys: vehicle_journeys_matrix: - line_routes: "Line's routes" + cancel_selection: "Cancel Selection" fetching_error: "There has been a problem fetching the data. Please reload the page to try again." - show_timetable: 'Show calendar' - show_purchase_window: 'Show the purchase window' + line_routes: "Line's routes" modal_confirm: 'Do you want to save mofications before moving on to the next page ?' + pagination: "Schedules %{minVJ} to %{maxVJ} over %{total}" + selected_journeys: "%{count} selected journeys" + show_purchase_window: 'Show the purchase window' + show_timetable: 'Show calendar' vehicle_journey: title_stopless: "Vehicle journey %{name}" title: "Vehicle journey leaving from %{stop} at %{time}" @@ -29,52 +32,54 @@ en: title_stopless: "Update vehicle journey %{name}" title: "Update vehicle journey %{name} leaving from %{stop} at %{time}" form: - stop_title: "Stop" - departure: "Departure" + arrival_at: "Arrival at" arrival: "Arrival" departure_at: "Departure at" - arrival_at: "Arrival at" - to_arrivals: "Copy departures to arrivals" - to_departures: "Copy arrivals to departures" - time_tables: "Associated calendars to vehicle journey" - slide: "Shift" - slide_title: "Shift all vehicle passing times" - set: "Set" - to: "at" + departure: "Departure" departure_range: label: Journey departure range start: Start end: End - show_journeys_without_schedule: "Show journeys without schedule" + infos: Informations + set: "Set" + show_arrival_time: "Show and edit arrival times" show_journeys_with_calendar: "Show journeys with calendar" - slide_departure: "departure time at first stop" + show_journeys_without_schedule: "Show journeys without schedule" slide_arrival: "arrival time at first stop" - submit_timed: "Create vehicle journey" + slide_departure: "departure time at first stop" + slide_title: "Shift all vehicle passing times" + slide: "Shift" + stop_title: "Stop" + submit_frequency_edit: "Edit frequency vehicle journey" submit_frequency: "Create frequency vehicle journey" submit_timed_edit: "Edit vehicle journey" - submit_frequency_edit: "Edit frequency vehicle journey" + submit_timed: "Create vehicle journey" + time_tables: "Associated calendars to vehicle journey" + to_arrivals: "Copy departures to arrivals" + to_departures: "Copy arrivals to departures" + to: "at" timeless: title: "Timeless vehicle journeys" vehicle_journeys: "Vehicle journeys with times at stop" vehicles_list: "Vehicle journeys list" show: - title: "Vehicle Journey %{vehicle journey}" - stop_title: "Stop" - departure: "Departure" arrival: "Arrival" - time_tables: "Calendars list" bounding: "From %{start} to %{end}" - translation_form: "Vehicle journey translations" + departure: "Departure" journey_frequencies: "Timeband" + stop_title: "Stop" + time_tables: "Calendars list" + title: "Vehicle Journey %{vehicle journey}" + translation_form: "Vehicle journey translations" index: - title: "Vehicle journeys on route %{route}" - vehicle_journeys: "Departure's times" - selection: "Filter on" - selection_all: "All" + advanced_search: "Advanced Search" select_journey_patterns: "Select journey pattern" select_time_tables: "Enter a timetable" + selection_all: "All" + selection: "Filter on" time_range: "Departure time threshold" - advanced_search: "Advanced Search" + title: "Vehicle journeys on route %{route}" + vehicle_journeys: "Departure's times" time_filter: time_range_filter: "Filter" sidebar: @@ -90,43 +95,47 @@ en: other: "vehicle journeys" attributes: vehicle_journey: - line: "Line" - route: "Route" - journey_pattern: "Journey Pattern" - journey_pattern_id: "Pattern ID" - time_tables: "Calendars" - time_slot: "Time Slot" - company: "Company" - number: "Number" + accessible: "Accessible" + arrival_time: "Arrival" + checksum: "Checksum" comment: "Comments" - status_value: "Status Value" - transport_mode: "Transport Mode" - mobility_restricted_suitability: "PRM accessibility" + company: "Company" + created_at: Created at + creator_id: "Created by" + departure_time: "Departure" + facility: "Facility" flexible_service: "On demond transportation" - unspecified_mrs: "Not specified" - accessible: "Accessible" + footnote_ids: "Footnotes" + id: "Journey ID" + journey_frequency_ids: "Timeband" + journey_name: "Name of the journey" + journey_pattern_id: "Pattern ID" + journey_pattern: "Journey Pattern" + line: "Line" + mobility_restricted_suitability: "PRM accessibility" + name: "Journey Name" not_accessible: "Not accessible" - unspecified_fs: "Not specified" + number: "Number" + object_version: "Version" + objectid: "Neptune identifier" on_demand_fs: "On demand service" - regular_fs: "Regular service" - published_journey_name: "Published Name" published_journey_identifier: "Published Identifier" - facility: "Facility" - vehicle_type_identifier: "Vehicle Type Identifier" + published_journey_name: "Published Name" + purchase_window: "Purchase availability" + regular_fs: "Regular service" + route: "Route" + status_value: "Status Value" + time_slot: "Time Slot" time_table_ids: "Calendar list" - vehicle_journey_at_stop_ids: "Time list" - journey_frequency_ids: "Timeband" - objectid: "Neptune identifier" - object_version: "Version" - created_at: Created at + time_tables: "Calendars" + train_number: "Train number" + transport_mode: "Transport Mode" + transport_submode: "Transport Submode" + unspecified_fs: "Not specified" + unspecified_mrs: "Not specified" updated_at: Updated at - creator_id: "Created by" - footnote_ids: "Footnotes" - departure_time: "Departure" - arrival_time: "Arrival" - purchase_window: "Purchase availability" - name: "Journey Name" - id: "Journey ID" + vehicle_journey_at_stop_ids: "Time list" + vehicle_type_identifier: "Vehicle Type Identifier" errors: models: vehicle_journey: diff --git a/config/locales/vehicle_journeys.fr.yml b/config/locales/vehicle_journeys.fr.yml index be5be2382..6bf167234 100644 --- a/config/locales/vehicle_journeys.fr.yml +++ b/config/locales/vehicle_journeys.fr.yml @@ -1,11 +1,14 @@ fr: vehicle_journeys: vehicle_journeys_matrix: - line_routes: "Séquences d'arrêts de la ligne" + cancel_selection: "Annuler la sélection" fetching_error: "La récupération des missions a rencontré un problème. Rechargez la page pour tenter de corriger le problème." - show_timetable: 'Voir le calendrier' - show_purchase_window: 'Voir le calendrier commercial' + line_routes: "Séquences d'arrêts de la ligne" modal_confirm: 'Voulez-vous valider vos modifications avant de changer de page?' + pagination: "Liste des horaires %{minVJ} à %{maxVJ} sur %{total}" + selected_journeys: "%{count} course(s) sélectionnée(s)" + show_purchase_window: 'Voir le calendrier commercial' + show_timetable: 'Voir le calendrier' vehicle_journey: title_stopless: "Course %{name}" title: "Course partant de %{stop} à %{time}" @@ -29,53 +32,55 @@ fr: title_stopless: "Editer la course %{name}" title: "Editer la course partant de %{stop} à %{time}" form: - stop_title: "Arrêt" - departure: "Départ" - departure_at: "Départ à" - arrival: "Arrivée" arrival_at: "Arrivée à" - to_arrivals: "Copie départs vers arrivées" - to_arrivals: "Copie départs vers arrivées" - to_departures: "Copie arrivées vers départs" - time_tables: "Calendriers associés à la course" - slide: "Décaler" - slide_title: "Décaler l'ensemble des horaires de course" - set: "Fixer" - to: "à" + arrival: "Arrivée" + departure_at: "Départ à" + departure: "Départ" departure_range: label: Plage horaire au départ de la course start: Début end: Fin - show_journeys_without_schedule: "Afficher les courses sans horaires" + infos: Informations + set: "Fixer" + show_arrival_time: "Afficher et éditer les horaires d'arrivée" show_journeys_with_calendar: "Afficher les courses avec calendrier" - slide_departure: "horaire de départ au 1° arrêt à" + show_journeys_without_schedule: "Afficher les courses sans horaires" slide_arrival: "horaire d'arrivée au 1° arrêt à" - submit_timed: "Créer course" + slide_departure: "horaire de départ au 1° arrêt à" + slide_title: "Décaler l'ensemble des horaires de course" + slide: "Décaler" + stop_title: "Arrêt" + submit_frequency_edit: "Editer course en fréquence" submit_frequency: "Créer course en fréquence" submit_timed_edit: "Editer course" - submit_frequency_edit: "Editer course en fréquence" + submit_timed: "Créer course" + time_tables: "Calendriers associés à la course" + to_arrivals: "Copie départs vers arrivées" + to_arrivals: "Copie départs vers arrivées" + to_departures: "Copie arrivées vers départs" + to: "à" timeless: title: "Courses sans horaire" vehicle_journeys: "Courses ayant des horaires" vehicles_list: "Liste des courses" show: - title: "Course au départ de %{stop} à %{time} sur la séquence %{route}" - stop_title: "Arrêt" - departure: "Départ" arrival: "Arrivée" - time_tables: "Liste des calendriers" bounding: "De %{start} à %{end}" - translation_form: "Cloner la course" + departure: "Départ" journey_frequencies: "Créneau horaire" + stop_title: "Arrêt" + time_tables: "Liste des calendriers" + title: "Course au départ de %{stop} à %{time} sur la séquence %{route}" + translation_form: "Cloner la course" index: - title: "Horaires de '%{route}'" - vehicle_journeys: "Horaires de départ aux arrêts" - selection: "Filtrer sur" - selection_all: "Tous" + advanced_search: "Recherche avancée" select_journey_patterns: "Sélectionner une mission" select_time_tables: "Saisir un calendrier" + selection_all: "Tous" + selection: "Filtrer sur" time_range: "Seuil horaire au départ" - advanced_search: "Recherche avancée" + title: "Horaires de '%{route}'" + vehicle_journeys: "Horaires de départ aux arrêts" time_filter: time_range_filter: "Filtrer" sidebar: @@ -91,43 +96,47 @@ fr: other: "courses" attributes: vehicle_journey: - line: "Ligne" - route: "Séquence d'arrêt" - journey_pattern: "Mission" - journey_pattern_id: "ID Mission" - time_tables: "Calendriers" - time_slot: "Fréquence" - company: "Transporteur" - number: "Numéro" + accessible: "Accessible" + arrival_time: "Arrivée" + checksum: "Signature métier" comment: "Commentaires" - status_value: "Etat de trafic" - transport_mode: "Mode de transport" - mobility_restricted_suitability: "Accessibilité PMR" + company: "Transporteur" + created_at: "Créé le" + creator_id: "Créé par" + departure_time: "Départ" + facility: "Equipement" flexible_service: "Transport à la demande" - unspecified_mrs: "Non spécifié" - accessible: "Accessible" + footnote_ids: "Notes de bas de page" + id: "ID Course" + journey_frequency_ids: "Créneau horaire" + journey_name: "Nom de la course" + journey_pattern_id: "ID Mission" + journey_pattern: "Mission" + line: "Ligne" + mobility_restricted_suitability: "Accessibilité PMR" + name: "Nom Course" not_accessible: "Non accessible" - unspecified_fs: "Non spécifié" + number: "Numéro" + object_version: "Version" + objectid: "Identifiant Neptune" on_demand_fs: "Service à la demande" - regular_fs: "Service régulier" - published_journey_name: "Nom public" published_journey_identifier: "Identifiant public" - facility: "Equipement" - vehicle_type_identifier: "Type d'identifiant du véhicule" + published_journey_name: "Nom public" + purchase_window: "Disponibilité commerciale" + regular_fs: "Service régulier" + route: "Séquence d'arrêt" + status_value: "Etat de trafic" + time_slot: "Fréquence" time_table_ids: "Liste des calendriers" - vehicle_journey_at_stop_ids: "Liste des horaires" - journey_frequency_ids: "Créneau horaire" - objectid: "Identifiant Neptune" - object_version: "Version" - created_at: "Créé le" + time_tables: "Calendriers" + train_number: "Numéro de train" + transport_mode: "Mode de transport" + transport_submode: "Sous-mode de transport" + unspecified_fs: "Non spécifié" + unspecified_mrs: "Non spécifié" updated_at: "Edité le" - creator_id: "Créé par" - footnote_ids: "Notes de bas de page" - departure_time: "Départ" - arrival_time: "Arrivée" - purchase_window: "Disponibilité commerciale" - name: "Nom Course" - id: "ID Course" + vehicle_journey_at_stop_ids: "Liste des horaires" + vehicle_type_identifier: "Type d'identifiant du véhicule" errors: models: vehicle_journey: -- cgit v1.2.3 From 7c0aee14eea2c560c1645dd49b54f1027ff8827c Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 7 Feb 2018 15:30:34 +0100 Subject: Update stif-reflex-api gem. Refs #5869 --- Gemfile.lock | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ffa63b535..805ee460d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,10 +16,11 @@ GIT GIT remote: git@github.com:af83/stif-reflex-api.git - revision: 7c517b98c3900c9bb0b81dd0ccab97f8e8f5f249 + revision: 7edaeddd971a1ed366bf6def1513bf8808ab2d1d specs: - reflex (0.0.1) - nokogiri (~> 1.6) + reflex (0.0.2) + nokogiri (>= 1.7.2) + ruby-filemagic GIT remote: https://github.com/af83/language_engine.git @@ -332,7 +333,7 @@ GEM net-ssh-gateway (2.0.0) net-ssh (>= 4.0.0) newrelic_rpm (4.0.0.332) - nokogiri (1.8.1) + nokogiri (1.8.2) mini_portile2 (~> 2.3.0) open4 (1.3.4) orm_adapter (0.5.0) @@ -463,6 +464,7 @@ GEM rspec-mocks (~> 3.5.0) rspec-support (~> 3.5.0) rspec-support (3.5.0) + ruby-filemagic (0.7.2) ruby-graphviz (1.2.3) rubycas-client (2.3.9) activesupport -- cgit v1.2.3 From 849f552b796118b4ab7cabbbda8b9ce1b5d4bc54 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 26 Jan 2018 16:17:22 +0100 Subject: Refs #5750 @1h; Add a "kind" attribute to StopAreas This determines if the StopArea is commercial or not The useless fields are hidden in the form for the non-commercials ones --- db/schema.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/db/schema.rb b/db/schema.rb index 5ff0a9326..fc308ecba 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -15,9 +15,10 @@ ActiveRecord::Schema.define(version: 20180129141656) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - enable_extension "postgis" enable_extension "hstore" + enable_extension "postgis" enable_extension "unaccent" + enable_extension "objectid" create_table "access_links", id: :bigserial, force: :cascade do |t| t.integer "access_point_id", limit: 8 @@ -119,6 +120,7 @@ ActiveRecord::Schema.define(version: 20180129141656) do t.datetime "updated_at" t.date "end_date" t.string "date_type" + t.string "mode" end add_index "clean_ups", ["referential_id"], name: "index_clean_ups_on_referential_id", using: :btree -- cgit v1.2.3 From 7710cae037c7e76b2648c751383909805d42c7e8 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 24 Jan 2018 07:28:57 +0100 Subject: Refs #5682; Add application_days field to calendars --- spec/models/chouette/time_table_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index a501f234a..856188f58 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -926,7 +926,7 @@ end end end end - + describe "#validity_out_between?" do let(:empty_tm) {build(:time_table)} it "should be false if empty calendar" do -- cgit v1.2.3 From f4bc83da367bd5823b75d4b2fac6807258349972 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 24 Jan 2018 16:56:16 +0100 Subject: Refs #5682 @3h; Use same UI as for timetables --- app/controllers/calendars_controller.rb | 26 ++++++++++++++++ app/models/concerns/timetable_support.rb | 3 +- app/views/calendars/_form.html.slim | 53 -------------------------------- 3 files changed, 28 insertions(+), 54 deletions(-) delete mode 100644 app/views/calendars/_form.html.slim diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index a9f792bd0..d06652569 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -55,6 +55,32 @@ class CalendarsController < ChouetteController end end + def month + @date = params['date'] ? Date.parse(params['date']) : Date.today + @calendar = resource + end + + def create + create! do + if @calendar.valid? && has_feature?('application_days_on_calendars') + redirect_to([:edit, @calendar]) + return + end + end + end + + def update + if params[:calendar] + super + else + state = JSON.parse request.raw_post + resource.state_update state + respond_to do |format| + format.json { render json: state, status: state['errors'] ? :unprocessable_entity : :ok } + end + end + end + private def decorate_calendars(calendars) diff --git a/app/models/concerns/timetable_support.rb b/app/models/concerns/timetable_support.rb index d2bc99d51..8c49723fe 100644 --- a/app/models/concerns/timetable_support.rb +++ b/app/models/concerns/timetable_support.rb @@ -100,7 +100,8 @@ module TimetableSupport period.period_start = Date.parse(item['period_start']) period.period_end = Date.parse(item['period_end']) - period.save if period.is_a?(ActiveRecord::Base) && period.changed? + + period.save if period === ActiveRecord::Base && period.changed? item['id'] = period.id end diff --git a/app/views/calendars/_form.html.slim b/app/views/calendars/_form.html.slim deleted file mode 100644 index bf9f4f3a7..000000000 --- a/app/views/calendars/_form.html.slim +++ /dev/null @@ -1,53 +0,0 @@ -= simple_form_for [@workgroup, @calendar], html: { class: 'form-horizontal', id: 'calendar_form' }, wrapper: :horizontal_form do |f| - .row - .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 col-xs-5 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 col-xs-7'} - - .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' -- cgit v1.2.3 From 0fa923fa3ae8b85244be727d7386aaf1b1a69f95 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Thu, 1 Feb 2018 22:26:00 +0100 Subject: Define @year in CalendarsController as expected by view. Refs #5682 --- app/controllers/calendars_controller.rb | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index d06652569..585851f00 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -10,10 +10,6 @@ class CalendarsController < ChouetteController belongs_to :workgroup - belongs_to :workgroup - - belongs_to :workgroup - def index index! do @calendars = decorate_calendars(@calendars) @@ -55,32 +51,6 @@ class CalendarsController < ChouetteController end end - def month - @date = params['date'] ? Date.parse(params['date']) : Date.today - @calendar = resource - end - - def create - create! do - if @calendar.valid? && has_feature?('application_days_on_calendars') - redirect_to([:edit, @calendar]) - return - end - end - end - - def update - if params[:calendar] - super - else - state = JSON.parse request.raw_post - resource.state_update state - respond_to do |format| - format.json { render json: state, status: state['errors'] ? :unprocessable_entity : :ok } - end - end - end - private def decorate_calendars(calendars) -- cgit v1.2.3 From 883813fcadf64da988bd3337bb0f86039f5f2774 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 2 Feb 2018 14:58:50 +0100 Subject: Refs #5417; Update parents checksum when children are created or updated --- spec/models/chouette/time_table_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 856188f58..a501f234a 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -926,7 +926,7 @@ end end end end - + describe "#validity_out_between?" do let(:empty_tm) {build(:time_table)} it "should be false if empty calendar" do -- cgit v1.2.3 From 60176816df7bf7291c1df23c52809816d6a8057f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 2 Feb 2018 17:44:32 +0100 Subject: StopArea: Don't auto-initialise a value for the `kind` attribute We were getting this error on `ReferentialVehicleJourneys#index`: Feb 1 17:48:32 chouette-dev rails/chouette[18900]: Started GET "/referentials/9/vehicle_journeys" for 172.28.10.14 at 2018-02-01 17:48:32 +0100 Feb 1 17:48:32 chouette-dev rails/chouette[18900]: Processing by ReferentialVehicleJourneysController#index as HTML Feb 1 17:48:32 chouette-dev rails/chouette[18900]: Parameters: {"referential_id"=>"9"} Feb 1 17:48:32 chouette-dev rails/chouette[18900]: locale set to :fr Feb 1 17:48:32 chouette-dev rails/chouette[18900]: Rendered referential_vehicle_journeys/_filters.html.slim (37.0ms) Feb 1 17:48:32 chouette-dev rails/chouette[18900]: Rendered referential_vehicle_journeys/index.html.slim within layouts/application (54.3ms) Feb 1 17:48:32 chouette-dev rails/chouette[18900]: Completed 500 Internal Server Error in 73ms (ActiveRecord: 10.4ms) Feb 1 17:48:32 chouette-dev rails/chouette[18900]: ActionView::Template::Error (missing attribute: kind):#012 23: = f.input :published_journey_name_lteq, label: false, wrapper_html: { class: 'w45'}#012 24: .form-group.togglable#012 25: = f.label Chouette::StopArea.model_name.human.pluralize, required: false, class: 'control-label'#012 26: = f.input :stop_area_ids, collection: @all_stop_areas.select(:id, :name).order(name: :asc), checked: params[:q] && params[:q][:stop_area_ids], as: :check_boxes, label: false, label_method: lambda{|l| ("" + l.name + "").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}, multiple: true#012 27: .form-group.togglable#012 28: = f.label Chouette::VehicleJourney.human_attribute_name(:purchase_window), class: 'control-label'#012 29: .filter_menu#012 app/models/chouette/stop_area.rb:51:in `block in '#012 app/views/referential_vehicle_journeys/_filters.html.slim:26:in `block in _app_views_referential_vehicle_journeys__filters_html_slim__692539656386688985_47285414929500'#012 app/views/referential_vehicle_journeys/_filters.html.slim:1:in `_app_views_referential_vehicle_journeys__filters_html_slim__692539656386688985_47285414929500'#012 app/views/referential_vehicle_journeys/index.html.slim:9:in `_app_views_referential_vehicle_journeys_index_html_slim___336434325333090796_47285419865660' Feb 1 17:48:32 chouette-dev rails/chouette[18900]: Processing by ErrorsController#server_error as HTML Feb 1 17:48:32 chouette-dev rails/chouette[18900]: Parameters: {"referential_id"=>"9"} Feb 1 17:48:32 chouette-dev rails/chouette[18900]: locale set to :fr or, this one locally which is easier to read: ActiveModel::MissingAttributeError in ReferentialVehicleJourneys#index Showing .../stif-boiv/app/views/referential_vehicle_journeys/_filters.html.slim where line #44 raised: missing attribute: kind Extracted source (around line #51): after_initialize do > self.kind ||= :commercial end def self.nullable_attributes Trace of template inclusion: app/views/referential_vehicle_journeys/index.html.slim Rails.root: .../stif-boiv Application Trace | Framework Trace | Full Trace app/models/chouette/stop_area.rb:51:in `block in ' app/views/referential_vehicle_journeys/_filters.html.slim:44:in `block in _app_views_referential_vehicle_journeys__filters_html_slim___131528464712770693_70134715599760' app/views/referential_vehicle_journeys/_filters.html.slim:1:in `_app_views_referential_vehicle_journeys__filters_html_slim___131528464712770693_70134715599760' app/views/referential_vehicle_journeys/index.html.slim:9:in `_app_views_referential_vehicle_journeys_index_html_slim__3124451149445015007_70134715309040' This is because on `ReferentialVehicleJourneys#index`, the StopArea filter makes this query: @all_stop_areas.select(:id, :name).order(name: :asc) Alban added a temporary fix for the release in c2bc391ee91cac70e726d188be97dd2323df0df2. After a discussion with Luc, he said we only want the initial value on the `#new` form, and we decided to take this out of the model and put it in the form template instead. Here, when a new `StopArea` is created, `:commercial` will be pre-filled in the `kind` field by default. On the `#edit` page, it should show the existing value of `kind` but not permit editing. Refs #5817 --- app/models/chouette/stop_area.rb | 4 ---- app/views/stop_areas/_form.html.slim | 11 +++++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index cf2afbc73..bb8747faa 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -47,10 +47,6 @@ module Chouette validate :parent_area_type_must_be_greater validate :area_type_of_right_kind - after_initialize do - self.kind ||= :commercial - end - def self.nullable_attributes [:registration_number, :street_name, :country_code, :fare_code, :nearest_topic_name, :comment, :long_lat_type, :zip_code, :city_name, :url, :time_zone] diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index 9897a27ac..bb1fbe1e9 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -12,8 +12,15 @@ .col-sm-9.col-xs-7 - f.object.localized_names.each do |k, v| .col-md-6= f.input "localized_names[#{k}]", input_html: {value: v}, label: label_for_country(k) - - = f.input :kind, as: :radio_buttons, checked: @stop_area.kind, :input_html => {:disabled => !@stop_area.new_record?}, :include_blank => false, item_wrapper_class: 'radio-inline', wrapper: :horizontal_form, disabled: !@stop_area.new_record? + + = f.input :kind, + as: :radio_buttons, + checked: @stop_area.new_record? ? :commercial : @stop_area.kind, + input_html: { disabled: !@stop_area.new_record? }, + include_blank: false, + item_wrapper_class: 'radio-inline', + wrapper: :horizontal_form, + disabled: !@stop_area.new_record? .slave data-master="[name='stop_area[kind]']" data-value="commercial" = f.input :parent_id, as: :select, :collection => [f.object.parent_id], input_html: { data: { select2_ajax: 'true', url: autocomplete_stop_area_referential_stop_areas_path(@stop_area_referential), initvalue: {id: f.object.parent_id, text: f.object.parent.try(:full_name)}}} - %i(non_commercial commercial).each do |kind| -- cgit v1.2.3 From a5c48d95d78cf611985b0f3dc0d36c070d9f601e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 2 Feb 2018 17:57:01 +0100 Subject: Revert "Prevent problem with StopArea#kind. Refs #5817" This reverts commit c2bc391ee91cac70e726d188be97dd2323df0df2. Thanks to 76abdbd66c16e6e1233685a5fa28a42cba5580d9, this temporary fix can be reverted. We don't actually need `kind` selected here, it was only added to appease the auto-initialisation of `kind` in `StopArea`. Now that we don't set a default value for `kind` on initialisation, we can remove it from this `select`. --- app/views/referential_vehicle_journeys/_filters.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/referential_vehicle_journeys/_filters.html.slim b/app/views/referential_vehicle_journeys/_filters.html.slim index bd8245e39..3104e3a71 100644 --- a/app/views/referential_vehicle_journeys/_filters.html.slim +++ b/app/views/referential_vehicle_journeys/_filters.html.slim @@ -42,7 +42,7 @@ = f.input :published_journey_name_lteq, label: false, wrapper_html: { class: 'w45'} .form-group.togglable class=filter_item_class(params[:q], :stop_area_ids) = f.label Chouette::StopArea.model_name.human.pluralize, required: false, class: 'control-label' - = f.input :stop_area_ids, collection: @all_stop_areas.select(:id, :name, :kind).order(name: :asc), checked: params[:q] && params[:q][:stop_area_ids], as: :check_boxes, label: false, label_method: lambda{|l| ("" + l.name + "").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}, multiple: true + = f.input :stop_area_ids, collection: @all_stop_areas.select(:id, :name).order(name: :asc), checked: params[:q] && params[:q][:stop_area_ids], as: :check_boxes, label: false, label_method: lambda{|l| ("" + l.name + "").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}, multiple: true .form-group.togglable class=filter_item_class(params[:q], :purchase_window) = f.label Chouette::VehicleJourney.human_attribute_name(:purchase_window), class: 'control-label' .filter_menu -- cgit v1.2.3 From 93ece87723191a33a830650cfa8c6cbc75470279 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 2 Feb 2018 18:14:03 +0100 Subject: Set all existing `StopArea`s with nil `kind`s to `:commercial` The other migration for this in `db/migrate/20180126134944_add_kind_to_stop_areas.rb` didn't handle `kind IS NULL`. Since all the `kind`s were initialised to NULL when the column was created, the `where` query didn't select any stop areas because it was looking for those with some varchar value, and thus it wasn't able to update any. This ensures our existing records all have a `kind` in case we end up using the field in a template at some point and our old data bugs out. Refs #5817 --- ...9_set_stop_areas_kind_to_commercial_on_existing_records.rb | 11 +++++++++++ db/schema.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20180202170009_set_stop_areas_kind_to_commercial_on_existing_records.rb diff --git a/db/migrate/20180202170009_set_stop_areas_kind_to_commercial_on_existing_records.rb b/db/migrate/20180202170009_set_stop_areas_kind_to_commercial_on_existing_records.rb new file mode 100644 index 000000000..6c6f6370e --- /dev/null +++ b/db/migrate/20180202170009_set_stop_areas_kind_to_commercial_on_existing_records.rb @@ -0,0 +1,11 @@ +class SetStopAreasKindToCommercialOnExistingRecords < ActiveRecord::Migration + def up + Chouette::StopArea + .where('kind != ? or kind is null', :non_commercial) + .update_all(kind: :commercial) + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/schema.rb b/db/schema.rb index fc308ecba..5474f9161 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: 20180129141656) do +ActiveRecord::Schema.define(version: 20180202170009) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" -- cgit v1.2.3 From 187581aae79a28c03d4f26b5a28c81c9b63b0469 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Thu, 1 Feb 2018 15:10:51 +0100 Subject: Begin workbench output show refactoring to use stif guidelines --- app/views/workbench_outputs/show.html.slim | 6 +----- config/locales/workbench_outputs.en.yml | 7 +++++++ config/locales/workbench_outputs.fr.yml | 7 +++++++ config/locales/workbenches.fr.yml | 4 ---- 4 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 config/locales/workbench_outputs.en.yml create mode 100644 config/locales/workbench_outputs.fr.yml diff --git a/app/views/workbench_outputs/show.html.slim b/app/views/workbench_outputs/show.html.slim index 4f71fb7ef..a9e106dbb 100644 --- a/app/views/workbench_outputs/show.html.slim +++ b/app/views/workbench_outputs/show.html.slim @@ -26,11 +26,7 @@ end \ ), \ TableBuilderHelper::Column.new( \ - key: :started_at, \ - attribute: Proc.new { |n| l(n.started_at, format: :long) if n.started_at }, \ - ), \ - TableBuilderHelper::Column.new( \ - key: :ended_at, \ + name: t(".table_headers.ended_at"), \ attribute: Proc.new { |n| l(n.ended_at, format: :long) if n.ended_at }, \ ), \ TableBuilderHelper::Column.new( \ diff --git a/config/locales/workbench_outputs.en.yml b/config/locales/workbench_outputs.en.yml new file mode 100644 index 000000000..05cf52d0e --- /dev/null +++ b/config/locales/workbench_outputs.en.yml @@ -0,0 +1,7 @@ +en: + workbench_outputs: + show: + title: "Finalisations de l'offre" + see_current_output: "Voir l'Offre actuelle" + table_headers: + ended_at: "Offer created date" diff --git a/config/locales/workbench_outputs.fr.yml b/config/locales/workbench_outputs.fr.yml new file mode 100644 index 000000000..560888c54 --- /dev/null +++ b/config/locales/workbench_outputs.fr.yml @@ -0,0 +1,7 @@ +fr: + workbench_outputs: + show: + title: "Finalisations de l'offre" + see_current_output: "Voir l'Offre actuelle" + table_headers: + ended_at: "Date et heure de création de l'offre" diff --git a/config/locales/workbenches.fr.yml b/config/locales/workbenches.fr.yml index 58fc8e416..e7a392e66 100644 --- a/config/locales/workbenches.fr.yml +++ b/config/locales/workbenches.fr.yml @@ -8,10 +8,6 @@ fr: other: "#{count} jeux de données dans cet espace de travail" actions: show_output: "Finaliser l'Offre" - workbench_outputs: - show: - title: "Finalisations de l'offre" - see_current_output: "Voir l'Offre actuelle" activerecord: models: workbench: -- cgit v1.2.3 From 308bf4338b3e79016e353555ee3677c917c71805 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Tue, 23 Jan 2018 22:46:16 -0800 Subject: First draft for including calendars into workgroup for having appropriate scoping --- app/helpers/table_builder_helper/url.rb | 2 +- db/schema.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb index 0e3dce0aa..57172301c 100644 --- a/app/helpers/table_builder_helper/url.rb +++ b/app/helpers/table_builder_helper/url.rb @@ -3,7 +3,7 @@ module TableBuilderHelper def self.polymorphic_url_parts(item, referential, workgroup) polymorph_url = [] - unless item.is_a?(Calendar) || item.is_a?(Referential) || item.is_a?(ComplianceControlSet) + unless item.is_a?(Referential) || item.is_a?(ComplianceControlSet) if referential polymorph_url << referential polymorph_url << item.line if item.respond_to? :line diff --git a/db/schema.rb b/db/schema.rb index 5474f9161..2b94f655b 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: 20180202170009) do +ActiveRecord::Schema.define(version: 20180123174450) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -94,6 +94,7 @@ ActiveRecord::Schema.define(version: 20180202170009) do t.integer "workgroup_id", limit: 8 t.integer "int_day_types" t.date "excluded_dates", array: true + t.integer "workgroup_id", limit: 8 end add_index "calendars", ["organisation_id"], name: "index_calendars_on_organisation_id", using: :btree -- cgit v1.2.3 From 4792234e05ca99012af9dae0858664a131c45c4f Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 24 Jan 2018 19:55:56 -0800 Subject: update calendar build_links for table builder --- app/controllers/calendars_controller.rb | 32 +++++++++++++++++++++++++++ app/controllers/concerns/workgroup_support.rb | 12 ++++++++++ app/helpers/table_builder_helper/url.rb | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 app/controllers/concerns/workgroup_support.rb diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 585851f00..17297c758 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -1,4 +1,5 @@ class CalendarsController < ChouetteController + include WorkgroupSupport include PolicyChecker include TimeTablesHelper @@ -54,10 +55,18 @@ class CalendarsController < ChouetteController private def decorate_calendars(calendars) +<<<<<<< HEAD CalendarDecorator.decorate( calendars, context: { workgroup: workgroup +======= + ModelDecorator.decorate( + calendars, + with: CalendarDecorator, + context: { + workgroup: current_workgroup +>>>>>>> update calendar build_links for table builder } ) end @@ -82,17 +91,30 @@ class CalendarsController < ChouetteController helper_method :workgroup def resource +<<<<<<< HEAD @calendar ||= workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true).find_by_id(params[:id]) +======= +<<<<<<< HEAD + @calendar = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).find_by_id(params[:id]).decorate +======= + @calendar = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id).find_by_id(params[:id], true, @workgroup.id) +>>>>>>> update calendar build_links for table builder +>>>>>>> update calendar build_links for table builder end def build_resource super.tap do |calendar| +<<<<<<< HEAD calendar.workgroup = workgroup +======= + calendar.workgroup = current_workgroup +>>>>>>> update calendar build_links for table builder calendar.organisation = current_organisation end end def collection +<<<<<<< HEAD @calendars ||= begin scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true) scope = shared_scope(scope) @@ -101,6 +123,16 @@ class CalendarsController < ChouetteController calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction calendars = calendars.paginate(page: params[:page]) end +======= + return @calendars if @calendars + scope = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, @workgroup.id) + scope = shared_scope(scope) + @q = scope.ransack(params[:q]) + + calendars = @q.result + calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction + @calendars = calendars.paginate(page: params[:page]) +>>>>>>> update calendar build_links for table builder end def ransack_contains_date diff --git a/app/controllers/concerns/workgroup_support.rb b/app/controllers/concerns/workgroup_support.rb new file mode 100644 index 000000000..a3b49bb12 --- /dev/null +++ b/app/controllers/concerns/workgroup_support.rb @@ -0,0 +1,12 @@ +module WorkgroupSupport + extend ActiveSupport::Concern + + included do + before_action :find_workgroup + end + + def find_workgroup + @workgroup ||= Workgroup.find params[:workgroup_id] + end + +end diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb index 57172301c..0e3dce0aa 100644 --- a/app/helpers/table_builder_helper/url.rb +++ b/app/helpers/table_builder_helper/url.rb @@ -3,7 +3,7 @@ module TableBuilderHelper def self.polymorphic_url_parts(item, referential, workgroup) polymorph_url = [] - unless item.is_a?(Referential) || item.is_a?(ComplianceControlSet) + unless item.is_a?(Calendar) || item.is_a?(Referential) || item.is_a?(ComplianceControlSet) if referential polymorph_url << referential polymorph_url << item.line if item.respond_to? :line -- cgit v1.2.3 From 9ae8cd98bc3a41dbecd725176bca13e6cdcc92f7 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Tue, 30 Jan 2018 23:07:07 -0800 Subject: Make some changes to avoid unnacessaty lines of code --- app/controllers/calendars_controller.rb | 36 ++------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 17297c758..e0dd68405 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -1,5 +1,4 @@ class CalendarsController < ChouetteController - include WorkgroupSupport include PolicyChecker include TimeTablesHelper @@ -8,7 +7,7 @@ class CalendarsController < ChouetteController respond_to :html respond_to :json, only: :show respond_to :js, only: :index - + belongs_to :workgroup def index @@ -55,18 +54,10 @@ class CalendarsController < ChouetteController private def decorate_calendars(calendars) -<<<<<<< HEAD CalendarDecorator.decorate( calendars, context: { workgroup: workgroup -======= - ModelDecorator.decorate( - calendars, - with: CalendarDecorator, - context: { - workgroup: current_workgroup ->>>>>>> update calendar build_links for table builder } ) end @@ -91,30 +82,17 @@ class CalendarsController < ChouetteController helper_method :workgroup def resource -<<<<<<< HEAD @calendar ||= workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true).find_by_id(params[:id]) -======= -<<<<<<< HEAD - @calendar = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).find_by_id(params[:id]).decorate -======= - @calendar = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id).find_by_id(params[:id], true, @workgroup.id) ->>>>>>> update calendar build_links for table builder ->>>>>>> update calendar build_links for table builder end def build_resource super.tap do |calendar| -<<<<<<< HEAD calendar.workgroup = workgroup -======= - calendar.workgroup = current_workgroup ->>>>>>> update calendar build_links for table builder calendar.organisation = current_organisation end end def collection -<<<<<<< HEAD @calendars ||= begin scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true) scope = shared_scope(scope) @@ -123,16 +101,6 @@ class CalendarsController < ChouetteController calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction calendars = calendars.paginate(page: params[:page]) end -======= - return @calendars if @calendars - scope = Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, @workgroup.id) - scope = shared_scope(scope) - @q = scope.ransack(params[:q]) - - calendars = @q.result - calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction - @calendars = calendars.paginate(page: params[:page]) ->>>>>>> update calendar build_links for table builder end def ransack_contains_date @@ -157,4 +125,4 @@ class CalendarsController < ChouetteController scope end -end +end \ No newline at end of file -- cgit v1.2.3 From bb638da38f8155c5433322c413f465dfa928d4e1 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 31 Jan 2018 11:39:39 +0100 Subject: Refs #5683 @2H; Fix specs and refactor action_links Note: Did not fix the missing workgroup in the calendar mailer --- app/controllers/calendars_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index e0dd68405..585851f00 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -7,7 +7,7 @@ class CalendarsController < ChouetteController respond_to :html respond_to :json, only: :show respond_to :js, only: :index - + belongs_to :workgroup def index @@ -125,4 +125,4 @@ class CalendarsController < ChouetteController scope end -end \ No newline at end of file +end -- cgit v1.2.3 From 0869a498ea0a101e70a5b3fd938eb4a2a3d04a32 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 24 Jan 2018 19:55:56 -0800 Subject: update calendar build_links for table builder --- app/controllers/calendars_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 585851f00..b02764f8f 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -1,4 +1,5 @@ class CalendarsController < ChouetteController + include WorkgroupSupport include PolicyChecker include TimeTablesHelper -- cgit v1.2.3 From e46fde25ca2ed406b215471404be21ef1e617f8d Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Tue, 30 Jan 2018 23:07:07 -0800 Subject: Make some changes to avoid unnacessaty lines of code --- app/controllers/calendars_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index b02764f8f..75d4cbd09 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -1,5 +1,4 @@ class CalendarsController < ChouetteController - include WorkgroupSupport include PolicyChecker include TimeTablesHelper @@ -126,4 +125,4 @@ class CalendarsController < ChouetteController scope end -end +end \ No newline at end of file -- cgit v1.2.3 From cb1c6c42cf0f053d52a08cb8ccdbb70a142ec5ad Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 26 Jan 2018 16:17:22 +0100 Subject: Refs #5750 @1h; Add a "kind" attribute to StopAreas This determines if the StopArea is commercial or not The useless fields are hidden in the form for the non-commercials ones --- app/models/chouette/stop_area.rb | 3 +++ db/schema.rb | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index bb8747faa..69aed144b 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -11,8 +11,11 @@ module Chouette extend Enumerize enumerize :area_type, in: Chouette::AreaType::ALL enumerize :kind, in: %i(commercial non_commercial) +<<<<<<< HEAD AVAILABLE_LOCALIZATIONS = %i(gb nl de fr it es) +======= +>>>>>>> Refs #5750 @1h; Add a "kind" attribute to StopAreas with_options dependent: :destroy do |assoc| assoc.has_many :stop_points diff --git a/db/schema.rb b/db/schema.rb index 2b94f655b..ec858a14a 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: 20180123174450) do +ActiveRecord::Schema.define(version: 20180126134944) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -95,6 +95,8 @@ ActiveRecord::Schema.define(version: 20180123174450) do t.integer "int_day_types" t.date "excluded_dates", array: true t.integer "workgroup_id", limit: 8 + t.integer "int_day_types" + t.date "excluded_dates", array: true end add_index "calendars", ["organisation_id"], name: "index_calendars_on_organisation_id", using: :btree @@ -794,7 +796,10 @@ ActiveRecord::Schema.define(version: 20180123174450) do t.string "stif_type" t.integer "waiting_time" t.string "kind" +<<<<<<< HEAD t.jsonb "localized_names" +======= +>>>>>>> Refs #5750 @1h; Add a "kind" attribute to StopAreas end add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree -- cgit v1.2.3 From 53009774ec18387a30689a25ae286ba76e0e15d8 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 24 Jan 2018 07:28:57 +0100 Subject: Refs #5682; Add application_days field to calendars --- app/models/calendar.rb | 3 +++ db/schema.rb | 3 --- spec/models/chouette/time_table_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 84b569ab4..50faa9bde 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -50,6 +50,7 @@ class Calendar < ActiveRecord::Base tt.periods << Chouette::TimeTablePeriod.new(period_start: p.begin, period_end: p.end) end tt.int_day_types = self.int_day_types +<<<<<<< HEAD end end @@ -87,6 +88,8 @@ class Calendar < ActiveRecord::Base def all_dates (dates + excluded_dates).sort.each_with_index.map do |d, i| OpenStruct.new(id: i, date: d, in_out: include_in_dates?(d)) +======= +>>>>>>> Refs #5682; Add application_days field to calendars end end diff --git a/db/schema.rb b/db/schema.rb index ec858a14a..43f989e38 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -796,10 +796,7 @@ ActiveRecord::Schema.define(version: 20180126134944) do t.string "stif_type" t.integer "waiting_time" t.string "kind" -<<<<<<< HEAD t.jsonb "localized_names" -======= ->>>>>>> Refs #5750 @1h; Add a "kind" attribute to StopAreas end add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index a501f234a..856188f58 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -926,7 +926,7 @@ end end end end - + describe "#validity_out_between?" do let(:empty_tm) {build(:time_table)} it "should be false if empty calendar" do -- cgit v1.2.3 From 37f77f03c15269a82bdd487fd36458f341536baa Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 24 Jan 2018 16:56:16 +0100 Subject: Refs #5682 @3h; Use same UI as for timetables --- app/models/calendar.rb | 3 --- app/models/chouette/stop_area.rb | 3 --- 2 files changed, 6 deletions(-) diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 50faa9bde..84b569ab4 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -50,7 +50,6 @@ class Calendar < ActiveRecord::Base tt.periods << Chouette::TimeTablePeriod.new(period_start: p.begin, period_end: p.end) end tt.int_day_types = self.int_day_types -<<<<<<< HEAD end end @@ -88,8 +87,6 @@ class Calendar < ActiveRecord::Base def all_dates (dates + excluded_dates).sort.each_with_index.map do |d, i| OpenStruct.new(id: i, date: d, in_out: include_in_dates?(d)) -======= ->>>>>>> Refs #5682; Add application_days field to calendars end end diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 69aed144b..bb8747faa 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -11,11 +11,8 @@ module Chouette extend Enumerize enumerize :area_type, in: Chouette::AreaType::ALL enumerize :kind, in: %i(commercial non_commercial) -<<<<<<< HEAD AVAILABLE_LOCALIZATIONS = %i(gb nl de fr it es) -======= ->>>>>>> Refs #5750 @1h; Add a "kind" attribute to StopAreas with_options dependent: :destroy do |assoc| assoc.has_many :stop_points -- cgit v1.2.3 From 208166eacaa429066d075ca6264ca2d2183e8a62 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 2 Feb 2018 14:58:50 +0100 Subject: Refs #5417; Update parents checksum when children are created or updated --- spec/models/chouette/time_table_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 856188f58..a501f234a 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -926,7 +926,7 @@ end end end end - + describe "#validity_out_between?" do let(:empty_tm) {build(:time_table)} it "should be false if empty calendar" do -- cgit v1.2.3 From cd0b21446d2b56505917fa310c2e9b23e5819e49 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 26 Jan 2018 16:17:22 +0100 Subject: Refs #5750 @1h; Add a "kind" attribute to StopAreas This determines if the StopArea is commercial or not The useless fields are hidden in the form for the non-commercials ones --- app/models/chouette/stop_area.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index bb8747faa..a5573959b 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -113,7 +113,13 @@ module Chouette end end +<<<<<<< HEAD alias_method :local_id, :user_objectid +======= + def local_id + id.to_s + end +>>>>>>> Refs #5750 @1h; Add a "kind" attribute to StopAreas def children_in_depth return [] if self.children.empty? -- cgit v1.2.3 From e07ef0eb9dac728ee5033b42c318692e2368b897 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Wed, 7 Feb 2018 16:38:06 +0100 Subject: Add workgroup to erd diagrams --- lib/tasks/erd.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/erd.rake b/lib/tasks/erd.rake index e2665374e..96bb7fe37 100644 --- a/lib/tasks/erd.rake +++ b/lib/tasks/erd.rake @@ -2,12 +2,12 @@ namespace :generate do desc "Create model diagrams for Chouette" task :model_diagram => :environment do - sh "bundle exec rake erd only='Organisation,Referential,User,Workbench' filename='organisation' title='Organisation'" + sh "bundle exec rake erd only='Organisation,Referential,User,Workbench,Workgroup' filename='organisation' title='Organisation'" sh "bundle exec rake erd only='Calendar,Referential,ReferentialMetadata,Chouette::Line,Chouette::Route,Chouette::JourneyPattern,Chouette::VehicleJourney,Chouette::VehicleJourneyAtStop,Chouette::TimeTable,Chouette::TimeTableDate,Chouette::TimeTablePeriod,Chouette::Footnote,Chouette::Network,Chouette::Company,Chouette::StopPoint,Chouette::StopArea' filename='offer_datas' title='Offer Datas'" sh "bundle exec rake erd only='Organisation,StopAreaReferential,StopAreaReferentialSync,StopAreaReferentialSyncMessage,StopAreaReferentialMembership,LineReferential,LineReferentialSync,LineReferentialSyncMessage,LineReferentialMembership' filename='referentiels_externes' title='Référentiels externes'" sh "bundle exec rake erd only='NetexImport,Import,WorkbenchImport,ImportResource,ImportMessage' filename='import' title='Import'" sh "bundle exec rake erd only='ComplianceControlSet,ComplianceControlBlock,ComplianceControl,ComplianceCheckSet,ComplianceCheckBlock,ComplianceCheck,ComplianceCheckResource,ComplianceCheckMessage' filename='validation' title='Validation'" - sh "bundle exec rake erd only='Organisation,Workbench,ReferentialSuite,Referential' filename='merge' title='Merge'" + sh "bundle exec rake erd only='Organisation,Workgroup,Workbench,ReferentialSuite,Referential' filename='merge' title='Merge'" #sh "bundle exec rake erd only='VehicleJourney,VehicleJourneyExport' filename='export' title='Export'" #sh "bundle exec rake erd only='' filename='integration' title='Integration'" #sh "bundle exec rake erd only='' filename='publication' title='Publication'" -- cgit v1.2.3 From 3334b12153f0d24a95b1198742fd0da2444223fe Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 7 Feb 2018 07:46:38 -0800 Subject: Update branch according to master --- app/models/chouette/stop_area.rb | 6 ------ db/schema.rb | 9 ++------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index a5573959b..bb8747faa 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -113,13 +113,7 @@ module Chouette end end -<<<<<<< HEAD alias_method :local_id, :user_objectid -======= - def local_id - id.to_s - end ->>>>>>> Refs #5750 @1h; Add a "kind" attribute to StopAreas def children_in_depth return [] if self.children.empty? diff --git a/db/schema.rb b/db/schema.rb index 43f989e38..596682ce8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,14 +11,13 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180126134944) do +ActiveRecord::Schema.define(version: 20180202170009) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - enable_extension "hstore" enable_extension "postgis" + enable_extension "hstore" enable_extension "unaccent" - enable_extension "objectid" create_table "access_links", id: :bigserial, force: :cascade do |t| t.integer "access_point_id", limit: 8 @@ -94,9 +93,6 @@ ActiveRecord::Schema.define(version: 20180126134944) do t.integer "workgroup_id", limit: 8 t.integer "int_day_types" t.date "excluded_dates", array: true - t.integer "workgroup_id", limit: 8 - t.integer "int_day_types" - t.date "excluded_dates", array: true end add_index "calendars", ["organisation_id"], name: "index_calendars_on_organisation_id", using: :btree @@ -123,7 +119,6 @@ ActiveRecord::Schema.define(version: 20180126134944) do t.datetime "updated_at" t.date "end_date" t.string "date_type" - t.string "mode" end add_index "clean_ups", ["referential_id"], name: "index_clean_ups_on_referential_id", using: :btree -- cgit v1.2.3 From 6e902fd70fdd21e0ee31fa5f2ee764357b0ea477 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 7 Feb 2018 07:52:47 -0800 Subject: Remove workgroup support --- app/controllers/concerns/workgroup_support.rb | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 app/controllers/concerns/workgroup_support.rb diff --git a/app/controllers/concerns/workgroup_support.rb b/app/controllers/concerns/workgroup_support.rb deleted file mode 100644 index a3b49bb12..000000000 --- a/app/controllers/concerns/workgroup_support.rb +++ /dev/null @@ -1,12 +0,0 @@ -module WorkgroupSupport - extend ActiveSupport::Concern - - included do - before_action :find_workgroup - end - - def find_workgroup - @workgroup ||= Workgroup.find params[:workgroup_id] - end - -end -- cgit v1.2.3 From 135637edcef986f80d024b8bdbb14b33477caf7f Mon Sep 17 00:00:00 2001 From: Xinhui Date: Fri, 5 Jan 2018 16:26:38 +0100 Subject: Edit support of list attributes Refs #5416 --- app/models/concerns/checksum_support.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/checksum_support.rb b/app/models/concerns/checksum_support.rb index a76995b0f..87218c977 100644 --- a/app/models/concerns/checksum_support.rb +++ b/app/models/concerns/checksum_support.rb @@ -24,10 +24,18 @@ module ChecksumSupport self.attributes.values end + def checksum_replace_nil_or_empty_values values + # Replace empty array by nil & nil by VALUE_FOR_NIL_ATTRIBUTE + values.map{ |x| x unless x.try(:empty?) }.map{ |x| x || VALUE_FOR_NIL_ATTRIBUTE }.map do |item| + item = item.kind_of?(Array) ? checksum_replace_nil_or_empty_values(item) : item + end + end + def current_checksum_source - source = self.checksum_attributes.map{ |x| x unless x.try(:empty?) } - source = source.map{ |x| x || VALUE_FOR_NIL_ATTRIBUTE } - source.map(&:to_s).join(SEPARATOR) + source = checksum_replace_nil_or_empty_values(self.checksum_attributes) + source.map{ |item| + item = item.kind_of?(Array) ? item.map{ |x| "(#{x.join(',')})"}.join(',') : item + }.join(SEPARATOR) end def set_current_checksum_source -- cgit v1.2.3 From 8a5898177d9a793e791a7e1dcb3162f8bf11aecf Mon Sep 17 00:00:00 2001 From: Xinhui Date: Fri, 5 Jan 2018 16:28:28 +0100 Subject: Edit checksum stop_points attributes for route Refs #5416 --- app/models/chouette/route.rb | 2 +- app/models/chouette/routing_constraint_zone.rb | 4 +++- app/models/concerns/checksum_support.rb | 6 +++++- spec/models/chouette/route/route_base_spec.rb | 4 ++-- spec/models/chouette/routing_constraint_zone_spec.rb | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 47c18af09..5cc5d8b0d 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -133,7 +133,7 @@ module Chouette def checksum_attributes values = self.slice(*['name', 'published_name', 'wayback']).values values.tap do |attrs| - attrs << self.stop_points.sort_by(&:position).map{|sp| "#{sp.stop_area.user_objectid}#{sp.for_boarding}#{sp.for_alighting}" }.join + attrs << self.stop_points.sort_by(&:position).map{|sp| [sp.stop_area.user_objectid, sp.for_boarding, sp.for_alighting]} attrs << self.routing_constraint_zones.map(&:checksum) end end diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb index 903922241..58703598e 100644 --- a/app/models/chouette/routing_constraint_zone.rb +++ b/app/models/chouette/routing_constraint_zone.rb @@ -25,7 +25,9 @@ module Chouette end def checksum_attributes - self.stop_points.map(&:stop_area).map(&:user_objectid) + [ + self.stop_points.map(&:stop_area).map(&:user_objectid) + ] end def stop_points_belong_to_route diff --git a/app/models/concerns/checksum_support.rb b/app/models/concerns/checksum_support.rb index 87218c977..397a22231 100644 --- a/app/models/concerns/checksum_support.rb +++ b/app/models/concerns/checksum_support.rb @@ -34,7 +34,11 @@ module ChecksumSupport def current_checksum_source source = checksum_replace_nil_or_empty_values(self.checksum_attributes) source.map{ |item| - item = item.kind_of?(Array) ? item.map{ |x| "(#{x.join(',')})"}.join(',') : item + if item.kind_of?(Array) + item.map{ |x| x.kind_of?(Array) ? "(#{x.join(',')})" : x }.join(',') + else + item + end }.join(SEPARATOR) end diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb index 26f57eae5..0e4d13d15 100644 --- a/spec/models/chouette/route/route_base_spec.rb +++ b/spec/models/chouette/route/route_base_spec.rb @@ -1,8 +1,8 @@ RSpec.describe Chouette::Route, :type => :model do + subject { create(:route, stop_points: create_list(:stop_point, 3)) } - subject { create(:route) } describe 'checksum' do - it_behaves_like 'checksum support', :route + it_behaves_like 'checksum support' 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) } diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb index 0282cb8b1..bda6bb04a 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -11,7 +11,7 @@ describe Chouette::RoutingConstraintZone, type: :model do it { is_expected.to be_versioned } describe 'checksum' do - it_behaves_like 'checksum support', :routing_constraint_zone + it_behaves_like 'checksum support' end describe 'validations' do -- cgit v1.2.3 From 31b7b91b46d2e8f740d2cfd493836219f5a4f42d Mon Sep 17 00:00:00 2001 From: Xinhui Date: Fri, 5 Jan 2018 16:43:37 +0100 Subject: Refactoring use subject as factory Refs #5416 --- spec/models/chouette/footnote_spec.rb | 12 ++++++------ spec/support/checksum_support.rb | 24 +++++++++++------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/spec/models/chouette/footnote_spec.rb b/spec/models/chouette/footnote_spec.rb index fc5e5f306..05f55c2f0 100644 --- a/spec/models/chouette/footnote_spec.rb +++ b/spec/models/chouette/footnote_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' describe Chouette::Footnote, type: :model do - let(:footnote) { create(:footnote) } + subject { create(:footnote) } it { should validate_presence_of :line } describe 'data_source_ref' do it 'should set default if omitted' do - expect(footnote.data_source_ref).to eq "DATASOURCEREF_EDITION_BOIV" + expect(subject.data_source_ref).to eq "DATASOURCEREF_EDITION_BOIV" end it 'should not set default if not omitted' do @@ -18,16 +18,16 @@ describe Chouette::Footnote, type: :model do end describe 'checksum' do - it_behaves_like 'checksum support', :footnote + it_behaves_like 'checksum support' context '#checksum_attributes' do it 'should return code and label' do - expected = [footnote.code, footnote.label] - expect(footnote.checksum_attributes).to include(*expected) + expected = [subject.code, subject.label] + expect(subject.checksum_attributes).to include(*expected) end it 'should not return other atrributes' do - expect(footnote.checksum_attributes).to_not include(footnote.updated_at) + expect(subject.checksum_attributes).to_not include(subject.updated_at) end end end diff --git a/spec/support/checksum_support.rb b/spec/support/checksum_support.rb index e02d9f9f3..9a4475e23 100644 --- a/spec/support/checksum_support.rb +++ b/spec/support/checksum_support.rb @@ -1,17 +1,15 @@ -shared_examples 'checksum support' do |factory_name| - let(:instance) { create(factory_name) } - +shared_examples 'checksum support' do describe '#current_checksum_source' do let(:attributes) { ['code_value', 'label_value'] } let(:seperator) { ChecksumSupport::SEPARATOR } let(:nil_value) { ChecksumSupport::VALUE_FOR_NIL_ATTRIBUTE } before do - allow_any_instance_of(instance.class).to receive(:checksum_attributes).and_return(attributes) + allow_any_instance_of(subject.class).to receive(:checksum_attributes).and_return(attributes) end it 'should separate attribute by seperator' do - expect(instance.current_checksum_source).to eq("code_value#{seperator}label_value") + expect(subject.current_checksum_source).to eq("code_value#{seperator}label_value") end context 'nil value' do @@ -19,7 +17,7 @@ shared_examples 'checksum support' do |factory_name| it 'should replace nil attributes by default value' do source = "code_value#{seperator}#{nil_value}" - expect(instance.current_checksum_source).to eq(source) + expect(subject.current_checksum_source).to eq(source) end end @@ -28,26 +26,26 @@ shared_examples 'checksum support' do |factory_name| it 'should convert to nil' do source = "code_value#{seperator}#{nil_value}" - expect(instance.current_checksum_source).to eq(source) + expect(subject.current_checksum_source).to eq(source) end end end it 'should save checksum on create' do - expect(instance.checksum).to_not be_nil + expect(subject.checksum).to_not be_nil end it 'should save checksum_source' do - expect(instance.checksum_source).to_not be_nil + expect(subject.checksum_source).to_not be_nil end it 'should trigger set_current_checksum_source on save' do - expect(instance).to receive(:set_current_checksum_source).at_least(:once) - instance.save + expect(subject).to receive(:set_current_checksum_source).at_least(:once) + subject.save end it 'should trigger update_checksum on save' do - expect(instance).to receive(:update_checksum).at_least(:once) - instance.save + expect(subject).to receive(:update_checksum).at_least(:once) + subject.save end end -- cgit v1.2.3 From 9d7e4b4bc23ce343a0c6acb7805112d64dd97a1a Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 7 Feb 2018 12:24:38 -0800 Subject: Refs #5709 Fix CCSet index table builder sorting & add show button in gear menu link --- .../compliance_control_sets_controller.rb | 40 ++++++++++++++++++++-- app/decorators/compliance_control_set_decorator.rb | 2 ++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb index ae1d01feb..8f9251155 100644 --- a/app/controllers/compliance_control_sets_controller.rb +++ b/app/controllers/compliance_control_sets_controller.rb @@ -7,10 +7,8 @@ class ComplianceControlSetsController < ChouetteController def index index! do |format| - scope = self.ransack_period_range(scope: @compliance_control_sets, error_message: t('imports.filters.error_period_filter'), query: :where_updated_at_between) - @q_for_form = scope.ransack(params[:q]) format.html { - @compliance_control_sets = decorate_compliance_control_sets(@q_for_form.result.paginate(page: params[:page], per_page: 30)) + @compliance_control_sets = decorate_compliance_control_sets(@compliance_control_sets) } end end @@ -37,6 +35,14 @@ class ComplianceControlSetsController < ChouetteController private + def collection + scope = self.ransack_period_range(scope: ComplianceControlSet.all, error_message: t('imports.filters.error_period_filter'), query: :where_updated_at_between) + @q_for_form = scope.ransack(params[:q]) + compliance_control_sets = @q_for_form.result + compliance_control_sets = joins_with_associated_objects(compliance_control_sets).order(sort_column + ' ' + sort_direction) if sort_column && sort_direction + @compliance_control_sets = compliance_control_sets.paginate(page: params[:page], per_page: 30) + end + def decorate_compliance_control_sets(compliance_control_sets) ComplianceControlSetDecorator.decorate(compliance_control_sets) end @@ -58,4 +64,32 @@ class ComplianceControlSetsController < ChouetteController @direct_compliance_controls = compliance_controls.delete nil @blocks_to_compliance_controls_map = compliance_controls end + + def sort_column + case params[:sort] + when 'name' then 'lower(compliance_control_sets.name)' + when 'owner_jdc' then 'lower(organisations.name)' + when 'control_numbers' then 'COUNT(compliance_controls.id)' + else + ComplianceControlSet.column_names.include?(params[:sort]) ? params[:sort] : 'lower(compliance_control_sets.name)' + end + end + + def joins_with_associated_objects(collection) + + # dont know if this is the right way to do it but since we need to join table deoending of the params + # it was to avoid loading associated objects if we don't need them + case params[:sort] + when 'owner_jdc' + collection.joins("LEFT JOIN organisations ON compliance_control_sets.organisation_id = organisations.id") + when 'control_numbers' + collection.joins("LEFT JOIN compliance_controls ON compliance_controls.compliance_control_set_id = compliance_control_sets.id").group(:id) + else + collection + end + end + + def sort_direction + %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' + end end diff --git a/app/decorators/compliance_control_set_decorator.rb b/app/decorators/compliance_control_set_decorator.rb index 387822c67..b16a06886 100644 --- a/app/decorators/compliance_control_set_decorator.rb +++ b/app/decorators/compliance_control_set_decorator.rb @@ -6,6 +6,8 @@ class ComplianceControlSetDecorator < AF83::Decorator end with_instance_decorator do |instance_decorator| + instance_decorator.show_action_link + instance_decorator.edit_action_link do |l| l.content t('compliance_control_sets.actions.edit') end -- cgit v1.2.3 From d9c5cdeb76c2e6df0711d6c1b538a583d42bff45 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Wed, 7 Feb 2018 12:58:44 -0800 Subject: Refs #5815 Add required fields to some compliance controls --- app/models/concerns/min_max_values_validation.rb | 1 + app/models/vehicle_journey_control/delta.rb | 1 + app/models/vehicle_journey_control/waiting_time.rb | 1 + spec/factories/compliance_controls/vehicle_journey_control_factories.rb | 2 ++ 4 files changed, 5 insertions(+) diff --git a/app/models/concerns/min_max_values_validation.rb b/app/models/concerns/min_max_values_validation.rb index 9b2e0d548..eff779d81 100644 --- a/app/models/concerns/min_max_values_validation.rb +++ b/app/models/concerns/min_max_values_validation.rb @@ -2,6 +2,7 @@ module MinMaxValuesValidation extend ActiveSupport::Concern included do + validates_presence_of :minimum, :maximum validate :min_max_values_validation end diff --git a/app/models/vehicle_journey_control/delta.rb b/app/models/vehicle_journey_control/delta.rb index f061b9fdd..737b7d78c 100644 --- a/app/models/vehicle_journey_control/delta.rb +++ b/app/models/vehicle_journey_control/delta.rb @@ -4,6 +4,7 @@ module VehicleJourneyControl store_accessor :control_attributes, :maximum validates_numericality_of :maximum, allow_nil: true, greater_than_or_equal_to: 0 + validates_presence_of :maximum def self.default_code; "3-VehicleJourney-3" end end diff --git a/app/models/vehicle_journey_control/waiting_time.rb b/app/models/vehicle_journey_control/waiting_time.rb index f2666cb72..89a18a5d9 100644 --- a/app/models/vehicle_journey_control/waiting_time.rb +++ b/app/models/vehicle_journey_control/waiting_time.rb @@ -3,6 +3,7 @@ module VehicleJourneyControl store_accessor :control_attributes, :maximum validates_numericality_of :maximum, allow_nil: true, greater_than_or_equal_to: 0 + validates_presence_of :maximum def self.default_code; "3-VehicleJourney-1" end end diff --git a/spec/factories/compliance_controls/vehicle_journey_control_factories.rb b/spec/factories/compliance_controls/vehicle_journey_control_factories.rb index e8f68cbdf..86a335aba 100644 --- a/spec/factories/compliance_controls/vehicle_journey_control_factories.rb +++ b/spec/factories/compliance_controls/vehicle_journey_control_factories.rb @@ -1,10 +1,12 @@ FactoryGirl.define do factory :vehicle_journey_control_wating_time, class: 'VehicleJourneyControl::WaitingTime' do + maximum 10 association :compliance_control_set end factory :vehicle_journey_control_delta, class: 'VehicleJourneyControl::Delta' do + maximum 10 association :compliance_control_set end -- cgit v1.2.3 From 25490fc70826d293cf57ade58776b47a5de82816 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Thu, 8 Feb 2018 10:46:29 +0100 Subject: Add i18n-js to capistrano deployment Refs #4126 @1 --- config/deploy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index 9be023adc..fc60113ce 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -78,7 +78,7 @@ namespace :deploy do run "ln -nfs #{shared_path}/tmp/imports #{release_path}/tmp/imports" end after 'deploy:update_code', 'deploy:symlink_shared' - before 'deploy:assets:precompile', 'deploy:symlink_shared' + before 'deploy:assets:precompile', 'deploy:symlink_shared', "deploy:i18n_js_export" desc "Make group writable all deployed files" task :group_writable do -- cgit v1.2.3 From f3769c9d9fa0d4bf3c620a9c95e0c7533da9801c Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 9 Jan 2018 14:46:40 +0100 Subject: Refactoring spec checksum support Refs #5416 --- spec/models/chouette/journey_pattern_spec.rb | 3 ++- spec/models/chouette/time_table_period_spec.rb | 2 +- spec/models/chouette/time_table_spec.rb | 2 +- .../chouette/vehicle_journey_at_stop_spec.rb | 4 +++- spec/models/chouette/vehicle_journey_spec.rb | 4 +++- spec/support/checksum_support.rb | 27 ++++++++++++++++++++++ 6 files changed, 37 insertions(+), 5 deletions(-) diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb index b5eb9004c..19a74a0e7 100644 --- a/spec/models/chouette/journey_pattern_spec.rb +++ b/spec/models/chouette/journey_pattern_spec.rb @@ -2,9 +2,10 @@ require 'spec_helper' describe Chouette::JourneyPattern, :type => :model do it { is_expected.to be_versioned } + subject { create(:journey_pattern) } describe 'checksum' do - it_behaves_like 'checksum support', :journey_pattern + it_behaves_like 'checksum support' end # context 'validate minimum stop_points size' do diff --git a/spec/models/chouette/time_table_period_spec.rb b/spec/models/chouette/time_table_period_spec.rb index cc1a3ae09..e14d38ade 100644 --- a/spec/models/chouette/time_table_period_spec.rb +++ b/spec/models/chouette/time_table_period_spec.rb @@ -10,7 +10,7 @@ describe Chouette::TimeTablePeriod, :type => :model do it { is_expected.to validate_presence_of :period_end } describe 'checksum' do - it_behaves_like 'checksum support', :time_table_period + it_behaves_like 'checksum support' end describe "#overlap" do diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index a501f234a..bb88877b9 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -1049,7 +1049,7 @@ end # it { is_expected.to validate_uniqueness_of :objectid } describe 'checksum' do - it_behaves_like 'checksum support', :time_table + it_behaves_like 'checksum support' it "handles newly built dates and periods" do time_table = build(:time_table) diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb index 02306883c..a97559a0c 100644 --- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb @@ -1,10 +1,12 @@ require 'spec_helper' RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do + subject { create(:vehicle_journey_at_stop) } + describe 'checksum' do let(:at_stop) { build_stubbed(:vehicle_journey_at_stop) } - it_behaves_like 'checksum support', :vehicle_journey_at_stop + it_behaves_like 'checksum support' context '#checksum_attributes' do it 'should return attributes' do diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 7279980a3..76e73d9cf 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Chouette::VehicleJourney, :type => :model do + subject { create(:vehicle_journey) } + it { is_expected.to be_versioned } it { should have_and_belong_to_many(:purchase_windows) } @@ -21,7 +23,7 @@ describe Chouette::VehicleJourney, :type => :model do end describe 'checksum' do - it_behaves_like 'checksum support', :vehicle_journey + it_behaves_like 'checksum support' it "changes when a vjas is updated" do vehicle_journey = create(:vehicle_journey) expect{vehicle_journey.vehicle_journey_at_stops.last.update_attribute(:departure_time, Time.now)}.to change{vehicle_journey.reload.checksum} diff --git a/spec/support/checksum_support.rb b/spec/support/checksum_support.rb index 9a4475e23..3d88d1d57 100644 --- a/spec/support/checksum_support.rb +++ b/spec/support/checksum_support.rb @@ -29,6 +29,33 @@ shared_examples 'checksum support' do expect(subject.current_checksum_source).to eq(source) end end + + context 'array value' do + let(:attributes) { [['v1', 'v2', 'v3'], 'code_value'] } + + it 'should convert to list' do + source = "v1,v2,v3#{seperator}code_value" + expect(subject.current_checksum_source).to eq(source) + end + end + + context 'array of array value' do + let(:attributes) { [[['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']], 'code_value'] } + + it 'should convert to list' do + source = "(a1,a2,a3),(b1,b2,b3)#{seperator}code_value" + expect(subject.current_checksum_source).to eq(source) + end + end + + context 'array of array value, with empty array' do + let(:attributes) { [[['a1', 'a2', 'a3'], []], 'code_value'] } + + it 'should convert to list' do + source = "(a1,a2,a3),-#{seperator}code_value" + expect(subject.current_checksum_source).to eq(source) + end + end end it 'should save checksum on create' do -- cgit v1.2.3 From ee1781d525bc04aff3f7f743be8297ee003ee9e0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 6 Feb 2018 17:12:09 +0100 Subject: ComplianceCheckSet: Add `.abort_old` Copy over the `Import.abort_old` method to this class. For now I haven't bothered with moving it to a consolidated module. We'll see, maybe that's a better approach. For now I'm going with a relaxed copy-paste solution until we decide that the increased complexity of the module is worth the deduplication. We need this method to be able to abort stale imports. We'll be doing this, similarly to imports, in a regular cron job. Refs #4758 --- app/models/compliance_check_set.rb | 12 ++++++++++++ spec/models/compliance_check_spec.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index f4c44d26d..3ea832048 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -19,6 +19,18 @@ class ComplianceCheckSet < ActiveRecord::Base where('created_at BETWEEN :begin AND :end', begin: period_range.begin, end: period_range.end) end + def self.finished_statuses + %w(successful failed warning aborted canceled) + end + + def self.abort_old + where( + 'created_at < ? AND status NOT IN (?)', + 4.hours.ago, + finished_statuses + ).update_all(status: 'aborted') + end + def notify_parent if parent # parent.child_change diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb index f83d78c29..ffa59245c 100644 --- a/spec/models/compliance_check_spec.rb +++ b/spec/models/compliance_check_spec.rb @@ -15,4 +15,36 @@ RSpec.describe ComplianceCheck, type: :model do it { should validate_presence_of :name } it { should validate_presence_of :code } it { should validate_presence_of :origin_code } + + describe ".abort_old" do + it "changes check sets older than 4 hours to aborted" do + Timecop.freeze(Time.now) do + old_check_set = create( + :compliance_check_set, + status: 'pending', + created_at: 4.hours.ago - 1.minute + ) + current_check_set = create(:compliance_check_set, status: 'pending') + + ComplianceCheckSet.abort_old + + expect(current_check_set.reload.status).to eq('pending') + expect(old_check_set.reload.status).to eq('aborted') + end + end + + it "doesn't work on check sets with a `finished_status`" do + Timecop.freeze(Time.now) do + check_set = create( + :compliance_check_set, + status: 'successful', + created_at: 4.hours.ago - 1.minute + ) + + ComplianceCheckSet.abort_old + + expect(check_set.reload.status).to eq('successful') + end + end + end end -- cgit v1.2.3 From 6134ed98a3fe29276a17a0d79a70a8ce3e3f548b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 7 Feb 2018 12:50:46 +0100 Subject: Add `ParentNotifier` service This is a takeoff on `ParentImportNotifier`. I just copied over the class and spec and generalised the service to work with `Import`-style interfaces. We can now use the same notifier service class for both imports and compliance check sets. Refs #4758 --- app/services/parent_notifier.rb | 19 ++++++++ spec/services/parent_notifier_spec.rb | 90 +++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 app/services/parent_notifier.rb create mode 100644 spec/services/parent_notifier_spec.rb diff --git a/app/services/parent_notifier.rb b/app/services/parent_notifier.rb new file mode 100644 index 000000000..653c98aff --- /dev/null +++ b/app/services/parent_notifier.rb @@ -0,0 +1,19 @@ +class ParentNotifier + def initialize(klass) + @klass = klass + end + + def notify_when_finished(collection = nil) + collection ||= objects_pending_notification + collection.each(&:notify_parent) + end + + def objects_pending_notification + @klass + .where( + notified_parent_at: nil, + status: @klass.finished_statuses + ) + .where.not(parent: nil) + end +end diff --git a/spec/services/parent_notifier_spec.rb b/spec/services/parent_notifier_spec.rb new file mode 100644 index 000000000..ecf508fcd --- /dev/null +++ b/spec/services/parent_notifier_spec.rb @@ -0,0 +1,90 @@ +RSpec.describe ParentNotifier do + let(:workbench_import) { create(:workbench_import) } + + describe ".notify_when_finished" do + it "calls #notify_parent on finished imports" do + workbench_import = build_stubbed(:workbench_import) + + finished_statuses = [:failed, :successful, :aborted, :canceled] + netex_imports = [] + + finished_statuses.each do |status| + netex_imports << build_stubbed( + :netex_import, + parent: workbench_import, + status: status + ) + end + + netex_imports.each do |netex_import| + expect(netex_import).to receive(:notify_parent) + end + + ParentNotifier.new(Import).notify_when_finished(netex_imports) + end + + it "doesn't call #notify_parent if its `notified_parent_at` is set" do + netex_import = create( + :netex_import, + parent: workbench_import, + status: :failed, + notified_parent_at: DateTime.now + ) + + expect(netex_import).not_to receive(:notify_parent) + + ParentNotifier.new(Import).notify_when_finished + end + end + + describe ".objects_pending_notification" do + it "includes imports with a parent and `notified_parent_at` unset" do + netex_import = create( + :netex_import, + parent: workbench_import, + status: :successful, + notified_parent_at: nil + ) + + expect( + ParentNotifier.new(Import).objects_pending_notification + ).to eq([netex_import]) + end + + it "doesn't include imports without a parent" do + create(:import, parent: nil) + + expect( + ParentNotifier.new(Import).objects_pending_notification + ).to be_empty + end + + it "doesn't include imports that aren't finished" do + [:new, :pending, :running].each do |status| + create( + :netex_import, + parent: workbench_import, + status: status, + notified_parent_at: nil + ) + end + + expect( + ParentNotifier.new(Import).objects_pending_notification + ).to be_empty + end + + it "doesn't include imports that have already notified their parent" do + create( + :netex_import, + parent: workbench_import, + status: :successful, + notified_parent_at: DateTime.now + ) + + expect( + ParentNotifier.new(Import).objects_pending_notification + ).to be_empty + end + end +end -- cgit v1.2.3 From 871a088ccffc47e5e09272b3105dabecf10974a6 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 7 Feb 2018 12:56:08 +0100 Subject: imports.rake(notify_parent): Use `ParentNotifier` Replace `ParentImportNotifier` with the new generalised `ParentNotifier`. This will allow us to use the same service for parent notification of both imports and compliance check sets. Delete the `ParentImportNotifier` class and spec as these are now superseded by `ParentNotifier`. Refs #4758 --- app/services/parent_import_notifier.rb | 15 ----- lib/tasks/imports.rake | 2 +- spec/services/parent_import_notifier_spec.rb | 90 ---------------------------- 3 files changed, 1 insertion(+), 106 deletions(-) delete mode 100644 app/services/parent_import_notifier.rb delete mode 100644 spec/services/parent_import_notifier_spec.rb diff --git a/app/services/parent_import_notifier.rb b/app/services/parent_import_notifier.rb deleted file mode 100644 index 47e6755e4..000000000 --- a/app/services/parent_import_notifier.rb +++ /dev/null @@ -1,15 +0,0 @@ -class ParentImportNotifier - def self.notify_when_finished(imports = nil) - imports ||= imports_pending_notification - imports.each(&:notify_parent) - end - - def self.imports_pending_notification - Import - .where( - notified_parent_at: nil, - status: Import.finished_statuses - ) - .where.not(parent: nil) - end -end diff --git a/lib/tasks/imports.rake b/lib/tasks/imports.rake index 6bc84acc8..55e017e7f 100644 --- a/lib/tasks/imports.rake +++ b/lib/tasks/imports.rake @@ -1,6 +1,6 @@ namespace :import do desc "Notify parent imports when children finish" task notify_parent: :environment do - ParentImportNotifier.notify_when_finished + ParentNotifier.new(Import).notify_when_finished end end diff --git a/spec/services/parent_import_notifier_spec.rb b/spec/services/parent_import_notifier_spec.rb deleted file mode 100644 index 3ab505f88..000000000 --- a/spec/services/parent_import_notifier_spec.rb +++ /dev/null @@ -1,90 +0,0 @@ -RSpec.describe ParentImportNotifier do - let(:workbench_import) { create(:workbench_import) } - - describe ".notify_when_finished" do - it "calls #notify_parent on finished imports" do - workbench_import = build_stubbed(:workbench_import) - - finished_statuses = [:failed, :successful, :aborted, :canceled] - netex_imports = [] - - finished_statuses.each do |status| - netex_imports << build_stubbed( - :netex_import, - parent: workbench_import, - status: status - ) - end - - netex_imports.each do |netex_import| - expect(netex_import).to receive(:notify_parent) - end - - ParentImportNotifier.notify_when_finished(netex_imports) - end - - it "doesn't call #notify_parent if its `notified_parent_at` is set" do - netex_import = create( - :netex_import, - parent: workbench_import, - status: :failed, - notified_parent_at: DateTime.now - ) - - expect(netex_import).not_to receive(:notify_parent) - - ParentImportNotifier.notify_when_finished - end - end - - describe ".imports_pending_notification" do - it "includes imports with a parent and `notified_parent_at` unset" do - netex_import = create( - :netex_import, - parent: workbench_import, - status: :successful, - notified_parent_at: nil - ) - - expect( - ParentImportNotifier.imports_pending_notification - ).to eq([netex_import]) - end - - it "doesn't include imports without a parent" do - create(:import, parent: nil) - - expect( - ParentImportNotifier.imports_pending_notification - ).to be_empty - end - - it "doesn't include imports that aren't finished" do - [:new, :pending, :running].each do |status| - create( - :netex_import, - parent: workbench_import, - status: status, - notified_parent_at: nil - ) - end - - expect( - ParentImportNotifier.imports_pending_notification - ).to be_empty - end - - it "doesn't include imports that have already notified their parent" do - create( - :netex_import, - parent: workbench_import, - status: :successful, - notified_parent_at: DateTime.now - ) - - expect( - ParentImportNotifier.imports_pending_notification - ).to be_empty - end - end -end -- cgit v1.2.3 From f6bc7ad342c19393d364341b3e753154df78a295 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 7 Feb 2018 13:01:01 +0100 Subject: schedule.rb: Add cron job to finalise `ComplianceCheckSet`s A new recurring job that does exactly the same thing as the import job. This finalises `ComplianceCheckSet`s. First we need to abort all unfinished `ComplianceCheckSet`s older than four hours. Then we finalise the imports by doing the same work in `Api::V1::Internals::ComplianceCheckSetsController#notify_parent`, namely calling `#notify_parent` on `ComplianceCheckSet`s (here, only on the ones that are finished). Add a couple new Rake tasks for compliance check sets that mirror those for imports, and do the work required by the cron job. Refs #4758 --- config/schedule.rb | 5 +++++ lib/tasks/compliance_check_sets.rb | 11 +++++++++++ 2 files changed, 16 insertions(+) create mode 100644 lib/tasks/compliance_check_sets.rb diff --git a/config/schedule.rb b/config/schedule.rb index 08488c255..532707470 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -43,6 +43,11 @@ every 5.minutes do rake "import:notify_parent" end +every 5.minutes do + rake "compliance_check_sets:abort_old" + rake "compliance_check_sets:notify_parent" +end + every 1.minute do command "/bin/echo HeartBeat" end diff --git a/lib/tasks/compliance_check_sets.rb b/lib/tasks/compliance_check_sets.rb new file mode 100644 index 000000000..c53c7f9ed --- /dev/null +++ b/lib/tasks/compliance_check_sets.rb @@ -0,0 +1,11 @@ +namespace :compliance_check_sets do + desc "Notify parent check sets when children finish" + task notify_parent: :environment do + ParentNotifier.new(ComplianceCheckSet).notify_when_finished + end + + desc "Mark old unfinished check sets as 'aborted'" + task abort_old: :environment do + ComplianceCheckSet.abort_old + end +end -- cgit v1.2.3 From f9e8dd00ff0a8ed935789e83d0cdc2ffdfb7d1bb Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 8 Feb 2018 11:56:35 +0100 Subject: checksum_support.rb: Rename `seperator` to `separator` Fix spelling. Refs #5416 --- spec/support/checksum_support.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/support/checksum_support.rb b/spec/support/checksum_support.rb index 3d88d1d57..760955274 100644 --- a/spec/support/checksum_support.rb +++ b/spec/support/checksum_support.rb @@ -1,22 +1,22 @@ shared_examples 'checksum support' do describe '#current_checksum_source' do let(:attributes) { ['code_value', 'label_value'] } - let(:seperator) { ChecksumSupport::SEPARATOR } + let(:separator) { ChecksumSupport::SEPARATOR } let(:nil_value) { ChecksumSupport::VALUE_FOR_NIL_ATTRIBUTE } before do allow_any_instance_of(subject.class).to receive(:checksum_attributes).and_return(attributes) end - it 'should separate attribute by seperator' do - expect(subject.current_checksum_source).to eq("code_value#{seperator}label_value") + it 'should separate attribute by separator' do + expect(subject.current_checksum_source).to eq("code_value#{separator}label_value") end context 'nil value' do let(:attributes) { ['code_value', nil] } it 'should replace nil attributes by default value' do - source = "code_value#{seperator}#{nil_value}" + source = "code_value#{separator}#{nil_value}" expect(subject.current_checksum_source).to eq(source) end end @@ -25,7 +25,7 @@ shared_examples 'checksum support' do let(:attributes) { ['code_value', []] } it 'should convert to nil' do - source = "code_value#{seperator}#{nil_value}" + source = "code_value#{separator}#{nil_value}" expect(subject.current_checksum_source).to eq(source) end end @@ -34,7 +34,7 @@ shared_examples 'checksum support' do let(:attributes) { [['v1', 'v2', 'v3'], 'code_value'] } it 'should convert to list' do - source = "v1,v2,v3#{seperator}code_value" + source = "v1,v2,v3#{separator}code_value" expect(subject.current_checksum_source).to eq(source) end end @@ -43,7 +43,7 @@ shared_examples 'checksum support' do let(:attributes) { [[['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']], 'code_value'] } it 'should convert to list' do - source = "(a1,a2,a3),(b1,b2,b3)#{seperator}code_value" + source = "(a1,a2,a3),(b1,b2,b3)#{separator}code_value" expect(subject.current_checksum_source).to eq(source) end end @@ -52,7 +52,7 @@ shared_examples 'checksum support' do let(:attributes) { [[['a1', 'a2', 'a3'], []], 'code_value'] } it 'should convert to list' do - source = "(a1,a2,a3),-#{seperator}code_value" + source = "(a1,a2,a3),-#{separator}code_value" expect(subject.current_checksum_source).to eq(source) end end -- cgit v1.2.3 From ffc1f992221fbc95c3338ceb1f75be0967838191 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 8 Feb 2018 16:40:09 +0100 Subject: checksum_support.rb: Simplify checksum value map Add Johan's suggestion for simplifying this line. This allows us to get rid of one of the `#map` calls. Refs #5416 --- app/models/concerns/checksum_support.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/checksum_support.rb b/app/models/concerns/checksum_support.rb index 397a22231..43dd9047c 100644 --- a/app/models/concerns/checksum_support.rb +++ b/app/models/concerns/checksum_support.rb @@ -26,7 +26,7 @@ module ChecksumSupport def checksum_replace_nil_or_empty_values values # Replace empty array by nil & nil by VALUE_FOR_NIL_ATTRIBUTE - values.map{ |x| x unless x.try(:empty?) }.map{ |x| x || VALUE_FOR_NIL_ATTRIBUTE }.map do |item| + values.map { |x| x.present? && x || VALUE_FOR_NIL_ATTRIBUTE }.map do |item| item = item.kind_of?(Array) ? checksum_replace_nil_or_empty_values(item) : item end end -- cgit v1.2.3 From efddc15bfc8807e4156fe61c058bae34ac05754c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 8 Feb 2018 16:51:19 +0100 Subject: checksum_support.rb: Add whitespace Make `#checksum_replace_nil_or_empty_values` more readable. Refs #5416 --- app/models/concerns/checksum_support.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/checksum_support.rb b/app/models/concerns/checksum_support.rb index 43dd9047c..92103798e 100644 --- a/app/models/concerns/checksum_support.rb +++ b/app/models/concerns/checksum_support.rb @@ -26,9 +26,16 @@ module ChecksumSupport def checksum_replace_nil_or_empty_values values # Replace empty array by nil & nil by VALUE_FOR_NIL_ATTRIBUTE - values.map { |x| x.present? && x || VALUE_FOR_NIL_ATTRIBUTE }.map do |item| - item = item.kind_of?(Array) ? checksum_replace_nil_or_empty_values(item) : item - end + values + .map { |x| x.present? && x || VALUE_FOR_NIL_ATTRIBUTE } + .map do |item| + item = + if item.kind_of?(Array) + checksum_replace_nil_or_empty_values(item) + else + item + end + end end def current_checksum_source -- cgit v1.2.3 From a3d7ced00bf68b44720cd4e09ebdb018c37c62bd Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 9 Feb 2018 10:09:57 +0100 Subject: Refs #5807; Bump webpacker --- Gemfile | 2 +- Gemfile.lock | 10 +++++----- config/webpack/environment.js | 2 +- config/webpack/production.js | 2 +- config/webpack/staging.js | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Gemfile b/Gemfile index bb1a42df0..788358c5a 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,7 @@ gem 'uglifier', '~> 2.7.2' gem 'coffee-rails', '~> 4.0.0' # Webpacker -gem 'webpacker', '3.0.2' +gem 'webpacker', '3.2.1' # Use jquery as the JavaScript library gem 'jquery-rails', '~> 3.1.4' # Update to v4 for Rails 4.2 diff --git a/Gemfile.lock b/Gemfile.lock index 805ee460d..2398037b2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -269,7 +269,7 @@ GEM htmlbeautifier (1.3.1) httparty (0.14.0) multi_xml (>= 0.5.2) - i18n (0.9.3) + i18n (0.9.4) concurrent-ruby (~> 1.0) i18n-tasks (0.9.15) activesupport (>= 4.0.2) @@ -318,7 +318,7 @@ GEM mime-types-data (3.2016.0521) mimemagic (0.3.2) mini_portile2 (2.3.0) - minitest (5.11.2) + minitest (5.11.3) money (6.10.1) i18n (>= 0.6.4, < 1.0) multi_json (1.12.1) @@ -553,7 +553,7 @@ GEM json (>= 1.8, < 3.0) parser (>= 2.3.0.7) rainbow (>= 1.99.1, < 3.0) - tzinfo (1.2.4) + tzinfo (1.2.5) thread_safe (~> 0.1) uglifier (2.7.2) execjs (>= 0.3.0) @@ -566,7 +566,7 @@ GEM addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff - webpacker (3.0.2) + webpacker (3.2.1) activesupport (>= 4.2) rack-proxy (>= 0.6.1) railties (>= 4.2) @@ -703,7 +703,7 @@ DEPENDENCIES transpec uglifier (~> 2.7.2) webmock - webpacker (= 3.0.2) + webpacker (= 3.2.1) whenever! will_paginate will_paginate-bootstrap diff --git a/config/webpack/environment.js b/config/webpack/environment.js index 688bcbe8e..743cf66a8 100644 --- a/config/webpack/environment.js +++ b/config/webpack/environment.js @@ -14,7 +14,7 @@ let cleanOptions = { }; -environment.plugins.set( +environment.plugins.append( 'CleanWebpack', new CleanWebpackPlugin(pathsToClean, cleanOptions) ) diff --git a/config/webpack/production.js b/config/webpack/production.js index 7703f8452..82478b156 100644 --- a/config/webpack/production.js +++ b/config/webpack/production.js @@ -2,7 +2,7 @@ const environment = require('./environment') const webpack = require('webpack') const UglifyJsPlugin = require('uglify-js') -environment.plugins.set( +environment.plugins.append( 'UglifyJs', new webpack.optimize.UglifyJsPlugin({ compress: { diff --git a/config/webpack/staging.js b/config/webpack/staging.js index 7703f8452..82478b156 100644 --- a/config/webpack/staging.js +++ b/config/webpack/staging.js @@ -2,7 +2,7 @@ const environment = require('./environment') const webpack = require('webpack') const UglifyJsPlugin = require('uglify-js') -environment.plugins.set( +environment.plugins.append( 'UglifyJs', new webpack.optimize.UglifyJsPlugin({ compress: { -- cgit v1.2.3 From 54c4cd2ddb23e3acf756881c23e78cf61d23e1a6 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 9 Feb 2018 10:18:56 +0100 Subject: Refs 5807; Force jest specs --- lib/tasks/ci.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 13d7b8d73..fdd813516 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -38,8 +38,8 @@ namespace :ci do end task :jest => "ci:assets" do - sh "yarn --no-progress install" # Hack to force install jest after webpack - sh "node_modules/.bin/jest" unless ["CHOUETTE_JEST_DISABLED"] + sh "yarn --no-progress install" # Hack to force install jest after webpack + sh "node_modules/.bin/jest" end desc "Deploy after CI" -- cgit v1.2.3 From 8b6e358e3e59c507eac738a38b54f45a133164cc Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 22 Jan 2018 16:45:19 +0100 Subject: Refs #5669 @2h; Add a snapshot mechanism in the specs --- Gemfile | 1 + Gemfile.lock | 7 +++++ spec/support/integration_spec_helper.rb | 7 +++++ spec/support/pundit/pundit_view_policy.rb | 7 ++++- spec/support/snapshot_support.rb | 23 ++++++++++++++ .../__snapshots__/referentials/show.snap | 7 +++++ .../__snapshots__/referentials/show_create.snap | 9 ++++++ .../__snapshots__/referentials/show_destroy.snap | 9 ++++++ .../referentials/show_purchase_windows.snap | 7 +++++ .../referentials/show_purchase_windows_create.snap | 9 ++++++ .../show_purchase_windows_destroy.snap | 9 ++++++ .../referentials/show_purchase_windows_update.snap | 12 ++++++++ .../__snapshots__/referentials/show_readonly.snap | 7 +++++ .../referentials/show_readonly_create.snap | 9 ++++++ .../referentials/show_readonly_destroy.snap | 7 +++++ .../referentials/show_readonly_update.snap | 7 +++++ .../show_referential_vehicle_journeys.snap | 7 +++++ .../show_referential_vehicle_journeys_create.snap | 9 ++++++ .../show_referential_vehicle_journeys_destroy.snap | 9 ++++++ .../show_referential_vehicle_journeys_update.snap | 12 ++++++++ .../__snapshots__/referentials/show_update.snap | 12 ++++++++ spec/views/referentials/show.html.erb_spec.rb | 36 ++++++++++++++++++++-- 22 files changed, 219 insertions(+), 3 deletions(-) create mode 100644 spec/support/snapshot_support.rb create mode 100644 spec/views/referentials/__snapshots__/referentials/show.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_create.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_destroy.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_readonly.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap create mode 100644 spec/views/referentials/__snapshots__/referentials/show_update.snap diff --git a/Gemfile b/Gemfile index bb1a42df0..b220e51e3 100644 --- a/Gemfile +++ b/Gemfile @@ -176,6 +176,7 @@ group :test do gem 'simplecov-rcov', :require => false gem 'htmlbeautifier' gem 'timecop' + gem 'rspec-snapshot' end group :test, :development, :dev do diff --git a/Gemfile.lock b/Gemfile.lock index 805ee460d..3d957b06b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -447,6 +447,10 @@ GEM roo (2.7.1) nokogiri (~> 1) rubyzip (~> 1.1, < 2.0.0) + rspec (3.5.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) rspec-core (3.5.4) rspec-support (~> 3.5.0) rspec-expectations (3.5.0) @@ -463,6 +467,8 @@ GEM rspec-expectations (~> 3.5.0) rspec-mocks (~> 3.5.0) rspec-support (~> 3.5.0) + rspec-snapshot (0.1.1) + rspec (> 3.0.0) rspec-support (3.5.0) ruby-filemagic (0.7.2) ruby-graphviz (1.2.3) @@ -681,6 +687,7 @@ DEPENDENCIES rgeo (~> 0.5.2) roo rspec-rails (~> 3.5.0) + rspec-snapshot rubyzip sass-rails (~> 4.0.3) sawyer (~> 0.6.0) diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 36306559d..a9a31f232 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -24,6 +24,13 @@ module IntegrationSpecHelper context('', &block) if block_given? end end + + def with_feature feature, &block + context "with feature #{feature}" do + let(:features){ [feature] } + context('', &block) if block_given? + end + end end def self.included into diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index 330209049..058f1f6ed 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -5,9 +5,14 @@ module Pundit into.let(:current_referential){ referential || build_stubbed(:referential, organisation: organisation) } into.let(:current_user){ create :user, permissions: permissions, organisation: organisation } into.let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } + into.let(:current_offer_workbench) { create :workbench, organisation: organisation} into.before do allow(view).to receive(:pundit_user) { pundit_user } - + allow(view).to receive(:current_user) { current_user } + allow(view).to receive(:current_organisation).and_return(organisation) + allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench) + allow(view).to receive(:has_feature?){ |f| features.include?(f)} + allow(view).to receive(:user_signed_in?).and_return true allow(view).to receive(:policy) do |instance| ::Pundit.policy pundit_user, instance end diff --git a/spec/support/snapshot_support.rb b/spec/support/snapshot_support.rb new file mode 100644 index 000000000..f1a6b1469 --- /dev/null +++ b/spec/support/snapshot_support.rb @@ -0,0 +1,23 @@ +RSpec::Matchers.define :match_actions_links_snapshot do |name| + match do |actual| + @content = Capybara::Node::Simple.new(rendered).find('.page_header').native.inner_html + expect(@content).to match_snapshot(name) + end + + failure_message do |actual| + out = ["Snapshots did not match."] + expected = File.read(File.dirname(method_missing(:class).metadata[:file_path]) + "/__snapshots__/#{name}.snap") + out << "Expected: #{expected}" + out << "Actual: #{@content}" + out << "\n\n --- DIFF ---" + out << differ.diff_as_string(@content, expected) + out.join("\n") + end + + def differ + RSpec::Support::Differ.new( + :object_preparer => lambda { |object| RSpec::Matchers::Composable.surface_descriptions_in(object) }, + :color => RSpec::Matchers.configuration.color? + ) + end +end diff --git a/spec/views/referentials/__snapshots__/referentials/show.snap b/spec/views/referentials/__snapshots__/referentials/show.snap new file mode 100644 index 000000000..d66428a4c --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show.snap @@ -0,0 +1,7 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_create.snap b/spec/views/referentials/__snapshots__/referentials/show_create.snap new file mode 100644 index 000000000..c513e63c4 --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_create.snap @@ -0,0 +1,9 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_destroy.snap new file mode 100644 index 000000000..ada47b018 --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_destroy.snap @@ -0,0 +1,9 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap new file mode 100644 index 000000000..d66428a4c --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap @@ -0,0 +1,7 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap new file mode 100644 index 000000000..c513e63c4 --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap @@ -0,0 +1,9 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap new file mode 100644 index 000000000..ada47b018 --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap @@ -0,0 +1,9 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap new file mode 100644 index 000000000..0150710ac --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap @@ -0,0 +1,12 @@ +
+
+

Jeu de données Jeu de données

+
+
Dernière mise à jour le 01/01/2018
+Editer +
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly.snap new file mode 100644 index 000000000..d66428a4c --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly.snap @@ -0,0 +1,7 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap new file mode 100644 index 000000000..721e82c76 --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap @@ -0,0 +1,9 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap new file mode 100644 index 000000000..d66428a4c --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap @@ -0,0 +1,7 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap new file mode 100644 index 000000000..d66428a4c --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap @@ -0,0 +1,7 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap new file mode 100644 index 000000000..d66428a4c --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap @@ -0,0 +1,7 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap new file mode 100644 index 000000000..c513e63c4 --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap @@ -0,0 +1,9 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap new file mode 100644 index 000000000..ada47b018 --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap @@ -0,0 +1,9 @@ +
+
+

Jeu de données Jeu de données

+
Dernière mise à jour le 01/01/2018
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap new file mode 100644 index 000000000..0150710ac --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap @@ -0,0 +1,12 @@ +
+
+

Jeu de données Jeu de données

+
+
Dernière mise à jour le 01/01/2018
+Editer +
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_update.snap b/spec/views/referentials/__snapshots__/referentials/show_update.snap new file mode 100644 index 000000000..0150710ac --- /dev/null +++ b/spec/views/referentials/__snapshots__/referentials/show_update.snap @@ -0,0 +1,12 @@ +
+
+

Jeu de données Jeu de données

+
+
Dernière mise à jour le 01/01/2018
+Editer +
+
+ +
\ No newline at end of file diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb index 6fd51949a..be29dbd79 100644 --- a/spec/views/referentials/show.html.erb_spec.rb +++ b/spec/views/referentials/show.html.erb_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe "referentials/show", type: :view do - let!(:referential) do referential = create(:referential, organisation: organisation) assign :referential, referential.decorate(context: { @@ -30,7 +29,6 @@ describe "referentials/show", type: :view do allow(referential).to receive(:referential_read_only?){ readonly } render template: "referentials/show", layout: "layouts/application" end - it "should not present edit button" do expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]") end @@ -48,4 +46,38 @@ describe "referentials/show", type: :view do end end + describe "action links" do + context "with a readonly referential" do + let(:readonly){ true } + it { should match_actions_links_snapshot "referentials/show_readonly" } + + %w(create destroy update).each do |p| + with_permission "referentials.#{p}" do + it { should match_actions_links_snapshot "referentials/show_readonly_#{p}" } + end + end + end + + context "with a non-readonly referential" do + it { should match_actions_links_snapshot "referentials/show" } + + %w(create destroy update).each do |p| + with_permission "referentials.#{p}" do + it { should match_actions_links_snapshot "referentials/show_#{p}" } + end + end + end + + %w(purchase_windows referential_vehicle_journeys).each do |f| + with_feature f do + it { should match_actions_links_snapshot "referentials/show_#{f}" } + + %w(create update destroy).each do |p| + with_permission "referentials.#{p}" do + it { should match_actions_links_snapshot "referentials/show_#{f}_#{p}" } + end + end + end + end + end end -- cgit v1.2.3 From 590ff858cf0fe71b420f8a59d393319e190f68aa Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 22 Jan 2018 21:11:28 +0100 Subject: Refs #5669; Add a preview for snapshots for easier debugging --- app/controllers/snapshots_controller.rb | 14 ++++++++++++++ app/views/layouts/snapshots/actions_links.html.slim | 21 +++++++++++++++++++++ app/views/layouts/snapshots/default.html.slim | 19 +++++++++++++++++++ config/routes.rb | 4 ++++ spec/support/snapshot_support.rb | 15 ++++++++++++++- 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 app/controllers/snapshots_controller.rb create mode 100644 app/views/layouts/snapshots/actions_links.html.slim create mode 100644 app/views/layouts/snapshots/default.html.slim diff --git a/app/controllers/snapshots_controller.rb b/app/controllers/snapshots_controller.rb new file mode 100644 index 000000000..e453b4965 --- /dev/null +++ b/app/controllers/snapshots_controller.rb @@ -0,0 +1,14 @@ +class SnapshotsController < ApplicationController + if Rails.env.development? || Rails.env.test? + layout :which_layout + def show + tpl = params[:snap] + tpl = tpl.gsub Rails.root.to_s, '' + render file: tpl + end + + def which_layout + "snapshots/#{params[:layout] || "default"}" + end + end +end diff --git a/app/views/layouts/snapshots/actions_links.html.slim b/app/views/layouts/snapshots/actions_links.html.slim new file mode 100644 index 000000000..f1fa55e87 --- /dev/null +++ b/app/views/layouts/snapshots/actions_links.html.slim @@ -0,0 +1,21 @@ +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" + + = csrf_meta_tag + + title = t('brandname') + + = stylesheet_link_tag 'base' + = stylesheet_link_tag 'application' + + = javascript_pack_tag 'application' + = javascript_include_tag 'application' + + body + = render 'layouts/navigation/main_nav' + = render 'layouts/flash_messages', flash: flash + div.page_header + = yield diff --git a/app/views/layouts/snapshots/default.html.slim b/app/views/layouts/snapshots/default.html.slim new file mode 100644 index 000000000..9e4565dcb --- /dev/null +++ b/app/views/layouts/snapshots/default.html.slim @@ -0,0 +1,19 @@ +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" + + = csrf_meta_tag + + title = t('brandname') + + = stylesheet_link_tag 'base' + = stylesheet_link_tag 'application' + + = javascript_pack_tag 'application' + = javascript_include_tag 'application' + + body + = yield + diff --git a/config/routes.rb b/config/routes.rb index 5fc39ba92..2715ca428 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -241,6 +241,10 @@ ChouetteIhm::Application.routes.draw do root :to => "dashboards#show" + if Rails.env.development? || Rails.env.test? + get "/snap" => "snapshots#show" + end + get '/help/(*slug)' => 'help#show' if Rails.application.config.development_toolbar diff --git a/spec/support/snapshot_support.rb b/spec/support/snapshot_support.rb index f1a6b1469..c37bb075c 100644 --- a/spec/support/snapshot_support.rb +++ b/spec/support/snapshot_support.rb @@ -6,14 +6,27 @@ RSpec::Matchers.define :match_actions_links_snapshot do |name| failure_message do |actual| out = ["Snapshots did not match."] - expected = File.read(File.dirname(method_missing(:class).metadata[:file_path]) + "/__snapshots__/#{name}.snap") + snap_path = File.dirname(method_missing(:class).metadata[:file_path]) + "/__snapshots__/#{name}.snap" + temp_path = Pathname.new "#{Rails.root}/tmp/__snapshots__/#{name}.failed.snap" + FileUtils.mkdir_p temp_path.dirname + tmp = File.new temp_path, "w" + tmp.write @content + tmp.close() + expected = File.read snap_path out << "Expected: #{expected}" out << "Actual: #{@content}" out << "\n\n --- DIFF ---" out << differ.diff_as_string(@content, expected) + out << "\n\n --- Previews : ---" + out << "Expected: \n" + snapshot_url(snap: snap_path, layout: :actions_links) + out << " \nActual: \n" + snapshot_url(snap: tmp.path, layout: :actions_links) out.join("\n") end + def snapshot_url snap:, layout: + "http://localhost:3000/snap/?snap=#{URI.encode(snap.to_s)}&layout=#{URI.encode(layout.to_s)}" + end + def differ RSpec::Support::Differ.new( :object_preparer => lambda { |object| RSpec::Matchers::Composable.surface_descriptions_in(object) }, -- cgit v1.2.3 From f114485e22c17239f3d7be06eb3bc1abffbbfe4b Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 23 Jan 2018 13:35:26 +0100 Subject: Refs #5669 @1h; Set invariant values in the snapshots --- spec/support/snapshot_support.rb | 24 ++++++++++++++++++++++ .../__snapshots__/referentials/show.snap | 6 +++--- .../__snapshots__/referentials/show_create.snap | 6 +++--- .../__snapshots__/referentials/show_destroy.snap | 6 +++--- .../referentials/show_purchase_windows.snap | 6 +++--- .../referentials/show_purchase_windows_create.snap | 6 +++--- .../show_purchase_windows_destroy.snap | 6 +++--- .../referentials/show_purchase_windows_update.snap | 8 ++++---- .../__snapshots__/referentials/show_readonly.snap | 6 +++--- .../referentials/show_readonly_create.snap | 6 +++--- .../referentials/show_readonly_destroy.snap | 6 +++--- .../referentials/show_readonly_update.snap | 6 +++--- .../show_referential_vehicle_journeys.snap | 6 +++--- .../show_referential_vehicle_journeys_create.snap | 6 +++--- .../show_referential_vehicle_journeys_destroy.snap | 6 +++--- .../show_referential_vehicle_journeys_update.snap | 8 ++++---- .../__snapshots__/referentials/show_update.snap | 8 ++++---- spec/views/referentials/show.html.erb_spec.rb | 8 +++++++- 18 files changed, 82 insertions(+), 52 deletions(-) diff --git a/spec/support/snapshot_support.rb b/spec/support/snapshot_support.rb index c37bb075c..b1ade5288 100644 --- a/spec/support/snapshot_support.rb +++ b/spec/support/snapshot_support.rb @@ -1,3 +1,27 @@ +module SnaphostSpecHelper + + module Methods + def set_invariant expr, val=nil + val ||= expr + chain = expr.split(".") + method = chain.pop + + before(:each) do + allow(eval(chain.join('.'))).to receive(method){ val } + end + end + end + + def self.included into + into.extend Methods + end +end + +RSpec.configure do |config| + config.include SnaphostSpecHelper, type: :view +end + + RSpec::Matchers.define :match_actions_links_snapshot do |name| match do |actual| @content = Capybara::Node::Simple.new(rendered).find('.page_header').native.inner_html diff --git a/spec/views/referentials/__snapshots__/referentials/show.snap b/spec/views/referentials/__snapshots__/referentials/show.snap index d66428a4c..06e60d910 100644 --- a/spec/views/referentials/__snapshots__/referentials/show.snap +++ b/spec/views/referentials/__snapshots__/referentials/show.snap @@ -1,7 +1,7 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_create.snap b/spec/views/referentials/__snapshots__/referentials/show_create.snap index c513e63c4..4f0f8352d 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_create.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_create.snap @@ -1,9 +1,9 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_destroy.snap index ada47b018..49ead7d2a 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_destroy.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_destroy.snap @@ -1,9 +1,9 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap index d66428a4c..06e60d910 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap @@ -1,7 +1,7 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap index c513e63c4..4f0f8352d 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap @@ -1,9 +1,9 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap index ada47b018..49ead7d2a 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap @@ -1,9 +1,9 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap index 0150710ac..9d8b4f276 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap @@ -1,12 +1,12 @@
-

Jeu de données Jeu de données

+

referential_full_name

-
Dernière mise à jour le 01/01/2018
-Editer +
Dernière mise à jour le 01/01/2000
+Editer
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly.snap index d66428a4c..06e60d910 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_readonly.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly.snap @@ -1,7 +1,7 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap index 721e82c76..6633fba3e 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap @@ -1,9 +1,9 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap index d66428a4c..06e60d910 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap @@ -1,7 +1,7 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap index d66428a4c..06e60d910 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap @@ -1,7 +1,7 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap index d66428a4c..06e60d910 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap @@ -1,7 +1,7 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap index c513e63c4..4f0f8352d 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap @@ -1,9 +1,9 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap index ada47b018..49ead7d2a 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap @@ -1,9 +1,9 @@
-

Jeu de données Jeu de données

-
Dernière mise à jour le 01/01/2018
+

referential_full_name

+
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap index 0150710ac..9d8b4f276 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap @@ -1,12 +1,12 @@
-

Jeu de données Jeu de données

+

referential_full_name

-
Dernière mise à jour le 01/01/2018
-Editer +
Dernière mise à jour le 01/01/2000
+Editer
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_update.snap b/spec/views/referentials/__snapshots__/referentials/show_update.snap index 0150710ac..9d8b4f276 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_update.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_update.snap @@ -1,12 +1,12 @@
-

Jeu de données Jeu de données

+

referential_full_name

-
Dernière mise à jour le 01/01/2018
-Editer +
Dernière mise à jour le 01/01/2000
+Editer
\ No newline at end of file diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb index be29dbd79..9aaa762fe 100644 --- a/spec/views/referentials/show.html.erb_spec.rb +++ b/spec/views/referentials/show.html.erb_spec.rb @@ -27,7 +27,6 @@ describe "referentials/show", type: :view do allow(view).to receive(:params).and_return({action: :show}) allow(referential).to receive(:referential_read_only?){ readonly } - render template: "referentials/show", layout: "layouts/application" end it "should not present edit button" do expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]") @@ -47,6 +46,13 @@ describe "referentials/show", type: :view do end describe "action links" do + set_invariant "referential.object.full_name", "referential_full_name" + set_invariant "referential.object.updated_at", "01/01/2000 00:00".to_time + set_invariant "referential.object.id", "99" + + before(:each){ + render template: "referentials/show", layout: "layouts/application" + } context "with a readonly referential" do let(:readonly){ true } it { should match_actions_links_snapshot "referentials/show_readonly" } -- cgit v1.2.3 From 81e6a92e128ac747f526a83efb5a88157f71635a Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 23 Jan 2018 14:05:11 +0100 Subject: Refs #5669; Add more snapshots --- .../companies/__snapshots__/companies/index.snap | 4 ++ .../__snapshots__/companies/index_create.snap | 4 ++ .../__snapshots__/companies/index_destroy.snap | 4 ++ .../__snapshots__/companies/index_update.snap | 4 ++ spec/views/companies/index.html.erb_spec.rb | 27 ++++++- spec/views/lines/__snapshots__/lines/index.snap | 4 ++ .../lines/__snapshots__/lines/index_create.snap | 4 ++ .../lines/__snapshots__/lines/index_destroy.snap | 4 ++ .../lines/__snapshots__/lines/index_update.snap | 4 ++ spec/views/lines/__snapshots__/lines/show.snap | 9 +++ .../lines/__snapshots__/lines/show_create.snap | 9 +++ .../lines/__snapshots__/lines/show_destroy.snap | 9 +++ .../lines/__snapshots__/lines/show_update.snap | 9 +++ spec/views/lines/index.html.slim_spec.rb | 84 +++++++++++++--------- spec/views/lines/show.html.erb_spec.rb | 21 ++++++ 15 files changed, 167 insertions(+), 33 deletions(-) create mode 100644 spec/views/companies/__snapshots__/companies/index.snap create mode 100644 spec/views/companies/__snapshots__/companies/index_create.snap create mode 100644 spec/views/companies/__snapshots__/companies/index_destroy.snap create mode 100644 spec/views/companies/__snapshots__/companies/index_update.snap create mode 100644 spec/views/lines/__snapshots__/lines/index.snap create mode 100644 spec/views/lines/__snapshots__/lines/index_create.snap create mode 100644 spec/views/lines/__snapshots__/lines/index_destroy.snap create mode 100644 spec/views/lines/__snapshots__/lines/index_update.snap create mode 100644 spec/views/lines/__snapshots__/lines/show.snap create mode 100644 spec/views/lines/__snapshots__/lines/show_create.snap create mode 100644 spec/views/lines/__snapshots__/lines/show_destroy.snap create mode 100644 spec/views/lines/__snapshots__/lines/show_update.snap diff --git a/spec/views/companies/__snapshots__/companies/index.snap b/spec/views/companies/__snapshots__/companies/index.snap new file mode 100644 index 000000000..2c5c23400 --- /dev/null +++ b/spec/views/companies/__snapshots__/companies/index.snap @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/index_create.snap b/spec/views/companies/__snapshots__/companies/index_create.snap new file mode 100644 index 000000000..edf531f62 --- /dev/null +++ b/spec/views/companies/__snapshots__/companies/index_create.snap @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/index_destroy.snap b/spec/views/companies/__snapshots__/companies/index_destroy.snap new file mode 100644 index 000000000..2c5c23400 --- /dev/null +++ b/spec/views/companies/__snapshots__/companies/index_destroy.snap @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/index_update.snap b/spec/views/companies/__snapshots__/companies/index_update.snap new file mode 100644 index 000000000..2c5c23400 --- /dev/null +++ b/spec/views/companies/__snapshots__/companies/index_update.snap @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/spec/views/companies/index.html.erb_spec.rb b/spec/views/companies/index.html.erb_spec.rb index 9db689ba6..8f3ce9ad3 100644 --- a/spec/views/companies/index.html.erb_spec.rb +++ b/spec/views/companies/index.html.erb_spec.rb @@ -3,7 +3,10 @@ require 'spec_helper' RSpec.describe "/companies/index", :type => :view do let!(:line_referential) { assign :line_referential, create(:line_referential) } - let!(:companies) { assign :companies, CompanyDecorator.decorate_collection(Array.new(2) { create(:company, line_referential: line_referential) }.paginate) } + let(:context){{referential: line_referential}} + let!(:companies) do + assign :companies, build_paginated_collection(:company, CompanyDecorator, line_referential: line_referential, context: context) + end let!(:search) { assign :q, Ransack::Search.new(Chouette::Company) } # Fixme #1795 @@ -22,4 +25,26 @@ RSpec.describe "/companies/index", :type => :view do # expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_line_referential_company_path(line_referential)}']") # end + before(:each) do + allow(view).to receive(:collection).and_return(companies) + allow(view).to receive(:current_referential).and_return(line_referential) + controller.request.path_parameters[:line_referential_id] = line_referential.id + end + + describe "action links" do + set_invariant "line_referential.id", "99" + + before(:each){ + render template: "companies/index", layout: "layouts/application" + } + + it { should match_actions_links_snapshot "companies/index" } + + %w(create update destroy).each do |p| + with_permission "companies.#{p}" do + it { should match_actions_links_snapshot "companies/index_#{p}" } + end + end + end + end diff --git a/spec/views/lines/__snapshots__/lines/index.snap b/spec/views/lines/__snapshots__/lines/index.snap new file mode 100644 index 000000000..2c5c23400 --- /dev/null +++ b/spec/views/lines/__snapshots__/lines/index.snap @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/index_create.snap b/spec/views/lines/__snapshots__/lines/index_create.snap new file mode 100644 index 000000000..5c875b18a --- /dev/null +++ b/spec/views/lines/__snapshots__/lines/index_create.snap @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/index_destroy.snap b/spec/views/lines/__snapshots__/lines/index_destroy.snap new file mode 100644 index 000000000..2c5c23400 --- /dev/null +++ b/spec/views/lines/__snapshots__/lines/index_destroy.snap @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/index_update.snap b/spec/views/lines/__snapshots__/lines/index_update.snap new file mode 100644 index 000000000..2c5c23400 --- /dev/null +++ b/spec/views/lines/__snapshots__/lines/index_update.snap @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/show.snap b/spec/views/lines/__snapshots__/lines/show.snap new file mode 100644 index 000000000..c66e8ee2b --- /dev/null +++ b/spec/views/lines/__snapshots__/lines/show.snap @@ -0,0 +1,9 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/show_create.snap b/spec/views/lines/__snapshots__/lines/show_create.snap new file mode 100644 index 000000000..c8c1f81e2 --- /dev/null +++ b/spec/views/lines/__snapshots__/lines/show_create.snap @@ -0,0 +1,9 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/show_destroy.snap b/spec/views/lines/__snapshots__/lines/show_destroy.snap new file mode 100644 index 000000000..040a6d994 --- /dev/null +++ b/spec/views/lines/__snapshots__/lines/show_destroy.snap @@ -0,0 +1,9 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/show_update.snap b/spec/views/lines/__snapshots__/lines/show_update.snap new file mode 100644 index 000000000..c66e8ee2b --- /dev/null +++ b/spec/views/lines/__snapshots__/lines/show_update.snap @@ -0,0 +1,9 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/lines/index.html.slim_spec.rb b/spec/views/lines/index.html.slim_spec.rb index fb436c545..df3622e1a 100644 --- a/spec/views/lines/index.html.slim_spec.rb +++ b/spec/views/lines/index.html.slim_spec.rb @@ -13,7 +13,7 @@ describe "/lines/index", :type => :view do let(:lines) do assign :lines, build_paginated_collection(:line, LineDecorator, line_referential: line_referential, context: context) end - let!(:q) { assign :q, Ransack::Search.new(Chouette::Line) } + let!(:q) { assign :q, Ransack::Search.new(Chouette::Line) } before :each do deactivated_line @@ -25,49 +25,69 @@ describe "/lines/index", :type => :view do render end - common_items = ->{ - it { should have_link_for_each_item(lines, "show", -> (line){ view.line_referential_line_path(line_referential, line) }) } - it { should have_link_for_each_item(lines, "network", -> (line){ view.line_referential_network_path(line_referential, line.network) }) } - it { should have_link_for_each_item(lines, "company", -> (line){ view.line_referential_company_path(line_referential, line.company) }) } - } + describe "action links" do + set_invariant "line_referential.id", "99" - common_items.call() - it { should have_the_right_number_of_links(lines, 3) } + before(:each){ + render template: "lines/index", layout: "layouts/application" + } - with_permission "lines.change_status" do - common_items.call() - it { should have_link_for_each_item(lines, "deactivate", -> (line){ view.deactivate_line_referential_line_path(line_referential, line) }) } - it { should have_the_right_number_of_links(lines, 4) } + it { should match_actions_links_snapshot "lines/index" } + + %w(create update destroy).each do |p| + with_permission "lines.#{p}" do + it { should match_actions_links_snapshot "lines/index_#{p}" } + end + end end - with_permission "lines.destroy" do - common_items.call() - it { - should have_link_for_each_item(lines, "destroy", { - href: ->(line){ view.line_referential_line_path(line_referential, line)}, - method: :delete - }) + context "links" do + before(:each){ render } + + common_items = ->{ + it { should have_link_for_each_item(lines, "show", -> (line){ view.line_referential_line_path(line_referential, line) }) } + it { should have_link_for_each_item(lines, "network", -> (line){ view.line_referential_network_path(line_referential, line.network) }) } + it { should have_link_for_each_item(lines, "company", -> (line){ view.line_referential_company_path(line_referential, line.company) }) } } - it { should have_the_right_number_of_links(lines, 4) } - end - context "with a deactivated item" do + common_items.call() + it { should have_the_right_number_of_links(lines, 3) } + with_permission "lines.change_status" do - let(:deactivated_line){ create :line, deactivated: true } + common_items.call() + it { should have_link_for_each_item(lines, "deactivate", -> (line){ view.deactivate_line_referential_line_path(line_referential, line) }) } + it { should have_the_right_number_of_links(lines, 4) } + end + with_permission "lines.destroy" do common_items.call() - it "should display an activate link for the deactivated one" do - lines.each do |line| - if line == deactivated_line - href = view.activate_line_referential_line_path(line_referential, line) - else - href = view.deactivate_line_referential_line_path(line_referential, line) + it { + should have_link_for_each_item(lines, "destroy", { + href: ->(line){ view.line_referential_line_path(line_referential, line)}, + method: :delete + }) + } + it { should have_the_right_number_of_links(lines, 4) } + end + + context "with a deactivated item" do + with_permission "lines.change_status" do + let(:deactivated_line){ create :line, deactivated: true } + + common_items.call() + it "should display an activate link for the deactivated one" do + lines.each do |line| + if line == deactivated_line + href = view.activate_line_referential_line_path(line_referential, line) + else + href = view.deactivate_line_referential_line_path(line_referential, line) + end + selector = "tr.#{TableBuilderHelper.item_row_class_name(lines)}-#{line.id} .actions a[href='#{href}']" + expect(rendered).to have_selector(selector, count: 1) end - selector = "tr.#{TableBuilderHelper.item_row_class_name(lines)}-#{line.id} .actions a[href='#{href}']" - expect(rendered).to have_selector(selector, count: 1) end + it { should have_the_right_number_of_links(lines, 4) } end - it { should have_the_right_number_of_links(lines, 4) } end end end diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb index 9649d9c8e..65ac6bdb6 100644 --- a/spec/views/lines/show.html.erb_spec.rb +++ b/spec/views/lines/show.html.erb_spec.rb @@ -16,5 +16,26 @@ describe "/lines/show", :type => :view do before do allow(view).to receive_messages(current_organisation: referential.organisation) + controller.request.path_parameters[:line_referential_id] = line_referential.id + controller.request.path_parameters[:id] = line.id + end + + describe "action links" do + set_invariant "line_referential.id", "99" + set_invariant "line.id", "99" + set_invariant "line.company.id", "99" + set_invariant "line.network.id", "99" + + before(:each){ + render template: "lines/show", layout: "layouts/application" + } + + it { should match_actions_links_snapshot "lines/show" } + + %w(create update destroy).each do |p| + with_permission "lines.#{p}" do + it { should match_actions_links_snapshot "lines/show_#{p}" } + end + end end end -- cgit v1.2.3 From 3e6f023f87984894c3d0c7e4d70ea65c8966f063 Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 23 Jan 2018 14:31:26 +0100 Subject: Refs #5669; And more snapshots --- .../companies/__snapshots__/companies/show.snap | 7 ++++++ .../__snapshots__/companies/show_create.snap | 7 ++++++ .../__snapshots__/companies/show_destroy.snap | 7 ++++++ .../__snapshots__/companies/show_update.snap | 7 ++++++ spec/views/companies/show.html.erb_spec.rb | 24 +++++++++++++++++++ .../networks/__snapshots__/networks/index.snap | 4 ++++ .../__snapshots__/networks/index_create.snap | 4 ++++ .../__snapshots__/networks/index_destroy.snap | 4 ++++ .../__snapshots__/networks/index_update.snap | 4 ++++ .../networks/__snapshots__/networks/show.snap | 7 ++++++ .../__snapshots__/networks/show_create.snap | 7 ++++++ .../__snapshots__/networks/show_destroy.snap | 7 ++++++ .../__snapshots__/networks/show_update.snap | 7 ++++++ spec/views/networks/index.html.erb_spec.rb | 26 ++++++++++++++++++++- spec/views/networks/show.html.erb_spec.rb | 27 ++++++++++++++++++---- 15 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 spec/views/companies/__snapshots__/companies/show.snap create mode 100644 spec/views/companies/__snapshots__/companies/show_create.snap create mode 100644 spec/views/companies/__snapshots__/companies/show_destroy.snap create mode 100644 spec/views/companies/__snapshots__/companies/show_update.snap create mode 100644 spec/views/networks/__snapshots__/networks/index.snap create mode 100644 spec/views/networks/__snapshots__/networks/index_create.snap create mode 100644 spec/views/networks/__snapshots__/networks/index_destroy.snap create mode 100644 spec/views/networks/__snapshots__/networks/index_update.snap create mode 100644 spec/views/networks/__snapshots__/networks/show.snap create mode 100644 spec/views/networks/__snapshots__/networks/show_create.snap create mode 100644 spec/views/networks/__snapshots__/networks/show_destroy.snap create mode 100644 spec/views/networks/__snapshots__/networks/show_update.snap diff --git a/spec/views/companies/__snapshots__/companies/show.snap b/spec/views/companies/__snapshots__/companies/show.snap new file mode 100644 index 000000000..1bdce4f81 --- /dev/null +++ b/spec/views/companies/__snapshots__/companies/show.snap @@ -0,0 +1,7 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+
+
\ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/show_create.snap b/spec/views/companies/__snapshots__/companies/show_create.snap new file mode 100644 index 000000000..763ade31f --- /dev/null +++ b/spec/views/companies/__snapshots__/companies/show_create.snap @@ -0,0 +1,7 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/show_destroy.snap b/spec/views/companies/__snapshots__/companies/show_destroy.snap new file mode 100644 index 000000000..dc221a1ac --- /dev/null +++ b/spec/views/companies/__snapshots__/companies/show_destroy.snap @@ -0,0 +1,7 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/show_update.snap b/spec/views/companies/__snapshots__/companies/show_update.snap new file mode 100644 index 000000000..adcbb3cd6 --- /dev/null +++ b/spec/views/companies/__snapshots__/companies/show_update.snap @@ -0,0 +1,7 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/companies/show.html.erb_spec.rb b/spec/views/companies/show.html.erb_spec.rb index aeb93aebb..76e6cd9c6 100644 --- a/spec/views/companies/show.html.erb_spec.rb +++ b/spec/views/companies/show.html.erb_spec.rb @@ -9,4 +9,28 @@ describe "/companies/show", :type => :view do # render # expect(rendered).to have_selector("#map", :class => 'company') # end + + before(:each) do + allow(view).to receive(:current_referential).and_return(line_referential) + allow(view).to receive(:resource).and_return(company) + controller.request.path_parameters[:line_referential_id] = line_referential.id + controller.request.path_parameters[:id] = company.id + end + + describe "action links" do + set_invariant "line_referential.id", "99" + set_invariant "company.id", "909" + + before(:each){ + render template: "companies/show", layout: "layouts/application" + } + + it { should match_actions_links_snapshot "companies/show" } + + %w(create update destroy).each do |p| + with_permission "companies.#{p}" do + it { should match_actions_links_snapshot "companies/show_#{p}" } + end + end + end end diff --git a/spec/views/networks/__snapshots__/networks/index.snap b/spec/views/networks/__snapshots__/networks/index.snap new file mode 100644 index 000000000..2c5c23400 --- /dev/null +++ b/spec/views/networks/__snapshots__/networks/index.snap @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/index_create.snap b/spec/views/networks/__snapshots__/networks/index_create.snap new file mode 100644 index 000000000..cf1d5b62f --- /dev/null +++ b/spec/views/networks/__snapshots__/networks/index_create.snap @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/index_destroy.snap b/spec/views/networks/__snapshots__/networks/index_destroy.snap new file mode 100644 index 000000000..2c5c23400 --- /dev/null +++ b/spec/views/networks/__snapshots__/networks/index_destroy.snap @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/index_update.snap b/spec/views/networks/__snapshots__/networks/index_update.snap new file mode 100644 index 000000000..2c5c23400 --- /dev/null +++ b/spec/views/networks/__snapshots__/networks/index_update.snap @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/show.snap b/spec/views/networks/__snapshots__/networks/show.snap new file mode 100644 index 000000000..ea20313c1 --- /dev/null +++ b/spec/views/networks/__snapshots__/networks/show.snap @@ -0,0 +1,7 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+
+
\ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/show_create.snap b/spec/views/networks/__snapshots__/networks/show_create.snap new file mode 100644 index 000000000..7530ef0e1 --- /dev/null +++ b/spec/views/networks/__snapshots__/networks/show_create.snap @@ -0,0 +1,7 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/show_destroy.snap b/spec/views/networks/__snapshots__/networks/show_destroy.snap new file mode 100644 index 000000000..da3edb94e --- /dev/null +++ b/spec/views/networks/__snapshots__/networks/show_destroy.snap @@ -0,0 +1,7 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/show_update.snap b/spec/views/networks/__snapshots__/networks/show_update.snap new file mode 100644 index 000000000..a84b4c6f1 --- /dev/null +++ b/spec/views/networks/__snapshots__/networks/show_update.snap @@ -0,0 +1,7 @@ +
+
+

Title

+
Dernière mise à jour le 23/01/2018
Par web service
+
+ +
\ No newline at end of file diff --git a/spec/views/networks/index.html.erb_spec.rb b/spec/views/networks/index.html.erb_spec.rb index d2dde7f87..f9f16db61 100644 --- a/spec/views/networks/index.html.erb_spec.rb +++ b/spec/views/networks/index.html.erb_spec.rb @@ -3,7 +3,11 @@ require 'spec_helper' describe "/networks/index", :type => :view do let!(:line_referential) { assign :line_referential, create(:line_referential) } - let!(:networks) { assign :networks, Array.new(2){ create(:network, line_referential: line_referential) }.paginate } + let(:context){{line_referential: line_referential}} + let!(:networks) do + assign :networks, build_paginated_collection(:network, NetworkDecorator, line_referential: line_referential, context: context) + end + let!(:search) { assign :q, Ransack::Search.new(Chouette::Network) } # it "should render a show link for each group" do @@ -18,5 +22,25 @@ describe "/networks/index", :type => :view do # render # expect(view.content_for(:sidebar)).to have_selector("a[href='#{new_line_referential_network_path(line_referential)}']") # end + before(:each) do + allow(view).to receive(:collection).and_return(networks) + allow(view).to receive(:current_referential).and_return(line_referential) + controller.request.path_parameters[:line_referential_id] = line_referential.id + end + + describe "action links" do + set_invariant "line_referential.id", "99" + + before(:each){ + render template: "networks/index", layout: "layouts/application" + } + + it { should match_actions_links_snapshot "networks/index" } + %w(create update destroy).each do |p| + with_permission "networks.#{p}" do + it { should match_actions_links_snapshot "networks/index_#{p}" } + end + end + end end diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index 3926ead14..9dc872415 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -11,8 +11,27 @@ describe "/networks/show", :type => :view do let!(:map) { assign(:map, double(:to_html => '
'.html_safe)) } let!(:line_referential) { assign :line_referential, network.line_referential } - # it "should display a map with class 'network'" do - # render - # expect(rendered).to have_selector("#map") - # end + before(:each) do + allow(view).to receive(:current_referential).and_return(line_referential) + allow(view).to receive(:resource).and_return(network) + controller.request.path_parameters[:line_referential_id] = line_referential.id + controller.request.path_parameters[:id] = network.id + end + + describe "action links" do + set_invariant "line_referential.id", "99" + set_invariant "network.id", "909" + + before(:each){ + render template: "networks/show", layout: "layouts/application" + } + + it { should match_actions_links_snapshot "networks/show" } + + %w(create update destroy).each do |p| + with_permission "networks.#{p}" do + it { should match_actions_links_snapshot "networks/show_#{p}" } + end + end + end end -- cgit v1.2.3 From 708c2fbe2f579426972a45f9a716d844a8e825ae Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 8 Feb 2018 13:48:13 +0100 Subject: Refs #5669 @2h; Fix Specs --- lib/af83/decorator/link.rb | 2 ++ spec/support/integration_spec_helper.rb | 8 ++++++-- .../companies/__snapshots__/companies/index_create.snap | 2 +- spec/views/companies/__snapshots__/companies/show.snap | 9 +++------ .../companies/__snapshots__/companies/show_create.snap | 9 +++------ .../companies/__snapshots__/companies/show_destroy.snap | 4 ++-- .../companies/__snapshots__/companies/show_update.snap | 14 +++++++------- spec/views/companies/index.html.erb_spec.rb | 2 ++ spec/views/companies/show.html.erb_spec.rb | 7 +++++-- spec/views/lines/__snapshots__/lines/index_create.snap | 2 +- spec/views/lines/__snapshots__/lines/show.snap | 6 +++--- spec/views/lines/__snapshots__/lines/show_create.snap | 6 +++--- spec/views/lines/__snapshots__/lines/show_destroy.snap | 6 +++--- spec/views/lines/__snapshots__/lines/show_update.snap | 6 +++--- spec/views/lines/index.html.slim_spec.rb | 4 ++-- spec/views/lines/show.html.erb_spec.rb | 5 ++++- .../networks/__snapshots__/networks/index_create.snap | 2 +- spec/views/networks/__snapshots__/networks/show.snap | 9 +++------ .../networks/__snapshots__/networks/show_create.snap | 9 +++------ .../networks/__snapshots__/networks/show_destroy.snap | 4 ++-- .../networks/__snapshots__/networks/show_update.snap | 4 ++-- spec/views/networks/index.html.erb_spec.rb | 2 ++ spec/views/networks/show.html.erb_spec.rb | 5 ++++- .../referentials/__snapshots__/referentials/show.snap | 4 +++- .../__snapshots__/referentials/show_create.snap | 2 +- .../__snapshots__/referentials/show_destroy.snap | 2 +- .../referentials/show_purchase_windows.snap | 4 +++- .../referentials/show_purchase_windows_create.snap | 2 +- .../referentials/show_purchase_windows_destroy.snap | 2 +- .../referentials/show_purchase_windows_update.snap | 2 +- .../__snapshots__/referentials/show_readonly.snap | 4 +++- .../__snapshots__/referentials/show_readonly_create.snap | 2 +- .../referentials/show_readonly_destroy.snap | 4 +++- .../__snapshots__/referentials/show_readonly_update.snap | 4 +++- .../referentials/show_referential_vehicle_journeys.snap | 4 +++- .../show_referential_vehicle_journeys_create.snap | 2 +- .../show_referential_vehicle_journeys_destroy.snap | 2 +- .../show_referential_vehicle_journeys_update.snap | 2 +- .../__snapshots__/referentials/show_update.snap | 2 +- spec/views/referentials/show.html.erb_spec.rb | 16 ---------------- 40 files changed, 95 insertions(+), 92 deletions(-) diff --git a/lib/af83/decorator/link.rb b/lib/af83/decorator/link.rb index de7106740..ee09f80dc 100644 --- a/lib/af83/decorator/link.rb +++ b/lib/af83/decorator/link.rb @@ -130,7 +130,9 @@ class AF83::Decorator::Link out[:method] = link_method out[:class] = extra_class out.delete(:link_class) + out.delete(:link_method) out[:class] += " disabled" if disabled + out[:class].strip! out[:disabled] = !!disabled out end diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index a9a31f232..7ba7e9f92 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -3,7 +3,11 @@ module IntegrationSpecHelper def paginate_collection klass, decorator, page=1, context={} collection = klass.page(page) if decorator - collection = ModelDecorator.decorate(collection, with: decorator, context: context) + if decorator < AF83::Decorator + collection = decorator.decorate(collection, context: context) + else + collection = ModelDecorator.decorate(collection, with: decorator, context: context) + end end collection end @@ -55,7 +59,7 @@ RSpec::Matchers.define :have_link_for_each_item do |collection, name, opts| end description { "have #{name} link for each item" } failure_message do - "expected view to have #{name} link for each item, failed with selector: \"#{@selector}\"" + "expected view to have one #{name} link for each item, failed with selector: \"#{@selector}\"" end end diff --git a/spec/views/companies/__snapshots__/companies/index_create.snap b/spec/views/companies/__snapshots__/companies/index_create.snap index edf531f62..df36d5f49 100644 --- a/spec/views/companies/__snapshots__/companies/index_create.snap +++ b/spec/views/companies/__snapshots__/companies/index_create.snap @@ -1,4 +1,4 @@ \ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/show.snap b/spec/views/companies/__snapshots__/companies/show.snap index 1bdce4f81..8fe847427 100644 --- a/spec/views/companies/__snapshots__/companies/show.snap +++ b/spec/views/companies/__snapshots__/companies/show.snap @@ -1,7 +1,4 @@ -
-
-

Title

+
+

Transporteur Company Name

Dernière mise à jour le 23/01/2018
Par web service
-
-
-
\ No newline at end of file +
\ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/show_create.snap b/spec/views/companies/__snapshots__/companies/show_create.snap index 763ade31f..8fe847427 100644 --- a/spec/views/companies/__snapshots__/companies/show_create.snap +++ b/spec/views/companies/__snapshots__/companies/show_create.snap @@ -1,7 +1,4 @@ -
-
-

Title

+
+

Transporteur Company Name

Dernière mise à jour le 23/01/2018
Par web service
-
- -
\ No newline at end of file +
\ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/show_destroy.snap b/spec/views/companies/__snapshots__/companies/show_destroy.snap index dc221a1ac..5799faf8e 100644 --- a/spec/views/companies/__snapshots__/companies/show_destroy.snap +++ b/spec/views/companies/__snapshots__/companies/show_destroy.snap @@ -1,7 +1,7 @@
-

Title

+

Transporteur Company Name

Dernière mise à jour le 23/01/2018
Par web service
- +
\ No newline at end of file diff --git a/spec/views/companies/__snapshots__/companies/show_update.snap b/spec/views/companies/__snapshots__/companies/show_update.snap index adcbb3cd6..c2fbd3297 100644 --- a/spec/views/companies/__snapshots__/companies/show_update.snap +++ b/spec/views/companies/__snapshots__/companies/show_update.snap @@ -1,7 +1,7 @@ -
-
-

Title

-
Dernière mise à jour le 23/01/2018
Par web service
-
- -
\ No newline at end of file +
+

Transporteur Company Name

+
+
Dernière mise à jour le 23/01/2018
Par web service
+Editer ce transporteur +
+
\ No newline at end of file diff --git a/spec/views/companies/index.html.erb_spec.rb b/spec/views/companies/index.html.erb_spec.rb index 8f3ce9ad3..8ed5f2c21 100644 --- a/spec/views/companies/index.html.erb_spec.rb +++ b/spec/views/companies/index.html.erb_spec.rb @@ -27,8 +27,10 @@ RSpec.describe "/companies/index", :type => :view do before(:each) do allow(view).to receive(:collection).and_return(companies) + allow(view).to receive(:decorated_collection).and_return(companies) allow(view).to receive(:current_referential).and_return(line_referential) controller.request.path_parameters[:line_referential_id] = line_referential.id + allow(view).to receive(:params).and_return({action: :index}) end describe "action links" do diff --git a/spec/views/companies/show.html.erb_spec.rb b/spec/views/companies/show.html.erb_spec.rb index 76e6cd9c6..b127bdf44 100644 --- a/spec/views/companies/show.html.erb_spec.rb +++ b/spec/views/companies/show.html.erb_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe "/companies/show", :type => :view do - let!(:company) { assign(:company, create(:company)) } + let!(:company) { c = create(:company); assign(:company, c.decorate(context: {referential: c.line_referential})) } let!(:line_referential) { assign :line_referential, company.line_referential } # it "should display a map with class 'company'" do @@ -15,11 +15,14 @@ describe "/companies/show", :type => :view do allow(view).to receive(:resource).and_return(company) controller.request.path_parameters[:line_referential_id] = line_referential.id controller.request.path_parameters[:id] = company.id + allow(view).to receive(:params).and_return({action: :show}) end describe "action links" do set_invariant "line_referential.id", "99" - set_invariant "company.id", "909" + set_invariant "company.object.id", "909" + set_invariant "company.object.name", "Company Name" + set_invariant "company.object.updated_at", "2018/01/23".to_time before(:each){ render template: "companies/show", layout: "layouts/application" diff --git a/spec/views/lines/__snapshots__/lines/index_create.snap b/spec/views/lines/__snapshots__/lines/index_create.snap index 5c875b18a..4e4f54e7f 100644 --- a/spec/views/lines/__snapshots__/lines/index_create.snap +++ b/spec/views/lines/__snapshots__/lines/index_create.snap @@ -1,4 +1,4 @@ \ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/show.snap b/spec/views/lines/__snapshots__/lines/show.snap index c66e8ee2b..30eb6786e 100644 --- a/spec/views/lines/__snapshots__/lines/show.snap +++ b/spec/views/lines/__snapshots__/lines/show.snap @@ -1,9 +1,9 @@
-

Title

+

Ligne Name

Dernière mise à jour le 23/01/2018
Par web service
-
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/show_create.snap b/spec/views/lines/__snapshots__/lines/show_create.snap index c8c1f81e2..30eb6786e 100644 --- a/spec/views/lines/__snapshots__/lines/show_create.snap +++ b/spec/views/lines/__snapshots__/lines/show_create.snap @@ -1,9 +1,9 @@
-

Title

+

Ligne Name

Dernière mise à jour le 23/01/2018
Par web service
-
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/show_destroy.snap b/spec/views/lines/__snapshots__/lines/show_destroy.snap index 040a6d994..dbfba7c66 100644 --- a/spec/views/lines/__snapshots__/lines/show_destroy.snap +++ b/spec/views/lines/__snapshots__/lines/show_destroy.snap @@ -1,9 +1,9 @@
-

Title

+

Ligne Name

Dernière mise à jour le 23/01/2018
Par web service
-
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/show_update.snap b/spec/views/lines/__snapshots__/lines/show_update.snap index c66e8ee2b..30eb6786e 100644 --- a/spec/views/lines/__snapshots__/lines/show_update.snap +++ b/spec/views/lines/__snapshots__/lines/show_update.snap @@ -1,9 +1,9 @@
-

Title

+

Ligne Name

Dernière mise à jour le 23/01/2018
Par web service
-
\ No newline at end of file diff --git a/spec/views/lines/index.html.slim_spec.rb b/spec/views/lines/index.html.slim_spec.rb index df3622e1a..20e1783e3 100644 --- a/spec/views/lines/index.html.slim_spec.rb +++ b/spec/views/lines/index.html.slim_spec.rb @@ -18,6 +18,7 @@ describe "/lines/index", :type => :view do before :each do deactivated_line allow(view).to receive(:collection).and_return(lines) + allow(view).to receive(:decorated_collection).and_return(lines) allow(view).to receive(:current_referential).and_return(line_referential) allow(view).to receive(:params).and_return({action: :index}) controller.request.path_parameters[:line_referential_id] = line_referential.id @@ -27,6 +28,7 @@ describe "/lines/index", :type => :view do describe "action links" do set_invariant "line_referential.id", "99" + set_invariant "line_referential.name", "Name" before(:each){ render template: "lines/index", layout: "layouts/application" @@ -42,8 +44,6 @@ describe "/lines/index", :type => :view do end context "links" do - before(:each){ render } - common_items = ->{ it { should have_link_for_each_item(lines, "show", -> (line){ view.line_referential_line_path(line_referential, line) }) } it { should have_link_for_each_item(lines, "network", -> (line){ view.line_referential_network_path(line_referential, line.network) }) } diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb index 65ac6bdb6..aeae62e98 100644 --- a/spec/views/lines/show.html.erb_spec.rb +++ b/spec/views/lines/show.html.erb_spec.rb @@ -15,16 +15,19 @@ describe "/lines/show", :type => :view do let!(:map) { assign(:map, double(:to_html => '
'.html_safe)) } before do - allow(view).to receive_messages(current_organisation: referential.organisation) + allow(view).to receive_messages(current_organisation: referential.organisation, resource: line) controller.request.path_parameters[:line_referential_id] = line_referential.id controller.request.path_parameters[:id] = line.id + allow(view).to receive(:params).and_return({action: :show}) end describe "action links" do set_invariant "line_referential.id", "99" set_invariant "line.id", "99" + set_invariant "line.object.name", "Name" set_invariant "line.company.id", "99" set_invariant "line.network.id", "99" + set_invariant "line.updated_at", "2018/01/23".to_time before(:each){ render template: "lines/show", layout: "layouts/application" diff --git a/spec/views/networks/__snapshots__/networks/index_create.snap b/spec/views/networks/__snapshots__/networks/index_create.snap index cf1d5b62f..afd4aa41b 100644 --- a/spec/views/networks/__snapshots__/networks/index_create.snap +++ b/spec/views/networks/__snapshots__/networks/index_create.snap @@ -1,4 +1,4 @@ \ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/show.snap b/spec/views/networks/__snapshots__/networks/show.snap index ea20313c1..8f2992065 100644 --- a/spec/views/networks/__snapshots__/networks/show.snap +++ b/spec/views/networks/__snapshots__/networks/show.snap @@ -1,7 +1,4 @@ -
-
-

Title

+
+

Réseau Name

Dernière mise à jour le 23/01/2018
Par web service
-
-
-
\ No newline at end of file +
\ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/show_create.snap b/spec/views/networks/__snapshots__/networks/show_create.snap index 7530ef0e1..8f2992065 100644 --- a/spec/views/networks/__snapshots__/networks/show_create.snap +++ b/spec/views/networks/__snapshots__/networks/show_create.snap @@ -1,7 +1,4 @@ -
-
-

Title

+
+

Réseau Name

Dernière mise à jour le 23/01/2018
Par web service
-
- -
\ No newline at end of file +
\ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/show_destroy.snap b/spec/views/networks/__snapshots__/networks/show_destroy.snap index da3edb94e..c525c05b7 100644 --- a/spec/views/networks/__snapshots__/networks/show_destroy.snap +++ b/spec/views/networks/__snapshots__/networks/show_destroy.snap @@ -1,7 +1,7 @@
-

Title

+

Réseau Name

Dernière mise à jour le 23/01/2018
Par web service
- +
\ No newline at end of file diff --git a/spec/views/networks/__snapshots__/networks/show_update.snap b/spec/views/networks/__snapshots__/networks/show_update.snap index a84b4c6f1..35f8ee9ac 100644 --- a/spec/views/networks/__snapshots__/networks/show_update.snap +++ b/spec/views/networks/__snapshots__/networks/show_update.snap @@ -1,7 +1,7 @@
-

Title

+

Réseau Name

Dernière mise à jour le 23/01/2018
Par web service
- +
\ No newline at end of file diff --git a/spec/views/networks/index.html.erb_spec.rb b/spec/views/networks/index.html.erb_spec.rb index f9f16db61..80e755163 100644 --- a/spec/views/networks/index.html.erb_spec.rb +++ b/spec/views/networks/index.html.erb_spec.rb @@ -24,8 +24,10 @@ describe "/networks/index", :type => :view do # end before(:each) do allow(view).to receive(:collection).and_return(networks) + allow(view).to receive(:decorated_collection).and_return(networks) allow(view).to receive(:current_referential).and_return(line_referential) controller.request.path_parameters[:line_referential_id] = line_referential.id + allow(view).to receive(:params).and_return({action: :index}) end describe "action links" do diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index 9dc872415..998e8ac44 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -16,11 +16,14 @@ describe "/networks/show", :type => :view do allow(view).to receive(:resource).and_return(network) controller.request.path_parameters[:line_referential_id] = line_referential.id controller.request.path_parameters[:id] = network.id + allow(view).to receive(:params).and_return({action: :show}) end describe "action links" do set_invariant "line_referential.id", "99" - set_invariant "network.id", "909" + set_invariant "network.object.id", "909" + set_invariant "network.object.updated_at", "2018/01/23".to_time + set_invariant "network.object.name", "Name" before(:each){ render template: "networks/show", layout: "layouts/application" diff --git a/spec/views/referentials/__snapshots__/referentials/show.snap b/spec/views/referentials/__snapshots__/referentials/show.snap index 06e60d910..83531ac0e 100644 --- a/spec/views/referentials/__snapshots__/referentials/show.snap +++ b/spec/views/referentials/__snapshots__/referentials/show.snap @@ -3,5 +3,7 @@

referential_full_name

Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_create.snap b/spec/views/referentials/__snapshots__/referentials/show_create.snap index 4f0f8352d..e5d309b96 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_create.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_create.snap @@ -4,6 +4,6 @@
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_destroy.snap index 49ead7d2a..d90198391 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_destroy.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_destroy.snap @@ -4,6 +4,6 @@
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap index 06e60d910..83531ac0e 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows.snap @@ -3,5 +3,7 @@

referential_full_name

Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap index 4f0f8352d..e5d309b96 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_create.snap @@ -4,6 +4,6 @@
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap index 49ead7d2a..d90198391 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_destroy.snap @@ -4,6 +4,6 @@
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap index 9d8b4f276..32d46beda 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_purchase_windows_update.snap @@ -7,6 +7,6 @@
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly.snap index 06e60d910..83531ac0e 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_readonly.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly.snap @@ -3,5 +3,7 @@

referential_full_name

Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap index 6633fba3e..82a77521a 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_create.snap @@ -4,6 +4,6 @@
Dernière mise à jour le 01/01/2000
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap index 06e60d910..83531ac0e 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_destroy.snap @@ -3,5 +3,7 @@

referential_full_name

Dernière mise à jour le 01/01/2000
- +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap b/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap index 06e60d910..83531ac0e 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_readonly_update.snap @@ -3,5 +3,7 @@

referential_full_name

Dernière mise à jour le 01/01/2000
-
Calendriers
+
+CoursesCalendriers commerciauxCalendriers +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap index 06e60d910..83531ac0e 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys.snap @@ -3,5 +3,7 @@

referential_full_name

Dernière mise à jour le 01/01/2000
-
Calendriers
+
+CoursesCalendriers commerciauxCalendriers +
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap index 4f0f8352d..e5d309b96 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_create.snap @@ -4,6 +4,6 @@
Dernière mise à jour le 01/01/2000
-CalendriersDupliquerValider +CoursesCalendriers commerciauxCalendriersDupliquerValider
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap index 49ead7d2a..d90198391 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_destroy.snap @@ -4,6 +4,6 @@
Dernière mise à jour le 01/01/2000
-CalendriersSupprimer +CoursesCalendriers commerciauxCalendriersSupprimer
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap index 9d8b4f276..32d46beda 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_referential_vehicle_journeys_update.snap @@ -7,6 +7,6 @@
-CalendriersConserver +CoursesCalendriers commerciauxCalendriersConserver
\ No newline at end of file diff --git a/spec/views/referentials/__snapshots__/referentials/show_update.snap b/spec/views/referentials/__snapshots__/referentials/show_update.snap index 9d8b4f276..32d46beda 100644 --- a/spec/views/referentials/__snapshots__/referentials/show_update.snap +++ b/spec/views/referentials/__snapshots__/referentials/show_update.snap @@ -7,6 +7,6 @@
-CalendriersConserver +CoursesCalendriers commerciauxCalendriersConserver
\ No newline at end of file diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb index 9aaa762fe..ea3bc1fe1 100644 --- a/spec/views/referentials/show.html.erb_spec.rb +++ b/spec/views/referentials/show.html.erb_spec.rb @@ -28,22 +28,6 @@ describe "referentials/show", type: :view do allow(referential).to receive(:referential_read_only?){ readonly } end - it "should not present edit button" do - expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]") - end - - with_permission "referentials.update" do - it "should present edit button" do - expect(rendered).to have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]") - end - - context "with a readonly referential" do - let(:readonly){ true } - it "should not present edit button" do - expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]") - end - end - end describe "action links" do set_invariant "referential.object.full_name", "referential_full_name" -- cgit v1.2.3 From 34dca4bbfc60b17a1648d8af34d592ec7c58c0ca Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 9 Feb 2018 10:52:01 +0100 Subject: Refs 5669; Fix specs --- spec/support/pundit/pundit_view_policy.rb | 1 + spec/views/companies/__snapshots__/companies/show_destroy.snap | 2 +- spec/views/lines/__snapshots__/lines/show_destroy.snap | 2 +- spec/views/lines/show.html.erb_spec.rb | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index 058f1f6ed..63970de02 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -11,6 +11,7 @@ module Pundit allow(view).to receive(:current_user) { current_user } allow(view).to receive(:current_organisation).and_return(organisation) allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench) + allow(view).to receive(:current_workgroup).and_return(current_offer_workbench.workgroup) allow(view).to receive(:has_feature?){ |f| features.include?(f)} allow(view).to receive(:user_signed_in?).and_return true allow(view).to receive(:policy) do |instance| diff --git a/spec/views/companies/__snapshots__/companies/show_destroy.snap b/spec/views/companies/__snapshots__/companies/show_destroy.snap index 5799faf8e..5d574e460 100644 --- a/spec/views/companies/__snapshots__/companies/show_destroy.snap +++ b/spec/views/companies/__snapshots__/companies/show_destroy.snap @@ -3,5 +3,5 @@

Transporteur Company Name

Dernière mise à jour le 23/01/2018
Par web service
-
Supprimer ce transporteur
+
Supprimer ce transporteur
\ No newline at end of file diff --git a/spec/views/lines/__snapshots__/lines/show_destroy.snap b/spec/views/lines/__snapshots__/lines/show_destroy.snap index dbfba7c66..8ed08a90d 100644 --- a/spec/views/lines/__snapshots__/lines/show_destroy.snap +++ b/spec/views/lines/__snapshots__/lines/show_destroy.snap @@ -4,6 +4,6 @@
Dernière mise à jour le 23/01/2018
Par web service
-Voir le réseauVoir le transporteur principalSupprimer cette ligne +Voir le réseauVoir le transporteur principalSupprimer cette ligne
\ No newline at end of file diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb index aeae62e98..effdcd014 100644 --- a/spec/views/lines/show.html.erb_spec.rb +++ b/spec/views/lines/show.html.erb_spec.rb @@ -23,7 +23,7 @@ describe "/lines/show", :type => :view do describe "action links" do set_invariant "line_referential.id", "99" - set_invariant "line.id", "99" + set_invariant "line.object.id", "99" set_invariant "line.object.name", "Name" set_invariant "line.company.id", "99" set_invariant "line.network.id", "99" -- cgit v1.2.3 From c608e69bb3908de4c319689fa8232cff4a046b86 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Fri, 9 Feb 2018 11:14:18 +0100 Subject: Fix display compliance_check_sets#index for referential destroyed Refs #5874 @1 --- app/views/compliance_check_sets/index.html.slim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/compliance_check_sets/index.html.slim b/app/views/compliance_check_sets/index.html.slim index ead467174..31ad31e5b 100644 --- a/app/views/compliance_check_sets/index.html.slim +++ b/app/views/compliance_check_sets/index.html.slim @@ -23,9 +23,9 @@ ), \ TableBuilderHelper::Column.new( \ key: :associated_object, \ - attribute: Proc.new{|n| n.referential.name}, \ + attribute: Proc.new{|n| n.referential.present? ? n.referential.name : ''}, \ link_to: lambda do |compliance_check_set| \ - referential_path(compliance_check_set.referential_id) \ + compliance_check_set.referential.present? ? referential_path(compliance_check_set.referential_id) : '#' \ end \ ), \ TableBuilderHelper::Column.new( \ -- cgit v1.2.3 From 5152b611d62849c7f9bac24f1708aba6a651fe75 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Thu, 1 Feb 2018 23:51:21 +0100 Subject: Remove Referential#stop_areas to use stop_areas has_many through. Refs #5824 --- app/models/referential.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/models/referential.rb b/app/models/referential.rb index baaa354da..f64db4ebf 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -153,10 +153,6 @@ class Referential < ActiveRecord::Base end end - def stop_areas - Chouette::StopArea.all - end - def access_points Chouette::AccessPoint.all end -- cgit v1.2.3 From 07090fa73906d46da046dddce689802be884ec8a Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Thu, 1 Feb 2018 23:52:06 +0100 Subject: Add table name in unaccent request (to avoid problem with Referential#stop_areas has_many through. Refs #5824 --- app/controllers/autocomplete_stop_areas_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/autocomplete_stop_areas_controller.rb b/app/controllers/autocomplete_stop_areas_controller.rb index d82fa316a..79154a6e0 100644 --- a/app/controllers/autocomplete_stop_areas_controller.rb +++ b/app/controllers/autocomplete_stop_areas_controller.rb @@ -21,7 +21,7 @@ class AutocompleteStopAreasController < ChouetteController scope = StopAreaPolicy::Scope.new(current_user, scope).search_scope(search_scope) end args = [].tap{|arg| 4.times{arg << "%#{params[:q]}%"}} - @stop_areas = scope.where("unaccent(name) ILIKE unaccent(?) OR unaccent(city_name) ILIKE unaccent(?) OR registration_number ILIKE ? OR objectid ILIKE ?", *args).limit(50) + @stop_areas = scope.where("unaccent(stop_areas.name) ILIKE unaccent(?) OR unaccent(stop_areas.city_name) ILIKE unaccent(?) OR stop_areas.registration_number ILIKE ? OR stop_areas.objectid ILIKE ?", *args).limit(50) @stop_areas end -- cgit v1.2.3 From 23882d8e525a63d15b4dca1731b2184984621f52 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 2 Feb 2018 10:20:22 +0100 Subject: Refs #5824; Fix specs --- spec/controllers/api/v1/stop_area_controller_spec.rb | 9 ++++----- spec/controllers/autocomplete_stop_areas_controller_spec.rb | 6 +++--- spec/features/access_points_spec.rb | 2 +- spec/features/referential_stop_areas_spec.rb | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/spec/controllers/api/v1/stop_area_controller_spec.rb b/spec/controllers/api/v1/stop_area_controller_spec.rb index eb0c87661..1ad71a95a 100644 --- a/spec/controllers/api/v1/stop_area_controller_spec.rb +++ b/spec/controllers/api/v1/stop_area_controller_spec.rb @@ -18,16 +18,15 @@ describe Api::V1::StopAreasController, :type => :controller do end end describe "GET #index, :q => { :name_cont => 'aa'}" do - let!(:sa1) { create(:stop_area, :name => "aaa") } - let!(:sa2) { create(:stop_area, :name => "aab") } - let!(:sa3) { create(:stop_area, :name => "abb") } + let!(:sa1) { create(:stop_area, :name => "aaa", stop_area_referential: referential.stop_area_referential) } + let!(:sa2) { create(:stop_area, :name => "aab", stop_area_referential: referential.stop_area_referential) } + let!(:sa3) { create(:stop_area, :name => "abb", stop_area_referential: referential.stop_area_referential) } before :each do config_formatted_request_with_authorization( "application/json") - get :index, :q => { :name_cont => "aa"} + get :index, :q => { :name_cont => "aa"} end it "should assign expected stop_areas" do expect(assigns[:stop_areas].map(&:name).sort).to eq([ sa1.name, sa2.name]) end end end - diff --git a/spec/controllers/autocomplete_stop_areas_controller_spec.rb b/spec/controllers/autocomplete_stop_areas_controller_spec.rb index 2af471361..e8733518c 100644 --- a/spec/controllers/autocomplete_stop_areas_controller_spec.rb +++ b/spec/controllers/autocomplete_stop_areas_controller_spec.rb @@ -4,9 +4,9 @@ RSpec.describe AutocompleteStopAreasController, type: :controller do login_user let(:referential) { Referential.first } - let!(:stop_area) { create :stop_area, name: 'écolà militaire' } - let!(:zdep_stop_area) { create :stop_area, area_type: "zdep" } - let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda" } + let!(:stop_area) { create :stop_area, name: 'écolà militaire', stop_area_referential: referential.stop_area_referential } + let!(:zdep_stop_area) { create :stop_area, area_type: "zdep", stop_area_referential: referential.stop_area_referential } + let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda", stop_area_referential: referential.stop_area_referential } describe 'GET #index' do it 'should be successful' do diff --git a/spec/features/access_points_spec.rb b/spec/features/access_points_spec.rb index c16039d67..890906de7 100644 --- a/spec/features/access_points_spec.rb +++ b/spec/features/access_points_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' describe "Access points", :type => :feature do login_user - let!(:stop_area) { create(:stop_area) } + let!(:stop_area) { create(:stop_area, stop_area_referential: referential.stop_area_referential) } let!(:access_points) { Array.new(2) { create(:access_point, :stop_area => stop_area) } } subject { access_points.first } diff --git a/spec/features/referential_stop_areas_spec.rb b/spec/features/referential_stop_areas_spec.rb index 0dc7951a7..5e70857e7 100644 --- a/spec/features/referential_stop_areas_spec.rb +++ b/spec/features/referential_stop_areas_spec.rb @@ -5,7 +5,7 @@ describe 'ReferentialStopAreas', type: :feature do login_user let(:referential) { Referential.first } - let(:stop_area_referential) { create :stop_area_referential } + let(:stop_area_referential) { referential.stop_area_referential } let!(:stop_areas) { Array.new(2) { create :stop_area, stop_area_referential: stop_area_referential } } describe 'index' do -- cgit v1.2.3 From 8f8ab427914c39fdfb0648978d4fdff25ccfdc63 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 5 Feb 2018 09:50:46 +0100 Subject: Refs #5824; Add specs (and fix some) --- .../controllers/autocomplete_stop_areas_controller_spec.rb | 14 +++++++++++--- spec/factories/chouette_stop_areas.rb | 8 ++++++++ spec/models/calendar_spec.rb | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/spec/controllers/autocomplete_stop_areas_controller_spec.rb b/spec/controllers/autocomplete_stop_areas_controller_spec.rb index e8733518c..e0d1cd714 100644 --- a/spec/controllers/autocomplete_stop_areas_controller_spec.rb +++ b/spec/controllers/autocomplete_stop_areas_controller_spec.rb @@ -4,9 +4,11 @@ RSpec.describe AutocompleteStopAreasController, type: :controller do login_user let(:referential) { Referential.first } - let!(:stop_area) { create :stop_area, name: 'écolà militaire', stop_area_referential: referential.stop_area_referential } - let!(:zdep_stop_area) { create :stop_area, area_type: "zdep", stop_area_referential: referential.stop_area_referential } - let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda", stop_area_referential: referential.stop_area_referential } + let(:other_referential) { create :referential } + let!(:stop_area) { create :stop_area, name: 'écolà militaire', referential: referential } + let!(:other_referential_stop_area) { create :stop_area, name: 'écolà militaire', referential: other_referential } + let!(:zdep_stop_area) { create :stop_area, area_type: "zdep", referential: referential } + let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda", referential: referential } describe 'GET #index' do it 'should be successful' do @@ -14,6 +16,12 @@ RSpec.describe AutocompleteStopAreasController, type: :controller do expect(response).to be_success end + it "should filter stop areas based on referential" do + get :index, referential_id: referential.id + expect(assigns(:stop_areas)).to include(stop_area) + expect(assigns(:stop_areas)).to_not include(other_referential_stop_area) + end + context 'search by name' do it 'should be successful' do get :index, referential_id: referential.id, q: 'écolà', :format => :json diff --git a/spec/factories/chouette_stop_areas.rb b/spec/factories/chouette_stop_areas.rb index 9b4764781..dab135ca6 100644 --- a/spec/factories/chouette_stop_areas.rb +++ b/spec/factories/chouette_stop_areas.rb @@ -10,6 +10,14 @@ FactoryGirl.define do association :stop_area_referential + transient do + referential nil + end + + before(:create) do |stop_area, evaluator| + stop_area.stop_area_referential = evaluator.referential.stop_area_referential if evaluator.referential + end + trait :deactivated do deleted_at { 1.hour.ago } end diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb index 3cffd0f8a..a5c0a7471 100644 --- a/spec/models/calendar_spec.rb +++ b/spec/models/calendar_spec.rb @@ -36,7 +36,7 @@ RSpec.describe Calendar, :type => :model do end it 'validates that dates and date_ranges do not overlap but allow for days not in the list' do - expect(build(:calendar, dates: [Date.today.beginning_of_week], date_ranges: [Date.today.beginning_of_week..Date.today], int_day_types: Calendar::THURSDAY)).to be_valid + expect(build(:calendar, dates: [Date.today.beginning_of_week - 1.week], date_ranges: [(Date.today.beginning_of_week - 1.week)..Date.today], int_day_types: Calendar::THURSDAY)).to be_valid end it 'validates that there are no duplicates in dates' do -- cgit v1.2.3 From 42cff5c818140b193eb90fbb40b31e8a0c708207 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 9 Feb 2018 12:21:30 +0100 Subject: checksum_support.rb: Add test that checksum is the same on update Ensure the checksum doesn't change when we save it (and thus call `#update_checksum`) if the source hasn't changed. Refs #5416 --- spec/support/checksum_support.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/support/checksum_support.rb b/spec/support/checksum_support.rb index 760955274..f8dffb1b7 100644 --- a/spec/support/checksum_support.rb +++ b/spec/support/checksum_support.rb @@ -75,4 +75,12 @@ shared_examples 'checksum support' do expect(subject).to receive(:update_checksum).at_least(:once) subject.save end + + it "doesn't change the checksum on save if the source hasn't been changed" do + checksum = subject.checksum + + subject.save + + expect(subject.checksum).to eq(checksum) + end end -- cgit v1.2.3 From ae36ee8a9270540cea2b0bea70b0f7c46a1818ef Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 7 Feb 2018 09:23:20 +0100 Subject: Refs #4126 @6h; Add i18n to JS --- .gitignore | 2 ++ Gemfile | 1 + Gemfile.lock | 3 +++ app/assets/javascripts/application.js | 3 +++ app/assets/javascripts/i18n/extended.coffee | 24 ++++++++++++++++++++++ app/assets/stylesheets/components/_tables.sass | 3 ++- .../vehicle_journeys/components/ConfirmModal.js | 6 +++--- .../vehicle_journeys/components/Filters.js | 18 ++++++++-------- .../vehicle_journeys/components/VehicleJourney.js | 10 ++++----- .../vehicle_journeys/components/VehicleJourneys.js | 18 ++++++++-------- .../components/tools/EditVehicleJourney.js | 2 +- app/views/calendars/_form_advanced.html.slim | 2 +- app/views/layouts/application.html.slim | 2 ++ app/views/routes/_form.html.slim | 2 +- app/views/time_tables/edit.html.slim | 2 +- app/views/time_tables/index.html.slim | 2 +- app/views/vehicle_journeys/index.html.slim | 2 +- app/views/workbenches/show.html.slim | 2 +- config/environments/development.rb | 1 + config/locales/en.yml | 5 +++++ config/locales/fr.yml | 4 ++++ config/locales/vehicle_journeys.en.yml | 15 ++++++++++++++ config/locales/vehicle_journeys.fr.yml | 16 +++++++++++++++ lib/tasks/ci.rake | 4 ++-- package.json | 4 ++++ spec/javascript/preprocessor.js | 15 ++++++++++++++ .../components/VehicleJourneys_spec.js | 7 +++++++ .../__snapshots__/VehicleJourneys_spec.js.snap | 20 +++++++++--------- 28 files changed, 149 insertions(+), 46 deletions(-) create mode 100644 app/assets/javascripts/i18n/extended.coffee create mode 100644 spec/javascript/preprocessor.js diff --git a/.gitignore b/.gitignore index acdb5e230..dd4d057ef 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ /tmp *~ public/assets/ +public/javascripts/i18n.js +public/javascripts/translations.js # for vim users *.swp diff --git a/Gemfile b/Gemfile index bb1a42df0..db5202bdf 100644 --- a/Gemfile +++ b/Gemfile @@ -103,6 +103,7 @@ gem 'will_paginate-bootstrap' gem 'gretel' gem 'country_select' gem 'flag-icons-rails' +gem 'i18n-js' # Format Output gem 'json' diff --git a/Gemfile.lock b/Gemfile.lock index 805ee460d..a6f54f9cb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -271,6 +271,8 @@ GEM multi_xml (>= 0.5.2) i18n (0.9.3) concurrent-ruby (~> 1.0) + i18n-js (3.0.4) + i18n (~> 0.6, >= 0.6.6) i18n-tasks (0.9.15) activesupport (>= 4.0.2) ast (>= 2.1.0) @@ -638,6 +640,7 @@ DEPENDENCIES gretel has_array_of! htmlbeautifier + i18n-js i18n-tasks inherited_resources jbuilder (~> 2.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4c5aff22f..6a79f7e8e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -22,3 +22,6 @@ //= require_directory . // require('whatwg-fetch') // require('babel-polyfill') +//= require "i18n" +//= require "i18n/extended" +//= require "i18n/translations" diff --git a/app/assets/javascripts/i18n/extended.coffee b/app/assets/javascripts/i18n/extended.coffee new file mode 100644 index 000000000..aeb67bd09 --- /dev/null +++ b/app/assets/javascripts/i18n/extended.coffee @@ -0,0 +1,24 @@ +#= require i18n + +decorateI18n = (_i18n)-> + _i18n.tc = (key, opts={}) -> + out = _i18n.t(key, opts) + out += " " if _i18n.locale == "fr" + out + ":" + + _i18n.model_name = (model, opts={}) -> + last_key = if opts.plural then "other" else "one" + _i18n.t("activerecord.models.#{model}.#{last_key}") + + _i18n.attribute_name = (model, attribute, opts={}) -> + _i18n.t("activerecord.attributes.#{model}.#{attribute}") + + _i18n.enumerize = (enumerize, key, opts={}) -> + I18n.t("enumerize.#{enumerize}.#{key}") + + _i18n + +module?.exports = decorateI18n + +if I18n? + decorateI18n(I18n) diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass index 35e1122f3..5f8b06f09 100644 --- a/app/assets/stylesheets/components/_tables.sass +++ b/app/assets/stylesheets/components/_tables.sass @@ -9,7 +9,6 @@ font-weight: 700 border-bottom: 2px solid $darkgrey vertical-align: middle - > a position: relative display: block @@ -326,6 +325,8 @@ padding: 6px 8px border-bottom: 2px solid rgba($grey, 0.5) border-top: 1px solid rgba($grey, 0.5) + text-transform: capitalize + .td position: relative padding: 6px 8px diff --git a/app/javascript/vehicle_journeys/components/ConfirmModal.js b/app/javascript/vehicle_journeys/components/ConfirmModal.js index 3bfc852fb..75e8a3932 100644 --- a/app/javascript/vehicle_journeys/components/ConfirmModal.js +++ b/app/javascript/vehicle_journeys/components/ConfirmModal.js @@ -7,7 +7,7 @@ export default function ConfirmModal({dispatch, modal, onModalAccept, onModalCan
-

Voulez-vous valider vos modifications avant de changer de page?

+

{I18n.t('vehicle_journeys.vehicle_journeys_matrix.modal_confirm')}

) -} +} ConfirmModal.propTypes = { vehicleJourneys: PropTypes.array.isRequired, modal: PropTypes.object.isRequired, onModalAccept: PropTypes.func.isRequired, onModalCancel: PropTypes.func.isRequired -} \ No newline at end of file +} diff --git a/app/javascript/vehicle_journeys/components/Filters.js b/app/javascript/vehicle_journeys/components/Filters.js index 2bd912e3e..f8697c930 100644 --- a/app/javascript/vehicle_journeys/components/Filters.js +++ b/app/javascript/vehicle_journeys/components/Filters.js @@ -46,10 +46,10 @@ export default function Filters({filters, pagination, missions, onFilter, onRese
{/* Plage horaire */}
- +
- +
- +
- +
@@ -122,7 +122,7 @@ export default function Filters({filters, pagination, missions, onFilter, onRese
{/* Switch avec/sans calendrier */}
- +
diff --git a/app/javascript/vehicle_journeys/components/VehicleJourney.js b/app/javascript/vehicle_journeys/components/VehicleJourney.js index 99a458f50..4a9432231 100644 --- a/app/javascript/vehicle_journeys/components/VehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/VehicleJourney.js @@ -23,7 +23,7 @@ export default class VehicleJourney extends Component { let ttURL = refURL + '/time_tables/' + tt.id return ( - + ) } @@ -32,7 +32,7 @@ export default class VehicleJourney extends Component { let ttURL = refURL + '/purchase_windows/' + tt.id return ( - + ) } @@ -65,7 +65,7 @@ export default class VehicleJourney extends Component { } >
{this.props.value.short_id || '-'}
-
{this.props.value.published_journey_name && this.props.value.published_journey_name != "non renseigné" ? this.props.value.published_journey_name : '-'}
+
{this.props.value.published_journey_name && this.props.value.published_journey_name != I18n.t('undefined') ? this.props.value.published_journey_name : '-'}
{this.props.value.journey_pattern.short_id || '-'}
{this.props.value.company ? this.props.value.company.name : '-'}
@@ -100,7 +100,7 @@ export default class VehicleJourney extends Component {
{this.props.filters.toggleArrivals && -
+
}
-
+
{(this.props.status.fetchSuccess == false) && (
- Erreur : - la récupération des missions a rencontré un problème. Rechargez la page pour tenter de corriger le problème. + {I18n.tc("error")} + {I18n.t("vehicle_journeys.vehicle_journeys_matrix.fetching_error")}
)} { this.vehicleJourneysList().errors && this.vehicleJourneysList().errors.length && _.some(this.vehicleJourneysList(), 'errors') && (
- Erreur : + {I18n.tc("error")} {this.vehicleJourneysList().map((vj, index) => vj.errors && vj.errors.map((err, i) => { return ( @@ -129,12 +129,12 @@ export default class VehicleJourneys extends Component {
0) ? '' : ' no_result')}>
-
ID course
-
Nom course
-
ID mission
-
Transporteur
-
Calendriers
- { this.hasFeature('purchase_windows') &&
Calendriers Commerciaux
} +
{I18n.attribute_name("vehicle_journey", "id")}
+
{I18n.attribute_name("vehicle_journey", "name")}
+
{I18n.attribute_name("vehicle_journey", "journey_pattern_id")}
+
{I18n.model_name("company")}
+
{I18n.model_name("time_table", "plural": true)}
+ { this.hasFeature('purchase_windows') &&
{I18n.model_name("purchase_window", "plural": true)}
}
{this.stopPoints().map((sp, i) =>{ return ( diff --git a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js index f6a0e3c61..bcfd4eb41 100644 --- a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js @@ -128,7 +128,7 @@ export default class EditVehicleJourney extends Component {
diff --git a/app/views/calendars/_form_advanced.html.slim b/app/views/calendars/_form_advanced.html.slim index b4154166b..e796e2e36 100644 --- a/app/views/calendars/_form_advanced.html.slim +++ b/app/views/calendars/_form_advanced.html.slim @@ -2,7 +2,7 @@ = javascript_tag do | window.actionType = "#{raw params[:action]}"; - | window.I18n = #{(I18n.backend.send(:translations)[I18n.locale].to_json).html_safe}; + // | window.I18n = #{(I18n.backend.send(:translations)[I18n.locale].to_json).html_safe}; | window.timetablesUrl = "#{calendar_url(@calendar).html_safe}"; = javascript_pack_tag 'calendars/edit.js' diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 34b373295..3921c8701 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -13,6 +13,8 @@ html lang=I18n.locale = javascript_pack_tag 'application' = javascript_include_tag 'application' + = javascript_tag do + | I18n.locale = '#{I18n.locale}' body = render 'layouts/navigation/main_nav' diff --git a/app/views/routes/_form.html.slim b/app/views/routes/_form.html.slim index 29e5be3d2..81f719437 100644 --- a/app/views/routes/_form.html.slim +++ b/app/views/routes/_form.html.slim @@ -27,7 +27,7 @@ // Get JSON data for route stop points = javascript_tag do | window.itinerary_stop = "#{URI.escape(route_json_for_edit(@route))}"; - | window.I18n = #{(I18n.backend.send(:translations)[I18n.locale].to_json).html_safe}; + // | window.I18n = #{(I18n.backend.send(:translations)[I18n.locale].to_json).html_safe}; / StopPoints Reactux component = javascript_pack_tag 'routes/edit.js' diff --git a/app/views/time_tables/edit.html.slim b/app/views/time_tables/edit.html.slim index e1c566ff4..d8cffb1b0 100644 --- a/app/views/time_tables/edit.html.slim +++ b/app/views/time_tables/edit.html.slim @@ -8,6 +8,6 @@ = javascript_tag do | window.actionType = "#{raw params[:action]}"; - | window.I18n = #{(I18n.backend.send(:translations)[I18n.locale].to_json).html_safe}; + // | window.I18n = #{(I18n.backend.send(:translations)[I18n.locale].to_json).html_safe}; = javascript_pack_tag 'time_tables/edit.js' diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim index f58fbb5ea..6913712a0 100644 --- a/app/views/time_tables/index.html.slim +++ b/app/views/time_tables/index.html.slim @@ -61,6 +61,6 @@ = replacement_msg t('time_tables.search_no_results') = javascript_tag do - | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe}; + // | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe}; = javascript_pack_tag 'date_filters' diff --git a/app/views/vehicle_journeys/index.html.slim b/app/views/vehicle_journeys/index.html.slim index caa8450a0..d53d8b50c 100644 --- a/app/views/vehicle_journeys/index.html.slim +++ b/app/views/vehicle_journeys/index.html.slim @@ -29,7 +29,7 @@ | window.features = #{raw @features}; | window.all_missions = #{(@all_missions.to_json).html_safe}; | window.custom_fields = #{(@custom_fields.to_json).html_safe}; - | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe}; + // | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe}; - if has_feature?(:vehicle_journeys_return_route) = javascript_tag do diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index a162ca334..aae34c51b 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -72,6 +72,6 @@ = replacement_msg t('referentials.search_no_results') = javascript_tag do - | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe}; + // | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe}; = javascript_pack_tag 'date_filters' diff --git a/config/environments/development.rb b/config/environments/development.rb index 1d2fee44f..446e72190 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -95,6 +95,7 @@ Rails.application.configure do config.i18n.available_locales = [:fr, :en] config.middleware.insert_after(ActionDispatch::Static, Rack::LiveReload) if ENV['LIVERELOAD'] + config.middleware.use I18n::JS::Middleware config.development_toolbar = false if ENV['TOOLBAR'] && File.exists?("config/development_toolbar.rb") config.development_toolbar = OpenStruct.new diff --git a/config/locales/en.yml b/config/locales/en.yml index e59960f95..d78d51dbe 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,6 +3,7 @@ en: "false": "No" "unknown": "Unknown" + time: formats: hour: "%Hh%M" @@ -61,3 +62,7 @@ en: reflex_data: 'Reflex datas' objectid: 'ID' brandname: IBOO + error: "Error" + undefined: 'undefined' + yes: yes + no: no diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 175b71ebc..d89c286af 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -61,3 +61,7 @@ fr: reflex_data: 'Données Reflex' objectid: 'ID' brandname: IBOO + error: "Erreur" + undefined: 'non renseigné' + yes: oui + no: non diff --git a/config/locales/vehicle_journeys.en.yml b/config/locales/vehicle_journeys.en.yml index abb1da530..a1f20a7e8 100644 --- a/config/locales/vehicle_journeys.en.yml +++ b/config/locales/vehicle_journeys.en.yml @@ -2,6 +2,10 @@ en: vehicle_journeys: vehicle_journeys_matrix: line_routes: "Line's routes" + fetching_error: "There has been a problem fetching the data. Please reload the page to try again." + show_timetable: 'Show calendar' + show_purchase_window: 'Show the purchase window' + modal_confirm: 'Do you want to save mofications before moving on to the next page ?' vehicle_journey: title_stopless: "Vehicle journey %{name}" title: "Vehicle journey leaving from %{stop} at %{time}" @@ -28,6 +32,8 @@ en: stop_title: "Stop" departure: "Departure" arrival: "Arrival" + departure_at: "Departure at" + arrival_at: "Arrival at" to_arrivals: "Copy departures to arrivals" to_departures: "Copy arrivals to departures" time_tables: "Associated calendars to vehicle journey" @@ -35,6 +41,12 @@ en: slide_title: "Shift all vehicle passing times" set: "Set" to: "at" + departure_range: + label: Journey departure range + start: Start + end: End + show_journeys_without_schedule: "Show journeys without schedule" + show_journeys_with_calendar: "Show journeys with calendar" slide_departure: "departure time at first stop" slide_arrival: "arrival time at first stop" submit_timed: "Create vehicle journey" @@ -81,6 +93,7 @@ en: line: "Line" route: "Route" journey_pattern: "Journey Pattern" + journey_pattern_id: "Pattern ID" time_tables: "Calendars" time_slot: "Time Slot" company: "Company" @@ -112,6 +125,8 @@ en: departure_time: "Departure" arrival_time: "Arrival" purchase_window: "Purchase availability" + name: "Journey Name" + id: "Journey ID" errors: models: vehicle_journey: diff --git a/config/locales/vehicle_journeys.fr.yml b/config/locales/vehicle_journeys.fr.yml index ca8475812..be5be2382 100644 --- a/config/locales/vehicle_journeys.fr.yml +++ b/config/locales/vehicle_journeys.fr.yml @@ -2,6 +2,10 @@ fr: vehicle_journeys: vehicle_journeys_matrix: line_routes: "Séquences d'arrêts de la ligne" + fetching_error: "La récupération des missions a rencontré un problème. Rechargez la page pour tenter de corriger le problème." + show_timetable: 'Voir le calendrier' + show_purchase_window: 'Voir le calendrier commercial' + modal_confirm: 'Voulez-vous valider vos modifications avant de changer de page?' vehicle_journey: title_stopless: "Course %{name}" title: "Course partant de %{stop} à %{time}" @@ -27,7 +31,10 @@ fr: form: stop_title: "Arrêt" departure: "Départ" + departure_at: "Départ à" arrival: "Arrivée" + arrival_at: "Arrivée à" + to_arrivals: "Copie départs vers arrivées" to_arrivals: "Copie départs vers arrivées" to_departures: "Copie arrivées vers départs" time_tables: "Calendriers associés à la course" @@ -35,6 +42,12 @@ fr: slide_title: "Décaler l'ensemble des horaires de course" set: "Fixer" to: "à" + departure_range: + label: Plage horaire au départ de la course + start: Début + end: Fin + show_journeys_without_schedule: "Afficher les courses sans horaires" + show_journeys_with_calendar: "Afficher les courses avec calendrier" slide_departure: "horaire de départ au 1° arrêt à" slide_arrival: "horaire d'arrivée au 1° arrêt à" submit_timed: "Créer course" @@ -81,6 +94,7 @@ fr: line: "Ligne" route: "Séquence d'arrêt" journey_pattern: "Mission" + journey_pattern_id: "ID Mission" time_tables: "Calendriers" time_slot: "Fréquence" company: "Transporteur" @@ -112,6 +126,8 @@ fr: departure_time: "Départ" arrival_time: "Arrivée" purchase_window: "Disponibilité commerciale" + name: "Nom Course" + id: "ID Course" errors: models: vehicle_journey: diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 13d7b8d73..889a5c0ad 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -38,7 +38,7 @@ namespace :ci do end task :jest => "ci:assets" do - sh "yarn --no-progress install" # Hack to force install jest after webpack + sh "yarn --no-progress install" # Hack to force install jest after webpack sh "node_modules/.bin/jest" unless ["CHOUETTE_JEST_DISABLED"] end @@ -59,4 +59,4 @@ namespace :ci do end desc "Run continuous integration tasks (spec, ...)" -task :ci => ["ci:setup", "ci:spec", "ci:jest", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] +task :ci => ["ci:setup", "ci:spec", "i18n:js:export", "ci:jest", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] diff --git a/package.json b/package.json index e80f5231e..25b158e3d 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,10 @@ "roots": [ "/spec/javascript" ], + "transform": { + "^.+\\.coffee$": "/spec/javascript/preprocessor.js", + "^.+\\.jsx?$": "babel-jest" + }, "testEnvironment": "jest-environment-jsdom-global", "setupFiles": [ "/spec/javascript/spec_helper.js", diff --git a/spec/javascript/preprocessor.js b/spec/javascript/preprocessor.js new file mode 100644 index 000000000..a2de8e4be --- /dev/null +++ b/spec/javascript/preprocessor.js @@ -0,0 +1,15 @@ +'use strict'; + +var coffee = require('coffeescript'); + +module.exports = { + process: function(src, filename) { + if (coffee.helpers.isCoffee(filename)) { + return coffee.compile(src, { + 'bare': false, + 'inlineMap': true + }) + } + return src; + } +}; diff --git a/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js b/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js index 87151c64b..2a84cb9ca 100644 --- a/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js +++ b/spec/javascript/vehicle_journeys/components/VehicleJourneys_spec.js @@ -1,6 +1,13 @@ import React, { Component } from 'react' import VehicleJourneys from '../../../../app/javascript/vehicle_journeys/components/VehicleJourneys' import renderer from 'react-test-renderer' +import fs from 'fs' + +import I18n from '../../../../public/javascripts/i18n' +import decorateI18n from '../../../../app/assets/javascripts/i18n/extended.coffee' +window.I18n = decorateI18n(I18n) +I18n.locale = "fr" +eval(fs.readFileSync('./public/javascripts/translations.js')+'') describe('stopPointHeader', () => { set('features', () => { diff --git a/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap b/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap index 703f727d7..cdd34cbbd 100644 --- a/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap +++ b/spec/javascript/vehicle_journeys/components/__snapshots__/VehicleJourneys_spec.js.snap @@ -19,19 +19,19 @@ exports[`stopPointHeader should display the city name 1`] = `
- ID course + ID Course
- Nom course + Nom Course
- ID mission + ID Mission
- Transporteur + transporteur
- Calendriers + calendrier
- ID course + ID Course
- Nom course + Nom Course
- ID mission + ID Mission
- Transporteur + transporteur
- Calendriers + calendrier
- Liste des horaires {minVJ} à {maxVJ} sur {pagination.totalCount} - + {I18n.t("vehicle_journeys.vehicle_journeys_matrix.pagination", {minVJ, maxVJ, total:pagination.totalCount})} {e.preventDefault()}}> + {I18n.t('vehicle_journeys.vehicle_journeys_matrix.selected_journeys', {count: actions.getSelected(vehicleJourneys).length})} +
) } diff --git a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js index bcfd4eb41..d3c01f154 100644 --- a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js @@ -59,7 +59,7 @@ export default class EditVehicleJourney extends Component {
-

Informations

+

{I18n.t('vehicle_journeys.form.infos')}

×
@@ -69,7 +69,7 @@ export default class EditVehicleJourney extends Component {
- +
- +
- +
- +
- +
- +
- + +
- +
) } } diff --git a/config/locales/vehicle_journeys.en.yml b/config/locales/vehicle_journeys.en.yml index a1f20a7e8..0c8a75b0c 100644 --- a/config/locales/vehicle_journeys.en.yml +++ b/config/locales/vehicle_journeys.en.yml @@ -1,11 +1,14 @@ en: vehicle_journeys: vehicle_journeys_matrix: - line_routes: "Line's routes" + cancel_selection: "Cancel Selection" fetching_error: "There has been a problem fetching the data. Please reload the page to try again." - show_timetable: 'Show calendar' - show_purchase_window: 'Show the purchase window' + line_routes: "Line's routes" modal_confirm: 'Do you want to save mofications before moving on to the next page ?' + pagination: "Schedules %{minVJ} to %{maxVJ} over %{total}" + selected_journeys: "%{count} selected journeys" + show_purchase_window: 'Show the purchase window' + show_timetable: 'Show calendar' vehicle_journey: title_stopless: "Vehicle journey %{name}" title: "Vehicle journey leaving from %{stop} at %{time}" @@ -29,52 +32,54 @@ en: title_stopless: "Update vehicle journey %{name}" title: "Update vehicle journey %{name} leaving from %{stop} at %{time}" form: - stop_title: "Stop" - departure: "Departure" + arrival_at: "Arrival at" arrival: "Arrival" departure_at: "Departure at" - arrival_at: "Arrival at" - to_arrivals: "Copy departures to arrivals" - to_departures: "Copy arrivals to departures" - time_tables: "Associated calendars to vehicle journey" - slide: "Shift" - slide_title: "Shift all vehicle passing times" - set: "Set" - to: "at" + departure: "Departure" departure_range: label: Journey departure range start: Start end: End - show_journeys_without_schedule: "Show journeys without schedule" + infos: Informations + set: "Set" + show_arrival_time: "Show and edit arrival times" show_journeys_with_calendar: "Show journeys with calendar" - slide_departure: "departure time at first stop" + show_journeys_without_schedule: "Show journeys without schedule" slide_arrival: "arrival time at first stop" - submit_timed: "Create vehicle journey" + slide_departure: "departure time at first stop" + slide_title: "Shift all vehicle passing times" + slide: "Shift" + stop_title: "Stop" + submit_frequency_edit: "Edit frequency vehicle journey" submit_frequency: "Create frequency vehicle journey" submit_timed_edit: "Edit vehicle journey" - submit_frequency_edit: "Edit frequency vehicle journey" + submit_timed: "Create vehicle journey" + time_tables: "Associated calendars to vehicle journey" + to_arrivals: "Copy departures to arrivals" + to_departures: "Copy arrivals to departures" + to: "at" timeless: title: "Timeless vehicle journeys" vehicle_journeys: "Vehicle journeys with times at stop" vehicles_list: "Vehicle journeys list" show: - title: "Vehicle Journey %{vehicle journey}" - stop_title: "Stop" - departure: "Departure" arrival: "Arrival" - time_tables: "Calendars list" bounding: "From %{start} to %{end}" - translation_form: "Vehicle journey translations" + departure: "Departure" journey_frequencies: "Timeband" + stop_title: "Stop" + time_tables: "Calendars list" + title: "Vehicle Journey %{vehicle journey}" + translation_form: "Vehicle journey translations" index: - title: "Vehicle journeys on route %{route}" - vehicle_journeys: "Departure's times" - selection: "Filter on" - selection_all: "All" + advanced_search: "Advanced Search" select_journey_patterns: "Select journey pattern" select_time_tables: "Enter a timetable" + selection_all: "All" + selection: "Filter on" time_range: "Departure time threshold" - advanced_search: "Advanced Search" + title: "Vehicle journeys on route %{route}" + vehicle_journeys: "Departure's times" time_filter: time_range_filter: "Filter" sidebar: @@ -90,43 +95,47 @@ en: other: "vehicle journeys" attributes: vehicle_journey: - line: "Line" - route: "Route" - journey_pattern: "Journey Pattern" - journey_pattern_id: "Pattern ID" - time_tables: "Calendars" - time_slot: "Time Slot" - company: "Company" - number: "Number" + accessible: "Accessible" + arrival_time: "Arrival" + checksum: "Checksum" comment: "Comments" - status_value: "Status Value" - transport_mode: "Transport Mode" - mobility_restricted_suitability: "PRM accessibility" + company: "Company" + created_at: Created at + creator_id: "Created by" + departure_time: "Departure" + facility: "Facility" flexible_service: "On demond transportation" - unspecified_mrs: "Not specified" - accessible: "Accessible" + footnote_ids: "Footnotes" + id: "Journey ID" + journey_frequency_ids: "Timeband" + journey_name: "Name of the journey" + journey_pattern_id: "Pattern ID" + journey_pattern: "Journey Pattern" + line: "Line" + mobility_restricted_suitability: "PRM accessibility" + name: "Journey Name" not_accessible: "Not accessible" - unspecified_fs: "Not specified" + number: "Number" + object_version: "Version" + objectid: "Neptune identifier" on_demand_fs: "On demand service" - regular_fs: "Regular service" - published_journey_name: "Published Name" published_journey_identifier: "Published Identifier" - facility: "Facility" - vehicle_type_identifier: "Vehicle Type Identifier" + published_journey_name: "Published Name" + purchase_window: "Purchase availability" + regular_fs: "Regular service" + route: "Route" + status_value: "Status Value" + time_slot: "Time Slot" time_table_ids: "Calendar list" - vehicle_journey_at_stop_ids: "Time list" - journey_frequency_ids: "Timeband" - objectid: "Neptune identifier" - object_version: "Version" - created_at: Created at + time_tables: "Calendars" + train_number: "Train number" + transport_mode: "Transport Mode" + transport_submode: "Transport Submode" + unspecified_fs: "Not specified" + unspecified_mrs: "Not specified" updated_at: Updated at - creator_id: "Created by" - footnote_ids: "Footnotes" - departure_time: "Departure" - arrival_time: "Arrival" - purchase_window: "Purchase availability" - name: "Journey Name" - id: "Journey ID" + vehicle_journey_at_stop_ids: "Time list" + vehicle_type_identifier: "Vehicle Type Identifier" errors: models: vehicle_journey: diff --git a/config/locales/vehicle_journeys.fr.yml b/config/locales/vehicle_journeys.fr.yml index be5be2382..6bf167234 100644 --- a/config/locales/vehicle_journeys.fr.yml +++ b/config/locales/vehicle_journeys.fr.yml @@ -1,11 +1,14 @@ fr: vehicle_journeys: vehicle_journeys_matrix: - line_routes: "Séquences d'arrêts de la ligne" + cancel_selection: "Annuler la sélection" fetching_error: "La récupération des missions a rencontré un problème. Rechargez la page pour tenter de corriger le problème." - show_timetable: 'Voir le calendrier' - show_purchase_window: 'Voir le calendrier commercial' + line_routes: "Séquences d'arrêts de la ligne" modal_confirm: 'Voulez-vous valider vos modifications avant de changer de page?' + pagination: "Liste des horaires %{minVJ} à %{maxVJ} sur %{total}" + selected_journeys: "%{count} course(s) sélectionnée(s)" + show_purchase_window: 'Voir le calendrier commercial' + show_timetable: 'Voir le calendrier' vehicle_journey: title_stopless: "Course %{name}" title: "Course partant de %{stop} à %{time}" @@ -29,53 +32,55 @@ fr: title_stopless: "Editer la course %{name}" title: "Editer la course partant de %{stop} à %{time}" form: - stop_title: "Arrêt" - departure: "Départ" - departure_at: "Départ à" - arrival: "Arrivée" arrival_at: "Arrivée à" - to_arrivals: "Copie départs vers arrivées" - to_arrivals: "Copie départs vers arrivées" - to_departures: "Copie arrivées vers départs" - time_tables: "Calendriers associés à la course" - slide: "Décaler" - slide_title: "Décaler l'ensemble des horaires de course" - set: "Fixer" - to: "à" + arrival: "Arrivée" + departure_at: "Départ à" + departure: "Départ" departure_range: label: Plage horaire au départ de la course start: Début end: Fin - show_journeys_without_schedule: "Afficher les courses sans horaires" + infos: Informations + set: "Fixer" + show_arrival_time: "Afficher et éditer les horaires d'arrivée" show_journeys_with_calendar: "Afficher les courses avec calendrier" - slide_departure: "horaire de départ au 1° arrêt à" + show_journeys_without_schedule: "Afficher les courses sans horaires" slide_arrival: "horaire d'arrivée au 1° arrêt à" - submit_timed: "Créer course" + slide_departure: "horaire de départ au 1° arrêt à" + slide_title: "Décaler l'ensemble des horaires de course" + slide: "Décaler" + stop_title: "Arrêt" + submit_frequency_edit: "Editer course en fréquence" submit_frequency: "Créer course en fréquence" submit_timed_edit: "Editer course" - submit_frequency_edit: "Editer course en fréquence" + submit_timed: "Créer course" + time_tables: "Calendriers associés à la course" + to_arrivals: "Copie départs vers arrivées" + to_arrivals: "Copie départs vers arrivées" + to_departures: "Copie arrivées vers départs" + to: "à" timeless: title: "Courses sans horaire" vehicle_journeys: "Courses ayant des horaires" vehicles_list: "Liste des courses" show: - title: "Course au départ de %{stop} à %{time} sur la séquence %{route}" - stop_title: "Arrêt" - departure: "Départ" arrival: "Arrivée" - time_tables: "Liste des calendriers" bounding: "De %{start} à %{end}" - translation_form: "Cloner la course" + departure: "Départ" journey_frequencies: "Créneau horaire" + stop_title: "Arrêt" + time_tables: "Liste des calendriers" + title: "Course au départ de %{stop} à %{time} sur la séquence %{route}" + translation_form: "Cloner la course" index: - title: "Horaires de '%{route}'" - vehicle_journeys: "Horaires de départ aux arrêts" - selection: "Filtrer sur" - selection_all: "Tous" + advanced_search: "Recherche avancée" select_journey_patterns: "Sélectionner une mission" select_time_tables: "Saisir un calendrier" + selection_all: "Tous" + selection: "Filtrer sur" time_range: "Seuil horaire au départ" - advanced_search: "Recherche avancée" + title: "Horaires de '%{route}'" + vehicle_journeys: "Horaires de départ aux arrêts" time_filter: time_range_filter: "Filtrer" sidebar: @@ -91,43 +96,47 @@ fr: other: "courses" attributes: vehicle_journey: - line: "Ligne" - route: "Séquence d'arrêt" - journey_pattern: "Mission" - journey_pattern_id: "ID Mission" - time_tables: "Calendriers" - time_slot: "Fréquence" - company: "Transporteur" - number: "Numéro" + accessible: "Accessible" + arrival_time: "Arrivée" + checksum: "Signature métier" comment: "Commentaires" - status_value: "Etat de trafic" - transport_mode: "Mode de transport" - mobility_restricted_suitability: "Accessibilité PMR" + company: "Transporteur" + created_at: "Créé le" + creator_id: "Créé par" + departure_time: "Départ" + facility: "Equipement" flexible_service: "Transport à la demande" - unspecified_mrs: "Non spécifié" - accessible: "Accessible" + footnote_ids: "Notes de bas de page" + id: "ID Course" + journey_frequency_ids: "Créneau horaire" + journey_name: "Nom de la course" + journey_pattern_id: "ID Mission" + journey_pattern: "Mission" + line: "Ligne" + mobility_restricted_suitability: "Accessibilité PMR" + name: "Nom Course" not_accessible: "Non accessible" - unspecified_fs: "Non spécifié" + number: "Numéro" + object_version: "Version" + objectid: "Identifiant Neptune" on_demand_fs: "Service à la demande" - regular_fs: "Service régulier" - published_journey_name: "Nom public" published_journey_identifier: "Identifiant public" - facility: "Equipement" - vehicle_type_identifier: "Type d'identifiant du véhicule" + published_journey_name: "Nom public" + purchase_window: "Disponibilité commerciale" + regular_fs: "Service régulier" + route: "Séquence d'arrêt" + status_value: "Etat de trafic" + time_slot: "Fréquence" time_table_ids: "Liste des calendriers" - vehicle_journey_at_stop_ids: "Liste des horaires" - journey_frequency_ids: "Créneau horaire" - objectid: "Identifiant Neptune" - object_version: "Version" - created_at: "Créé le" + time_tables: "Calendriers" + train_number: "Numéro de train" + transport_mode: "Mode de transport" + transport_submode: "Sous-mode de transport" + unspecified_fs: "Non spécifié" + unspecified_mrs: "Non spécifié" updated_at: "Edité le" - creator_id: "Créé par" - footnote_ids: "Notes de bas de page" - departure_time: "Départ" - arrival_time: "Arrivée" - purchase_window: "Disponibilité commerciale" - name: "Nom Course" - id: "ID Course" + vehicle_journey_at_stop_ids: "Liste des horaires" + vehicle_type_identifier: "Type d'identifiant du véhicule" errors: models: vehicle_journey: -- cgit v1.2.3 From b23083a061bce7a4dc7f53825b6986b5a44d2f69 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Thu, 8 Feb 2018 10:46:29 +0100 Subject: Add i18n-js to capistrano deployment Refs #4126 @1 --- config/deploy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index 9be023adc..fc60113ce 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -78,7 +78,7 @@ namespace :deploy do run "ln -nfs #{shared_path}/tmp/imports #{release_path}/tmp/imports" end after 'deploy:update_code', 'deploy:symlink_shared' - before 'deploy:assets:precompile', 'deploy:symlink_shared' + before 'deploy:assets:precompile', 'deploy:symlink_shared', "deploy:i18n_js_export" desc "Make group writable all deployed files" task :group_writable do -- cgit v1.2.3 From 31187359f2ae54510076269350cf41627578a78f Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Fri, 9 Feb 2018 14:09:20 +0100 Subject: Fix ci build chain Refs #4126 @1 --- lib/tasks/ci.rake | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 889a5c0ad..6b3b1bc32 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -31,14 +31,11 @@ namespace :ci do sh "bundle exec bundle-audit check --update" end - task :spec => ["ci:assets","spec"] - task :assets do sh "RAILS_ENV=test bundle exec rake assets:precompile" end - task :jest => "ci:assets" do - sh "yarn --no-progress install" # Hack to force install jest after webpack + task :jest do sh "node_modules/.bin/jest" unless ["CHOUETTE_JEST_DISABLED"] end @@ -59,4 +56,4 @@ namespace :ci do end desc "Run continuous integration tasks (spec, ...)" -task :ci => ["ci:setup", "ci:spec", "i18n:js:export", "ci:jest", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] +task :ci => ["ci:setup", "ci:assets", "i18n:js:export", "spec", "ci:jest", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] -- cgit v1.2.3 From 8147a3bd838aaaa959c3f488c1bc9016a5401645 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Fri, 9 Feb 2018 14:28:38 +0100 Subject: Fix ci build chain for i18n:js:export to use rails environment test Refs #4126 @1 --- lib/tasks/ci.rake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 6b3b1bc32..c46cf7416 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -35,6 +35,10 @@ namespace :ci do sh "RAILS_ENV=test bundle exec rake assets:precompile" end + task :i18n_js_export do + sh "RAILS_ENV=test bundle exec rake i18n:js:export" + end + task :jest do sh "node_modules/.bin/jest" unless ["CHOUETTE_JEST_DISABLED"] end @@ -56,4 +60,4 @@ namespace :ci do end desc "Run continuous integration tasks (spec, ...)" -task :ci => ["ci:setup", "ci:assets", "i18n:js:export", "spec", "ci:jest", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] +task :ci => ["ci:setup", "ci:assets", "ci:i18n_js_export", "spec", "ci:jest", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] -- cgit v1.2.3 From 9c2a5ba3ef93deefd18a9301e6cf8cfc0787200d Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Fri, 9 Feb 2018 15:39:33 +0100 Subject: Fix in deploy.rb the call for i18n:js:export task --- config/deploy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index fc60113ce..331addb4b 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -78,7 +78,7 @@ namespace :deploy do run "ln -nfs #{shared_path}/tmp/imports #{release_path}/tmp/imports" end after 'deploy:update_code', 'deploy:symlink_shared' - before 'deploy:assets:precompile', 'deploy:symlink_shared', "deploy:i18n_js_export" + before 'deploy:assets:precompile', 'deploy:symlink_shared', "i18n:js:export" desc "Make group writable all deployed files" task :group_writable do -- cgit v1.2.3 From 99ea4f09708c05aef8f16138ec2829bdeb3c8f4f Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Fri, 9 Feb 2018 16:28:48 +0100 Subject: Fix in deploy.rb task i18n_js_export call --- config/deploy.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index 331addb4b..36ceaf8a0 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -78,7 +78,8 @@ namespace :deploy do run "ln -nfs #{shared_path}/tmp/imports #{release_path}/tmp/imports" end after 'deploy:update_code', 'deploy:symlink_shared' - before 'deploy:assets:precompile', 'deploy:symlink_shared', "i18n:js:export" + before 'deploy:assets:precompile', 'deploy:symlink_shared' + after 'deploy:assets:precompile', "deploy:i18n_js_export" desc "Make group writable all deployed files" task :group_writable do @@ -92,6 +93,11 @@ namespace :deploy do end after "deploy:restart", "deploy:sidekiq_restart" + desc "Run i18n:js:export" + task :i18n_js_export do + run "cd #{current_path} && #{rake} i18n:js:export RAILS_ENV=#{rails_env}" + end + desc "Run db:seed" task :seed do run "cd #{current_path} && #{rake} db:seed RAILS_ENV=#{rails_env}" -- cgit v1.2.3 From a22431f51860699546486c407cfc398a9ae5a911 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 9 Feb 2018 16:49:58 +0100 Subject: Refs #5432; Fix vj#show.rabl --- app/views/vehicle_journeys/show.rabl | 4 +--- .../vehicle_journeys_controller_spec.rb | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/app/views/vehicle_journeys/show.rabl b/app/views/vehicle_journeys/show.rabl index dca0866b3..546c851a4 100644 --- a/app/views/vehicle_journeys/show.rabl +++ b/app/views/vehicle_journeys/show.rabl @@ -39,10 +39,8 @@ child :footnotes, :object_root => false do |footnotes| end child(:vehicle_journey_at_stops_matrix, :object_root => false) do |vehicle_stops| + attributes :id, :connecting_service_id, :boarding_alighting_possibility node do |vehicle_stop| - [:id, :connecting_service_id, :boarding_alighting_possibility].map do |att| - node(att) { vehicle_stop.send(att) ? vehicle_stop.send(att) : nil } - end node(:dummy) { vehicle_stop.dummy } node(:area_kind) { vehicle_stop.stop_point.stop_area.kind } diff --git a/spec/controllers/vehicle_journeys_controller_spec.rb b/spec/controllers/vehicle_journeys_controller_spec.rb index 416450c21..300684532 100644 --- a/spec/controllers/vehicle_journeys_controller_spec.rb +++ b/spec/controllers/vehicle_journeys_controller_spec.rb @@ -26,4 +26,28 @@ RSpec.describe VehicleJourneysController, :type => :controller do end end + describe "GET index" do + login_user + render_views + + context "in JSON" do + let(:vehicle_journey){ create :vehicle_journey } + let(:route){ vehicle_journey.route } + let(:line){ route.line } + let!(:request){ get :index, referential_id: referential.id, line_id: line.id, route_id: route.id, format: :json} + let(:parsed_response){ JSON.parse response.body } + it "should have all the attributes" do + expect(response).to have_http_status 200 + vehicle_journey = parsed_response["vehicle_journeys"].first + vehicle_journey_at_stops_matrix = vehicle_journey["vehicle_journey_at_stops"] + vehicle_journey_at_stops_matrix.each do |received_vjas| + expect(received_vjas).to have_key("id") + vjas = Chouette::VehicleJourneyAtStop.find received_vjas["id"] + [:connecting_service_id, :boarding_alighting_possibility].each do |att| + expect(received_vjas[att]).to eq vjas.send(att) + end + end + end + end + end end -- cgit v1.2.3 From f1067f0a3af9b1e801f01f57b3a010cb849c6794 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 9 Feb 2018 17:01:46 +0100 Subject: Fix package.json for production env --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 25b158e3d..1a63eeac3 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "redux-logger": "3.0.6", "redux-promise": "0.5.3", "redux-thunk": "2.2.0", + "uglify-js": "3.3.2", "whatwg-fetch": "2.0.3" }, "license": "MIT", @@ -41,7 +42,6 @@ "react-addons-test-utils": "15.6.2", "react-test-renderer": "^16.2.0", "sinon": "4.1.3", - "uglify-js": "3.3.2", "webpack-dev-server": "2.9.7" }, "jest": { -- cgit v1.2.3 From c259d7e3e24259e14b4756f181b3a8784d8d1919 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 9 Feb 2018 18:16:24 +0100 Subject: route_base_spec.rb: Fix checksum test as a result of factory * The factory already creates `StopPoint`s for us, so we don't need to create any additional ones in the test. Previously this would give us eight stop points instead of three or five. * Update the checksum in the factory after generating stop points. We need to do this because otherwise the checksum will be incorrect, not taking into account the new stop points. Without this change, the checksum starts out in an inconsistent state and causes the: 1) Chouette::Route checksum behaves like checksum support doesn't change the checksum on save if the source hasn't been changed Failure/Error: expect(subject.checksum).to eq(checksum) expected: "bc0e7b37243682904bd7013108258fdc744b03e0c59ed1a30e24e112a49242c1" got: "b39d643fdd4f9d6ff62547750508af728a187de29a3d6e4295f9bb3d13559a51" (compared using ==) Shared Example Group: "checksum support" called from ./spec/models/chouette/route/route_base_spec.rb:5 # ./spec/support/checksum_support.rb:84:in `block (2 levels) in ' test to fail. Refs #5416 --- spec/factories/chouette_routes.rb | 1 + spec/models/chouette/route/route_base_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb index 7443d08bc..92a50b924 100644 --- a/spec/factories/chouette_routes.rb +++ b/spec/factories/chouette_routes.rb @@ -19,6 +19,7 @@ FactoryGirl.define do after(:create) do |route, evaluator| create_list(:stop_point, evaluator.stop_points_count, route: route) route.reload + route.update_checksum! end factory :route_with_journey_patterns do diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb index 0e4d13d15..98cb3e358 100644 --- a/spec/models/chouette/route/route_base_spec.rb +++ b/spec/models/chouette/route/route_base_spec.rb @@ -1,5 +1,5 @@ RSpec.describe Chouette::Route, :type => :model do - subject { create(:route, stop_points: create_list(:stop_point, 3)) } + subject { create(:route) } describe 'checksum' do it_behaves_like 'checksum support' -- cgit v1.2.3 From 038ecf8c41dc11087b63fc9b569f795051aec9df Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Fri, 9 Feb 2018 20:22:37 +0100 Subject: Fix in deploy.rb task i18n_js_export call --- config/deploy.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 36ceaf8a0..3474f97cb 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -95,11 +95,11 @@ namespace :deploy do desc "Run i18n:js:export" task :i18n_js_export do - run "cd #{current_path} && #{rake} i18n:js:export RAILS_ENV=#{rails_env}" + run "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} i18n:js:export" end desc "Run db:seed" task :seed do - run "cd #{current_path} && #{rake} db:seed RAILS_ENV=#{rails_env}" + run "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} db:seed" end end -- cgit v1.2.3 From 970f57794a225ad053f51af009b0965ed1b1c4af Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Fri, 9 Feb 2018 21:46:25 +0100 Subject: Fix in deploy.rb task i18n_js_export to use release_path and not current path --- config/deploy.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 3474f97cb..098a0233c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -95,11 +95,11 @@ namespace :deploy do desc "Run i18n:js:export" task :i18n_js_export do - run "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} i18n:js:export" + run "cd #{release_path} && RAILS_ENV=#{rails_env} #{rake} i18n:js:export" end desc "Run db:seed" task :seed do - run "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} db:seed" + run "cd #{release_path} && RAILS_ENV=#{rails_env} #{rake} db:seed" end end -- cgit v1.2.3 From daa0e3bb7f2be6ddf1bfa794187c892423b8227a Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Mon, 12 Feb 2018 00:06:14 +0100 Subject: Add CHOUETTE_DEPLOY_DISABLED to disable deploy in ci task --- lib/tasks/ci.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index c46cf7416..89f9aa9c8 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -40,11 +40,13 @@ namespace :ci do end task :jest do - sh "node_modules/.bin/jest" unless ["CHOUETTE_JEST_DISABLED"] + sh "node_modules/.bin/jest" unless ENV["CHOUETTE_JEST_DISABLED"] end desc "Deploy after CI" task :deploy do + return if ENV["CHOUETTE_DEPLOY_DISABLED"] + if deploy_env sh "cap #{deploy_env} deploy:migrations" else -- cgit v1.2.3 From 045afc75458d1d3fc4a56875bd86e112f0a665da Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Mon, 12 Feb 2018 00:38:30 +0100 Subject: Use @workgroup instead of current_workgroup in calendars#_filters. Refs #5683 --- app/views/calendars/_filters.html.slim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/calendars/_filters.html.slim b/app/views/calendars/_filters.html.slim index 35441b053..8bfe1974e 100644 --- a/app/views/calendars/_filters.html.slim +++ b/app/views/calendars/_filters.html.slim @@ -1,4 +1,4 @@ -= search_form_for @q, url: workgroup_calendars_path(current_workgroup), builder: SimpleForm::FormBuilder, html: { method: :get, class: 'form form-filter' } do |f| += search_form_for @q, url: workgroup_calendars_path(@workgroup), builder: SimpleForm::FormBuilder, html: { method: :get, class: 'form form-filter' } do |f| .ffg-row .input-group.search_bar class=filter_item_class(params[:q], :name_or_short_name_cont) = f.search_field :name_or_short_name_cont, class: 'form-control', placeholder: 'Indiquez un nom/nom court de calendrier...' @@ -18,5 +18,5 @@ = f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date smart_date' }, class: 'form-control', include_blank: true .actions - = link_to 'Effacer', workgroup_calendars_path(current_workgroup), class: 'btn btn-link' + = link_to 'Effacer', workgroup_calendars_path(@workgroup), class: 'btn btn-link' = f.submit 'Filtrer', id: 'calendar_filter_btn', class: 'btn btn-default' -- cgit v1.2.3 From 2f895a1ee52922565b7ca1a0c00defe68f40aebd Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 12 Feb 2018 09:33:53 +0100 Subject: Refs #5888; Fix I18n in JS --- app/javascript/routes/components/BSelect2.js | 2 +- app/javascript/routes/components/OlMap.js | 24 +++++++++++----------- app/javascript/routes/components/StopPoint.js | 12 +++++------ app/javascript/routes/components/StopPointList.js | 8 ++++---- app/javascript/time_tables/actions/index.js | 12 +++++------ .../time_tables/components/ConfirmModal.js | 10 ++++----- .../time_tables/components/ErrorModal.js | 6 +++--- app/javascript/time_tables/components/Metas.js | 12 +++++------ .../time_tables/components/PeriodForm.js | 14 ++++++------- .../time_tables/components/TagsSelect2.js | 2 +- app/javascript/time_tables/components/Timetable.js | 8 ++++---- app/views/time_tables/_form.html.slim | 2 +- config/locales/stop_points.en.yml | 1 + config/locales/stop_points.fr.yml | 3 ++- 14 files changed, 59 insertions(+), 57 deletions(-) diff --git a/app/javascript/routes/components/BSelect2.js b/app/javascript/routes/components/BSelect2.js index 158deaa17..035bce155 100644 --- a/app/javascript/routes/components/BSelect2.js +++ b/app/javascript/routes/components/BSelect2.js @@ -85,7 +85,7 @@ class BSelect2 extends Component{ onSelect={ this.props.onSelect } ref='newSelect' options={{ - placeholder: this.context.I18n.routes.edit.select2.placeholder, + placeholder: this.context.I18n.t("routes.edit.select2.placeholder"), allowClear: true, language: 'fr', /* Doesn't seem to work... :( */ theme: 'bootstrap', diff --git a/app/javascript/routes/components/OlMap.js b/app/javascript/routes/components/OlMap.js index 056bddbcb..4beb02872 100644 --- a/app/javascript/routes/components/OlMap.js +++ b/app/javascript/routes/components/OlMap.js @@ -115,40 +115,40 @@ export default class OlMap extends Component{ {this.props.value.olMap.json.name}

- {this.context.I18n.routes.edit.stop_point_type} : + {this.context.I18n.t('routes.edit.map.stop_point_type')} : {this.props.value.olMap.json.area_type}

- {this.context.I18n.routes.edit.short_name} : + {this.context.I18n.t('routes.edit.map.short_name')} : {this.props.value.olMap.json.short_name}

- {this.context.I18n.id_reflex} : + {this.context.I18n.t('id_reflex')} : {this.props.value.olMap.json.user_objectid}

-

{this.context.I18n.routes.edit.map.coordinates} :

+

{this.context.I18n.t('routes.edit.map.coordinates')} :

- {this.context.I18n.routes.edit.map.proj}.: WSG84
- {this.context.I18n.routes.edit.map.lat}.: {this.props.value.olMap.json.latitude}
- {this.context.I18n.routes.edit.map.lon}.: {this.props.value.olMap.json.longitude} + {this.context.I18n.t('routes.edit.map.proj')}.: WSG84
+ {this.context.I18n.t('routes.edit.map.lat')}.: {this.props.value.olMap.json.latitude}
+ {this.context.I18n.t('routes.edit.map.lon')}.: {this.props.value.olMap.json.longitude}

- {this.context.I18n.routes.edit.map.postal_code} : + {this.context.I18n.t('routes.edit.map.postal_code')} : {this.props.value.olMap.json.zip_code}

- {this.context.I18n.routes.edit.map.city} : + {this.context.I18n.t('routes.edit.map.city')} : {this.props.value.olMap.json.city_name}

- {this.context.I18n.routes.edit.map.comment} : + {this.context.I18n.t('routes.edit.map.comment')} : {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)}} - >{this.context.I18n.actions.select}
+ >{this.context.I18n.t('actions.select')}
)}
@@ -162,7 +162,7 @@ export default class OlMap extends Component{ } } -OlMap.PropTypes = { +OlMap.propTypes = { } OlMap.contextTypes = { diff --git a/app/javascript/routes/components/StopPoint.js b/app/javascript/routes/components/StopPoint.js index 2d47e802b..af51a6bb4 100644 --- a/app/javascript/routes/components/StopPoint.js +++ b/app/javascript/routes/components/StopPoint.js @@ -18,15 +18,15 @@ export default function StopPoint(props, {I18n}) {
@@ -77,7 +77,7 @@ export default function StopPoint(props, {I18n}) { ) } -StopPoint.PropTypes = { +StopPoint.propTypes = { onToggleMap: PropTypes.func.isRequired, onToggleEdit: PropTypes.func.isRequired, onDeleteClick: PropTypes.func.isRequired, @@ -93,4 +93,4 @@ StopPoint.PropTypes = { StopPoint.contextTypes = { I18n: PropTypes.object -} \ No newline at end of file +} diff --git a/app/javascript/routes/components/StopPointList.js b/app/javascript/routes/components/StopPointList.js index b39fa0c9c..b227abdea 100644 --- a/app/javascript/routes/components/StopPointList.js +++ b/app/javascript/routes/components/StopPointList.js @@ -10,22 +10,22 @@ export default function StopPointList({ stopPoints, onDeleteClick, onMoveUpClick
- +
- +
- +
- +
diff --git a/app/javascript/time_tables/actions/index.js b/app/javascript/time_tables/actions/index.js index 4a36ec4e1..98b9eab4b 100644 --- a/app/javascript/time_tables/actions/index.js +++ b/app/javascript/time_tables/actions/index.js @@ -8,7 +8,7 @@ const I18n = clone(window, "I18n") const actions = { weekDays: (index) => { - return range(1, 8).map(n => I18n.time_tables.edit.metas.days[n]) + return range(1, 8).map(n => I18n.t('time_tables.edit.metas.days')[n]) }, strToArrayDayTypes: (str) =>{ return actions.weekDays().map(day => str.indexOf(day) !== -1) @@ -155,7 +155,7 @@ const actions = { type : 'CLOSE_MODAL' }), monthName(strDate) { - let monthList = range(1,13).map(n => I18n.calendars.months[n]) + let monthList = range(1,13).map(n => I18n.t('calendars.months.'+ n )) let date = new Date(strDate) return monthList[date.getUTCMonth()] }, @@ -225,7 +225,7 @@ const actions = { let period = periods[i] if (index !== i && !period.deleted) { if (new Date(period.period_start) <= end && new Date(period.period_end) >= start) { - error = I18n.time_tables.edit.error_submit.periods_overlaps + error = I18n.t('time_tables.edit.error_submit.periods_overlaps') break } } @@ -239,7 +239,7 @@ const actions = { for (let day of in_days) { if (start <= new Date(day.date) && end >= new Date(day.date)) { - error = I18n.time_tables.edit.error_submit.dates_overlaps + error = I18n.t('time_tables.edit.error_submit.dates_overlaps') break } } @@ -316,9 +316,9 @@ const actions = { errorModalMessage: (errorKey) => { switch (errorKey) { case "withoutPeriodsWithDaysTypes": - return I18n.time_tables.edit.error_modal.withoutPeriodsWithDaysTypes + return I18n.t('time_tables.edit.error_modal.withoutPeriodsWithDaysTypes') case "withPeriodsWithoutDayTypes": - return I18n.time_tables.edit.error_modal.withPeriodsWithoutDayTypes + return I18n.t('time_tables.edit.error_modal.withPeriodsWithoutDayTypes') default: return errorKey diff --git a/app/javascript/time_tables/components/ConfirmModal.js b/app/javascript/time_tables/components/ConfirmModal.js index 845e7ed1b..4e8583bc0 100644 --- a/app/javascript/time_tables/components/ConfirmModal.js +++ b/app/javascript/time_tables/components/ConfirmModal.js @@ -9,11 +9,11 @@ export default function ConfirmModal({dispatch, modal, onModalAccept, onModalCan
-

{I18n.time_tables.edit.confirm_modal.title}

+

{I18n.t('time_tables.edit.confirm_modal.title')}

-

{I18n.time_tables.edit.confirm_modal.message}

+

{I18n.t('time_tables.edit.confirm_modal.message')}

@@ -23,7 +23,7 @@ export default function ConfirmModal({dispatch, modal, onModalAccept, onModalCan type='button' onClick={() => { onModalCancel(modal.confirmModal.callback) }} > - {I18n.cancel} + {I18n.t('cancel')}
@@ -49,4 +49,4 @@ ConfirmModal.propTypes = { ConfirmModal.contextTypes = { I18n: PropTypes.object -} \ No newline at end of file +} diff --git a/app/javascript/time_tables/components/ErrorModal.js b/app/javascript/time_tables/components/ErrorModal.js index 543177e54..8af12f1d1 100644 --- a/app/javascript/time_tables/components/ErrorModal.js +++ b/app/javascript/time_tables/components/ErrorModal.js @@ -10,7 +10,7 @@ export default function ErrorModal({dispatch, modal, onModalClose}, {I18n}) {
-

{I18n.time_tables.edit.error_modal.title}

+

{I18n.t('time_tables.edit.error_modal.title')}

@@ -24,7 +24,7 @@ export default function ErrorModal({dispatch, modal, onModalClose}, {I18n}) { type='button' onClick={() => { onModalClose() }} > - {I18n.back} + {I18n.t('back')}
@@ -41,4 +41,4 @@ ErrorModal.propTypes = { ErrorModal.contextTypes = { I18n: PropTypes.object -} \ No newline at end of file +} diff --git a/app/javascript/time_tables/components/Metas.js b/app/javascript/time_tables/components/Metas.js index 3c6848d27..08a6e26fe 100644 --- a/app/javascript/time_tables/components/Metas.js +++ b/app/javascript/time_tables/components/Metas.js @@ -13,7 +13,7 @@ export default function Metas({metas, onUpdateDayTypes, onUpdateComment, onUpdat {/* comment (name) */}
- +
@@ -124,7 +124,7 @@ export default function PeriodForm({modal, timetable, metas, onOpenAddPeriodForm className='btn btn-outline-primary' onClick={onOpenAddPeriodForm} > - {I18n.time_tables.actions.add_period} + {I18n.t('time_tables.actions.add_period')}
} @@ -132,7 +132,7 @@ export default function PeriodForm({modal, timetable, metas, onOpenAddPeriodForm
- ) + ) } PeriodForm.propTypes = { @@ -147,4 +147,4 @@ PeriodForm.propTypes = { PeriodForm.contextTypes = { I18n: PropTypes.object -} \ No newline at end of file +} diff --git a/app/javascript/time_tables/components/TagsSelect2.js b/app/javascript/time_tables/components/TagsSelect2.js index dc3739d58..43cf59fdf 100644 --- a/app/javascript/time_tables/components/TagsSelect2.js +++ b/app/javascript/time_tables/components/TagsSelect2.js @@ -40,7 +40,7 @@ export default class TagsSelect2 extends Component { allowClear: true, theme: 'bootstrap', width: '100%', - placeholder: this.context.I18n.time_tables.edit.select2.tag.placeholder, + placeholder: this.context.I18n.t('time_tables.edit.select2.tag.placeholder'), ajax: { url: origin + path + '/tags.json', dataType: 'json', diff --git a/app/javascript/time_tables/components/Timetable.js b/app/javascript/time_tables/components/Timetable.js index c44f2a134..991f31435 100644 --- a/app/javascript/time_tables/components/Timetable.js +++ b/app/javascript/time_tables/components/Timetable.js @@ -31,11 +31,11 @@ export default class Timetable extends Component {
-
{this.context.I18n.time_tables.synthesis}
+
{this.context.I18n.t('time_tables.edit.synthesis')}
-
{this.context.I18n.time_tables.edit.day_types}
-
{this.context.I18n.time_tables.edit.periods}
-
{this.context.I18n.time_tables.edit.exceptions}
+
{this.context.I18n.t('time_tables.edit.day_types')}
+
{this.context.I18n.t('time_tables.edit.periods')}
+
{this.context.I18n.t('time_tables.edit.exceptions')}
diff --git a/app/views/time_tables/_form.html.slim b/app/views/time_tables/_form.html.slim index d06fdf444..007044e65 100644 --- a/app/views/time_tables/_form.html.slim +++ b/app/views/time_tables/_form.html.slim @@ -5,7 +5,7 @@ = form.input :comment, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.comment")} - if @time_table.new_record? && !@time_table.created_from - = form.input :calendar_id, as: :select, input_html: { class: 'tt_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}} + = form.input :calendar_id, as: :select, input_html: { class: 'tt_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_workgroup_calendars_path(current_workgroup)}} - if @time_table.created_from = form.input :created_from, disabled: true, input_html: { value: @time_table.created_from.comment } diff --git a/config/locales/stop_points.en.yml b/config/locales/stop_points.en.yml index d22d85731..72e138270 100644 --- a/config/locales/stop_points.en.yml +++ b/config/locales/stop_points.en.yml @@ -55,3 +55,4 @@ en: name: Stop Point for_boarding: "Pickup" for_alighting: "Drop off" + reflex_id: ID diff --git a/config/locales/stop_points.fr.yml b/config/locales/stop_points.fr.yml index d3c873442..71be684f6 100644 --- a/config/locales/stop_points.fr.yml +++ b/config/locales/stop_points.fr.yml @@ -52,6 +52,7 @@ fr: simple_form: labels: stop_point: - name: Arrêt + name: Arrêt for_boarding: "Montée" for_alighting: "Descente" + reflex_id: ID -- cgit v1.2.3 From d2653a46bbaabd682d6029ec6907d6c7c0419542 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 5 Feb 2018 10:48:14 +0100 Subject: Refs #5843; Fix wrong translation --- config/locales/vehicle_journeys.fr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/vehicle_journeys.fr.yml b/config/locales/vehicle_journeys.fr.yml index 6bf167234..1034a3fba 100644 --- a/config/locales/vehicle_journeys.fr.yml +++ b/config/locales/vehicle_journeys.fr.yml @@ -124,7 +124,7 @@ fr: published_journey_name: "Nom public" purchase_window: "Disponibilité commerciale" regular_fs: "Service régulier" - route: "Séquence d'arrêt" + route: "Itinéraire" status_value: "Etat de trafic" time_slot: "Fréquence" time_table_ids: "Liste des calendriers" -- cgit v1.2.3 From 5877ed29f0566ba07247aaa1c10e0dd98df1efc7 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 12 Feb 2018 10:19:40 +0100 Subject: Refs #5150; Update decorators --- app/decorators/time_table_decorator.rb | 2 +- config/locales/journey_patterns.en.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/decorators/time_table_decorator.rb b/app/decorators/time_table_decorator.rb index 95b1fd959..e4f9d7dbc 100644 --- a/app/decorators/time_table_decorator.rb +++ b/app/decorators/time_table_decorator.rb @@ -14,7 +14,7 @@ class TimeTableDecorator < AF83::Decorator l.href { [:edit, context[:referential], object] } end - instance_decorator.action_link if: ->{ object.calendar }, secondary: true do |l| + instance_decorator.action_link policy: :actualize, if: ->{ object.calendar }, secondary: true do |l| l.content t('actions.actualize') l.href do h.actualize_referential_time_table_path( diff --git a/config/locales/journey_patterns.en.yml b/config/locales/journey_patterns.en.yml index e5248c29c..9d9bc21e2 100644 --- a/config/locales/journey_patterns.en.yml +++ b/config/locales/journey_patterns.en.yml @@ -6,6 +6,7 @@ en: vehicle_journeys_count: "Vehicle journeys: %{count}" vehicle_journey_at_stops: "Vehicle journey at stops" actions: + index: "Journey patterns" new: "Add a new journey_pattern" edit: "Edit this journey pattern" destroy: "Remove this journey pattern" -- cgit v1.2.3 From 7e7371087b61aaf8a128d5f5f5ec6c43c06fd4ca Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Tue, 6 Feb 2018 21:52:02 -0800 Subject: Refs #5707 Add status to the application to track 'blocked objects' --- app/controllers/statuses_controller.rb | 21 +++++++++++++++++++++ app/models/compliance_check_set.rb | 2 ++ app/models/import.rb | 2 ++ app/models/referential.rb | 1 + config/routes.rb | 2 ++ 5 files changed, 28 insertions(+) create mode 100644 app/controllers/statuses_controller.rb diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb new file mode 100644 index 000000000..81e668ad4 --- /dev/null +++ b/app/controllers/statuses_controller.rb @@ -0,0 +1,21 @@ +class StatusesController < ChouetteController + respond_to :json + + def index + + status = { + status: global_status, + referentials_blocked: Referential.blocked.count, + imports_blocked: Import.blocked.count, + compliance_check_sets_blocked: ComplianceCheckSet.blocked.count + } + render json: status.to_json + end + + private + + def global_status + blocked_items = Referential.blocked.count + Import.blocked.count + ComplianceCheckSet.blocked.count + blocked_items > 0 ? 'ko' : 'ok' + end +end \ No newline at end of file diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 3ea832048..289fc134f 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -19,6 +19,8 @@ class ComplianceCheckSet < ActiveRecord::Base where('created_at BETWEEN :begin AND :end', begin: period_range.begin, end: period_range.end) end + scope :blocked, -> { where('created_at < ? AND status = ?', 4.hours.ago, 'running') } + def self.finished_statuses %w(successful failed warning aborted canceled) end diff --git a/app/models/import.rb b/app/models/import.rb index 049a65f40..d8e763bf3 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -13,6 +13,8 @@ class Import < ActiveRecord::Base where('started_at BETWEEN :begin AND :end', begin: period_range.begin, end: period_range.end) end + scope :blocked, -> { where('created_at < ? AND status = ?', 4.hours.ago, 'running') } + extend Enumerize enumerize :status, in: %w(new pending successful warning failed running aborted canceled), scope: true, default: :new diff --git a/app/models/referential.rb b/app/models/referential.rb index f64db4ebf..509e0412f 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -62,6 +62,7 @@ class Referential < ActiveRecord::Base scope :order_by_validity_period, ->(dir) { joins(:metadatas).order("unnest(periodes) #{dir}") } scope :order_by_lines, ->(dir) { joins(:metadatas).group("referentials.id").order("sum(array_length(referential_metadata.line_ids,1)) #{dir}") } scope :not_in_referential_suite, -> { where referential_suite_id: nil } + scope :blocked, -> { where('ready = ? AND created_at < ?', false, 4.hours.ago) } def save_with_table_lock_timeout(options = {}) save_without_table_lock_timeout(options) diff --git a/config/routes.rb b/config/routes.rb index 2715ca428..0b657b028 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -256,4 +256,6 @@ ChouetteIhm::Application.routes.draw do match '/422', to: 'errors#server_error', via: :all, as: 'unprocessable_entity' match '/500', to: 'errors#server_error', via: :all, as: 'server_error' + match '/status', to: 'statuses#index', via: :get + end -- cgit v1.2.3 From 6b9dd49ee49bcd43626ed507549fa0b8a71cc366 Mon Sep 17 00:00:00 2001 From: cedricnjanga Date: Sun, 11 Feb 2018 21:16:07 -0800 Subject: Refs #5707 update the global status method to avoid unacessary db requests --- app/controllers/statuses_controller.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb index 81e668ad4..e3a236e81 100644 --- a/app/controllers/statuses_controller.rb +++ b/app/controllers/statuses_controller.rb @@ -1,6 +1,6 @@ class StatusesController < ChouetteController respond_to :json - + def index status = { @@ -9,13 +9,12 @@ class StatusesController < ChouetteController imports_blocked: Import.blocked.count, compliance_check_sets_blocked: ComplianceCheckSet.blocked.count } - render json: status.to_json + render json: status.to_json end - private + private def global_status - blocked_items = Referential.blocked.count + Import.blocked.count + ComplianceCheckSet.blocked.count - blocked_items > 0 ? 'ko' : 'ok' + blocked_items = Referential.blocked.exists? || Import.blocked.exists? || ComplianceCheckSet.blocked.exists? ? 'ko' : 'ok' end -end \ No newline at end of file +end -- cgit v1.2.3 From 49c4c822d5e7f526ad7be9c0aa21c201653f24ea Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 13 Feb 2018 09:06:25 +0100 Subject: Refs #5707; Add specs --- app/controllers/statuses_controller.rb | 6 ++-- spec/controllers/statuses_controller_spec.rb | 50 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 spec/controllers/statuses_controller_spec.rb diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb index e3a236e81..e38a92982 100644 --- a/app/controllers/statuses_controller.rb +++ b/app/controllers/statuses_controller.rb @@ -4,17 +4,17 @@ class StatusesController < ChouetteController def index status = { - status: global_status, referentials_blocked: Referential.blocked.count, imports_blocked: Import.blocked.count, compliance_check_sets_blocked: ComplianceCheckSet.blocked.count } + status[:status] = global_status status render json: status.to_json end private - def global_status - blocked_items = Referential.blocked.exists? || Import.blocked.exists? || ComplianceCheckSet.blocked.exists? ? 'ko' : 'ok' + def global_status status + status.values.all?(&:zero?) ? 'ok' : 'ko' end end diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb new file mode 100644 index 000000000..8a6db8e28 --- /dev/null +++ b/spec/controllers/statuses_controller_spec.rb @@ -0,0 +1,50 @@ +RSpec.describe StatusesController, :type => :controller do + + describe "GET index" do + login_user + render_views + + + let(:request){ get :index} + let(:parsed_response){ JSON.parse response.body } + it "should be ok" do + request + expect(response).to have_http_status 200 + expect(parsed_response["status"]).to eq "ok" + end + context "without blocked object" do + before do + create :referential + create :import + create :compliance_check_set + request + end + + it "should be ok" do + expect(response).to have_http_status 200 + expect(parsed_response["status"]).to eq "ok" + expect(parsed_response["referentials_blocked"]).to eq 0 + expect(parsed_response["imports_blocked"]).to eq 0 + expect(parsed_response["imports_blocked"]).to eq 0 + end + end + + context "with a blocked object" do + before do + create :referential, created_at: 5.hours.ago, ready: false + create :import + create :compliance_check_set + request + end + + it "should be ko" do + expect(Referential.blocked.count).to eq 1 + expect(response).to have_http_status 200 + expect(parsed_response["status"]).to eq "ko" + expect(parsed_response["referentials_blocked"]).to eq 1 + expect(parsed_response["imports_blocked"]).to eq 0 + expect(parsed_response["imports_blocked"]).to eq 0 + end + end + end +end -- cgit v1.2.3 From 56de2fc715ccaeb908d1646c1f554ed50c2a1de8 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Tue, 13 Feb 2018 09:36:37 +0100 Subject: Must use current_release for bd:seed task in deploy.rb --- config/deploy.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/deploy.rb b/config/deploy.rb index 098a0233c..136c60196 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -100,6 +100,6 @@ namespace :deploy do desc "Run db:seed" task :seed do - run "cd #{release_path} && RAILS_ENV=#{rails_env} #{rake} db:seed" + run "cd #{current_path} && RAILS_ENV=#{rails_env} #{rake} db:seed" end end -- cgit v1.2.3