aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-02-08 10:33:46 +0100
committerLuc Donnet2018-02-20 10:20:18 +0100
commit3dcea81c627c1c740630ce7306bac55256ce8037 (patch)
tree1ff79bdb5f04aba4503b47c781aaa0146d1ac32a
parent3809301116aec5466445b29637026804da3d6745 (diff)
downloadchouette-core-3dcea81c627c1c740630ce7306bac55256ce8037.tar.bz2
Refs #5863 @6h; Remove workbench id from the querystring
Infer it when possible, and use a nested otherwise
-rw-r--r--app/controllers/application_controller.rb10
-rw-r--r--app/controllers/referentials_controller.rb12
-rw-r--r--app/decorators/referential_decorator.rb4
-rw-r--r--app/helpers/referentials_helper.rb10
-rw-r--r--app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js10
-rw-r--r--app/models/chouette/stop_area.rb2
-rw-r--r--app/models/organisation.rb4
-rw-r--r--app/models/user.rb1
-rw-r--r--app/models/workbench.rb7
-rw-r--r--app/views/dashboards/_dashboard.html.slim30
-rw-r--r--app/views/layouts/navigation/_main_nav_left_content_stif.html.slim10
-rw-r--r--app/views/referentials/_form.html.slim4
-rw-r--r--app/views/referentials/select_compliance_control_set.html.slim2
-rw-r--r--app/views/stif/dashboards/_dashboard.html.slim6
-rw-r--r--app/views/workbenches/show.html.slim4
-rw-r--r--config/breadcrumbs.rb6
-rw-r--r--config/routes.rb208
-rw-r--r--spec/controllers/referentials_controller_spec.rb52
-rw-r--r--spec/decorators/referential_decorator_spec.rb15
-rw-r--r--spec/features/referentials_spec.rb12
-rw-r--r--spec/features/workbenches/workbenches_permissions_spec.rb2
-rw-r--r--spec/features/workbenches/workbenches_show_spec.rb4
-rw-r--r--spec/helpers/table_builder_helper_spec.rb22
-rw-r--r--spec/support/decorator_helpers.rb1
-rw-r--r--spec/views/referentials/show.html.erb_spec.rb57
25 files changed, 273 insertions, 222 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 8bd3da2f9..45b7f55f6 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -36,16 +36,6 @@ class ApplicationController < ActionController::Base
end
helper_method :current_organisation
- def current_offer_workbench
- current_organisation.workbenches.find_by_name("Gestion de l'offre")
- end
- helper_method :current_offer_workbench
-
- def current_workgroup
- current_offer_workbench.workgroup
- end
- helper_method :current_workgroup
-
def current_functional_scope
functional_scope = current_organisation.sso_attributes.try(:[], "functional_scope") if current_organisation
JSON.parse(functional_scope) if functional_scope
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index 0ed3f75dd..5267c15d8 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -1,5 +1,6 @@
class ReferentialsController < ChouetteController
defaults :resource_class => Referential
+ before_action :load_workbench
include PolicyChecker
respond_to :html
@@ -30,7 +31,7 @@ class ReferentialsController < ChouetteController
def show
resource.switch
show! do |format|
- @referential = @referential.decorate(context: { current_workbench_id: params[:current_workbench_id] } )
+ @referential = @referential.decorate()
@reflines = lines_collection.paginate(page: params[:page], per_page: 10)
@reflines = ReferentialLineDecorator.decorate(
@reflines,
@@ -141,7 +142,6 @@ class ReferentialsController < ChouetteController
if params[:from]
source_referential = Referential.find(params[:from])
@referential = Referential.new_from(source_referential, current_functional_scope)
- @referential.workbench_id = params[:current_workbench_id]
end
@referential.data_format = current_organisation.data_format
@@ -175,4 +175,12 @@ class ReferentialsController < ChouetteController
)
end
+ def load_workbench
+ @workbench ||= Workbench.find(params[:workbench_id]) if params[:workbench_id]
+ @workbench ||= resource&.workbench if params[:id]
+ @workbench
+ end
+
+ alias_method :current_workbench, :load_workbench
+ helper_method :current_workbench
end
diff --git a/app/decorators/referential_decorator.rb b/app/decorators/referential_decorator.rb
index 3132cbf92..41cad237d 100644
--- a/app/decorators/referential_decorator.rb
+++ b/app/decorators/referential_decorator.rb
@@ -22,12 +22,12 @@ class ReferentialDecorator < AF83::Decorator
instance_decorator.action_link policy: :clone, secondary: :show do |l|
l.content t('actions.clone')
- l.href { h.new_referential_path(from: object.id, current_workbench_id: context[:current_workbench_id]) }
+ l.href { h.duplicate_workbench_referential_path(object) }
end
instance_decorator.action_link policy: :validate, secondary: :show do |l|
l.content t('actions.validate')
- l.href { h.referential_select_compliance_control_set_path(object.id) }
+ l.href { h.select_compliance_control_set_referential_path(object.id) }
end
instance_decorator.action_link policy: :archive, secondary: :show do |l|
diff --git a/app/helpers/referentials_helper.rb b/app/helpers/referentials_helper.rb
index 8251377aa..e464ec8a5 100644
--- a/app/helpers/referentials_helper.rb
+++ b/app/helpers/referentials_helper.rb
@@ -15,4 +15,14 @@ module ReferentialsHelper
service = ReferentialOverview.new referential, self
render partial: "referentials/overview", locals: {referential: referential, overview: service}
end
+
+ def mutual_workbench workbench
+ current_user.organisation.workbenches.where(workgroup_id: workbench.workgroup_id).last
+ end
+
+ def duplicate_workbench_referential_path referential
+ workbench = mutual_workbench referential.workbench
+ raise "Missing workbench for referential #{referential.name}" unless workbench.present?
+ new_workbench_referential_path(workbench, from: referential.id)
+ end
end
diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js
index 7ab85a1ea..72dbd0152 100644
--- a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js
+++ b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js
@@ -29,11 +29,11 @@ export default class BSelect4 extends Component {
val = this.props.selection.selectedJPModal
}
}
- if(this.useAjax()){
- val = val.published_name
- }
- else{
- if(val){
+ if(val){
+ if(this.useAjax()){
+ val = val.published_name
+ }
+ else{
val = val.id
}
}
diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb
index bb8747faa..830fe8b78 100644
--- a/app/models/chouette/stop_area.rb
+++ b/app/models/chouette/stop_area.rb
@@ -384,8 +384,8 @@ module Chouette
def country_name
return unless country_code
-
country = ISO3166::Country[country_code]
+ return unless country
country.translations[I18n.locale.to_s] || country.name
end
diff --git a/app/models/organisation.rb b/app/models/organisation.rb
index da7d1fcf3..e8fb4e060 100644
--- a/app/models/organisation.rb
+++ b/app/models/organisation.rb
@@ -80,4 +80,8 @@ class Organisation < ActiveRecord::Base
features && features.include?(feature.to_s)
end
+ def default_workbench
+ workbenches.default
+ end
+
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 1342f60ed..31e634415 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -15,6 +15,7 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
# attr_accessible :email, :password, :current_password, :password_confirmation, :remember_me, :name, :organisation_attributes
belongs_to :organisation
+ has_many :workbenches, through: :organisation
accepts_nested_attributes_for :organisation
validates :organisation, :presence => true
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index b80fa64ac..eb53af7aa 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -1,4 +1,6 @@
class Workbench < ActiveRecord::Base
+ DEFAULT_WORKBENCH_NAME = "Gestion de l'offre"
+
include ObjectidFormatterSupport
belongs_to :organisation
belongs_to :line_referential
@@ -40,6 +42,11 @@ class Workbench < ActiveRecord::Base
end
end
+ def self.default
+ self.last if self.count == 1
+ where(name: DEFAULT_WORKBENCH_NAME).last
+ end
+
private
def initialize_output
diff --git a/app/views/dashboards/_dashboard.html.slim b/app/views/dashboards/_dashboard.html.slim
index 05257a766..7f78934a6 100644
--- a/app/views/dashboards/_dashboard.html.slim
+++ b/app/views/dashboards/_dashboard.html.slim
@@ -14,25 +14,25 @@
- if workbench.referentials.present?
.list-group
- workbench.referentials.limit(5).each do |referential|
- = link_to referential.name, referential_path(referential, workbench_id: referential.workbench_id, current_workbench_id: workbench.id), class: 'list-group-item'
+ = link_to referential.name, referential_path(referential), class: 'list-group-item'
- else
.panel-body
em.small.text-muted = t('workbenches.index.offers.no_content')
- .panel.panel-default
- .panel-heading
- h3.panel-title.with_actions
- = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), workgroup_calendars_path(current_workgroup)
- div
- = 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, workgroup_calendars_path(current_workgroup, calendar), class: 'list-group-item'
- - else
- .panel-body
- em.small.text-muted
- = t('dasboard.calendars.none')
+ .panel.panel-default
+ .panel-heading
+ h3.panel-title.with_actions
+ = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), workgroup_calendars_path(workbench.workgroup)
+ div
+ = link_to '', workgroup_calendars_path(workbench.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, workgroup_calendars_path(workbench.workgroup, calendar), class: 'list-group-item'
+ - else
+ .panel-body
+ em.small.text-muted
+ = t('dasboard.calendars.none')
.col-lg-6.col-md-6.col-sm-6.col-xs-12
.panel.panel-default
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 1b7293d21..cb0698cf8 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
@@ -24,14 +24,14 @@
#miTwo.panel-collapse.collapse
.list-group
- - if current_user
- = link_to workbench_path(current_offer_workbench), class: "list-group-item #{params[:controller] == 'workbenches' ? 'active' : ''}" do
+ - current_user.workbenches.each do |current_workbench|
+ = link_to workbench_path(current_workbench), class: "list-group-item #{params[:controller] == 'workbenches' ? 'active' : ''}" do
span Jeux de données
- = link_to workbench_imports_path(current_offer_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do
+ = link_to workbench_imports_path(current_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do
span Import
- = link_to workgroup_calendars_path(current_workgroup), class: 'list-group-item' do
+ = link_to workgroup_calendars_path(current_workbench.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
+ = link_to workbench_compliance_check_sets_path(current_workbench), class: 'list-group-item' do
span Rapport de contrôle
= link_to compliance_control_sets_path, class: 'list-group-item' do
span Jeux de contrôle
diff --git a/app/views/referentials/_form.html.slim b/app/views/referentials/_form.html.slim
index 9927f05bd..1e59ab566 100644
--- a/app/views/referentials/_form.html.slim
+++ b/app/views/referentials/_form.html.slim
@@ -1,4 +1,6 @@
-= simple_form_for @referential, html: {class: 'form-horizontal', id: 'referential_form'}, wrapper: :horizontal_form do |form|
+- url = @referential.new_record? ? [@workbench, @referential] : [@referential]
+
+= simple_form_for @referential, url: url, html: {class: 'form-horizontal', id: 'referential_form'}, wrapper: :horizontal_form do |form|
.row
.col-lg-12
diff --git a/app/views/referentials/select_compliance_control_set.html.slim b/app/views/referentials/select_compliance_control_set.html.slim
index 87a888c0a..69c87aab2 100644
--- a/app/views/referentials/select_compliance_control_set.html.slim
+++ b/app/views/referentials/select_compliance_control_set.html.slim
@@ -2,7 +2,7 @@
.container-fluid
.row
.col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1
- = form_tag validate_referential_path(params[:referential_id]), {class: 'form-horizontal', id: 'select_compliance_control_set', wrapper: :horizontal_form} do
+ = form_tag validate_referential_path(@referential), {class: 'form-horizontal', id: 'select_compliance_control_set', wrapper: :horizontal_form} do
.row
.col-lg-12
.form-group
diff --git a/app/views/stif/dashboards/_dashboard.html.slim b/app/views/stif/dashboards/_dashboard.html.slim
index c28696a94..83a2106bb 100644
--- a/app/views/stif/dashboards/_dashboard.html.slim
+++ b/app/views/stif/dashboards/_dashboard.html.slim
@@ -47,7 +47,7 @@
- if @dashboard.referentials.present?
.list-group
- @dashboard.referentials.first(5).each_with_index do |referential, i|
- = link_to referential.name, referential_path(referential, workbench_id: referential.workbench_id, current_workbench_id: @dashboard.workbench.id), class: 'list-group-item' if i < 6
+ = link_to referential.name, referential_path(referential), class: 'list-group-item' if i < 6
- else
.panel-body
@@ -60,12 +60,12 @@
span.badge.ml-xs = @dashboard.calendars.count if @dashboard.calendars.present?
div
- = link_to '', workgroup_calendars_path(current_workgroup), class: ' fa fa-chevron-right pull-right', title: t('.see')
+ = link_to '', workgroup_calendars_path(@dashboard.workbench.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, workgroup_calendar_path(current_workgroup, calendar), class: 'list-group-item' if i < 6
+ = link_to calendar.name, workgroup_calendar_path(@dashboard.workbench.workgroup, calendar), class: 'list-group-item' if i < 6
- else
.panel-body
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index aae34c51b..159aa8ea2 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -5,7 +5,7 @@
.col-lg-12.text-right
- if policy(Referential).create?
= link_to t('actions.import'), workbench_imports_path(@workbench), class: 'btn btn-primary'
- = link_to t('actions.add'), new_referential_path(workbench_id: @workbench), class: 'btn btn-primary'
+ = link_to t('actions.add'), new_workbench_referential_path(@workbench), class: 'btn btn-primary'
= link_to t('workbenches.actions.show_output'), workbench_output_path(@workbench), class: 'btn btn-primary'
.page_content
@@ -25,7 +25,7 @@
key: :name, \
attribute: 'name', \
link_to: lambda do |referential| \
- referential_path(referential, current_workbench_id: params[:id]) \
+ referential_path(referential) \
end \
), \
TableBuilderHelper::Column.new( \
diff --git a/config/breadcrumbs.rb b/config/breadcrumbs.rb
index 2772895fe..00ccf16bd 100644
--- a/config/breadcrumbs.rb
+++ b/config/breadcrumbs.rb
@@ -23,12 +23,12 @@ end
crumb :referential do |referential|
link breadcrumb_name(referential), referential_path(referential)
- parent :workbench, current_offer_workbench
+ parent :workbench, mutual_workbench(referential.workbench)
end
crumb :referentials do |referential|
- link I18n.t('referentials.index.title'), referentials_path()
- parent :workbench, current_offer_workbench
+ link I18n.t('referentials.index.title'), workbench_path(current_workbench)
+ parent :workbench, mutual_workbench(current_workbench)
end
crumb :referential_companies do |referential|
diff --git a/config/routes.rb b/config/routes.rb
index 0b657b028..456cb66f5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -19,99 +19,10 @@ ChouetteIhm::Application.routes.draw do
resource :output, controller: :workbench_outputs
resources :merges
- end
-
- devise_for :users, :controllers => {
- :registrations => 'users/registrations', :invitations => 'users/invitations'
- }
-
- devise_scope :user do
- authenticated :user do
- root :to => 'workbenches#index', as: :authenticated_root
- end
-
- unauthenticated :user do
- target = 'devise/sessions#new'
-
- if Rails.application.config.chouette_authentication_settings[:type] == "cas"
- target = 'devise/cas_sessions#new'
- end
-
- root :to => target, as: :unauthenticated_root
- end
- end
-
- mount Sidekiq::Web => '/sidekiq'
-
- namespace :api do
- namespace :v1 do
- resources :workbenches, only: [:index, :show] do
- resources :imports, only: [:index, :show, :create]
- end
- resources :access_links, only: [:index, :show]
- resources :access_points, only: [:index, :show]
- resources :connection_links, only: [:index, :show]
- resources :companies, only: [:index, :show]
- resources :group_of_lines, only: [:index, :show]
- resources :netex_imports, only: :create
- resources :journey_patterns, only: :show
- resources :lines, only: [:index, :show] do
- resources :journey_patterns, only: [:index, :show]
- resources :routes, only: [:index, :show] do
- resources :vehicle_journeys, only: [:index, :show]
- resources :journey_patterns, only: [:index, :show]
- resources :stop_areas, only: [:index, :show]
- end
- end
- resources :networks, only: [:index, :show]
- resources :routes, only: :show
- resources :stop_areas, only: [:index, :show]
- resources :time_tables, only: [:index, :show]
- resources :vehicle_journeys, only: :show
- namespace :internals do
- get 'compliance_check_sets/:id/notify_parent', to: 'compliance_check_sets#notify_parent'
- get 'netex_imports/:id/notify_parent', to: 'netex_imports#notify_parent'
- end
- end
- end
- resource :organisation, :only => [:show, :edit, :update] do
- resources :users
+ resources :referentials, only: %w(new create)
end
- resources :api_keys, :only => [:edit, :update, :new, :create, :destroy]
-
- resources :compliance_control_sets do
- get :simple, on: :member
- get :clone, on: :member
- resources :compliance_controls, except: :index do
- get :select_type, on: :collection
- end
- resources :compliance_control_blocks, :except => [:show, :index]
- end
-
- deactivable = Proc.new do
- put :deactivate, on: :member
- put :activate, on: :member
- end
-
- resources :stop_area_referentials, :only => [:show] do
- post :sync, on: :member
- resources :stop_areas do
- put :deactivate, on: :member
- put :activate, on: :member
- get :autocomplete, on: :collection
- end
- end
-
- resources :line_referentials, :only => [:show, :edit, :update] do
- post :sync, on: :member
- resources :lines, &deactivable
- resources :group_of_lines
- resources :companies
- resources :networks
- end
-
resources :workgroups do
resources :calendars do
get :autocomplete, on: :collection, controller: 'autocomplete_calendars'
@@ -121,13 +32,19 @@ ChouetteIhm::Application.routes.draw do
end
end
- resources :referentials, except: :index do
+ resources :referentials, except: %w(new create) do
+
+ member do
+ put :archive
+ put :unarchive
+ get :select_compliance_control_set
+ post :validate
+ end
+
resources :autocomplete_stop_areas, only: [:show, :index] do
get 'around', on: :member
end
resources :autocomplete_purchase_windows, only: [:index]
- get :select_compliance_control_set
- post :validate, on: :member
resources :autocomplete_time_tables, only: [:index]
resources :autocomplete_timebands
resources :group_of_lines, controller: "referential_group_of_lines" do
@@ -136,12 +53,6 @@ ChouetteIhm::Application.routes.draw do
end
end
- # Archive/unarchive
- member do
- put :archive
- put :unarchive
- end
-
resources :networks, controller: "referential_networks"
match 'lines' => 'lines#destroy_all', :via => :delete
@@ -239,6 +150,105 @@ ChouetteIhm::Application.routes.draw do
resources :clean_ups
end
+ devise_for :users, :controllers => {
+ :registrations => 'users/registrations', :invitations => 'users/invitations'
+ }
+
+ devise_scope :user do
+ authenticated :user do
+ root :to => 'workbenches#index', as: :authenticated_root
+ end
+
+ unauthenticated :user do
+ target = 'devise/sessions#new'
+
+ if Rails.application.config.chouette_authentication_settings[:type] == "cas"
+ target = 'devise/cas_sessions#new'
+ end
+
+ root :to => target, as: :unauthenticated_root
+ end
+ end
+
+ mount Sidekiq::Web => '/sidekiq'
+
+ namespace :api do
+ namespace :v1 do
+ resources :workbenches, only: [:index, :show] do
+ resources :imports, only: [:index, :show, :create]
+ end
+ resources :access_links, only: [:index, :show]
+ resources :access_points, only: [:index, :show]
+ resources :connection_links, only: [:index, :show]
+ resources :companies, only: [:index, :show]
+ resources :group_of_lines, only: [:index, :show]
+ resources :netex_imports, only: :create
+ resources :journey_patterns, only: :show
+ resources :lines, only: [:index, :show] do
+ resources :journey_patterns, only: [:index, :show]
+ resources :routes, only: [:index, :show] do
+ resources :vehicle_journeys, only: [:index, :show]
+ resources :journey_patterns, only: [:index, :show]
+ resources :stop_areas, only: [:index, :show]
+ end
+ end
+ resources :networks, only: [:index, :show]
+ resources :routes, only: :show
+ resources :stop_areas, only: [:index, :show]
+ resources :time_tables, only: [:index, :show]
+ resources :vehicle_journeys, only: :show
+ namespace :internals do
+ get 'compliance_check_sets/:id/notify_parent', to: 'compliance_check_sets#notify_parent'
+ get 'netex_imports/:id/notify_parent', to: 'netex_imports#notify_parent'
+ end
+ end
+ end
+
+ resource :organisation, :only => [:show, :edit, :update] do
+ resources :users
+ end
+
+ resources :api_keys, :only => [:edit, :update, :new, :create, :destroy]
+
+ resources :compliance_control_sets do
+ get :simple, on: :member
+ get :clone, on: :member
+ resources :compliance_controls, except: :index do
+ get :select_type, on: :collection
+ end
+ resources :compliance_control_blocks, :except => [:show, :index]
+ end
+
+ deactivable = Proc.new do
+ put :deactivate, on: :member
+ put :activate, on: :member
+ end
+
+ resources :stop_area_referentials, :only => [:show] do
+ post :sync, on: :member
+ resources :stop_areas do
+ put :deactivate, on: :member
+ put :activate, on: :member
+ get :autocomplete, on: :collection
+ end
+ end
+
+ resources :line_referentials, :only => [:show, :edit, :update] do
+ post :sync, on: :member
+ resources :lines, &deactivable
+ resources :group_of_lines
+ resources :companies
+ resources :networks
+ end
+
+ resources :calendars do
+ get :autocomplete, on: :collection, controller: 'autocomplete_calendars'
+ member do
+ get 'month', defaults: { format: :json }
+ end
+ end
+
+
root :to => "dashboards#show"
if Rails.env.development? || Rails.env.test?
diff --git a/spec/controllers/referentials_controller_spec.rb b/spec/controllers/referentials_controller_spec.rb
index f97480600..5e0b1e505 100644
--- a/spec/controllers/referentials_controller_spec.rb
+++ b/spec/controllers/referentials_controller_spec.rb
@@ -15,8 +15,7 @@ describe ReferentialsController, :type => :controller do
end
context "user's organisation doesn't match referential's organisation" do
- pending "hotfix opens all unknow actions need to close the uneeded later" do
- #it 'raises a ActiveRecord::RecordNotFound' do
+ it 'raises a ActiveRecord::RecordNotFound' do
expect { put :archive, id: other_referential.id }.to raise_error(ActiveRecord::RecordNotFound)
end
end
@@ -26,7 +25,7 @@ describe ReferentialsController, :type => :controller do
it 'gets compliance control set for current organisation' do
compliance_control_set = create(:compliance_control_set, organisation: @user.organisation)
create(:compliance_control_set)
- get :select_compliance_control_set, referential_id: referential.id
+ get :select_compliance_control_set, id: referential.id
expect(assigns[:compliance_control_sets]).to eq([compliance_control_set])
end
end
@@ -43,16 +42,51 @@ describe ReferentialsController, :type => :controller do
end
end
+ describe "GET #new" do
+ context "when duplicating" do
+ let(:workbench){ create :workbench}
+ let(:request){
+ get :new,
+ workbench_id: workbench.id,
+ from: referential.id
+ }
+
+ it "duplicates the given referential" do
+ request
+ new_referential = assigns(:referential)
+ expect(new_referential.line_referential).to eq referential.line_referential
+ expect(new_referential.stop_area_referential).to eq referential.stop_area_referential
+ expect(new_referential.objectid_format).to eq referential.objectid_format
+ expect(new_referential.prefix).to eq referential.prefix
+ expect(new_referential.slug).to eq "#{referential.slug}_clone"
+ expect(new_referential.workbench).to eq workbench
+ end
+ end
+ end
+
describe "POST #create" do
+ let(:workbench){ create :workbench}
context "when duplicating" do
- it "displays a flash message", pending: 'requires more params to create a valid Referential' do
+ let(:request){
post :create,
- from: referential.id,
- current_workbench_id: referential.workbench_id,
- referential: {
- name: 'Duplicated'
- }
+ workbench_id: workbench.id,
+ referential: {
+ name: 'Duplicated',
+ created_from_id: referential.id,
+ stop_area_referential: referential.stop_area_referential,
+ line_referential: referential.line_referential,
+ objectid_format: referential.objectid_format,
+ workbench_id: referential.workbench_id
+ }
+ }
+
+ it "creates the new referential" do
+ expect{request}.to change{Referential.count}.by 1
+ expect(Referential.last.name).to eq "Duplicated"
+ end
+ it "displays a flash message" do
+ request
expect(controller).to set_flash[:notice].to(
I18n.t('notice.referentials.duplicate')
)
diff --git a/spec/decorators/referential_decorator_spec.rb b/spec/decorators/referential_decorator_spec.rb
index efc438132..1224aaf75 100644
--- a/spec/decorators/referential_decorator_spec.rb
+++ b/spec/decorators/referential_decorator_spec.rb
@@ -1,7 +1,8 @@
RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
include Support::DecoratorHelpers
- let( :object ){ build_stubbed :referential }
+ let( :workbench ){ build_stubbed :workbench }
+ let( :object ){ build_stubbed :referential, workbench: workbench }
let( :referential ){ object }
let( :user ){ build_stubbed :user }
@@ -35,7 +36,7 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
expect_action_link_hrefs.to eq([
[object],
referential_time_tables_path(object),
- new_referential_path(from: object)
+ new_workbench_referential_path(referential.workbench, from: object.id)
])
end
end
@@ -50,8 +51,8 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
[object],
[:edit, object],
referential_time_tables_path(object),
- new_referential_path(from: object),
- referential_select_compliance_control_set_path(object),
+ new_workbench_referential_path(referential.workbench, from: object.id),
+ select_compliance_control_set_referential_path(object),
archive_referential_path(object),
referential_path(object)
])
@@ -65,8 +66,8 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
expect_action_link_hrefs(action).to eq([
[:edit, object],
referential_time_tables_path(object),
- new_referential_path(from: object),
- referential_select_compliance_control_set_path(object),
+ new_workbench_referential_path(referential.workbench, from: object.id),
+ select_compliance_control_set_referential_path(object),
archive_referential_path(object),
"#",
referential_path(object)
@@ -91,7 +92,7 @@ RSpec.describe ReferentialDecorator, type: [:helper, :decorator] do
expect_action_link_hrefs.to eq([
[object],
referential_time_tables_path(object),
- new_referential_path(from: object)
+ new_workbench_referential_path(referential.workbench, from: object.id)
])
end
end
diff --git a/spec/features/referentials_spec.rb b/spec/features/referentials_spec.rb
index 9af0ed32e..d4890fda4 100644
--- a/spec/features/referentials_spec.rb
+++ b/spec/features/referentials_spec.rb
@@ -55,7 +55,7 @@ describe "Referentials", :type => :feature do
context 'user has the permission to create referentials' do
it 'shows the clone link for referetnial' do
- expect(page).to have_link(I18n.t('actions.clone'), href: new_referential_path(from: referential.id))
+ expect(page).to have_link(I18n.t('actions.clone'), href: new_workbench_referential_path(referential.workbench, from: referential.id))
end
end
@@ -63,7 +63,7 @@ describe "Referentials", :type => :feature do
it 'does not show the clone link for referetnial' do
@user.update_attribute(:permissions, [])
visit referential_path(referential)
- expect(page).not_to have_link(I18n.t('actions.clone'), href: new_referential_path(from: referential.id))
+ expect(page).not_to have_link(I18n.t('actions.clone'), href: new_workbench_referential_path(referential.workbench, from: referential.id))
end
end
@@ -108,8 +108,9 @@ describe "Referentials", :type => :feature do
end
describe "create" do
+ let(:workbench){ @user.organisation.workbenches.last }
it "should" do
- visit new_referential_path
+ visit new_workbench_referential_path(workbench)
fill_in "Nom", :with => "Test"
click_button "Valider"
@@ -132,7 +133,7 @@ describe "Referentials", :type => :feature do
context "when user is from the same organisation" do
xit "should" do
- visit new_referential_path(from: referential.id, current_workbench_id: @user.organisation.workbenches.first.id)
+ visit new_workbench_referential_path(referential.workbench, from: referential.id, current_workbench_id: @user.organisation.workbenches.first.id)
select "2018", :from => "referential_metadatas_attributes_0_periods_attributes_0_begin_1i"
@@ -187,7 +188,8 @@ describe "Referentials", :type => :feature do
end
describe "destroy" do
- let(:referential) { create(:referential, :organisation => @user.organisation) }
+ let(:workbench){ @user.organisation.workbenches.last }
+ let(:referential) { create(:referential, :organisation => @user.organisation, workbench: workbench) }
it "should remove referential" do
visit referential_path(referential)
diff --git a/spec/features/workbenches/workbenches_permissions_spec.rb b/spec/features/workbenches/workbenches_permissions_spec.rb
index d58293538..1c073a4c5 100644
--- a/spec/features/workbenches/workbenches_permissions_spec.rb
+++ b/spec/features/workbenches/workbenches_permissions_spec.rb
@@ -22,7 +22,7 @@ describe 'Workbenches', type: :feature do
let( :permission ){ true }
it 'shows the corresponding button' do
- expected_href = new_referential_path(workbench_id: workbench)
+ expected_href = new_workbench_referential_path(workbench)
expect( page ).to have_link('Créer', href: expected_href)
end
end
diff --git a/spec/features/workbenches/workbenches_show_spec.rb b/spec/features/workbenches/workbenches_show_spec.rb
index 7be813b94..405fdce82 100644
--- a/spec/features/workbenches/workbenches_show_spec.rb
+++ b/spec/features/workbenches/workbenches_show_spec.rb
@@ -232,7 +232,7 @@ RSpec.describe 'Workbenches', type: :feature do
context 'user has the permission to create referentials' do
it 'shows the link for a new referetnial' do
- expect(page).to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbench.id))
+ expect(page).to have_link(I18n.t('actions.add'), href: new_workbench_referential_path(workbench))
end
end
@@ -240,7 +240,7 @@ RSpec.describe 'Workbenches', type: :feature do
it 'does not show the clone link for referential' do
@user.update_attribute(:permissions, [])
visit referential_path(referential)
- expect(page).not_to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbench.id))
+ expect(page).not_to have_link(I18n.t('actions.add'), href: new_workbench_referential_path(workbench))
end
end
end
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 5bddbb16f..478875118 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -15,8 +15,9 @@ describe TableBuilderHelper, type: :helper do
describe "#table_builder_2" do
it "builds a table" do
- referential = build_stubbed(:workbench_referential)
+ referential = create(:workbench_referential)
workbench = referential.workbench
+ referential.organisation.workbenches << workbench
user_context = UserContext.new(
build_stubbed(
@@ -30,7 +31,8 @@ describe TableBuilderHelper, type: :helper do
),
referential: referential
)
- allow(helper).to receive(:current_user).and_return(user_context)
+ allow(helper).to receive(:pundit_user).and_return(user_context)
+ allow(helper).to receive(:current_user).and_return(user_context.user)
referentials = [referential]
@@ -90,7 +92,7 @@ describe TableBuilderHelper, type: :helper do
</ul>
<ul class="other">
<li class=""><a href="/referentials/#{referential.id}/time_tables">Calendriers</a></li>
- <li class=""><a href="/referentials/new?from=#{referential.id}">Dupliquer</a></li>
+ <li class=""><a href="/workbenches/#{workbench.id}/referentials/new?from=#{referential.id}">Dupliquer</a></li>
<li class=""><a href="/referentials/#{referential.id}/select_compliance_control_set">Valider</a></li>
<li class=""><a rel="nofollow" data-method="put" href="/referentials/#{referential.id}/archive">Conserver</a></li>
</ul>
@@ -193,7 +195,8 @@ describe TableBuilderHelper, type: :helper do
),
referential: referential
)
- allow(helper).to receive(:current_user).and_return(user_context)
+ allow(helper).to receive(:pundit_user).and_return(user_context)
+ allow(helper).to receive(:current_user).and_return(user_context.user)
allow(helper).to receive(:current_referential)
.and_return(referential)
@@ -307,7 +310,8 @@ describe TableBuilderHelper, type: :helper do
),
referential: referential
)
- allow(helper).to receive(:current_user).and_return(user_context)
+ allow(helper).to receive(:pundit_user).and_return(user_context)
+ allow(helper).to receive(:current_user).and_return(user_context.user)
allow(helper).to receive(:current_referential)
.and_return(referential)
@@ -398,8 +402,8 @@ describe TableBuilderHelper, type: :helper do
end
context "on a single row" do
- let(:referential){ build_stubbed :referential }
- let(:other_referential){ build_stubbed :referential }
+ let(:referential){ build_stubbed :workbench_referential }
+ let(:other_referential){ build_stubbed :workbench_referential }
let(:user_context){
UserContext.new(
build_stubbed(
@@ -432,7 +436,9 @@ describe TableBuilderHelper, type: :helper do
let(:items){ [item, other_item] }
before(:each){
- allow(helper).to receive(:current_user).and_return(user_context)
+ allow(helper).to receive(:pundit_user).and_return(user_context)
+ allow(helper).to receive(:current_user).and_return(user_context.user)
+ allow(helper).to receive(:mutual_workbench).and_return(referential.workbench)
}
context "with all rows non-selectable" do
diff --git a/spec/support/decorator_helpers.rb b/spec/support/decorator_helpers.rb
index b2c41e842..544604f61 100644
--- a/spec/support/decorator_helpers.rb
+++ b/spec/support/decorator_helpers.rb
@@ -8,6 +8,7 @@ module Support
let( :features ){ [] }
let( :filtered_action_links){}
before do
+ allow(subject.h).to receive(:duplicate_workbench_referential_path).and_return new_workbench_referential_path(referential.workbench, from: referential.id)
allow_any_instance_of(Draper::HelperProxy).to receive(:policy).and_return policy
allow_any_instance_of(AF83::Decorator::Link).to receive(:check_feature){|f|
features.include?(f)
diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb
index ea3bc1fe1..a7f37d180 100644
--- a/spec/views/referentials/show.html.erb_spec.rb
+++ b/spec/views/referentials/show.html.erb_spec.rb
@@ -1,73 +1,48 @@
require 'spec_helper'
describe "referentials/show", type: :view do
+
let!(:referential) do
- referential = create(:referential, organisation: organisation)
+ referential = create(:workbench_referential)
assign :referential, referential.decorate(context: {
current_organisation: referential.organisation
})
end
+ let(:organisation){ referential.try(:organisation) }
let(:permissions){ [] }
let(:current_organisation) { 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)
allow(view).to receive(:has_feature?).and_return(true)
allow(view).to receive(:user_signed_in?).and_return true
+ allow(view).to receive(:mutual_workbench).and_return referential.workbench
controller.request.path_parameters[:id] = referential.id
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
- 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" }
-
- %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" }
+ it "should not present edit button" do
+ expect(rendered).to_not have_selector("a[href=\"#{view.edit_referential_path(referential)}\"]")
+ end
- %w(create destroy update).each do |p|
- with_permission "referentials.#{p}" do
- it { should match_actions_links_snapshot "referentials/show_#{p}" }
- end
- 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
- %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
+ 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
+
end