diff options
| -rw-r--r-- | app/controllers/calendars_controller.rb | 21 | ||||
| -rw-r--r-- | app/decorators/calendar_decorator.rb | 2 | ||||
| -rw-r--r-- | app/decorators/company_decorator.rb | 19 | ||||
| -rw-r--r-- | app/decorators/compliance_control_decorator.rb | 18 | ||||
| -rw-r--r-- | app/decorators/import_decorator.rb | 7 | ||||
| -rw-r--r-- | app/decorators/line_decorator.rb | 10 | ||||
| -rw-r--r-- | app/decorators/network_decorator.rb | 14 | ||||
| -rw-r--r-- | app/decorators/purchase_window_decorator.rb | 18 | ||||
| -rw-r--r-- | app/decorators/referential_line_decorator.rb | 10 | ||||
| -rw-r--r-- | app/decorators/referential_network_decorator.rb | 21 | ||||
| -rw-r--r-- | app/decorators/route_decorator.rb | 29 | ||||
| -rw-r--r-- | app/decorators/routing_constraint_zone_decorator.rb | 39 | ||||
| -rw-r--r-- | app/decorators/stop_area_decorator.rb | 22 | ||||
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 1 | ||||
| -rw-r--r-- | lib/af83/decorator.rb | 63 | ||||
| -rw-r--r-- | lib/af83/decorator/enhanced_decorator.rb | 22 | ||||
| -rw-r--r-- | lib/af83/decorator/link.rb | 3 | ||||
| -rw-r--r-- | spec/support/pundit/pundit_view_policy.rb | 5 | ||||
| -rw-r--r-- | spec/support/referential.rb | 4 | ||||
| -rw-r--r-- | spec/views/referentials/show.html.erb_spec.rb | 6 | 
20 files changed, 114 insertions, 220 deletions
| diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 193680342..6f1522428 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -4,7 +4,7 @@ class CalendarsController < ChouetteController    before_action :ransack_contains_date, only: [:index]    respond_to :html    respond_to :js, only: :index -   +    belongs_to :workgroup    def index @@ -24,9 +24,8 @@ class CalendarsController < ChouetteController    private    def decorate_calendars(calendars) -    ModelDecorator.decorate( +    CalendarDecorator.decorate(        calendars, -      with: CalendarDecorator,        context: {          workgroup: workgroup        } @@ -65,13 +64,13 @@ class CalendarsController < ChouetteController    def collection      @calendars ||= begin -		    scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true) -		    scope = shared_scope(scope) -		    @q = scope.ransack(params[:q]) -		    calendars = @q.result -		    calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction -		    calendars = calendars.paginate(page: params[:page]) -                  end  +      scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true) +      scope = shared_scope(scope) +      @q = scope.ransack(params[:q]) +      calendars = @q.result +      calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction +      calendars = calendars.paginate(page: params[:page]) +    end    end    def ransack_contains_date @@ -96,4 +95,4 @@ class CalendarsController < ChouetteController      scope    end -end
\ No newline at end of file +end diff --git a/app/decorators/calendar_decorator.rb b/app/decorators/calendar_decorator.rb index be1f9e3bf..0a7cbc312 100644 --- a/app/decorators/calendar_decorator.rb +++ b/app/decorators/calendar_decorator.rb @@ -1,6 +1,8 @@  class CalendarDecorator < AF83::Decorator    decorates Calendar +  set_scope { context[:workgroup] } +    create_action_link    with_instance_decorator do |instance_decorator| diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb index aadce68bb..5580e0d4a 100644 --- a/app/decorators/company_decorator.rb +++ b/app/decorators/company_decorator.rb @@ -1,34 +1,21 @@  class CompanyDecorator < AF83::Decorator    decorates Chouette::Company +  set_scope { context[:referential] } +    create_action_link do |l|      l.content { h.t('companies.actions.new') } -    l.href    { [:new, context[:referential], :company] }    end    with_instance_decorator do |instance_decorator| -    instance_decorator.show_action_link do |l| -      l.href { [context[:referential], object] } -    end +    instance_decorator.show_action_link      instance_decorator.edit_action_link do |l|        l.content {|l| l.action == "show" ? h.t('actions.edit') : h.t('companies.actions.edit') } -      l.href { -        h.edit_line_referential_company_path( -          context[:referential], -          object -        ) -      }      end      instance_decorator.destroy_action_link do |l|        l.content { h.destroy_link_content('companies.actions.destroy') } -      l.href { -        h.edit_line_referential_company_path( -          context[:referential], -          object -        ) -      }        l.data {{ confirm: h.t('companies.actions.destroy_confirm') }}      end    end diff --git a/app/decorators/compliance_control_decorator.rb b/app/decorators/compliance_control_decorator.rb index c57a7ccc7..fd2dbd9ce 100644 --- a/app/decorators/compliance_control_decorator.rb +++ b/app/decorators/compliance_control_decorator.rb @@ -1,6 +1,8 @@  class ComplianceControlDecorator < AF83::Decorator    decorates ComplianceControl +  set_scope { object.compliance_control_set } +    with_instance_decorator do |instance_decorator|      instance_decorator.show_action_link do |l|        l.content h.t('compliance_control_sets.actions.show') @@ -12,23 +14,9 @@ class ComplianceControlDecorator < AF83::Decorator        end      end -    instance_decorator.edit_action_link do |l| -      l.href do -        h.edit_compliance_control_set_compliance_control_path( -          object.compliance_control_set_id, -          object.id -        ) -      end -    end +    instance_decorator.edit_action_link      instance_decorator.destroy_action_link do |l| -      l.content h.destroy_link_content -      l.href do -        h.compliance_control_set_compliance_control_path( -          object.compliance_control_set.id, -          object.id -        ) -      end        l.data confirm: h.t('compliance_controls.actions.destroy_confirm')      end    end diff --git a/app/decorators/import_decorator.rb b/app/decorators/import_decorator.rb index c6b1f2349..1964365ae 100644 --- a/app/decorators/import_decorator.rb +++ b/app/decorators/import_decorator.rb @@ -1,6 +1,8 @@  class ImportDecorator < AF83::Decorator    decorates Import +  set_scope { context[:workbench] } +    define_instance_method :import_status_css_class do      cls =''      cls = 'overheaded-success' if object.status == 'successful' @@ -11,13 +13,10 @@ class ImportDecorator < AF83::Decorator    create_action_link do |l|      l.content t('imports.actions.new') -    l.href { h.new_workbench_import_path(workbench_id: context[:workbench]) }    end    with_instance_decorator do |instance_decorator| -    instance_decorator.show_action_link do |l| -      l.href { h.workbench_import_path(context[:workbench], object) } -    end +    instance_decorator.show_action_link      instance_decorator.action_link secondary: :show do |l|        l.content t('imports.actions.download') diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb index 9171a6310..039ad90a3 100644 --- a/app/decorators/line_decorator.rb +++ b/app/decorators/line_decorator.rb @@ -1,9 +1,10 @@  class LineDecorator < AF83::Decorator    decorates Chouette::Line +  set_scope { context[:line_referential] } +    create_action_link do |l|      l.content t('lines.actions.new') -    l.href    { h.new_line_referential_line_path(context[:line_referential]) }    end    with_instance_decorator do |instance_decorator| @@ -14,17 +15,16 @@ class LineDecorator < AF83::Decorator      instance_decorator.show_action_link do |l|        l.content t('lines.actions.show') -      l.href   { [context[:line_referential], object] }      end      instance_decorator.action_link secondary: :show do |l|        l.content t('lines.actions.show_network') -      l.href   { [context[:line_referential], object.network] } +      l.href   { [scope, object.network] }      end      instance_decorator.action_link secondary: :show do |l|        l.content  t('lines.actions.show_company') -      l.href     { [context[:line_referential], object.company] } +      l.href     { [scope, object.company] }        l.disabled { object.company.nil? }      end @@ -33,7 +33,6 @@ class LineDecorator < AF83::Decorator      instance_decorator.with_condition can_edit_line do        edit_action_link do |l|          l.content {|l| l.primary? ? h.t('actions.edit') : h.t('lines.actions.edit') } -        l.href    { h.edit_line_referential_line_path(context[:line_referential], object.id) }        end        action_link on: :index, secondary: :index do |l| @@ -63,7 +62,6 @@ class LineDecorator < AF83::Decorator      instance_decorator.destroy_action_link do |l|        l.content  { h.destroy_link_content('lines.actions.destroy') } -      l.href     { h.line_referential_line_path(context[:line_referential], object) }        l.data     confirm: h.t('lines.actions.destroy_confirm')        l.add_class "delete-action"      end diff --git a/app/decorators/network_decorator.rb b/app/decorators/network_decorator.rb index 90f0d0e82..ea0f73dc2 100644 --- a/app/decorators/network_decorator.rb +++ b/app/decorators/network_decorator.rb @@ -1,6 +1,7 @@  class NetworkDecorator < AF83::Decorator    decorates Chouette::Network +  set_scope { context[:line_referential] }    # Action links require:    #   context: {    #     line_referential: , @@ -8,15 +9,10 @@ class NetworkDecorator < AF83::Decorator    create_action_link do |l|      l.content t('networks.actions.new') -    l.href { h.new_line_referential_network_path(context[:line_referential]) }    end    with_instance_decorator do |instance_decorator| -    instance_decorator.show_action_link do |l| -      l.href do -        h.line_referential_network_path(context[:line_referential], object) -      end -    end +    instance_decorator.show_action_link      instance_decorator.action_link secondary: true, policy: :edit do |l|        l.content t('networks.actions.edit') @@ -30,12 +26,6 @@ class NetworkDecorator < AF83::Decorator      instance_decorator.destroy_action_link do |l|        l.content h.destroy_link_content('networks.actions.destroy') -      l.href do -        h.line_referential_network_path( -          context[:line_referential], -          object -        ) -      end        l.data confirm: h.t('networks.actions.destroy_confirm')      end    end diff --git a/app/decorators/purchase_window_decorator.rb b/app/decorators/purchase_window_decorator.rb index 54b241173..9b58577b2 100644 --- a/app/decorators/purchase_window_decorator.rb +++ b/app/decorators/purchase_window_decorator.rb @@ -1,32 +1,20 @@  class PurchaseWindowDecorator < AF83::Decorator    decorates Chouette::PurchaseWindow +  set_scope { context[:referential] } +    create_action_link do |l|      l.content t('purchase_windows.actions.new') -    l.href { h.new_referential_purchase_window_path(context[:referential]) }    end    with_instance_decorator do |instance_decorator|      instance_decorator.show_action_link do |l|        l.content t('purchase_windows.actions.show') -      l.href do -        h.referential_purchase_window_path( -          context[:referential], -          object -        ) -      end      end -    instance_decorator.edit_action_link do |l| -      l.href do -        h.edit_referential_purchase_window_path(context[:referential].id, object) -      end -    end +    instance_decorator.edit_action_link      instance_decorator.destroy_action_link do |l| -      l.href do -        h.referential_purchase_window_path(context[:referential].id, object) -      end        l.data confirm: h.t('purchase_windows.actions.destroy_confirm')      end    end diff --git a/app/decorators/referential_line_decorator.rb b/app/decorators/referential_line_decorator.rb index 8f884a8e0..3ac846d76 100644 --- a/app/decorators/referential_line_decorator.rb +++ b/app/decorators/referential_line_decorator.rb @@ -1,6 +1,8 @@  class ReferentialLineDecorator < AF83::Decorator    decorates Chouette::Line +  set_scope { context[:referential] } +    # Action links require:    #   context: {    #     referential: , @@ -8,9 +10,7 @@ class ReferentialLineDecorator < AF83::Decorator    #   }    with_instance_decorator do |instance_decorator| -    instance_decorator.show_action_link do |l| -      l.href { h.referential_line_path(context[:referential], object) } -    end +    instance_decorator.show_action_link      instance_decorator.action_link secondary: true do |l|        l.content Chouette::Line.human_attribute_name(:footnotes) @@ -21,7 +21,7 @@ class ReferentialLineDecorator < AF83::Decorator        l.content h.t('routing_constraint_zones.index.title')        l.href do          h.referential_line_routing_constraint_zones_path( -          context[:referential], +          scope,            object          )        end @@ -37,7 +37,7 @@ class ReferentialLineDecorator < AF83::Decorator        secondary: true      ) do |l|        l.content h.t('routes.actions.new') -      l.href { h.new_referential_line_route_path(context[:referential], object) } +      l.href { h.new_referential_line_route_path(scope, object) }      end    end  end diff --git a/app/decorators/referential_network_decorator.rb b/app/decorators/referential_network_decorator.rb index ff3467188..c508452c0 100644 --- a/app/decorators/referential_network_decorator.rb +++ b/app/decorators/referential_network_decorator.rb @@ -1,6 +1,8 @@  class ReferentialNetworkDecorator < AF83::Decorator    decorates Chouette::Network +  set_scope { context[:referential] } +    # Action links require:    #   context: {    #     referential: , @@ -8,33 +10,18 @@ class ReferentialNetworkDecorator < AF83::Decorator    create_action_link do |l|      l.content t('networks.actions.new') -    l.href { h.new_referential_network_path(context[:referential]) }    end    with_instance_decorator do |instance_decorator| -    instance_decorator.show_action_link do |l| -      l.href { h.referential_network_path(context[:referential], object) } -    end +    instance_decorator.show_action_link      instance_decorator.edit_action_link do |l|        l.content t('networks.actions.edit') -      l.href do -        h.edit_referential_network_path( -          context[:referential], -          object -        ) -      end      end      instance_decorator.destroy_action_link do |l|        l.content h.destroy_link_content('networks.actions.destroy') -      l.href do -        h.referential_network_path( -          context[:referential], -          object -        ) -      end        l.data confirm: h.t('networks.actions.destroy_confirm')      end    end -end
\ No newline at end of file +end diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb index 7e3ea889f..75ef20d63 100644 --- a/app/decorators/route_decorator.rb +++ b/app/decorators/route_decorator.rb @@ -7,26 +7,12 @@ class RouteDecorator < AF83::Decorator    #     line:    #   } +  set_scope { [context[:referential], context[:line]] } +    with_instance_decorator do |instance_decorator| -    instance_decorator.show_action_link do |l| -      l.href do -        h.referential_line_route_path( -          context[:referential], -          context[:line], -          object -        ) -      end -    end +    instance_decorator.show_action_link -    instance_decorator.edit_action_link do |l| -      l.href do -        h.edit_referential_line_route_path( -          context[:referential], -          context[:line], -          object -        ) -      end -    end +    instance_decorator.edit_action_link      instance_decorator.action_link(        if: ->() { object.stop_points.any? }, @@ -85,13 +71,6 @@ class RouteDecorator < AF83::Decorator      end      instance_decorator.destroy_action_link do |l| -      l.href do -        h.referential_line_route_path( -          context[:referential], -          context[:line], -          object -        ) -      end        l.data confirm: h.t('routes.actions.destroy_confirm')      end    end diff --git a/app/decorators/routing_constraint_zone_decorator.rb b/app/decorators/routing_constraint_zone_decorator.rb index 962625fa7..de73068be 100644 --- a/app/decorators/routing_constraint_zone_decorator.rb +++ b/app/decorators/routing_constraint_zone_decorator.rb @@ -1,6 +1,8 @@  class RoutingConstraintZoneDecorator < AF83::Decorator    decorates Chouette::RoutingConstraintZone +  set_scope { [context[:referential], context[:line]] } +    # Action links require:    #   context: {    #     referential: , @@ -12,44 +14,13 @@ class RoutingConstraintZoneDecorator < AF83::Decorator        h.policy(Chouette::RoutingConstraintZone).create? &&          context[:referential].organisation == h.current_organisation      } -  ) do |l| -    l.href do -      h.new_referential_line_routing_constraint_zone_path( -       context[:referential], -       context[:line] -     ) -    end -  end +  )    with_instance_decorator do |instance_decorator| -    instance_decorator.show_action_link do |l| -      l.href do -        h.referential_line_routing_constraint_zone_path( -          context[:referential], -          context[:line], -          object -        ) -      end -    end - -    instance_decorator.edit_action_link do |l| -      l.href do -        h.edit_referential_line_routing_constraint_zone_path( -          context[:referential], -          context[:line], -          object -        ) -      end -    end +    instance_decorator.show_action_link +    instance_decorator.edit_action_link      instance_decorator.destroy_action_link do |l| -      l.href do -        h.referential_line_routing_constraint_zone_path( -          context[:referential], -          context[:line], -          object -        ) -      end        l.data confirm: h.t('routing_constraint_zones.actions.destroy_confirm')      end    end diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb index 2e57da0e4..525681971 100644 --- a/app/decorators/stop_area_decorator.rb +++ b/app/decorators/stop_area_decorator.rb @@ -7,23 +7,11 @@ class StopAreaDecorator < AF83::Decorator    end    with_instance_decorator do |instance_decorator| -    instance_decorator.show_action_link do |l| -      l.href do -        h.stop_area_referential_stop_area_path( -          object.stop_area_referential, -          object -        ) -      end -    end +    set_scope { object.stop_area_referential } +    instance_decorator.show_action_link      instance_decorator.edit_action_link do |l|        l.content h.t('stop_areas.actions.edit') -      l.href do -        h.edit_stop_area_referential_stop_area_path( -          object.stop_area_referential, -          object -        ) -      end      end      instance_decorator.action_link policy: :deactivate, secondary: true do |l| @@ -54,12 +42,6 @@ class StopAreaDecorator < AF83::Decorator      instance_decorator.destroy_action_link do |l|        l.content h.destroy_link_content('stop_areas.actions.destroy') -      l.href do -        h.stop_area_referential_stop_area_path( -          object.stop_area_referential, -          object -        ) -      end        l.data confirm: h.t('stop_areas.actions.destroy_confirm')      end    end diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index f48075ed9..2068dd23c 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -395,7 +395,6 @@ module TableBuilderHelper      klass << link.extra_class if link.extra_class      klass << 'delete-action' if link.method == :delete      klass << 'disabled' if link.disabled -      content_tag(        :li,        link_to( diff --git a/lib/af83/decorator.rb b/lib/af83/decorator.rb index f990555fe..71cf1170d 100644 --- a/lib/af83/decorator.rb +++ b/lib/af83/decorator.rb @@ -2,40 +2,49 @@ class AF83::Decorator < ModelDecorator    include AF83::Decorator::EnhancedDecorator    extend AF83::Decorator::EnhancedDecorator::ClassMethods -  def self.decorates klass -    instance_decorator.decorates klass -  end +  class << self +    def decorates klass +      instance_decorator.decorates klass +    end -  def self.instance_decorator -    @instance_decorator ||= begin -      klass = Class.new(AF83::Decorator::InstanceDecorator) -      klass.delegate_all -      klass +    def instance_decorator +      @instance_decorator ||= begin +        klass = Class.new(AF83::Decorator::InstanceDecorator) +        klass.delegate_all +        klass +      end      end -  end -  def self.with_instance_decorator -    @_with_instance_decorator = true -    yield instance_decorator -    @_with_instance_decorator = false -  end +    def with_instance_decorator +      @_with_instance_decorator = true +      yield instance_decorator +      @_with_instance_decorator = false +    end + +    def decorate object, options = {} +      if object.is_a?(ActiveRecord::Base) +        return instance_decorator.decorate object, options +      else +        self.new object, options.update(with: instance_decorator) +      end +    end -  def self.decorate object, options = {} -    if object.is_a?(ActiveRecord::Base) -      return instance_decorator.decorate object, options -    else -      self.new object, options.update(with: instance_decorator) +    def define_instance_method method_name, &block +      instance_decorator.send(:define_method, method_name, &block)      end -  end -  def self.define_instance_method method_name, &block -    instance_decorator.send(:define_method, method_name, &block) -  end +    # Defines a class method on the decorated object's class. These +    # can be called like `object.class.my_method`. +    def define_instance_class_method method_name, &block +      instance_decorator.send(:define_singleton_method, method_name, &block) +    end + +    def set_scope_with_instance_decorator value=nil, &block +      set_scope_without_instance_decorator value, &block +      instance_decorator.set_scope value, &block +    end -  # Defines a class method on the decorated object's class. These -  # can be called like `object.class.my_method`. -  def self.define_instance_class_method method_name, &block -    instance_decorator.send(:define_singleton_method, method_name, &block) +    alias_method_chain :set_scope, :instance_decorator    end    class ActionLinks diff --git a/lib/af83/decorator/enhanced_decorator.rb b/lib/af83/decorator/enhanced_decorator.rb index 904d1b2da..fff8bb8b3 100644 --- a/lib/af83/decorator/enhanced_decorator.rb +++ b/lib/af83/decorator/enhanced_decorator.rb @@ -25,7 +25,7 @@ module AF83::Decorator::EnhancedDecorator          policy: :create,          before_block: -> (l){            l.content { h.t('actions.add') } -          l.href    { [:new, object.klass.name.underscore.singularize] } +          l.href    { [:new, scope, object.klass.model_name.singular] }          }        }        action_link opts.update(args), &block @@ -37,7 +37,7 @@ module AF83::Decorator::EnhancedDecorator          primary: :index,          before_block: -> (l){            l.content { h.t('actions.show') } -          l.href { [object] } +          l.href { [scope, object] }          }        }        action_link opts.update(args), &block @@ -49,7 +49,7 @@ module AF83::Decorator::EnhancedDecorator          policy: :edit,          before_block: -> (l){            l.content { h.t('actions.edit') } -          l.href { [:edit, object] } +          l.href { [:edit, scope, object] }          }        }        action_link opts.update(args), &block @@ -62,7 +62,7 @@ module AF83::Decorator::EnhancedDecorator          secondary: :show,          before_block: -> (l){            l.content { h.destroy_link_content } -          l.href { [object] } +          l.href { [scope, object] }            l.method :delete            l.data {{ confirm: h.t('actions.destroy_confirm') }}          } @@ -70,6 +70,14 @@ module AF83::Decorator::EnhancedDecorator        action_link opts.update(args), &block      end +    def set_scope value=nil, &block +      @scope = value || block +    end + +    def scope +      @scope +    end +      def t key        eval  "-> (l){ h.t('#{key}') }"      end @@ -142,4 +150,10 @@ module AF83::Decorator::EnhancedDecorator    def check_feature feature      h.has_feature? feature    end + +  def scope +    scope = self.class.scope +    scope = instance_exec &scope if scope.is_a? Proc +    scope +  end  end diff --git a/lib/af83/decorator/link.rb b/lib/af83/decorator/link.rb index 7d2896e6a..de7106740 100644 --- a/lib/af83/decorator/link.rb +++ b/lib/af83/decorator/link.rb @@ -30,7 +30,8 @@ class AF83::Decorator::Link        @options[name] = block      elsif args.size == 0        out = @options[name] -      out = context.instance_exec(self, &out)  if out.is_a?(Proc) +      out = context.instance_exec(self, &out) if out.is_a?(Proc) +      out = out.flatten.compact if name.to_s == "href" && out.is_a?(Array)        out      else        # we can use l.foo("bar") or l.foo = "bar" diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index 91be0624c..330209049 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -2,9 +2,8 @@ module Pundit    module PunditViewPolicy      def self.included into        into.let(:permissions){ nil } -      into.let(:organisation){ referential.try(:organisation) } -      into.let(:current_referential){ referential || build_stubbed(:referential) } -      into.let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation } +      into.let(:current_referential){ referential || build_stubbed(:referential, organisation: organisation) } +      into.let(:current_user){ create :user, permissions: permissions, organisation: organisation }        into.let(:pundit_user){ UserContext.new(current_user, referential: current_referential) }        into.before do          allow(view).to receive(:pundit_user) { pundit_user } diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 497ff47a8..9acdce73a 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -11,8 +11,8 @@ module ReferentialHelper    def self.included(base)      base.class_eval do        extend ClassMethods -      alias_method :referential, :first_referential -      alias_method :organisation, :first_organisation +      base.let(:referential){ first_referential } +      base.let(:organisation){ first_organisation }      end    end diff --git a/spec/views/referentials/show.html.erb_spec.rb b/spec/views/referentials/show.html.erb_spec.rb index 4a2afe2ca..6fd51949a 100644 --- a/spec/views/referentials/show.html.erb_spec.rb +++ b/spec/views/referentials/show.html.erb_spec.rb @@ -3,20 +3,22 @@ require 'spec_helper'  describe "referentials/show", type: :view do    let!(:referential) do -    referential = create(:referential) +    referential = create(:referential, organisation: organisation)      assign :referential, referential.decorate(context: {        current_organisation: referential.organisation      })    end    let(:permissions){ [] }    let(:current_organisation) { organisation } -  let(:current_offer_workbench) { create :workbench, organisation: current_organisation} +  let(:current_offer_workbench) { create :workbench, organisation: organisation} +  let(:current_workgroup) { current_offer_workbench.workgroup }    let(:readonly){ false }    before :each do      assign :reflines, []      allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench)      allow(view).to receive(:current_organisation).and_return(current_organisation) +    allow(view).to receive(:current_workgroup).and_return(current_workgroup)      allow(view).to receive(:current_user).and_return(current_user)      allow(view).to receive(:resource).and_return(referential) | 
