diff options
| author | Guillaume | 2017-09-28 10:35:55 +0200 | 
|---|---|---|
| committer | Guillaume | 2017-09-28 10:35:55 +0200 | 
| commit | 689a8f7c89ea0841fee1e2da97dacf98ff458104 (patch) | |
| tree | 9cee685ae1a8afb43ca2a2497b9d4f4e1c6fb7b2 | |
| parent | b84188abb33417a24274fc3ba179b6eb2ba8a067 (diff) | |
| parent | 2b5815827005f7fa69403b9177feafa4d42c3cb2 (diff) | |
| download | chouette-core-689a8f7c89ea0841fee1e2da97dacf98ff458104.tar.bz2 | |
Merge branch 'master' of https://github.com/af83/stif-boiv
65 files changed, 377 insertions, 301 deletions
| @@ -114,7 +114,7 @@ gem 'sequel'  gem 'draper' -gem 'enumerize', '~> 0.10.0' +gem 'enumerize', '~> 2.1.2'  gem 'deep_cloneable', '~> 2.0.0'  gem 'acts-as-taggable-on', '~> 4.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 1d05e0540..2c04def92 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -209,7 +209,7 @@ GEM      email_spec (1.6.0)        launchy (~> 2.1)        mail (~> 2.2) -    enumerize (0.10.1) +    enumerize (2.1.2)        activesupport (>= 3.2)      erubis (2.7.0)      execjs (2.7.0) @@ -590,7 +590,7 @@ DEPENDENCIES    devise_invitable    draper    email_spec -  enumerize (~> 0.10.0) +  enumerize (~> 2.1.2)    fabrication (~> 2.14.1)    factory_girl_rails (~> 4.0)    faker diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb index 20ddcbe97..306b2eac7 100644 --- a/app/controllers/compliance_control_sets_controller.rb +++ b/app/controllers/compliance_control_sets_controller.rb @@ -14,11 +14,15 @@ class ComplianceControlSetsController < BreadcrumbController    end    def show -    show! do -      @compliance_control_set = @compliance_control_set.decorate +    show! do |format| +      format.html { +        @compliance_control_set = @compliance_control_set.decorate +        @compliance_controls = decorate_compliance_controls(@compliance_control_set.compliance_controls) +      }      end    end +  private    def decorate_compliance_control_sets(compliance_control_sets)      ModelDecorator.decorate(        compliance_control_sets, @@ -33,6 +37,12 @@ class ComplianceControlSetsController < BreadcrumbController    # end    private +  def decorate_compliance_controls(compliance_controls) +    ModelDecorator.decorate( +      compliance_controls, +      with: ComplianceControlDecorator, +    ) +  end    def ransack_updated_at_params      start_date = [] diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb index dad9b935a..eb1ba68ea 100644 --- a/app/controllers/compliance_controls_controller.rb +++ b/app/controllers/compliance_controls_controller.rb @@ -1,18 +1,11 @@  class ComplianceControlsController < BreadcrumbController -  include PolicyChecker    defaults resource_class: ComplianceControl    belongs_to :compliance_control_set -  def index -    index! do |format| -      format.html { -        @compliance_controls = decorate_compliance_controls(@compliance_controls) -      } -    end -  end - -  def create -    create!(notice: t('notice.compliance_control.created')) +  def new +    @compliance_control_set = parent +    @compliance_control = GenericAttributeControl::MinMax.new +    @compliance_control.build_compliance_control_block    end    def update @@ -20,19 +13,14 @@ class ComplianceControlsController < BreadcrumbController      update!(notice: t('notice.compliance_control.updated')) { path }    end -  def destroy -    destroy!(notice: t('notice.compliance_control.destroyed')) -  end -    private -  def decorate_compliance_controls(compliance_controls) -    ModelDecorator.decorate( -      compliance_controls, -      with: ComplianceControlDecorator, -    ) +  def dynamic_attributes_params +    params.require(:compliance_control).permit(:type).values[0].constantize.dynamic_attributes    end    def compliance_control_params -    params.require(:compliance_control).permit(:name, :code, :criticity, :comment, :control_attributes) +    base = [:name, :code, :origin_code, :criticity, :comment, :control_attributes, :type, compliance_control_block_attributes: [:name, :transport_mode]] +    permited = base + dynamic_attributes_params +    params.require(:compliance_control).permit(permited)    end  end diff --git a/app/decorators/compliance_control_decorator.rb b/app/decorators/compliance_control_decorator.rb index 38b968ad1..3a05a5c59 100644 --- a/app/decorators/compliance_control_decorator.rb +++ b/app/decorators/compliance_control_decorator.rb @@ -4,21 +4,21 @@ class ComplianceControlDecorator < Draper::Decorator    def action_links      links = [] -    if h.policy(object).destroy? +    # if h.policy(object).destroy?        links << Link.new(          content: h.destroy_link_content,          href: h.compliance_control_set_compliance_control_path(object.compliance_control_set.id, object.id),          method: :delete,          data: { confirm: h.t('compliance_controls.actions.destroy_confirm') }        ) -    end +    # end -    if h.policy(object).edit? +    # if h.policy(object).edit?        links << Link.new(          content: h.t('compliance_controls.actions.edit'), -        href:  h.edit_compliance_control_set_path(object.compliance_control_set.id, object.id) +        href:  h.edit_compliance_control_set_compliance_control_path(object.compliance_control_set.id, object.id)        ) -    end +    # end      links    end diff --git a/app/decorators/compliance_control_set_decorator.rb b/app/decorators/compliance_control_set_decorator.rb index 876a54d09..f9e4de836 100644 --- a/app/decorators/compliance_control_set_decorator.rb +++ b/app/decorators/compliance_control_set_decorator.rb @@ -19,6 +19,13 @@ class ComplianceControlSetDecorator < Draper::Decorator          href:  h.edit_compliance_control_set_path(object.id)        )      # end + +    # if h.policy(ComplianceControl).create? +      links << Link.new( +        content: h.t('compliance_control_sets.actions.add_compliance_control'), +        href:  h.new_compliance_control_set_compliance_control_path(object.id) +      ) +    # end      links    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_control.rb b/app/models/compliance_control.rb index 12ff4737a..c5389e832 100644 --- a/app/models/compliance_control.rb +++ b/app/models/compliance_control.rb @@ -1,12 +1,42 @@  class ComplianceControl < ActiveRecord::Base +  extend Enumerize    belongs_to :compliance_control_set -  belongs_to :compliance_control_block +  has_one :compliance_control_block, dependent: :destroy +  accepts_nested_attributes_for :compliance_control_block + +  @@default_criticity = :warning +  @@default_code = "" -  extend Enumerize    enumerize :criticity, in: %i(info warning error), scope: true, default: :info    validates :criticity, presence: true    validates :name, presence: true    validates :code, presence: true +  validates :origin_code, presence: true    validates :compliance_control_set, presence: true + +  def self.policy_class +    ComplianceControlPolicy +  end + +  def self.inherited(child) +    child.instance_eval do +      def model_name +        ComplianceControl.model_name +      end +    end +    super +  end + +  before_validation(on: :create) do +   self.name ||= self.class.name +   self.code ||= @@default_code +   self.origin_code ||= @@default_code +   self.criticity ||= @@default_criticity +  end +  end + +# Ensure STI subclasses are loaded +# http://guides.rubyonrails.org/autoloading_and_reloading_constants.html#autoloading-and-sti +require_dependency 'generic_attribute_control/min_max' diff --git a/app/models/compliance_control_block.rb b/app/models/compliance_control_block.rb index cf5a9d72b..a08e271f6 100644 --- a/app/models/compliance_control_block.rb +++ b/app/models/compliance_control_block.rb @@ -1,3 +1,16 @@  class ComplianceControlBlock < ActiveRecord::Base    belongs_to :compliance_control_set +  belongs_to :compliance_control + +  before_save :set_compliance_control_set + +  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  end diff --git a/app/models/compliance_control_set.rb b/app/models/compliance_control_set.rb index 4dafd48c7..f8f491cba 100644 --- a/app/models/compliance_control_set.rb +++ b/app/models/compliance_control_set.rb @@ -1,11 +1,9 @@  class ComplianceControlSet < ActiveRecord::Base    belongs_to :organisation -  has_many :compliance_controls +  has_many :compliance_controls, dependent: :destroy    validates :name, presence: true -    scope :where_updated_at_between, ->(start_date, end_date) do      where('updated_at BETWEEN ? AND ?', start_date, end_date)    end -  end diff --git a/app/models/generic_attribute_control/min_max.rb b/app/models/generic_attribute_control/min_max.rb new file mode 100644 index 000000000..6a2e1f284 --- /dev/null +++ b/app/models/generic_attribute_control/min_max.rb @@ -0,0 +1,17 @@ +module GenericAttributeControl +  class MinMax < ComplianceControl +    hstore_accessor :control_attributes, minimum: :integer, maximum: :integer + +    @@default_criticity = :warning +    @@default_code = "3-Generic-2" + +    validate :min_max_values +    def min_max_values +      true +    end + +    def self.dynamic_attributes +      self.hstore_metadata_for_control_attributes.keys +    end +  end +end diff --git a/app/models/generic_attribute_control/pattern.rb b/app/models/generic_attribute_control/pattern.rb new file mode 100644 index 000000000..5b27da54e --- /dev/null +++ b/app/models/generic_attribute_control/pattern.rb @@ -0,0 +1,13 @@ +module GenericAttributeControl +  class Pattern < ComplianceControl +    hstore_accessor :control_attributes, value: :string, pattern: :string + +    @@default_criticity = :warning +    @@default_code = "3-Generic-3" + +    validate :pattern_match +    def pattern_match +      true +    end +  end +end
\ No newline at end of file diff --git a/app/models/generic_attribute_control/uniqueness.rb b/app/models/generic_attribute_control/uniqueness.rb new file mode 100644 index 000000000..4f1a82083 --- /dev/null +++ b/app/models/generic_attribute_control/uniqueness.rb @@ -0,0 +1,13 @@ +module GenericAttributeControl +  class Uniqueness < ComplianceControl +    hstore_accessor :control_attributes, name: :string + +    @@default_criticity = :warning +    @@default_code = "3-Generic-3" + +    validate :unique_values +    def unique_values +      true +    end +  end +end
\ No newline at end of file diff --git a/app/models/generic_attribute_min_max.rb b/app/models/generic_attribute_min_max.rb deleted file mode 100644 index e9a127c56..000000000 --- a/app/models/generic_attribute_min_max.rb +++ /dev/null @@ -1,27 +0,0 @@ -#module ComplianceControls - -  class GenericAttributeMinMax < ComplianceControl - - -    hstore_accessor :control_attributes, minimum: :integer, maximum: :integer -    #attribute :minimum, type: :integer, optionnal: true -    #attribute :maximum, type: :integer, optionnal: true -    # #attribute :target, type: ModelAttribute - -    @@default_criticity = :warning -    @@default_code = "3-Generic-2" - -    validate :min_max_values -    def min_max_values -      true -    end - -    after_initialize do -      self.name = 'GenericAttributeMinMax' -      self.code = @@default_code -      self.criticity = @@default_criticity -    end - -  end - -#end diff --git a/app/models/generic_attribute_pattern.rb b/app/models/generic_attribute_pattern.rb deleted file mode 100644 index 0043f1563..000000000 --- a/app/models/generic_attribute_pattern.rb +++ /dev/null @@ -1,23 +0,0 @@ -#module ComplianceControls - -  class GenericAttributePattern < ComplianceControl - -    hstore_accessor :control_attributes, value: :string, pattern: :string - -    @@default_criticity = :warning -    @@default_code = "3-Generic-3" - -    validate :pattern_match -    def pattern_match -      true -    end - -    after_initialize do -      self.name = 'GenericAttributeMinMax' -      self.code = @@default_code -      self.criticity = @@default_criticity -    end - -  end - -#end
\ No newline at end of file diff --git a/app/models/generic_attribute_uniqueness.rb b/app/models/generic_attribute_uniqueness.rb deleted file mode 100644 index dcf4a16c2..000000000 --- a/app/models/generic_attribute_uniqueness.rb +++ /dev/null @@ -1,23 +0,0 @@ -#module ComplianceControls - -  class GenericAttributeUniqueness < ComplianceControl - -    hstore_accessor :control_attributes, name: :string - -    @@default_criticity = :warning -    @@default_code = "3-Generic-3" - -    validate :unique_values -    def unique_values -      true -    end - -    after_initialize do -      self.name = 'GenericAttributeMinMax' -      self.code = @@default_code -      self.criticity = @@default_criticity -    end - -  end - -#end
\ No newline at end of file diff --git a/app/models/journey_pattern_control/duplicates.rb b/app/models/journey_pattern_control/duplicates.rb index 78ca07e90..d3908cfc0 100644 --- a/app/models/journey_pattern_control/duplicates.rb +++ b/app/models/journey_pattern_control/duplicates.rb @@ -3,11 +3,5 @@ module JourneyPatternControl      @@default_criticity = :warning      @@default_code = "3-JourneyPattern-1" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/journey_pattern_control/vehicle_journey.rb b/app/models/journey_pattern_control/vehicle_journey.rb index a90c16138..d7151f147 100644 --- a/app/models/journey_pattern_control/vehicle_journey.rb +++ b/app/models/journey_pattern_control/vehicle_journey.rb @@ -3,11 +3,5 @@ module JourneyPatternControl      @@default_criticity = :warning      @@default_code = "3-JourneyPattern-2" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end
\ No newline at end of file diff --git a/app/models/line_control/route.rb b/app/models/line_control/route.rb index 8ac13a080..21c5eca06 100644 --- a/app/models/line_control/route.rb +++ b/app/models/line_control/route.rb @@ -3,11 +3,5 @@ module LineControl      @@default_criticity = :warning      @@default_code = "3-Line-1" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end
\ No newline at end of file diff --git a/app/models/route_control/duplicates.rb b/app/models/route_control/duplicates.rb index 379d7cf98..fb9c34e0a 100644 --- a/app/models/route_control/duplicates.rb +++ b/app/models/route_control/duplicates.rb @@ -3,11 +3,5 @@ module RouteControl      @@default_criticity = :warning      @@default_code = "3-Route-4" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/route_control/journey_pattern.rb b/app/models/route_control/journey_pattern.rb index 0559fac42..08f603d8f 100644 --- a/app/models/route_control/journey_pattern.rb +++ b/app/models/route_control/journey_pattern.rb @@ -3,11 +3,5 @@ module RouteControl      @@default_criticity = :warning      @@default_code = "3-Route-3" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end
\ No newline at end of file diff --git a/app/models/route_control/minimum_length.rb b/app/models/route_control/minimum_length.rb index 14bc7064f..f42b88748 100644 --- a/app/models/route_control/minimum_length.rb +++ b/app/models/route_control/minimum_length.rb @@ -3,11 +3,5 @@ module RouteControl      @@default_criticity = :error      @@default_code = "3-Route-6" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/route_control/omnibus_journey_pattern.rb b/app/models/route_control/omnibus_journey_pattern.rb index 2f09ff735..3b9f6d06f 100644 --- a/app/models/route_control/omnibus_journey_pattern.rb +++ b/app/models/route_control/omnibus_journey_pattern.rb @@ -3,11 +3,5 @@ module RouteControl      @@default_criticity = :warning      @@default_code = "3-Route-9" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/route_control/opposite_route.rb b/app/models/route_control/opposite_route.rb index d5f2bc59e..e91b081e2 100644 --- a/app/models/route_control/opposite_route.rb +++ b/app/models/route_control/opposite_route.rb @@ -3,12 +3,5 @@ module RouteControl      @@default_criticity = :error      @@default_code = "3-Route-2" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end -    end  end diff --git a/app/models/route_control/opposite_route_terminus.rb b/app/models/route_control/opposite_route_terminus.rb index e72229ca3..fd62b7684 100644 --- a/app/models/route_control/opposite_route_terminus.rb +++ b/app/models/route_control/opposite_route_terminus.rb @@ -3,11 +3,5 @@ module RouteControl      @@default_criticity = :warning      @@default_code = "3-Route-5" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end
\ No newline at end of file diff --git a/app/models/route_control/speed.rb b/app/models/route_control/speed.rb index fb07b5c87..0a2b6ac76 100644 --- a/app/models/route_control/speed.rb +++ b/app/models/route_control/speed.rb @@ -5,11 +5,5 @@ module VehicleJourneyControl      @@default_criticity = :warning      @@default_code = "3-VehicleJourney-2" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/route_control/stop_points_in_journey_pattern.rb b/app/models/route_control/stop_points_in_journey_pattern.rb index 195257a4a..dced6c005 100644 --- a/app/models/route_control/stop_points_in_journey_pattern.rb +++ b/app/models/route_control/stop_points_in_journey_pattern.rb @@ -3,11 +3,5 @@ module RouteControl      @@default_criticity = :error      @@default_code = "3-Route-6" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/route_control/time_table.rb b/app/models/route_control/time_table.rb index 911807ba9..5d0f21b40 100644 --- a/app/models/route_control/time_table.rb +++ b/app/models/route_control/time_table.rb @@ -3,11 +3,5 @@ module VehicleJourneyControl      @@default_criticity = :error      @@default_code = "3-VehicleJourney-4" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/route_control/unactivated_stop_points.rb b/app/models/route_control/unactivated_stop_points.rb index 8ab680490..dee846cbb 100644 --- a/app/models/route_control/unactivated_stop_points.rb +++ b/app/models/route_control/unactivated_stop_points.rb @@ -3,11 +3,5 @@ module RouteControl      @@default_criticity = :warning      @@default_code = "3-Route-10" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/route_control/vehicle_journey_at_stops.rb b/app/models/route_control/vehicle_journey_at_stops.rb index 02a43fb10..149282fe6 100644 --- a/app/models/route_control/vehicle_journey_at_stops.rb +++ b/app/models/route_control/vehicle_journey_at_stops.rb @@ -3,11 +3,5 @@ module VehicleJourneyControl      @@default_criticity = :error      @@default_code = "3-VehicleJourney-5" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/route_control/zdl_stop_area.rb b/app/models/route_control/zdl_stop_area.rb index 4561c9b2e..088a1d2f2 100644 --- a/app/models/route_control/zdl_stop_area.rb +++ b/app/models/route_control/zdl_stop_area.rb @@ -3,11 +3,5 @@ module RouteControl      @@default_criticity = :warning      @@default_code = "3-Route-1" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/routing_constaint_zone_control/maximum_length.rb b/app/models/routing_constaint_zone_control/maximum_length.rb index fd63ffeda..4d289de63 100644 --- a/app/models/routing_constaint_zone_control/maximum_length.rb +++ b/app/models/routing_constaint_zone_control/maximum_length.rb @@ -3,11 +3,5 @@ module RoutingConstaintZoneControl      @@default_criticity = :warning      @@default_code = "3-ITL-2" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end
\ No newline at end of file diff --git a/app/models/routing_constaint_zone_control/minimum_length.rb b/app/models/routing_constaint_zone_control/minimum_length.rb index c17bbc834..28f0791a7 100644 --- a/app/models/routing_constaint_zone_control/minimum_length.rb +++ b/app/models/routing_constaint_zone_control/minimum_length.rb @@ -3,11 +3,5 @@ module RoutingConstaintZoneControl      @@default_criticity = :warning      @@default_code = "3-ITL-3" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end
\ No newline at end of file diff --git a/app/models/routing_constaint_zone_control/unactivated_stop_point.rb b/app/models/routing_constaint_zone_control/unactivated_stop_point.rb index 92a1d1a58..fe5381a34 100644 --- a/app/models/routing_constaint_zone_control/unactivated_stop_point.rb +++ b/app/models/routing_constaint_zone_control/unactivated_stop_point.rb @@ -3,11 +3,5 @@ module RoutingConstaintZoneControl      @@default_criticity = :warning      @@default_code = "3-ITL-1" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/vechicle_journey_control/delta.rb b/app/models/vechicle_journey_control/delta.rb index d4e1e6eca..d77eff48a 100644 --- a/app/models/vechicle_journey_control/delta.rb +++ b/app/models/vechicle_journey_control/delta.rb @@ -5,11 +5,5 @@ module VehicleJourneyControl      @@default_criticity = :warning      @@default_code = "3-VehicleJourney-3" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/vechicle_journey_control/waiting_time.rb b/app/models/vechicle_journey_control/waiting_time.rb index a7e90b6ac..cbffa5526 100644 --- a/app/models/vechicle_journey_control/waiting_time.rb +++ b/app/models/vechicle_journey_control/waiting_time.rb @@ -3,11 +3,5 @@ module VehicleJourneyControl      @@default_criticity = :warning      @@default_code = "3-VehicleJourney-1" - -    after_initialize do -      self.name = self.class.name -      self.code = @@default_code -      self.criticity = @@default_criticity -    end    end  end diff --git a/app/models/workbench.rb b/app/models/workbench.rb index 30692e625..fe4e6cce1 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -2,6 +2,7 @@ class Workbench < ActiveRecord::Base    belongs_to :organisation    belongs_to :line_referential    belongs_to :stop_area_referential +  belongs_to :output, class_name: 'ReferentialSuite'    has_many :lines, -> (workbench) { Stif::MyWorkbenchScopes.new(workbench).line_scope(self) }, through: :line_referential    has_many :networks, through: :line_referential @@ -13,10 +14,13 @@ class Workbench < ActiveRecord::Base    validates :name, presence: true    validates :organisation, presence: true +  validates :output, presence: true    has_many :referentials    has_many :referential_metadatas, through: :referentials, source: :metadatas +  before_validation :initialize_output +    def all_referentials      if line_ids.empty? @@ -26,4 +30,12 @@ class Workbench < ActiveRecord::Base      end    end +  private + +  def initialize_output +    # Don't reset `output` if it's already initialised +    return if !output.nil? + +    self.output = ReferentialSuite.create +  end  end diff --git a/app/policies/compliance_control_policy.rb b/app/policies/compliance_control_policy.rb index fbea366f5..09250f013 100644 --- a/app/policies/compliance_control_policy.rb +++ b/app/policies/compliance_control_policy.rb @@ -6,14 +6,17 @@ class ComplianceControlPolicy < ApplicationPolicy    end    def destroy? -    user.has_permission?('compliance_controls.destroy') +    # user.has_permission?('compliance_controls.destroy') +    true    end    def create? -    user.has_permission?('compliance_controls.create') +    # user.has_permission?('compliance_controls.create') +    true    end    def update? -    user.has_permission?('compliance_controls.update') +    # user.has_permission?('compliance_controls.update') +    true    end  end diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim index b4a5b2260..d7d4678ba 100644 --- a/app/views/compliance_control_sets/show.html.slim +++ b/app/views/compliance_control_sets/show.html.slim @@ -22,4 +22,38 @@      .row        .col-lg-6.col-md-6.col-sm-12.col-xs-12          = definition_list t('metadatas'), -            ComplianceControlSet.human_attribute_name(:name) => @compliance_control_set.name
\ No newline at end of file +            ComplianceControlSet.human_attribute_name(:name) => @compliance_control_set.name + +  .container-fluid +    .row +      .col-lg-12 +        /= render 'filters' +      .row +        .col-lg-12 +          .select_table +            = table_builder_2 @compliance_controls, +                    [ \ +                TableBuilderHelper::Column.new( \ +                  key: :code, \ +                  attribute: 'code' \ +                ), \ +                TableBuilderHelper::Column.new( \ +                  key: :name, \ +                  attribute: 'name', \ +                  link_to: lambda do |compliance_control| \ +                      compliance_control_set_compliance_control_path(@compliance_control_set, compliance_control) \ +                    end \ +                ), \ +                TableBuilderHelper::Column.new( \ +                  key: :criticity, \ +                  attribute: 'criticity' \ +                ), \ +                TableBuilderHelper::Column.new( \ +                  key: :comment, \ +                  attribute: 'comment' \ +                ), \ +              ], +              sortable: true, +              cls: 'table has-filter has-search' + + diff --git a/app/views/compliance_controls/_form.html.slim b/app/views/compliance_controls/_form.html.slim index 1377ed12b..bb8f68464 100644 --- a/app/views/compliance_controls/_form.html.slim +++ b/app/views/compliance_controls/_form.html.slim @@ -2,11 +2,19 @@    .row      .col-lg-12        = f.input :name -      = f.input :type +      = f.input :type, as: :select, collection: ComplianceControl.subclasses        = f.input :code        = f.input :criticity        = f.input :comment +      - 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/compliance_controls/edit.html.slim b/app/views/compliance_controls/edit.html.slim index e69de29bb..6824c7e40 100644 --- a/app/views/compliance_controls/edit.html.slim +++ b/app/views/compliance_controls/edit.html.slim @@ -0,0 +1,9 @@ += pageheader 'compliance-control', +        t('compliance_control.index.edit') + + +.page_content +  .container-fluid +    .row +      .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 +        = render 'form' diff --git a/app/views/compliance_controls/show.html.slim b/app/views/compliance_controls/show.html.slim index e69de29bb..a665f1ab1 100644 --- a/app/views/compliance_controls/show.html.slim +++ b/app/views/compliance_controls/show.html.slim @@ -0,0 +1,3 @@ += @compliance_control.inspect +br += @compliance_control.compliance_control_block.inspect diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index b8f86a751..0393c7bdd 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -20,6 +20,7 @@ Apartment.configure do |config|    config.excluded_models = [      'Referential',      'ReferentialMetadata', +    'ReferentialSuite',      'Organisation',      'User',      'Api::V1::ApiKey', @@ -48,6 +49,7 @@ Apartment.configure do |config|      'ImportMessage',      'ImportResource',      'ComplianceControl', +    'GenericAttributeControl::MinMax',      'ComplianceControlSet',      'ComplianceControlBlock',      'ComplianceCheck', diff --git a/config/locales/compliance_control_sets.en.yml b/config/locales/compliance_control_sets.en.yml index 497ca50c3..b7133aea5 100644 --- a/config/locales/compliance_control_sets.en.yml +++ b/config/locales/compliance_control_sets.en.yml @@ -1,24 +1,25 @@ -fr: +en:    compliance_control_sets:      index: -      title: Control games -      new: Creating a control set -      edit: Editing a Control Game +      title: Compliance control set +      new: New compliance control set +      edit: Edit compliance control set      actions: -          new: Add -          edit: Edit -          destroy: Delete -          destroy_confirm: Are you sure to remove the control games ? +      new: Add +      edit: Edit +      destroy: Destroy +      add_compliance_control: Add a compliance control +      destroy_confirm: Are you sur ?      filters: -          name: Specify a control game name... -    search_no_results: No control game matches your search +      name: 'Enter name ...' +    search_no_results: 'No compliance control set found'    activerecord: -          models: -            compliance_control_set: Calendar -          attributes: -            compliance_control_set: -              name: Name -              assignment: Affectation -              owner_jdc: Owner of the control game -              control_numbers: Nb contrôle -              updated_at: Update
\ No newline at end of file +    models: +      compliance_control_set: Calendar +    attributes: +      compliance_control_set: +        name: Name +        assignment: Assignment +        owner_jdc: Owner +        control_numbers: Control number +        updated_at: Updated at diff --git a/config/locales/compliance_control_sets.fr.yml b/config/locales/compliance_control_sets.fr.yml index f5bb7c67b..8310aa0db 100644 --- a/config/locales/compliance_control_sets.fr.yml +++ b/config/locales/compliance_control_sets.fr.yml @@ -5,20 +5,21 @@ fr:        new: Création d'un jeux de contrôle        edit: Édition d'un jeux de contrôle      actions: -          new: Ajouter -          edit: Editer -          destroy: Supprimer -          destroy_confirm: Etes vous sûr de supprimer ce jeux de contrôle ? +      new: Ajouter +      edit: Editer +      destroy: Supprimer +      add_compliance_control: Ajouter un JDC +      destroy_confirm: Etes vous sûr de supprimer ce jeux de contrôle ?      filters: -          name: Indiquez un nom de jeux de contrôle... -    search_no_results: Aucun jeu de contrôle ne correspond à votre recherche +      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
\ No newline at end of file +    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 diff --git a/config/routes.rb b/config/routes.rb index ef625db1f..1d34a4854 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -70,7 +70,7 @@ ChouetteIhm::Application.routes.draw do    resources :api_keys, :only => [:edit, :update, :new, :create, :destroy]    resources :compliance_control_sets do -    resources :compliance_controls +    resources :compliance_controls, except: :index    end    resources :stop_area_referentials, :only => [:show] do diff --git a/db/migrate/20170922121609_add_compliance_control_id_to_compliance_control_blocks.rb b/db/migrate/20170922121609_add_compliance_control_id_to_compliance_control_blocks.rb new file mode 100644 index 000000000..18a6b12cf --- /dev/null +++ b/db/migrate/20170922121609_add_compliance_control_id_to_compliance_control_blocks.rb @@ -0,0 +1,5 @@ +class AddComplianceControlIdToComplianceControlBlocks < ActiveRecord::Migration +  def change +    add_reference :compliance_control_blocks, :compliance_control, index: true, foreign_key: true +  end +end diff --git a/db/migrate/20170922123838_remove_compliance_control_block_id_from_compliance_controls.rb b/db/migrate/20170922123838_remove_compliance_control_block_id_from_compliance_controls.rb new file mode 100644 index 000000000..e3a6dfcb4 --- /dev/null +++ b/db/migrate/20170922123838_remove_compliance_control_block_id_from_compliance_controls.rb @@ -0,0 +1,5 @@ +class RemoveComplianceControlBlockIdFromComplianceControls < ActiveRecord::Migration +  def change +    remove_reference :compliance_controls, :compliance_control_block, index: true, foreign_key: true +  end +end diff --git a/db/migrate/20170925123159_add_output_to_workbenches.rb b/db/migrate/20170925123159_add_output_to_workbenches.rb new file mode 100644 index 000000000..d6aea96a0 --- /dev/null +++ b/db/migrate/20170925123159_add_output_to_workbenches.rb @@ -0,0 +1,5 @@ +class AddOutputToWorkbenches < ActiveRecord::Migration +  def change +    add_column :workbenches, :output_id, :bigint, index: true +  end +end diff --git a/db/migrate/20170925154017_create_referential_suite_for_each_existing_workbench.rb b/db/migrate/20170925154017_create_referential_suite_for_each_existing_workbench.rb new file mode 100644 index 000000000..530850a5a --- /dev/null +++ b/db/migrate/20170925154017_create_referential_suite_for_each_existing_workbench.rb @@ -0,0 +1,12 @@ +class CreateReferentialSuiteForEachExistingWorkbench < ActiveRecord::Migration +  def up +    Workbench.where(output: nil).each do |workbench| +      workbench.output = ReferentialSuite.create +      workbench.save +    end +  end + +  def down +    raise ActiveRecord::IrreversibleMigration +  end +end diff --git a/db/migrate/20170927095022_add_origin_code_to_compliance_controls.rb b/db/migrate/20170927095022_add_origin_code_to_compliance_controls.rb new file mode 100644 index 000000000..36f109b91 --- /dev/null +++ b/db/migrate/20170927095022_add_origin_code_to_compliance_controls.rb @@ -0,0 +1,5 @@ +class AddOriginCodeToComplianceControls < ActiveRecord::Migration +  def change +    add_column :compliance_controls, :origin_code, :string +  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/schema.rb b/db/schema.rb index 89f002aee..a8c90b111 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: 20170922165315) do +ActiveRecord::Schema.define(version: 20170925154017) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -217,8 +217,10 @@ ActiveRecord::Schema.define(version: 20170922165315) 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| @@ -232,18 +234,16 @@ ActiveRecord::Schema.define(version: 20170922165315) do    create_table "compliance_controls", id: :bigserial, force: :cascade do |t|      t.integer  "compliance_control_set_id" -    t.integer  "compliance_control_block_id"      t.string   "type"      t.json     "control_attributes"      t.string   "name"      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    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| @@ -969,6 +969,7 @@ ActiveRecord::Schema.define(version: 20170922165315) do      t.datetime "updated_at"      t.integer  "line_referential_id",      limit: 8      t.integer  "stop_area_referential_id", limit: 8 +    t.integer  "output_id",                limit: 8    end    add_index "workbenches", ["line_referential_id"], name: "index_workbenches_on_line_referential_id", using: :btree @@ -986,8 +987,8 @@ ActiveRecord::Schema.define(version: 20170922165315) 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/spec/controllers/compliance_controls_controller_spec.rb b/spec/controllers/compliance_controls_controller_spec.rb index 165c00329..a39408ccb 100644 --- a/spec/controllers/compliance_controls_controller_spec.rb +++ b/spec/controllers/compliance_controls_controller_spec.rb @@ -3,8 +3,10 @@ require 'rails_helper'  RSpec.describe ComplianceControlsController, type: :controller do    login_user -  let(:compliance_control)     { create :compliance_control } -  let(:compliance_control_set) { compliance_control.compliance_control_set } + +  let(:compliance_control)        { create(:compliance_control) } +  let!(:compliance_control_set)   { compliance_control.compliance_control_set } +  let(:compliance_control_params) { compliance_control.as_json.merge(type: 'GenericAttributeControl::MinMax') }    describe "GET show" do      it 'should be successful' do @@ -13,13 +15,6 @@ RSpec.describe ComplianceControlsController, type: :controller do      end    end -  describe "GET index" do -    it 'should be successful' do -      get :index, compliance_control_set_id: compliance_control_set.id -      expect(response).to be_success -    end -  end -    describe 'GET #edit' do      it 'should be successful' do        get :edit, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id @@ -36,24 +31,24 @@ RSpec.describe ComplianceControlsController, type: :controller do    describe 'POST #create' do      it 'should be successful' do -      post :create, compliance_control_set_id: compliance_control_set.id, compliance_control: build(:compliance_control).as_json +      post :create, compliance_control_set_id: compliance_control_set.id, compliance_control: compliance_control_params        expect(response).to have_http_status(302) -      expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.created'))      end    end    describe 'POST #update' do      it 'should be successful' do -      post :update, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id, compliance_control: compliance_control.as_json +      post :update, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id, compliance_control: compliance_control_params        expect(response).to redirect_to compliance_control_set_compliance_control_path(compliance_control_set, compliance_control) -      expect(flash[:notice]).to eq(I18n.t('notice.compliance_control.updated'))      end    end    describe 'DELETE #destroy' do      it 'should be successful' do -      delete :destroy, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id -      expect(flash[:notice]).to eq I18n.t('notice.compliance_control.destroyed') +      expect { +        delete :destroy, compliance_control_set_id: compliance_control_set.id, id: compliance_control.id +      }.to change(GenericAttributeControl::MinMax, :count).by(-1) +      expect(response).to have_http_status(302)      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 5bc45cc75..1b043324e 100644 --- a/spec/factories/compliance_control_blocks.rb +++ b/spec/factories/compliance_control_blocks.rb @@ -2,5 +2,6 @@ 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 8aa16b674..ced505565 100644 --- a/spec/factories/compliance_controls.rb +++ b/spec/factories/compliance_controls.rb @@ -1,11 +1,11 @@  FactoryGirl.define do    factory :compliance_control do      sequence(:name) { |n| "Compliance control #{n}" } -    type "ComplianceControl" +    type "GenericAttributeControl::MinMax"      criticity :warning      code "code" +    origin_code "code"      comment "Text"      association :compliance_control_set -    association :compliance_control_block    end  end diff --git a/spec/factories/referential_suites.rb b/spec/factories/referential_suites.rb new file mode 100644 index 000000000..bb17b085c --- /dev/null +++ b/spec/factories/referential_suites.rb @@ -0,0 +1,3 @@ +FactoryGirl.define do +  factory :referential_suite +end diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb index d55141513..57bef2203 100644 --- a/spec/factories/workbenches.rb +++ b/spec/factories/workbenches.rb @@ -5,5 +5,6 @@ FactoryGirl.define do      association :organisation      association :line_referential      association :stop_area_referential +    association :output, factory: :referential_suite    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 248049b0c..f45ec3d42 100644 --- a/spec/models/compliance_control_block_spec.rb +++ b/spec/models/compliance_control_block_spec.rb @@ -1,9 +1,12 @@  require 'rails_helper'  RSpec.describe ComplianceControlBlock, type: :model do +  subject { create(:compliance_control_block) } +    it 'should have a valid factory' do      expect(FactoryGirl.build(:compliance_control_block)).to be_valid    end    it { should belong_to :compliance_control_set } +  it { should belong_to :compliance_control }  end diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb index ededec5e0..edc684bbc 100644 --- a/spec/models/compliance_control_set_spec.rb +++ b/spec/models/compliance_control_set_spec.rb @@ -6,7 +6,7 @@ RSpec.describe ComplianceControlSet, type: :model do    end    it { should belong_to :organisation } -  it { should have_many :compliance_controls } +  it { should have_many(:compliance_controls).dependent(:destroy) }    it { should validate_presence_of :name }  end diff --git a/spec/models/compliance_control_spec.rb b/spec/models/compliance_control_spec.rb index b00ff4c5a..d7bffb0b2 100644 --- a/spec/models/compliance_control_spec.rb +++ b/spec/models/compliance_control_spec.rb @@ -1,14 +1,41 @@  require 'rails_helper'  RSpec.describe ComplianceControl, type: :model do + +  let(:compliance_control) { create :compliance_control } +    it 'should have a valid factory' do -    expect(FactoryGirl.build(:compliance_control)).to be_valid +    expect(compliance_control).to be_valid    end    it { should belong_to :compliance_control_set } -  it { should belong_to :compliance_control_block } +  it { should have_one(:compliance_control_block).dependent(:destroy) } + +  it 'should validate_presence_of criticity' do +    compliance_control.criticity = nil +    expect(compliance_control).not_to be_valid +  end + +  it 'should validate_presence_of name' do +    compliance_control.name = nil +    expect(compliance_control).not_to be_valid +  end + +  it 'should validate_presence_of code' do +    compliance_control.code = nil +    expect(compliance_control).not_to be_valid +  end + +  it 'should validate_presence_of origin_code' do +    compliance_control.origin_code = nil +    expect(compliance_control).not_to be_valid +  end -  it { should validate_presence_of :criticity } -  it { should validate_presence_of :name } -  it { should validate_presence_of :code } +  #TODO dont know why the 'shortcuts' below to validates presence dont work +  # That's why we dont it 'manually' +  # 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/workbench_spec.rb b/spec/models/workbench_spec.rb index 84149ddb0..037537b60 100644 --- a/spec/models/workbench_spec.rb +++ b/spec/models/workbench_spec.rb @@ -11,6 +11,7 @@ RSpec.describe Workbench, :type => :model do    it { should belong_to(:organisation) }    it { should belong_to(:line_referential) }    it { should belong_to(:stop_area_referential) } +  it { should belong_to(:output).class_name('ReferentialSuite') }    it { should have_many(:lines).through(:line_referential) }    it { should have_many(:networks).through(:line_referential) } @@ -19,6 +20,15 @@ RSpec.describe Workbench, :type => :model do    it { should have_many(:stop_areas).through(:stop_area_referential) } +  it do +    # This callback interferes with the validation test +    Workbench.skip_callback(:validation, :before, :initialize_output) + +    should validate_presence_of(:output) + +    Workbench.set_callback(:validation, :before, :initialize_output) +  end +    context '.lines' do      let!(:ids) { ['STIF:CODIFLIGNE:Line:C00840', 'STIF:CODIFLIGNE:Line:C00086'] }      let!(:organisation) { create :organisation, sso_attributes: { functional_scope: ids.to_json } } @@ -33,4 +43,18 @@ RSpec.describe Workbench, :type => :model do        expect(lines.map(&:objectid)).to include(*ids)      end    end + +  describe ".create" do +    it "must automatically create a ReferentialSuite when being created" do +      workbench = Workbench.create +      expect(workbench.output).to be_an_instance_of(ReferentialSuite) +    end + +    it "must not overwrite a given ReferentialSuite" do +      referential_suite = create(:referential_suite) +      workbench = create(:workbench, output: referential_suite) + +      expect(workbench.output).to eq(referential_suite) +    end +  end  end diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 3b74cb639..6f60bd86b 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -52,8 +52,21 @@ RSpec.configure do |config|        referential.add_member organisation, owner: true      end -    workbench = Workbench.create!(:name => "Gestion de l'offre", organisation: organisation, line_referential: line_referential, stop_area_referential: stop_area_referential) -    referential = Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, workbench: workbench +    workbench = FactoryGirl.create( +      :workbench, +      name: "Gestion de l'offre", +      organisation: organisation, +      line_referential: line_referential, +      stop_area_referential: stop_area_referential +    ) +    referential = FactoryGirl.create( +      :referential, +      prefix: "first", +      name: "first", +      slug: "first", +      organisation: organisation, +      workbench: workbench +    )    end    config.before(:each) do | 
