diff options
| author | Alban Peignier | 2016-09-09 16:03:18 +0200 |
|---|---|---|
| committer | Alban Peignier | 2016-09-09 16:03:18 +0200 |
| commit | 2a37af5299a413755945c7a0391abc3ed8c81fbb (patch) | |
| tree | f471419281aec133a6551229e6eacb074a5327c1 | |
| parent | febca10492e68c10a18f48860577bf21748bc7cd (diff) | |
| parent | 3b24aa5a922f41a748f340bd99c202d7ef488c80 (diff) | |
| download | chouette-core-2a37af5299a413755945c7a0391abc3ed8c81fbb.tar.bz2 | |
Merge branch 'master' into staging
55 files changed, 526 insertions, 137 deletions
diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index 1abaca9a8..cd0467a21 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -1,13 +1,15 @@ -class CompaniesController < ChouetteController +class CompaniesController < BreadcrumbController + include ApplicationHelper + defaults :resource_class => Chouette::Company respond_to :html respond_to :xml respond_to :json respond_to :js, :only => :index - belongs_to :referential, :parent_class => Referential + belongs_to :line_referential - def index + def index index! do |format| format.html { @@ -16,25 +18,27 @@ class CompaniesController < ChouetteController end } build_breadcrumb :index - end + end end - + protected - def collection - @q = referential.companies.search(params[:q]) + def collection + @q = line_referential.companies.search(params[:q]) @companies ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) end def resource_url(company = nil) - referential_company_path(referential, company || resource) + line_referential_company_path(line_referential, company || resource) end def collection_url - referential_companies_path(referential) + line_referential_companies_path(line_referential) end + alias_method :line_referential, :parent + def company_params params.require(:company).permit( :objectid, :object_version, :creation_time, :creator_id, :name, :short_name, :organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :registration_number, :url, :time_zone ) end diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb new file mode 100644 index 000000000..104deba9f --- /dev/null +++ b/app/controllers/referential_companies_controller.rb @@ -0,0 +1,45 @@ +class ReferentialCompaniesController < ChouetteController + defaults :resource_class => Chouette::Company, :collection_name => 'companies', :instance_name => 'company' + respond_to :html + respond_to :xml + respond_to :json + respond_to :js, :only => :index + + belongs_to :referential, :parent_class => Referential + + def index + index! do |format| + format.html { + if collection.out_of_bounds? + redirect_to params.merge(:page => 1) + end + } + build_breadcrumb :index + end + end + + protected + + def build_resource + super.tap do |company| + company.line_referential = referential.line_referential + end + end + + def collection + @q = referential.companies.search(params[:q]) + @companies ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) + end + + def resource_url(company = nil) + referential_company_path(referential, company || resource) + end + + def collection_url + referential_companies_path(referential) + end + + def company_params + params.require(:company).permit( :objectid, :object_version, :creation_time, :creator_id, :name, :short_name, :organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :registration_number, :url, :time_zone ) + end +end diff --git a/app/controllers/referential_stop_areas_controller.rb b/app/controllers/referential_stop_areas_controller.rb index 06305bb1f..e0eae9aed 100644 --- a/app/controllers/referential_stop_areas_controller.rb +++ b/app/controllers/referential_stop_areas_controller.rb @@ -43,7 +43,7 @@ class ReferentialStopAreasController < ChouetteController def index request.format.kml? ? @per_page = nil : @per_page = 12 - @zip_codes = referential.stop_areas.collect(&:zip_code).compact.uniq + @zip_codes = referential.stop_areas.where("zip_code is NOT null").distinct.pluck(:zip_code) index! do |format| format.html { if collection.out_of_bounds? diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 275066efa..b37709e84 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -51,7 +51,7 @@ class StopAreasController < BreadcrumbController def index request.format.kml? ? @per_page = nil : @per_page = 12 - @zip_codes = stop_area_referential.stop_areas.collect(&:zip_code).compact.uniq + @zip_codes = stop_area_referential.stop_areas.where("zip_code is NOT null").distinct.pluck(:zip_code) index! do |format| format.html { if collection.out_of_bounds? @@ -131,7 +131,7 @@ class StopAreasController < BreadcrumbController @q = parent.present? ? parent.stop_areas.search(params[:q]) : referential.stop_areas.search(params[:q]) @stop_areas ||= begin - stop_areas = @q.result(:distinct => true).order(:name) + stop_areas = @q.result.order(:name) stop_areas = stop_areas.paginate(:page => params[:page], :per_page => @per_page) if @per_page.present? stop_areas end diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index 453c2c622..6cbeee4c9 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -52,6 +52,8 @@ module BreadcrumbHelper user_breadcrumb action when "Referential" referential_breadcrumb action + when "LineReferential" + line_referential_breadcrumb action when "Organisation" organisation_breadcrumb action when "Api::V1::ApiKey" @@ -160,10 +162,23 @@ module BreadcrumbHelper route_breadcrumb :edit end + def line_referential_breadcrumb(action = :edit) + organisation_breadcrumb + if @line_referential + add_breadcrumb breadcrumb_label(@line_referential), line_referential_path(@line_referential), :title => breadcrumb_tooltip(@line_referential) if action == :edit || action == :show || action == :update + end + end + def company_breadcrumb (action) - referential_breadcrumb - add_breadcrumb Chouette::Company.model_name.human(:count => 2), referential_companies_path(@referential) unless action == :index - add_breadcrumb breadcrumb_label(@company), referential_company_path(@referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit + if @line_referential + line_referential_breadcrumb + add_breadcrumb Chouette::Company.model_name.human(:count => 2), line_referential_companies_path(@line_referential) unless action == :index + add_breadcrumb breadcrumb_label(@company), referential_company_path(@line_referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit + else + referential_breadcrumb + add_breadcrumb Chouette::Company.model_name.human(:count => 2), referential_companies_path(@referential) unless action == :index + add_breadcrumb breadcrumb_label(@company), referential_company_path(@referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit + end end def import_breadcrumb (action) diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index 85464f5af..7592bb5f1 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -4,6 +4,7 @@ class LineReferential < ActiveRecord::Base has_many :lines, class_name: 'Chouette::Line' has_many :group_of_lines, class_name: 'Chouette::GroupOfLine' + has_many :companies, class_name: 'Chouette::Company' has_one :line_referential_sync diff --git a/app/models/referential.rb b/app/models/referential.rb index d4bdc8374..0063244e8 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -28,6 +28,8 @@ class Referential < ActiveRecord::Base belongs_to :line_referential # validates_presence_of :line_referential has_many :lines, through: :line_referential + has_many :companies, through: :line_referential + has_many :group_of_lines, through: :line_referential belongs_to :stop_area_referential # validates_presence_of :stop_area_referential @@ -61,14 +63,6 @@ class Referential < ActiveRecord::Base Chouette::Network.all end - def group_of_lines - Chouette::GroupOfLine.all - end - - def companies - Chouette::Company.all - end - def stop_areas Chouette::StopArea.all end @@ -221,5 +215,5 @@ class Referential < ActiveRecord::Base # self.archived = false update_column :archived_at, nil end - -end
\ No newline at end of file + +end diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb index 325385011..58e0c559c 100644 --- a/app/models/stop_area_referential.rb +++ b/app/models/stop_area_referential.rb @@ -3,6 +3,7 @@ class StopAreaReferential < ActiveRecord::Base has_many :organisations, through: :stop_area_referential_memberships has_many :stop_areas, class_name: 'Chouette::StopArea' + has_one :stop_area_referential_sync def add_member(organisation, options = {}) attributes = options.merge organisation: organisation diff --git a/app/models/stop_area_referential_sync.rb b/app/models/stop_area_referential_sync.rb new file mode 100644 index 000000000..3a9b2d03b --- /dev/null +++ b/app/models/stop_area_referential_sync.rb @@ -0,0 +1,9 @@ +class StopAreaReferentialSync < ActiveRecord::Base + belongs_to :stop_area_referential + has_many :stop_area_sync_operations, dependent: :destroy + + def record_status status, message + stop_area_sync_operations << StopAreaSyncOperation.new(status: status, message: message) + stop_area_sync_operations.first.destroy while stop_area_sync_operations.count > 30 + end +end diff --git a/app/models/stop_area_sync_operation.rb b/app/models/stop_area_sync_operation.rb new file mode 100644 index 000000000..ca0fde4db --- /dev/null +++ b/app/models/stop_area_sync_operation.rb @@ -0,0 +1,3 @@ +class StopAreaSyncOperation < ActiveRecord::Base + belongs_to :stop_area_referential_sync +end diff --git a/app/views/companies/_company.html.slim b/app/views/companies/_company.html.slim index ca1b9f366..a6707b36c 100644 --- a/app/views/companies/_company.html.slim +++ b/app/views/companies/_company.html.slim @@ -2,12 +2,12 @@ .panel-heading .panel-title.clearfix span.pull-right - = link_to edit_referential_company_path(@referential, company), class: 'btn btn-default btn-sm' do + = link_to edit_line_referential_company_path(@line_referential, company), class: 'btn btn-default btn-sm' do span.fa.fa-pencil - = link_to referential_company_path(@referential, company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do + = link_to line_referential_company_path(@line_referential, company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do span.fa.fa-trash-o h5 - = link_to [@referential, company], class: 'preview', title: "#{Chouette::Company.model_name.human.capitalize} #{company.name}" do + = link_to [@line_referential, company], class: 'preview', title: "#{Chouette::Company.model_name.human.capitalize} #{company.name}" do span.name = truncate(company.name, length: 20) .panel-body diff --git a/app/views/companies/_form.html.slim b/app/views/companies/_form.html.slim index 3f8663949..caf75bd8b 100644 --- a/app/views/companies/_form.html.slim +++ b/app/views/companies/_form.html.slim @@ -1,6 +1,6 @@ -= semantic_form_for [@referential, @company] do |form| += semantic_form_for [@line_referential, @company] do |form| = form.inputs do - = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.name") } + = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.name") } = form.input :short_name = form.input :organizational_unit = form.input :operating_department_name @@ -10,9 +10,9 @@ = form.input :email, as: :email = form.input :time_zone, include_blank: true = form.input :url - = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.registration_number") } + = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.registration_number") } = form.input :objectid, :required => !@company.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.objectid") } = form.actions do - = form.action :submit, as: :button + = form.action :submit, as: :button = form.action :cancel, as: :link
\ No newline at end of file diff --git a/app/views/companies/index.html.slim b/app/views/companies/index.html.slim index 711b88607..2fb042fa1 100644 --- a/app/views/companies/index.html.slim +++ b/app/views/companies/index.html.slim @@ -1,6 +1,6 @@ = title_tag t('companies.index.title') -= search_form_for @q, :url => referential_companies_path(@referential), remote: true, :html => {:method => :get, class: 'form-inline', id: 'search', role: "form"} do |f| += search_form_for @q, :url => referential_companies_path(@line_referential), remote: true, :html => {:method => :get, class: 'form-inline', id: 'search', role: "form"} do |f| .panel.panel-default .panel-heading @@ -9,7 +9,7 @@ .input-group-btn button.btn.btn-default type="submit" i.fa.fa-search - + / <!-- /input-group --> / <!-- <a data-toggle="collapse" data-parent="#search" href="#advanced_search"> --> / <!-- <i class="fa fa-plus"></i> <%= "#{t('.advanced_search')}" %> --> @@ -21,5 +21,5 @@ - content_for :sidebar do ul.actions li - = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + = link_to t('companies.actions.new'), new_line_referential_company_path(@line_referential), class: 'add' br
\ No newline at end of file diff --git a/app/views/companies/show.html.slim b/app/views/companies/show.html.slim index a445dad61..693cea352 100644 --- a/app/views/companies/show.html.slim +++ b/app/views/companies/show.html.slim @@ -45,11 +45,11 @@ - content_for :sidebar do ul.actions li - = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + = link_to t('companies.actions.new'), new_line_referential_company_path(@line_referential), class: 'add' li - = link_to t('companies.actions.edit'), edit_referential_company_path(@referential, @company), class: 'edit' + = link_to t('companies.actions.edit'), edit_line_referential_company_path(@line_referential, @company), class: 'edit' li - = link_to t('companies.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'remove' + = link_to t('companies.actions.destroy'), line_referential_company_path(@line_referential, @company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'remove' br = creation_tag(@company)
\ No newline at end of file diff --git a/app/views/line_referentials/_form.html.slim b/app/views/line_referentials/_form.html.slim new file mode 100644 index 000000000..0a58a70ae --- /dev/null +++ b/app/views/line_referentials/_form.html.slim @@ -0,0 +1,7 @@ += semantic_form_for @line_referential, :url => line_referential_path do |form| + = form.inputs do + = form.input :sync_interval + + = form.actions do + = form.action :submit, as: :button + = form.action :cancel, as: :link
\ No newline at end of file diff --git a/app/views/line_referentials/edit.html.slim b/app/views/line_referentials/edit.html.slim new file mode 100644 index 000000000..820b788e5 --- /dev/null +++ b/app/views/line_referentials/edit.html.slim @@ -0,0 +1,3 @@ += title_tag t('line_referentials.edit.title', line_referential: @line_referential.name) + += render 'form'
\ No newline at end of file diff --git a/app/views/line_referentials/show.html.slim b/app/views/line_referentials/show.html.slim index 5d35d84b4..019a0650a 100644 --- a/app/views/line_referentials/show.html.slim +++ b/app/views/line_referentials/show.html.slim @@ -8,24 +8,22 @@ li.list-group-item span.badge = @line_referential.group_of_lines.size = link_to Referential.human_attribute_name("group_of_lines"), line_referential_group_of_lines_path(@line_referential) - + li.list-group-item span.badge = @line_referential.operating_lines.size = link_to Referential.human_attribute_name("lines"), line_referential_lines_path(@line_referential) + li.list-group-item + span.badge = @line_referential.companies.size + = link_to Referential.human_attribute_name("companies"), line_referential_companies_path(@line_referential) + - unless @line_referential.line_referential_sync.line_sync_operations.empty? - = title_tag "Historique des synchronisations" + h3 Historique des synchronisations ul.list-group width="75%" - @line_referential.line_referential_sync.line_sync_operations.each do |sync| li = "#{sync.created_at.to_formatted_s(:short)} - #{sync.message}" -= semantic_form_for @line_referential, :url => line_referential_path do |form| - = form.inputs do - = form.input :sync_interval - - = form.actions do - = form.action :submit, as: :button - - content_for :sidebar do - ul.actions
\ No newline at end of file + ul.actions + = link_to t('line_referentials.actions.edit'), edit_line_referential_path(@line_referential), class: 'edit'
\ No newline at end of file diff --git a/app/views/referential_companies/_companies.html.slim b/app/views/referential_companies/_companies.html.slim new file mode 100644 index 000000000..bcd471cc7 --- /dev/null +++ b/app/views/referential_companies/_companies.html.slim @@ -0,0 +1,9 @@ +.page_info + span.search = t('will_paginate.page_entries_info.search') + = page_entries_info(@companies) + +.companies.paginated_content + = paginated_content(@companies) + +.pagination + = will_paginate @companies, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer
\ No newline at end of file diff --git a/app/views/referential_companies/_company.html.slim b/app/views/referential_companies/_company.html.slim new file mode 100644 index 000000000..06e13764e --- /dev/null +++ b/app/views/referential_companies/_company.html.slim @@ -0,0 +1,16 @@ +#index_item.company.panel.panel-default + .panel-heading + .panel-title.clearfix + span.pull-right + = link_to edit_referential_company_path(@referential, company), class: 'btn btn-default btn-sm' do + span.fa.fa-pencil + = link_to referential_company_path(@referential, company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm' do + span.fa.fa-trash-o + h5 + = link_to [@referential, company], class: 'preview', title: "#{Chouette::Company.model_name.human.capitalize} #{company.name}" do + span.name + = truncate(company.name, length: 20) + .panel-body + p + = company.human_attribute_name('code') + = company.code
\ No newline at end of file diff --git a/app/views/referential_companies/_form.html.slim b/app/views/referential_companies/_form.html.slim new file mode 100644 index 000000000..b02eab3f1 --- /dev/null +++ b/app/views/referential_companies/_form.html.slim @@ -0,0 +1,18 @@ += semantic_form_for [@referential, @company] do |form| + = form.inputs do + = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.name") } + = form.input :short_name + = form.input :organizational_unit + = form.input :operating_department_name + = form.input :code + = form.input :phone, as: :phone + = form.input :fax, as: :phone + = form.input :email, as: :email + = form.input :time_zone, include_blank: true + = form.input :url + = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.registration_number") } + = form.input :objectid, :required => !@company.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.objectid") } + + = form.actions do + = form.action :submit, as: :button + = form.action :cancel, as: :link
\ No newline at end of file diff --git a/app/views/referential_companies/edit.html.slim b/app/views/referential_companies/edit.html.slim new file mode 100644 index 000000000..6c415edfb --- /dev/null +++ b/app/views/referential_companies/edit.html.slim @@ -0,0 +1,2 @@ += title_tag t('companies.edit.title', company: @company.name) += render 'form'
\ No newline at end of file diff --git a/app/views/referential_companies/index.html.slim b/app/views/referential_companies/index.html.slim new file mode 100644 index 000000000..b32f206ca --- /dev/null +++ b/app/views/referential_companies/index.html.slim @@ -0,0 +1,24 @@ += title_tag t('companies.index.title') + += search_form_for @q, :url => referential_companies_path(@referential), remote: true, :html => {:method => :get, class: 'form-inline', id: 'search', role: "form"} do |f| + + .panel.panel-default + .panel-heading + .input-group.col-md-12 + = f.text_field :name_cont, placeholder: t('.name'), class: 'form-control' + .input-group-btn + button.btn.btn-default type="submit" + i.fa.fa-search + + / <!-- /input-group --> + / <!-- <a data-toggle="collapse" data-parent="#search" href="#advanced_search"> --> + / <!-- <i class="fa fa-plus"></i> <%= "#{t('.advanced_search')}" %> --> + / <!-- </a> --> +#companies + = render partial: 'companies', object: @companies + +- content_for :sidebar do + ul.actions + li + = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + br
\ No newline at end of file diff --git a/app/views/referential_companies/index.js.slim b/app/views/referential_companies/index.js.slim new file mode 100644 index 000000000..cfb1c719c --- /dev/null +++ b/app/views/referential_companies/index.js.slim @@ -0,0 +1 @@ +| $('#companies').html("= escape_javascript(render('companies'))");
\ No newline at end of file diff --git a/app/views/referential_companies/new.html.slim b/app/views/referential_companies/new.html.slim new file mode 100644 index 000000000..1acb1786f --- /dev/null +++ b/app/views/referential_companies/new.html.slim @@ -0,0 +1,2 @@ += title_tag t('companies.new.title') += render 'form'
\ No newline at end of file diff --git a/app/views/referential_companies/show.html.slim b/app/views/referential_companies/show.html.slim new file mode 100644 index 000000000..a445dad61 --- /dev/null +++ b/app/views/referential_companies/show.html.slim @@ -0,0 +1,55 @@ += title_tag t('companies.show.title', company: @company.name) + +.company_show + .summary + p + label = "#{Chouette::Company.human_attribute_name('short_name')} : " + = @company.short_name + + p + label = "#{Chouette::Company.human_attribute_name('organizational_unit')} : " + = @company.organizational_unit + + p + label = "#{Chouette::Company.human_attribute_name('operating_department_name')} : " + = @company.operating_department_name + + p + label = "#{Chouette::Company.human_attribute_name('code')} : " + = @company.code + + p + label = "#{Chouette::Company.human_attribute_name('phone')} : " + = @company.phone + + p + label = "#{Chouette::Company.human_attribute_name('fax')} : " + = @company.fax + + p + label = "#{Chouette::Company.human_attribute_name('email')} : " + = @company.email + + p + label = "#{Chouette::Company.human_attribute_name('time_zone')} : " + = @company.time_zone + + p + label = "#{Chouette::Company.human_attribute_name('url')} : " + = @company.url + + p + label = "#{Chouette::Company.human_attribute_name('registration_number')} : " + = @company.registration_number + +- content_for :sidebar do + ul.actions + li + = link_to t('companies.actions.new'), new_referential_company_path(@referential), class: 'add' + li + = link_to t('companies.actions.edit'), edit_referential_company_path(@referential, @company), class: 'edit' + li + = link_to t('companies.actions.destroy'), referential_company_path(@referential, @company), :method => :delete, :data => {:confirm => t('companies.actions.destroy_confirm')}, class: 'remove' + br + + = creation_tag(@company)
\ No newline at end of file diff --git a/app/views/stop_areas/_genealogical.html.slim b/app/views/stop_areas/_genealogical.html.slim index c70106a17..a31cd9529 100644 --- a/app/views/stop_areas/_genealogical.html.slim +++ b/app/views/stop_areas/_genealogical.html.slim @@ -2,7 +2,7 @@ h3 = genealogical_title - if @stop_area.parent.present? .parent - = link_to([@referential, @stop_area.parent], title: t("area_types.label.#{ @stop_area.parent.stop_area_type}") + " #{ @stop_area.parent.name}") do + = link_to([@stop_area_referential, @stop_area.parent], title: t("area_types.label.#{ @stop_area.parent.stop_area_type}") + " #{ @stop_area.parent.name}") do = image_tag "map/" + @stop_area.parent.stop_area_type + ".png" span = @stop_area.parent.name @@ -12,7 +12,7 @@ h3 = genealogical_title .lines - @stop_area.routing_lines.each do |line| .line - = link_to([@referential, line]) do + = link_to([@stop_area_referential, line]) do span = line.name .link = image_tag "icons/link.png" @@ -29,7 +29,7 @@ h3 = genealogical_title .children - @stop_area.children.each do |child| .child - = link_to([@referential, child], :title => t("area_types.label.#{ child.stop_area_type}") + " #{ child.name}") do + = link_to([@stop_area_referential, child], :title => t("area_types.label.#{ child.stop_area_type}") + " #{ child.name}") do = image_tag "map/" + child.stop_area_type + ".png" span = child.name @@ -38,7 +38,7 @@ h3 = genealogical_title .children - @stop_area.routing_stops.each do |stop| .child - = link_to([@referential, stop], :title => t("area_types.label.#{ stop.stop_area_type}") + " #{ stop.name}") do + = link_to([@stop_area_referential, stop], :title => t("area_types.label.#{ stop.stop_area_type}") + " #{ stop.name}") do = image_tag "map/" + stop.stop_area_type + ".png" span = "#{stop.name} #{' [' + stop.registration_number + ']' if stop.registration_number.present? }" @@ -47,8 +47,8 @@ h3 = genealogical_title .children - @stop_area.routes.each do |route| .child - = link_to([@referential, route.line ]) do + = link_to([@stop_area_referential, route.line ]) do span = route.line.number - = link_to([@referential, route.line , route]) do - span = route.name
\ No newline at end of file + = link_to([@stop_area_referential, route.line , route]) do + span = route.name diff --git a/config/environments/development.rb b/config/environments/development.rb index 12dafdc73..47e365098 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -57,7 +57,7 @@ Rails.application.configure do config.accept_user_creation = false # Reflex api url - config.reflex_api_url = "https://reflex.stif.info/ws/reflex/V1/service=getData" + config.reflex_api_url = "https://195.46.215.128/ws/reflex/V1/service=getData" # config.chouette_authentication_settings = { # type: "database" diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index e3e5c5d5d..59bbea437 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -17,7 +17,20 @@ Apartment.configure do |config| # # config.excluded_models = %w{Tenant} # - config.excluded_models = ["Referential", "Organisation", "User", "Delayed::Backend::ActiveRecord::Job", "Api::V1::ApiKey", "RuleParameterSet", "StopAreaReferential", "Chouette::StopArea", "LineReferential", "Chouette::Line", "Chouette::GroupOfLine"] + config.excluded_models = [ + "Referential", + "Organisation", + "User", + "Delayed::Backend::ActiveRecord::Job", + "Api::V1::ApiKey", + "RuleParameterSet", + "StopAreaReferential", + "Chouette::StopArea", + "LineReferential", + "Chouette::Line", + "Chouette::GroupOfLine", + "Chouette::Company" + ] # use postgres schemas? config.use_schemas = true diff --git a/config/locales/companies.en.yml b/config/locales/companies.en.yml index 760ef91e4..7393a2af7 100644 --- a/config/locales/companies.en.yml +++ b/config/locales/companies.en.yml @@ -1,12 +1,12 @@ en: - companies: + companies: &en_companies actions: new: "Add a new company" edit: "Edit this company" destroy: "Remove this company" destroy_confirm: "Are you sure you want destroy this company?" new: - title: "Add a new company" + title: "Add a new company" edit: title: "Update company %{company}" show: @@ -62,5 +62,7 @@ en: hub: company: name: "maximum 75 characters" - registration_number: "Positif integer, unique key, of no more than 8 digits." + registration_number: "Positif integer, unique key, of no more than 8 digits." objectid: "[prefix]:Company:[unique_key] : prefix contains only alphanumerical or underscore characters, unique_key accepts also minus character. Maximum length of the unique key = 3." + referential_companies: + <<: *en_companies
\ No newline at end of file diff --git a/config/locales/companies.fr.yml b/config/locales/companies.fr.yml index b3b437220..909ee1045 100644 --- a/config/locales/companies.fr.yml +++ b/config/locales/companies.fr.yml @@ -1,5 +1,5 @@ fr: - companies: + companies: &fr_companies actions: new: "Ajouter un transporteur" edit: "Modifier ce transporteur" @@ -64,3 +64,5 @@ fr: name: "maximum 75 caractères" registration_number: "Entier positif, clé unique, d'un maximum de 8 chiffres." objectid: "[prefixe]:Company:[clé_unique] caractères autorisés : alphanumériques et 'souligné' pour le préfixe, la clé unique accepte en plus le 'moins'. Longueur maximale de la clé unique = 3." + referential_companies: + <<: *fr_companies
\ No newline at end of file diff --git a/config/locales/line_referentials.en.yml b/config/locales/line_referentials.en.yml index ad4cfa45c..d7cd6c519 100644 --- a/config/locales/line_referentials.en.yml +++ b/config/locales/line_referentials.en.yml @@ -1,8 +1,16 @@ en: + line_referentials: + actions: + edit: "Edit this referential" + edit: + title: "Edit %{line_referential} referential" synchronization: message: "Synchronization successful in %{time} seconds with %{imported} objects from Codifligne. %{deleted} objects were deleted." failure: "Synchronization interrupted after %{time} seconds." activerecord: + models: + line_referential: + one: "referential" attributes: line_referential: sync_interval: "Synchronisation frequency"
\ No newline at end of file diff --git a/config/locales/line_referentials.fr.yml b/config/locales/line_referentials.fr.yml index 6378087d7..adb96cbe0 100644 --- a/config/locales/line_referentials.fr.yml +++ b/config/locales/line_referentials.fr.yml @@ -1,9 +1,18 @@ fr: + line_referentials: + actions: + edit: "Modifier ce référentiel" + edit: + title: "Modifier le référentiel %{line_referential}" synchronization: - message: - success: "Synchronisation réussie après %{time} secondes avec %{imported} éléments importés de Codifligne. %{deleted} éléments ont été supprimés." - failure: "Synchronisation interrompue après %{time} secondes." + codifligne: + message: + success: "Synchronisation réussie après %{time} secondes avec %{imported} éléments importés de Codifligne. %{deleted} éléments ont été supprimés." + failure: "Synchronisation interrompue après %{time} secondes." activerecord: + models: + line_referential: + one: "référentiel" attributes: line_referential: - sync_interval: "Fréquence de synchronisation"
\ No newline at end of file + sync_interval: "Fréquence de synchronisation" diff --git a/config/locales/stop_area_referentials.en.yml b/config/locales/stop_area_referentials.en.yml new file mode 100644 index 000000000..9ac0daede --- /dev/null +++ b/config/locales/stop_area_referentials.en.yml @@ -0,0 +1,5 @@ +en: + synchronization: + reflex: + message: "Synchronization successful in %{time} seconds with %{imported} objects from Reflex. %{deleted} objects were deleted." + failure: "Synchronization interrupted after %{time} seconds." diff --git a/config/locales/stop_area_referentials.fr.yml b/config/locales/stop_area_referentials.fr.yml new file mode 100644 index 000000000..89254384f --- /dev/null +++ b/config/locales/stop_area_referentials.fr.yml @@ -0,0 +1,6 @@ +fr: + synchronization: + reflex: + message: + success: "Synchronisation réussie après %{time} secondes avec %{imported} éléments importés de Reflex. %{deleted} éléments ont été supprimés." + failure: "Synchronisation interrompue après %{time} secondes." diff --git a/config/routes.rb b/config/routes.rb index af466f640..1cd809c59 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ ChouetteIhm::Application.routes.draw do authenticated :user do root :to => 'referentials#index', as: :authenticated_root end - + unauthenticated :user do target = 'devise/sessions#new' @@ -55,9 +55,10 @@ ChouetteIhm::Application.routes.draw do resources :stop_areas end - resources :line_referentials, :only => [:show, :update] do + resources :line_referentials, :only => [:show, :edit, :update] do resources :lines resources :group_of_lines + resources :companies end resources :referentials do @@ -148,7 +149,7 @@ ChouetteIhm::Application.routes.draw do end end - resources :companies + resources :companies, controller: "referential_companies" resources :time_tables do collection do diff --git a/db/migrate/20160909092812_create_stop_area_referential_syncs.rb b/db/migrate/20160909092812_create_stop_area_referential_syncs.rb new file mode 100644 index 000000000..eb68f662b --- /dev/null +++ b/db/migrate/20160909092812_create_stop_area_referential_syncs.rb @@ -0,0 +1,9 @@ +class CreateStopAreaReferentialSyncs < ActiveRecord::Migration + def change + create_table :stop_area_referential_syncs do |t| + t.references :stop_area_referential, index: true + + t.timestamps + end + end +end diff --git a/db/migrate/20160909093322_create_stop_area_sync_operations.rb b/db/migrate/20160909093322_create_stop_area_sync_operations.rb new file mode 100644 index 000000000..fef4f5e1f --- /dev/null +++ b/db/migrate/20160909093322_create_stop_area_sync_operations.rb @@ -0,0 +1,12 @@ +class CreateStopAreaSyncOperations < ActiveRecord::Migration + def change + create_table :stop_area_sync_operations do |t| + t.string :status + t.references :stop_area_referential_sync + t.string :message + + t.timestamps + end + add_index :stop_area_sync_operations, :stop_area_referential_sync_id, name: 'stop_area_referential_sync_id' + end +end diff --git a/db/migrate/20160909125235_disable_company_foreign_keys.rb b/db/migrate/20160909125235_disable_company_foreign_keys.rb new file mode 100644 index 000000000..5aac344c7 --- /dev/null +++ b/db/migrate/20160909125235_disable_company_foreign_keys.rb @@ -0,0 +1,17 @@ +class DisableCompanyForeignKeys < ActiveRecord::Migration + def change + disable_foreign_key :vehicle_journeys, :vj_company_fkey + end + + def disable_foreign_key(table, name) + if foreign_key?(table, name) + remove_foreign_key table, name: name + end + end + + def foreign_key?(table, name) + @connection.foreign_keys(table).any? do |foreign_key| + foreign_key.options[:name] == name.to_s + end + end +end diff --git a/db/migrate/20160909130810_add_index_to_stop_areas.rb b/db/migrate/20160909130810_add_index_to_stop_areas.rb new file mode 100644 index 000000000..e5d4d2f40 --- /dev/null +++ b/db/migrate/20160909130810_add_index_to_stop_areas.rb @@ -0,0 +1,5 @@ +class AddIndexToStopAreas < ActiveRecord::Migration + def change + add_index :stop_areas, :name + end +end diff --git a/db/schema.rb b/db/schema.rb index a5b18db68..0e606fb3e 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: 20160905094930) do +ActiveRecord::Schema.define(version: 20160909130810) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -407,10 +407,10 @@ ActiveRecord::Schema.define(version: 20160905094930) do t.integer "object_version" t.datetime "creation_time" t.string "creator_id" - t.float "distance" - t.boolean "no_processing" t.spatial "input_geometry", limit: {:srid=>4326, :type=>"line_string"} t.spatial "processed_geometry", limit: {:srid=>4326, :type=>"line_string"} + t.float "distance" + t.boolean "no_processing" end create_table "routes", force: true do |t| @@ -449,12 +449,30 @@ ActiveRecord::Schema.define(version: 20160905094930) do t.boolean "owner" end + create_table "stop_area_referential_syncs", force: true do |t| + t.integer "stop_area_referential_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "stop_area_referential_syncs", ["stop_area_referential_id"], :name => "index_stop_area_referential_syncs_on_stop_area_referential_id" + create_table "stop_area_referentials", force: true do |t| t.string "name" t.datetime "created_at" t.datetime "updated_at" end + create_table "stop_area_sync_operations", force: true do |t| + t.string "status" + t.integer "stop_area_referential_sync_id" + t.string "message" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "stop_area_sync_operations", ["stop_area_referential_sync_id"], :name => "stop_area_referential_sync_id" + create_table "stop_areas", force: true do |t| t.integer "parent_id", limit: 8 t.string "objectid", null: false @@ -486,6 +504,7 @@ ActiveRecord::Schema.define(version: 20160905094930) do t.datetime "deleted_at" end + add_index "stop_areas", ["name"], :name => "index_stop_areas_on_name" add_index "stop_areas", ["objectid"], :name => "stop_areas_objectid_key", :unique => true add_index "stop_areas", ["parent_id"], :name => "index_stop_areas_on_parent_id" add_index "stop_areas", ["stop_area_referential_id"], :name => "index_stop_areas_on_stop_area_referential_id" @@ -695,7 +714,6 @@ ActiveRecord::Schema.define(version: 20160905094930) do add_foreign_key "vehicle_journey_at_stops", "stop_points", name: "vjas_sp_fkey", dependent: :delete add_foreign_key "vehicle_journey_at_stops", "vehicle_journeys", name: "vjas_vj_fkey", dependent: :delete - add_foreign_key "vehicle_journeys", "companies", name: "vj_company_fkey", dependent: :nullify add_foreign_key "vehicle_journeys", "journey_patterns", name: "vj_jp_fkey", dependent: :delete add_foreign_key "vehicle_journeys", "routes", name: "vj_route_fkey", dependent: :delete diff --git a/db/seeds.rb b/db/seeds.rb index a975b07f8..14640e608 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -42,6 +42,7 @@ line_referential = LineReferential.find_or_create_by(name: "CodifLigne") do |ref end LineReferentialSync.find_or_create_by(line_referential: line_referential) +StopAreaReferentialSync.find_or_create_by(stop_area_referential: stop_area_referential) 10.times do |n| line_referential.lines.find_or_create_by name: "Test #{n}" do |l| @@ -50,7 +51,6 @@ LineReferentialSync.find_or_create_by(line_referential: line_referential) end - offer_workbench = OfferWorkbench.find_or_create_by(name: "Gestion de l'offre", organisation: operator) [["parissudest201604", "Paris Sud-Est Avril 2016"], diff --git a/lib/stif/codif_line_synchronization.rb b/lib/stif/codif_line_synchronization.rb index 01ad29afc..9da0e30cc 100644 --- a/lib/stif/codif_line_synchronization.rb +++ b/lib/stif/codif_line_synchronization.rb @@ -61,12 +61,12 @@ module Stif total_deleted = deleted_op + deleted_li + deleted_ne + deleted_gr total_time = elapsed_time_since start_time - LineReferential.first.line_referential_sync.record_status :ok, I18n.t('synchronization.message.success', time: total_time, imported: total_codifligne_elements, deleted: total_deleted) + LineReferential.first.line_referential_sync.record_status :ok, I18n.t('synchronization.codifligne.message.success', time: total_time, imported: total_codifligne_elements, deleted: total_deleted) rescue Exception => e total_time = elapsed_time_since start_time Rails.logger.error "Codifligne:sync - Error: #{e}, ended after #{total_time} seconds" - LineReferential.first.line_referential_sync.record_status :ko, I18n.t('synchronization.message.failure', time: total_time) + LineReferential.first.line_referential_sync.record_status :ko, I18n.t('synchronization.codifligne.message.failure', time: total_time) end end @@ -174,4 +174,4 @@ module Stif end end end -end
\ No newline at end of file +end diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index 55fe3d404..eab86caf1 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -11,45 +11,52 @@ module Stif end def synchronize - start = Time.now - client = Reflex::API.new - processed = [] + tstart = Time.now + begin + client = Reflex::API.new + processed = [] - ['getOR', 'getOP'].each do |method| - results = client.process method - Rails.logger.info "Reflex:sync - Process #{method} done in #{Time.now - start} seconds" - results.each do |type, entries| - Rails.logger.info "Reflex:sync - #{entries.count} #{type} retrieved" - end + ['getOR', 'getOP'].each do |method| + start = Time.now + results = client.process method + Rails.logger.info "Reflex:sync - Process #{method} done in #{Time.now - start} seconds" + results.each do |type, entries| + Rails.logger.info "Reflex:sync - #{entries.count} #{type} retrieved" + end - # Create or update stop_area for every quay, stop_place - stop_areas = results[:Quay].merge(results[:StopPlace]) - start = Time.now - stop_areas.each do |id, entry| - processed << self.create_or_update_stop_area(entry).objectid - end - Rails.logger.info "Reflex:sync - Create or update StopArea done in #{Time.now - start} seconds" + # Create or update stop_area for every quay, stop_place + stop_areas = results[:Quay].merge(results[:StopPlace]) + start = Time.now + stop_areas.each do |id, entry| + processed << self.create_or_update_stop_area(entry).objectid + end + Rails.logger.info "Reflex:sync - Create or update StopArea done in #{Time.now - start} seconds" - # Walk through every entry and set parent stop_area - start = Time.now - stop_areas.each do |id, entry| - self.stop_area_set_parent entry + # Walk through every entry and set parent stop_area + start = Time.now + stop_areas.each do |id, entry| + self.stop_area_set_parent entry + end + Rails.logger.info "Reflex:sync - StopArea set parent done in #{Time.now - start} seconds" end - Rails.logger.info "Reflex:sync - StopArea set parent done in #{Time.now - start} seconds" + + # Purge deleted stop_area + deleted = self.set_deleted_stop_area processed.uniq + self.defaut_referential.stop_area_referential_sync.record_status :ok, I18n.t('synchronization.reflex.message.success', time: Time.now - tstart, imported: processed.uniq.size, deleted: deleted.size) + rescue Exception => e + Rails.logger.error "Reflex:sync - Error: #{e}, ended after #{Time.now - tstart} seconds" + LineReferential.first.line_referential_sync.record_status :ko, I18n.t('synchronization.reflex.message.failure', time: Time.now - tstart) end - # Purge deleted stop_area - self.set_deleted_stop_area processed.uniq end def set_deleted_stop_area processed - Rails.logger.info "Reflex:sync - StopArea start deleted_stop_area" start = Time.now deleted = Chouette::StopArea.where(deleted_at: nil).pluck(:objectid).uniq - processed deleted.each_slice(50) do |object_ids| Chouette::StopArea.where(objectid: object_ids).update_all(deleted_at: Time.now) end - Rails.logger.info "Reflex:sync - StopArea #{deleted.size} stop_area deleted since last sync" - Rails.logger.info "Reflex:sync - StopArea purge deleted in #{Time.now - start} seconds" + Rails.logger.info "Reflex:sync - StopArea #{deleted.size} stop_area deleted since last sync in #{Time.now - start} seconds" + deleted end def stop_area_set_parent entry diff --git a/spec/factories/stop_area_referential_syncs.rb b/spec/factories/stop_area_referential_syncs.rb new file mode 100644 index 000000000..e86a67400 --- /dev/null +++ b/spec/factories/stop_area_referential_syncs.rb @@ -0,0 +1,15 @@ +FactoryGirl.define do + factory :stop_area_referential_sync do + stop_area_referential nil + + factory :stop_area_referential_sync_with_record do + transient do + stop_area_sync_operations_count rand(1..30) + end + + after(:create) do |stop_area_referential_sync, evaluator| + create_list(:stop_area_sync_operation, evaluator.stop_area_sync_operations_count, stop_area_referential_sync: stop_area_referential_sync) + end + end + end +end diff --git a/spec/factories/stop_area_sync_operations.rb b/spec/factories/stop_area_sync_operations.rb new file mode 100644 index 000000000..c62f7f9c6 --- /dev/null +++ b/spec/factories/stop_area_sync_operations.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :stop_area_sync_operation do + status "MyString" +stop_area_referential_sync nil +message "MyString" + end + +end diff --git a/spec/features/companies_spec.rb b/spec/features/companies_spec.rb index c85f6f2cd..3f72ccb4d 100644 --- a/spec/features/companies_spec.rb +++ b/spec/features/companies_spec.rb @@ -4,42 +4,43 @@ require 'spec_helper' describe "Companies", :type => :feature do login_user - let!(:companies) { Array.new(2) { create :company } } + let(:line_referential) { create :line_referential } + let!(:companies) { Array.new(2) { create :company, line_referential: line_referential } } subject { companies.first } describe "list" do it "display companies" do - visit referential_companies_path(referential) + visit line_referential_companies_path(line_referential) expect(page).to have_content(companies.first.name) expect(page).to have_content(companies.last.name) end - - end - describe "show" do + end + + describe "show" do it "display company" do - visit referential_companies_path(referential) + visit line_referential_companies_path(line_referential) click_link "#{companies.first.name}" expect(page).to have_content(companies.first.name) end - + end - describe "new" do + describe "new" do it "creates company and return to show" do - visit referential_companies_path(referential) + visit line_referential_companies_path(line_referential) click_link "Ajouter un transporteur" fill_in "company_name", :with => "Company 1" fill_in "Numéro d'enregistrement", :with => "test-1" - fill_in "Identifiant Neptune", :with => "chouette:test:Company:1" + fill_in "Identifiant Neptune", :with => "chouette:test:Company:1" click_button("Créer transporteur") expect(page).to have_content("Company 1") end end - describe "edit and return to show" do + describe "edit and return to show" do it "edit company" do - visit referential_company_path(referential, subject) + visit line_referential_company_path(line_referential, subject) click_link "Modifier ce transporteur" fill_in "company_name", :with => "Company Modified" fill_in "Numéro d'enregistrement", :with => "test-1" diff --git a/spec/models/stop_area_referential_sync_spec.rb b/spec/models/stop_area_referential_sync_spec.rb new file mode 100644 index 000000000..bc5f92b2d --- /dev/null +++ b/spec/models/stop_area_referential_sync_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe StopAreaReferentialSync, :type => :model do + it 'should have a valid factory' do + expect(FactoryGirl.build(:stop_area_referential_sync)).to be_valid + end + + it { is_expected.to belong_to(:stop_area_referential) } + it { is_expected.to have_many(:stop_area_sync_operations) } + + describe '.record_status' + let!(:stop_area_ref_sync) { create(:stop_area_referential_sync) } + let!(:stop_area_ref_sync_with_records) { create(:stop_area_referential_sync_with_record, stop_area_sync_operations_count: 30) } + + it 'should add a new record' do + stop_area_ref_sync.record_status :ok, "message" + expect(stop_area_ref_sync.stop_area_sync_operations.count).to eq(1) + end + + it 'should not have more than 30 records' do + stop_area_ref_sync_with_records.record_status :ok, "message" + expect(stop_area_ref_sync_with_records.stop_area_sync_operations.count).to eq(30) + end +end diff --git a/spec/models/stop_area_sync_operation_spec.rb b/spec/models/stop_area_sync_operation_spec.rb new file mode 100644 index 000000000..a98108d71 --- /dev/null +++ b/spec/models/stop_area_sync_operation_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe StopAreaSyncOperation, :type => :model do + it 'should have a valid factory' do + expect(FactoryGirl.build(:stop_area_sync_operation)).to be_valid + end + + it { is_expected.to belong_to(:stop_area_referential_sync) } +end diff --git a/spec/models/vehicle_translation_spec.rb b/spec/models/vehicle_translation_spec.rb index 7a02eaf94..9864c18cc 100644 --- a/spec/models/vehicle_translation_spec.rb +++ b/spec/models/vehicle_translation_spec.rb @@ -3,11 +3,13 @@ require 'spec_helper' describe VehicleTranslation, :type => :model do let!(:company){ create(:company )} let!(:journey_pattern){create(:journey_pattern)} + # To fix : need to comment :company => company + # after adding company to apartment excluded models let!(:vehicle_journey){ create(:vehicle_journey, :objectid => "dummy", :journey_pattern => journey_pattern, :route => journey_pattern.route, - :company => company, + # :company => company, :transport_mode => Chouette::TransportMode.new("metro"), :published_journey_name => "dummy" )} diff --git a/spec/routing/companies_spec.rb b/spec/routing/companies_spec.rb index 25f86325b..df16079f3 100644 --- a/spec/routing/companies_spec.rb +++ b/spec/routing/companies_spec.rb @@ -3,21 +3,21 @@ require 'spec_helper' describe CompaniesController do describe "routing" do it "not recognize #routes" do - get( "/referentials/1/companies/2/routes").should_not route_to( + get( "/line_referentials/1/companies/2/routes").should_not route_to( :controller => "companies", :action => "routes", - :referential_id => "1", :id => "2" + :line_referential_id => "1", :id => "2" ) end it "not recognize #lines" do - get( "/referentials/1/companies/2/lines").should_not route_to( + get( "/line_referentials/1/companies/2/lines").should_not route_to( :controller => "companies", :action => "lines", - :referential_id => "1", :id => "2" + :line_referential_id => "1", :id => "2" ) end it "recognize and generate #show" do - get( "/referentials/1/companies/2").should route_to( + get( "/line_referentials/1/companies/2").should route_to( :controller => "companies", :action => "show", - :referential_id => "1", :id => "2" + :line_referential_id => "1", :id => "2" ) end end diff --git a/spec/tasks/reflex_rake_spec.rb b/spec/tasks/reflex_rake_spec.rb index bf1a81a82..3a0ce0632 100644 --- a/spec/tasks/reflex_rake_spec.rb +++ b/spec/tasks/reflex_rake_spec.rb @@ -7,7 +7,9 @@ describe 'reflex:sync' do stub_request(:get, "https://reflex.stif.info/ws/reflex/V1/service=getData/?format=xml&idRefa=0&method=#{method}"). to_return(body: File.open("#{fixture_path}/reflex.zip"), status: 200) end - create(:stop_area_referential, name: 'Reflex') + + stop_area_ref = create(:stop_area_referential, name: 'Reflex') + create(:stop_area_referential_sync, stop_area_referential: stop_area_ref) Stif::ReflexSynchronization.synchronize end @@ -42,6 +44,11 @@ describe 'reflex:sync' do Stif::ReflexSynchronization.synchronize end + it 'should log sync operations' do + expect(StopAreaSyncOperation.count).to eq 2 + expect(StopAreaSyncOperation.take.status).to eq "ok" + end + it 'should not create duplicate stop_area' do expect(Chouette::StopArea.count).to eq 6 expect(Chouette::AccessPoint.count).to eq 2 diff --git a/spec/views/companies/edit.html.erb_spec.rb b/spec/views/companies/edit.html.erb_spec.rb index 871efac10..4566ed64c 100644 --- a/spec/views/companies/edit.html.erb_spec.rb +++ b/spec/views/companies/edit.html.erb_spec.rb @@ -1,13 +1,14 @@ require 'spec_helper' describe "/companies/edit", :type => :view do - assign_referential + let!(:company) { assign(:company, create(:company)) } let!(:companies) { Array.new(2) { create(:company) } } + let!(:line_referential) { assign :line_referential, company.line_referential } describe "test" do it "should render h2 with the company name" do - render + render expect(rendered).to have_selector("h2", :text => Regexp.new(company.name)) end end diff --git a/spec/views/companies/index.html.erb_spec.rb b/spec/views/companies/index.html.erb_spec.rb index bf8ff5a38..0e25bac63 100644 --- a/spec/views/companies/index.html.erb_spec.rb +++ b/spec/views/companies/index.html.erb_spec.rb @@ -2,20 +2,20 @@ require 'spec_helper' describe "/companies/index", :type => :view do - assign_referential - let!(:companies) { assign :companies, Array.new(2) { create(:company) }.paginate } + let!(:line_referential) { assign :line_referential, create(:line_referential) } + let!(:companies) { assign :companies, Array.new(2) { create(:company, line_referential: line_referential) }.paginate } let!(:search) { assign :q, Ransack::Search.new(Chouette::Company) } - it "should render a show link for each group" do - render - companies.each do |company| - expect(rendered).to have_selector(".company a[href='#{view.referential_company_path(referential, company)}']", :text => company.name) + it "should render a show link for each group" do + render + companies.each do |company| + expect(rendered).to have_selector(".company a[href='#{view.line_referential_company_path(line_referential, company)}']", :text => company.name) end end it "should render a link to create a new group" do render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_referential_company_path(referential)}']") + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_line_referential_company_path(line_referential)}']") end end diff --git a/spec/views/companies/new.html.erb_spec.rb b/spec/views/companies/new.html.erb_spec.rb index 427cd21ac..ebb8c03c5 100644 --- a/spec/views/companies/new.html.erb_spec.rb +++ b/spec/views/companies/new.html.erb_spec.rb @@ -1,11 +1,12 @@ require 'spec_helper' describe "/companies/new", :type => :view do - assign_referential + let!(:company) { assign(:company, build(:company)) } + let!(:line_referential) { assign :line_referential, company.line_referential } describe "form" do - + it "should render input for name" do render expect(rendered).to have_selector("form") do diff --git a/spec/views/companies/show.html.erb_spec.rb b/spec/views/companies/show.html.erb_spec.rb index f15fb3cd0..6c488e130 100644 --- a/spec/views/companies/show.html.erb_spec.rb +++ b/spec/views/companies/show.html.erb_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' describe "/companies/show", :type => :view do - - assign_referential + let!(:company) { assign(:company, create(:company)) } + let!(:line_referential) { assign :line_referential, company.line_referential } it "should render h2 with the company name" do render @@ -17,12 +17,12 @@ describe "/companies/show", :type => :view do it "should render a link to edit the company" do render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_company_path(referential, company)}']") + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_line_referential_company_path(line_referential, company)}']") end it "should render a link to remove the company" do render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_company_path(referential, company)}'][class='remove']") + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.line_referential_company_path(line_referential, company)}'][class='remove']") end end |
