aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2017-09-28 15:06:41 +0200
committerLuc Donnet2017-09-28 15:06:41 +0200
commit02f4e2483751af82b0086a1800e761f37f244aa8 (patch)
tree6b1ef2086449c6d18b449bab4c06d6156110d432
parentc86a9c0bd4e8cb7bc677051e44e1e33d1419a409 (diff)
parentd4f93417331115d36880db771903446e6397a8bc (diff)
downloadchouette-core-02f4e2483751af82b0086a1800e761f37f244aa8.tar.bz2
Merge branch 'master' of github.com:AF83/stif-boiv
-rw-r--r--app/controllers/compliance_check_sets_controller.rb51
-rw-r--r--app/controllers/compliance_controls_controller.rb2
-rw-r--r--app/decorators/compliance_check_set_decorator.rb8
-rw-r--r--app/helpers/referentials_helper.rb10
-rw-r--r--app/models/compliance_check.rb1
-rw-r--r--app/models/compliance_check_set.rb5
-rw-r--r--app/models/compliance_control.rb3
-rw-r--r--app/models/compliance_control_block.rb8
-rw-r--r--app/models/workbench.rb1
-rw-r--r--app/policies/compliance_check_set_policy.rb7
-rw-r--r--app/views/compliance_check_sets/_filters.html.slim24
-rw-r--r--app/views/compliance_check_sets/index.html.slim54
-rw-r--r--app/views/compliance_check_sets/show.html.slim11
-rw-r--r--app/views/compliance_control_sets/index.html.slim10
-rw-r--r--app/views/compliance_controls/_form.html.slim5
-rw-r--r--app/views/layouts/navigation/_main_nav_left.html.slim2
-rw-r--r--app/views/lines/index.html.slim2
-rw-r--r--app/views/referentials/show.html.slim2
-rw-r--r--app/views/routes/show.html.slim2
-rw-r--r--app/views/stop_areas/index.html.slim2
-rw-r--r--config/locales/compliance_check_sets.en.yml23
-rw-r--r--config/locales/compliance_check_sets.fr.yml23
-rw-r--r--config/locales/compliance_control_sets.en.yml18
-rw-r--r--config/locales/compliance_control_sets.fr.yml18
-rw-r--r--config/routes.rb4
-rw-r--r--db/migrate/20170928075431_add_origin_code_to_compliance_checks.rb5
-rw-r--r--db/migrate/20170928085904_add_compliance_control_block_to_compliance_control.rb5
-rw-r--r--db/migrate/20170928090016_remove_compliance_control_from_compliance_control_block.rb5
-rw-r--r--db/schema.rb14
-rw-r--r--lib/stif/permission_translator.rb9
-rw-r--r--spec/controllers/compliance_check_sets_controller_spec.rb22
-rw-r--r--spec/factories/compliance_checks.rb1
-rw-r--r--spec/factories/compliance_control_blocks.rb1
-rw-r--r--spec/factories/compliance_controls.rb1
-rw-r--r--spec/models/compliance_check_spec.rb1
-rw-r--r--spec/models/compliance_control_block_spec.rb2
-rw-r--r--spec/models/compliance_control_spec.rb4
37 files changed, 310 insertions, 56 deletions
diff --git a/app/controllers/compliance_check_sets_controller.rb b/app/controllers/compliance_check_sets_controller.rb
new file mode 100644
index 000000000..d61fbafdb
--- /dev/null
+++ b/app/controllers/compliance_check_sets_controller.rb
@@ -0,0 +1,51 @@
+class ComplianceCheckSetsController < BreadcrumbController
+ defaults resource_class: ComplianceCheckSet
+ before_action :ransack_created_at_params, only: [:index]
+ respond_to :html
+
+ belongs_to :workbench
+
+ def index
+ index! do |format|
+ scope = ransack_period @compliance_check_sets
+ @q_for_form = scope.ransack(params[:q])
+ format.html {
+ @compliance_check_sets = ModelDecorator.decorate(
+ @q_for_form.result,
+ with: ComplianceCheckSetDecorator
+ )
+ }
+ end
+ end
+
+
+ private
+
+ def ransack_created_at_params
+ start_date = []
+ end_date = []
+
+ if params[:q] && params[:q][:created_at] && !params[:q][:created_at].has_value?(nil) && !params[:q][:created_at].has_value?("")
+ [1, 2, 3].each do |key|
+ start_date << params[:q][:created_at]["begin(#{key}i)"].to_i
+ end_date << params[:q][:created_at]["end(#{key}i)"].to_i
+ end
+ params[:q].delete(:created_at)
+ @begin_range = DateTime.new(*start_date, 0, 0, 0) rescue nil
+ @end_range = DateTime.new(*end_date, 23, 59, 59) rescue nil
+ end
+ end
+
+ # Fake ransack filter
+ def ransack_period scope
+ return scope unless !!@begin_range && !!@end_range
+
+ if @begin_range > @end_range
+ flash.now[:error] = t('compliance_check_sets.filters.error_period_filter')
+ else
+ scope = scope.where_created_at_between(@begin_range, @end_range)
+ end
+ scope
+ end
+
+end \ No newline at end of file
diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb
index eb1ba68ea..846dbb253 100644
--- a/app/controllers/compliance_controls_controller.rb
+++ b/app/controllers/compliance_controls_controller.rb
@@ -19,7 +19,7 @@ class ComplianceControlsController < BreadcrumbController
end
def compliance_control_params
- base = [:name, :code, :origin_code, :criticity, :comment, :control_attributes, :type, compliance_control_block_attributes: [:name, :transport_mode]]
+ base = [:name, :code, :origin_code, :criticity, :comment, :control_attributes, :type]
permited = base + dynamic_attributes_params
params.require(:compliance_control).permit(permited)
end
diff --git a/app/decorators/compliance_check_set_decorator.rb b/app/decorators/compliance_check_set_decorator.rb
new file mode 100644
index 000000000..5f3821cbe
--- /dev/null
+++ b/app/decorators/compliance_check_set_decorator.rb
@@ -0,0 +1,8 @@
+class ComplianceCheckSetDecorator < Draper::Decorator
+ delegate_all
+
+ def action_links
+ links = []
+ end
+
+end
diff --git a/app/helpers/referentials_helper.rb b/app/helpers/referentials_helper.rb
index 73384bef6..f3c18d9f8 100644
--- a/app/helpers/referentials_helper.rb
+++ b/app/helpers/referentials_helper.rb
@@ -1,2 +1,12 @@
module ReferentialsHelper
+ # Line statuses helper
+ def line_status(status)
+ if status
+ cls = 'danger'
+ content_tag :span, status ? " #{t('false')} " : " #{t('true')}", class: "fa fa-exclamation-circle fa-lg text-#{cls}"
+ else
+ cls = 'success'
+ content_tag :span, status ? " #{t('false')} " : " #{t('true')}", class: "fa fa-check-circle fa-lg text-#{cls}"
+ end
+ end
end
diff --git a/app/models/compliance_check.rb b/app/models/compliance_check.rb
index 85cf5e37e..4c29129b9 100644
--- a/app/models/compliance_check.rb
+++ b/app/models/compliance_check.rb
@@ -6,4 +6,5 @@ class ComplianceCheck < ActiveRecord::Base
validates :criticity, presence: true
validates :name, presence: true
validates :code, presence: true
+ validates :origin_code, presence: true
end
diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb
index 7b6400a21..3c62221f0 100644
--- a/app/models/compliance_check_set.rb
+++ b/app/models/compliance_check_set.rb
@@ -7,4 +7,9 @@ class ComplianceCheckSet < ActiveRecord::Base
belongs_to :parent, polymorphic: true
enumerize :status, in: %w[new pending successful warning failed running aborted canceled]
+
+ scope :where_created_at_between, ->(start_date, end_date) do
+ where('created_at BETWEEN ? AND ?', start_date, end_date)
+ end
+
end
diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb
index c5389e832..42f45b6ca 100644
--- a/app/models/compliance_control.rb
+++ b/app/models/compliance_control.rb
@@ -1,8 +1,7 @@
class ComplianceControl < ActiveRecord::Base
extend Enumerize
belongs_to :compliance_control_set
- has_one :compliance_control_block, dependent: :destroy
- accepts_nested_attributes_for :compliance_control_block
+ belongs_to :compliance_control_block
@@default_criticity = :warning
@@default_code = ""
diff --git a/app/models/compliance_control_block.rb b/app/models/compliance_control_block.rb
index a08e271f6..e03c4ce85 100644
--- a/app/models/compliance_control_block.rb
+++ b/app/models/compliance_control_block.rb
@@ -1,15 +1,9 @@
class ComplianceControlBlock < ActiveRecord::Base
belongs_to :compliance_control_set
- belongs_to :compliance_control
-
- before_save :set_compliance_control_set
+ has_many :compliance_controls, dependent: :destroy
hstore_accessor :condition_attributes, transport_mode: :string
- def set_compliance_control_set
- self.compliance_control_set = self.compliance_control.compliance_control_set
- end
-
def self.transport_modes
["all"] + StifTransportModeEnumerations.transport_mode.values
end
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index fe4e6cce1..ae111a9c5 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -11,6 +11,7 @@ class Workbench < ActiveRecord::Base
has_many :stop_areas, through: :stop_area_referential
has_many :imports
has_many :workbench_imports
+ has_many :compliance_check_sets
validates :name, presence: true
validates :organisation, presence: true
diff --git a/app/policies/compliance_check_set_policy.rb b/app/policies/compliance_check_set_policy.rb
new file mode 100644
index 000000000..3f715649e
--- /dev/null
+++ b/app/policies/compliance_check_set_policy.rb
@@ -0,0 +1,7 @@
+class ComplianceCheckSetPolicy < ApplicationPolicy
+ class Scope < Scope
+ def resolve
+ scope
+ end
+ end
+end
diff --git a/app/views/compliance_check_sets/_filters.html.slim b/app/views/compliance_check_sets/_filters.html.slim
new file mode 100644
index 000000000..609754eec
--- /dev/null
+++ b/app/views/compliance_check_sets/_filters.html.slim
@@ -0,0 +1,24 @@
+= search_form_for @q_for_form, url: workbench_compliance_check_sets_path(current_offer_workbench), builder: SimpleForm::FormBuilder, class: 'form form-filter' do |f|
+ .ffg-row
+ .input-group.search_bar
+ = f.search_field :referential_name_cont, class: 'form-control', placeholder: t('compliance_check_sets.filters.name')
+ span.input-group-btn
+ button.btn.btn-default type='submit'
+ span.fa.fa-search
+
+ .ffg-row
+ .form-group.togglable
+ = f.label t('activerecord.attributes.compliance_check_set.assigned_to'), required: false, class: 'control-label'
+ = f.input :parent_type_eq_any, collection: ComplianceCheckSet.order('parent_type'), as: :check_boxes, label: false, label_method: lambda {|w| ("<span>#{w}</span>").html_safe}, required: false, wrapper_html: {class: 'checkbox_list'}
+
+ .form-group.togglable
+ = f.label Import.human_attribute_name(:created_at), required: false, class: 'control-label'
+ .filter_menu
+ = f.simple_fields_for :created_at do |p|
+ = p.input :begin, as: :date, label: false, wrapper_html: {class: 'date smart_date filter_menu-item'}, default: @begin_range, include_blank: @begin_range ? false : true
+ = p.input :end, as: :date, label: false, wrapper_html: {class: 'date smart_date filter_menu-item'}, default: @end_range, include_blank: @end_range ? false : true
+
+ .actions
+ = link_to t('actions.erase'), @compliance_checks_sets, class: 'btn btn-link'
+ = f.submit t('actions.filter'), class: 'btn btn-default', id: 'referential_filter_btn'
+
diff --git a/app/views/compliance_check_sets/index.html.slim b/app/views/compliance_check_sets/index.html.slim
new file mode 100644
index 000000000..38c4babcf
--- /dev/null
+++ b/app/views/compliance_check_sets/index.html.slim
@@ -0,0 +1,54 @@
+/ PageHeader
+- header_params = ['jeux-de-donnees',
+ t('compliance_check_sets.index.title'),
+ '']
+= pageheader(*header_params) do
+
+ / Below is secundary actions & optional contents (filters, ...)
+ .row.mb-sm
+ .col-lg-12.text-right
+
+/ PageContent
+.page_content
+ .container-fluid
+ .row
+ .col-lg-12
+ = render 'filters'
+ .row
+ .col-lg-12
+ .select_table
+ = table_builder_2 @compliance_check_sets,
+ [ \
+ TableBuilderHelper::Column.new( \
+ key: :ref, \
+ attribute: 'referential_id' \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :creation_date, \
+ attribute: Proc.new { |n| l(n.created_at, format: :long) if n.created_at } \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :associated_object, \
+ attribute: Proc.new{|n| n.referential.name}, \
+ link_to: lambda do |referential| \
+ referential_path(referential, current_workbench_id: params[:id]) \
+ end \
+ ), \
+ TableBuilderHelper::Column.new( \
+ key: :assigned_to, \
+ attribute: 'parent_type' \
+ ), \
+ TableBuilderHelper::Column.new(\
+ key: :compliance_control_set, \
+ attribute: Proc.new{ |n| (n.compliance_control_set.name) if n.compliance_control_set} \
+ ), \
+ ],
+ sortable: true,
+ links: [:show],
+ cls: 'table has-filter has-search'
+ - unless @compliance_check_sets.any?
+ .row.mt-xs
+ .col-lg-12
+ = replacement_msg t('compliance_check_sets.search_no_results')
+
+
diff --git a/app/views/compliance_check_sets/show.html.slim b/app/views/compliance_check_sets/show.html.slim
new file mode 100644
index 000000000..4e965947d
--- /dev/null
+++ b/app/views/compliance_check_sets/show.html.slim
@@ -0,0 +1,11 @@
+/ PageHeader
+= pageheader 'jeux-de-donnees',
+ @compliance_check_set.referential.name
+/ PageContent
+.page_content
+ .container-fluid
+ .row
+ .col-lg-6.col-md-6.col-sm-12.col-xs-12
+ = definition_list t('metadatas'),
+ ComplianceCheckSet.human_attribute_name(:id) => @compliance_check_set.referential.id,
+ ComplianceCheckSet.human_attribute_name(:name) => @compliance_check_set.referential.name \ No newline at end of file
diff --git a/app/views/compliance_control_sets/index.html.slim b/app/views/compliance_control_sets/index.html.slim
index aee1595ef..ecb4eb75b 100644
--- a/app/views/compliance_control_sets/index.html.slim
+++ b/app/views/compliance_control_sets/index.html.slim
@@ -19,7 +19,7 @@
.col-lg-12
.select_table
= table_builder_2 @compliance_control_sets,
- [ \
+ [ \
TableBuilderHelper::Column.new( \
key: :name, \
attribute: 'name', \
@@ -28,7 +28,7 @@
end \
), \
TableBuilderHelper::Column.new( \
- key: :assignment, \
+ key: :assigned_to, \
attribute: 'assignment' \
), \
TableBuilderHelper::Column.new( \
@@ -44,9 +44,9 @@
attribute: Proc.new { |n| l(n.updated_at, format: :long) if n.updated_at }, \
) \
],
- sortable: true,
- links: [:show],
- cls: 'table has-filter has-search'
+ sortable: true,
+ links: [:show],
+ cls: 'table has-filter has-search'
- unless @compliance_control_sets.any?
.row.mt-xs
.col-lg-12
diff --git a/app/views/compliance_controls/_form.html.slim b/app/views/compliance_controls/_form.html.slim
index bb8f68464..3928f3550 100644
--- a/app/views/compliance_controls/_form.html.slim
+++ b/app/views/compliance_controls/_form.html.slim
@@ -10,11 +10,6 @@
- f.object.class.dynamic_attributes.each do |attribute|
= f.input attribute.to_sym
end
-
- = f.simple_fields_for :compliance_control_block do |c|
- = c.input :name
- = c.input :transport_mode, as: :select, collection:ComplianceControlBlock.transport_modes
- end
.separator
= f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'compliance_control_form'
diff --git a/app/views/layouts/navigation/_main_nav_left.html.slim b/app/views/layouts/navigation/_main_nav_left.html.slim
index 12139c93b..062c9383c 100644
--- a/app/views/layouts/navigation/_main_nav_left.html.slim
+++ b/app/views/layouts/navigation/_main_nav_left.html.slim
@@ -37,7 +37,7 @@
span Import
= link_to calendars_path, class: 'list-group-item' do
span Modèles de calendrier
- = link_to '#', class: 'list-group-item' do
+ = link_to workbench_compliance_check_sets_path(current_offer_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/lines/index.html.slim b/app/views/lines/index.html.slim
index dda5afd44..fb07c45a2 100644
--- a/app/views/lines/index.html.slim
+++ b/app/views/lines/index.html.slim
@@ -36,7 +36,7 @@
), \
TableBuilderHelper::Column.new( \
key: :deactivated, \
- attribute: Proc.new{|n| n.deactivated? ? t('false') : t('true')} \
+ attribute: Proc.new { |n| line_status(n.deactivated?) } \
), \
TableBuilderHelper::Column.new( \
key: 'networks.name', \
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index e1d89cba4..0fdd79e14 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -58,7 +58,7 @@
), \
TableBuilderHelper::Column.new( \
key: :deactivated, \
- attribute: Proc.new { |n| n.deactivated? ? t('false') : t('true') } \
+ attribute: Proc.new { |n| line_status(n.deactivated?) } \
), \
TableBuilderHelper::Column.new( \
key: :transport_mode, \
diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim
index e2681d215..edc2d254b 100644
--- a/app/views/routes/show.html.slim
+++ b/app/views/routes/show.html.slim
@@ -48,7 +48,7 @@
), \
TableBuilderHelper::Column.new( \
key: :deleted_at, \
- attribute: Proc.new { |s| s.try(:stop_area).deleted_at ? t('false') : t('true') }, \
+ attribute: Proc.new { |s| line_status(s.try(:stop_area).deleted_at) } \
), \
TableBuilderHelper::Column.new( \
key: :zip_code, \
diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim
index 4c95761d2..95b9b1b0e 100644
--- a/app/views/stop_areas/index.html.slim
+++ b/app/views/stop_areas/index.html.slim
@@ -39,7 +39,7 @@
), \
TableBuilderHelper::Column.new( \
key: :deleted_at, \
- attribute: Proc.new { |s| s.deleted_at ? t('false') : t('true') } \
+ attribute: Proc.new { |s| line_status(s.deleted_at) } \
), \
TableBuilderHelper::Column.new( \
key: :zip_code, \
diff --git a/config/locales/compliance_check_sets.en.yml b/config/locales/compliance_check_sets.en.yml
new file mode 100644
index 000000000..89c142a49
--- /dev/null
+++ b/config/locales/compliance_check_sets.en.yml
@@ -0,0 +1,23 @@
+en:
+ compliance_check_sets:
+ index:
+ title: Control reports
+ new: Creating a Control Report
+ edit: Update a Control Report
+ actions:
+ new: Add a control report
+ edit: Edit a control report
+ destroy: Delete
+ destroy_confirm: Are you sure you want to delete this control report?
+ filters:
+ name: Specify a control report name...
+ error_period_filter: End date must be greater than or equal to begin date
+ search_no_results: No control reports match your search
+ activerecord:
+ attributes:
+ compliance_check_set:
+ ref: réf
+ creation_date: Created at
+ associated_object: Associated object
+ assigned_to: Assigned to
+ compliance_control_set: Compliance control set
diff --git a/config/locales/compliance_check_sets.fr.yml b/config/locales/compliance_check_sets.fr.yml
new file mode 100644
index 000000000..8c21f33fd
--- /dev/null
+++ b/config/locales/compliance_check_sets.fr.yml
@@ -0,0 +1,23 @@
+fr:
+ compliance_check_sets:
+ index:
+ title: Rapports de contrôle
+ new: Création d'un rapport de contrôle
+ edit: Édition d'un rapport de contrôle
+ actions:
+ new: Ajouter
+ edit: Editer
+ destroy: Supprimer
+ destroy_confirm: Etes vous sûr de supprimer ce rapport de contrôle ?
+ filters:
+ name: Indiquez un nom d'un objet associé...
+ error_period_filter: La date de fin doit être supérieure ou égale à la date de début0
+ search_no_results: Aucun rapport de contrôle ne correspond à votre recherche
+ activerecord:
+ attributes:
+ compliance_check_set:
+ ref: réf
+ creation_date: Date et heure de création
+ associated_object: Objet associé
+ assigned_to: Affectation
+ compliance_control_set: jeu de contrôle
diff --git a/config/locales/compliance_control_sets.en.yml b/config/locales/compliance_control_sets.en.yml
index b7133aea5..4e2c8f485 100644
--- a/config/locales/compliance_control_sets.en.yml
+++ b/config/locales/compliance_control_sets.en.yml
@@ -14,12 +14,12 @@ en:
name: 'Enter name ...'
search_no_results: 'No compliance control set found'
activerecord:
- models:
- compliance_control_set: Calendar
- attributes:
- compliance_control_set:
- name: Name
- assignment: Assignment
- owner_jdc: Owner
- control_numbers: Control number
- updated_at: Updated at
+ models:
+ compliance_control_set: Calendar
+ attributes:
+ compliance_control_set:
+ name: Name
+ assigned_to: Assigned to
+ owner_jdc: Owner of the control game
+ control_numbers: Nb contrôle
+ updated_at: Update \ No newline at end of file
diff --git a/config/locales/compliance_control_sets.fr.yml b/config/locales/compliance_control_sets.fr.yml
index 8310aa0db..d808698c5 100644
--- a/config/locales/compliance_control_sets.fr.yml
+++ b/config/locales/compliance_control_sets.fr.yml
@@ -14,12 +14,12 @@ fr:
name: 'Indiquez un nom de jeux de contrôle...'
search_no_results: 'Aucun jeu de contrôle ne correspond à votre recherche'
activerecord:
- models:
- compliance_control_set: Calendrier
- attributes:
- compliance_control_set:
- name: Nom
- assignment: Affectation
- owner_jdc: Propriétaire du jeu de contrôle
- control_numbers: Nb contrôle
- updated_at: Mis a jour
+ models:
+ compliance_control_set: Calendrier
+ attributes:
+ compliance_control_set:
+ name: Nom
+ assigned_to: Affectation
+ owner_jdc: Propriétaire du jeu de contrôle
+ control_numbers: Nb contrôle
+ updated_at: Mis a jour \ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 1d34a4854..9ee85d6e8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -8,7 +8,9 @@ ChouetteIhm::Application.routes.draw do
resources :import_resources, only: [:index] do
resources :import_messages, only: [:index]
end
-
+ end
+ resources :compliance_check_sets, only: [:index, :show] do
+ resources :compliance_checks, only: [:show]
end
end
diff --git a/db/migrate/20170928075431_add_origin_code_to_compliance_checks.rb b/db/migrate/20170928075431_add_origin_code_to_compliance_checks.rb
new file mode 100644
index 000000000..43849bcfe
--- /dev/null
+++ b/db/migrate/20170928075431_add_origin_code_to_compliance_checks.rb
@@ -0,0 +1,5 @@
+class AddOriginCodeToComplianceChecks < ActiveRecord::Migration
+ def change
+ add_column :compliance_checks, :origin_code, :string
+ end
+end
diff --git a/db/migrate/20170928085904_add_compliance_control_block_to_compliance_control.rb b/db/migrate/20170928085904_add_compliance_control_block_to_compliance_control.rb
new file mode 100644
index 000000000..ae6128396
--- /dev/null
+++ b/db/migrate/20170928085904_add_compliance_control_block_to_compliance_control.rb
@@ -0,0 +1,5 @@
+class AddComplianceControlBlockToComplianceControl < ActiveRecord::Migration
+ def change
+ add_reference :compliance_controls, :compliance_control_block, index: true, foreign_key: true
+ end
+end
diff --git a/db/migrate/20170928090016_remove_compliance_control_from_compliance_control_block.rb b/db/migrate/20170928090016_remove_compliance_control_from_compliance_control_block.rb
new file mode 100644
index 000000000..147bd09c8
--- /dev/null
+++ b/db/migrate/20170928090016_remove_compliance_control_from_compliance_control_block.rb
@@ -0,0 +1,5 @@
+class RemoveComplianceControlFromComplianceControlBlock < ActiveRecord::Migration
+ def change
+ remove_reference :compliance_control_blocks, :compliance_control, index: true, foreign_key: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a8c90b111..32a867d07 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: 20170925154017) do
+ActiveRecord::Schema.define(version: 20170928090016) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -206,6 +206,7 @@ ActiveRecord::Schema.define(version: 20170925154017) do
t.text "comment"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.string "origin_code"
end
add_index "compliance_checks", ["compliance_check_block_id"], name: "index_compliance_checks_on_compliance_check_block_id", using: :btree
@@ -217,10 +218,8 @@ ActiveRecord::Schema.define(version: 20170925154017) do
t.integer "compliance_control_set_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
- t.integer "compliance_control_id"
end
- add_index "compliance_control_blocks", ["compliance_control_id"], name: "index_compliance_control_blocks_on_compliance_control_id", using: :btree
add_index "compliance_control_blocks", ["compliance_control_set_id"], name: "index_compliance_control_blocks_on_compliance_control_set_id", using: :btree
create_table "compliance_control_sets", id: :bigserial, force: :cascade do |t|
@@ -240,10 +239,13 @@ ActiveRecord::Schema.define(version: 20170925154017) do
t.string "code"
t.string "criticity"
t.text "comment"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.string "origin_code"
+ t.integer "compliance_control_block_id"
end
+ add_index "compliance_controls", ["compliance_control_block_id"], name: "index_compliance_controls_on_compliance_control_block_id", using: :btree
add_index "compliance_controls", ["compliance_control_set_id"], name: "index_compliance_controls_on_compliance_control_set_id", using: :btree
create_table "connection_links", id: :bigserial, force: :cascade do |t|
@@ -987,8 +989,8 @@ ActiveRecord::Schema.define(version: 20170925154017) do
add_foreign_key "compliance_checks", "compliance_check_blocks"
add_foreign_key "compliance_checks", "compliance_check_sets"
add_foreign_key "compliance_control_blocks", "compliance_control_sets"
- add_foreign_key "compliance_control_blocks", "compliance_controls"
add_foreign_key "compliance_control_sets", "organisations"
+ add_foreign_key "compliance_controls", "compliance_control_blocks"
add_foreign_key "compliance_controls", "compliance_control_sets"
add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", on_delete: :cascade
add_foreign_key "journey_frequencies", "timebands", on_delete: :nullify
diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb
index 15d5ffc89..095f726bd 100644
--- a/lib/stif/permission_translator.rb
+++ b/lib/stif/permission_translator.rb
@@ -17,15 +17,20 @@ module Stif
def all_resources
%w[
access_points
- connection_links calendars
+ connection_links
+ calendars
footnotes
imports
journey_patterns
- referentials routes routing_constraint_zones
+ referentials
+ routes
+ routing_constraint_zones
time_tables
vehicle_journeys
api_keys
compliance_controls
+ compliance_controls_sets
+ compliance_check_sets
]
end
diff --git a/spec/controllers/compliance_check_sets_controller_spec.rb b/spec/controllers/compliance_check_sets_controller_spec.rb
new file mode 100644
index 000000000..804b0a658
--- /dev/null
+++ b/spec/controllers/compliance_check_sets_controller_spec.rb
@@ -0,0 +1,22 @@
+require 'rails_helper'
+
+RSpec.describe ComplianceCheckSetsController, type: :controller do
+ login_user
+
+ let(:compliance_check_set) { create :compliance_check_set }
+
+ describe "GET show" do
+ it 'should be successful' do
+ get :show, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id
+ expect(response).to be_success
+ end
+ end
+
+ describe "GET index" do
+ it 'should be successful' do
+ get :index, workbench_id: compliance_check_set.workbench.id, id: compliance_check_set.id
+ expect(response).to be_success
+ end
+ end
+
+end
diff --git a/spec/factories/compliance_checks.rb b/spec/factories/compliance_checks.rb
index 4009653da..f9af62c73 100644
--- a/spec/factories/compliance_checks.rb
+++ b/spec/factories/compliance_checks.rb
@@ -4,6 +4,7 @@ FactoryGirl.define do
type "Type"
criticity :info
code "code"
+ origin_code "code"
comment "Text"
association :compliance_check_set
association :compliance_check_block
diff --git a/spec/factories/compliance_control_blocks.rb b/spec/factories/compliance_control_blocks.rb
index 1b043324e..5bc45cc75 100644
--- a/spec/factories/compliance_control_blocks.rb
+++ b/spec/factories/compliance_control_blocks.rb
@@ -2,6 +2,5 @@ FactoryGirl.define do
factory :compliance_control_block do
sequence(:name) { |n| "Compliance control block #{n}" }
association :compliance_control_set
- association :compliance_control
end
end
diff --git a/spec/factories/compliance_controls.rb b/spec/factories/compliance_controls.rb
index ced505565..83169b13a 100644
--- a/spec/factories/compliance_controls.rb
+++ b/spec/factories/compliance_controls.rb
@@ -7,5 +7,6 @@ FactoryGirl.define do
origin_code "code"
comment "Text"
association :compliance_control_set
+ association :compliance_control_block
end
end
diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb
index 4fbc23d42..acdcc3ebf 100644
--- a/spec/models/compliance_check_spec.rb
+++ b/spec/models/compliance_check_spec.rb
@@ -11,4 +11,5 @@ RSpec.describe ComplianceCheck, type: :model do
it { should validate_presence_of :criticity }
it { should validate_presence_of :name }
it { should validate_presence_of :code }
+ it { should validate_presence_of :origin_code }
end
diff --git a/spec/models/compliance_control_block_spec.rb b/spec/models/compliance_control_block_spec.rb
index f45ec3d42..a50fe026b 100644
--- a/spec/models/compliance_control_block_spec.rb
+++ b/spec/models/compliance_control_block_spec.rb
@@ -8,5 +8,5 @@ RSpec.describe ComplianceControlBlock, type: :model do
end
it { should belong_to :compliance_control_set }
- it { should belong_to :compliance_control }
+ it { should have_many(:compliance_controls).dependent(:destroy) }
end
diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb
index d7bffb0b2..0fc830021 100644
--- a/spec/models/compliance_control_spec.rb
+++ b/spec/models/compliance_control_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe ComplianceControl, type: :model do
end
it { should belong_to :compliance_control_set }
- it { should have_one(:compliance_control_block).dependent(:destroy) }
+ it { should belong_to :compliance_control_block }
it 'should validate_presence_of criticity' do
compliance_control.criticity = nil
@@ -37,5 +37,5 @@ RSpec.describe ComplianceControl, type: :model do
# it { should validate_presence_of :name }
# it { should validate_presence_of :code }
# it { should validate_presence_of :origin_code }
-
+
end