Module: CancanUnitTest::CanCan::ControllerResource

Extended by:
ActiveSupport::Concern
Defined in:
lib/cancan_unit_test/cancan/controller_resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.show_warningsObject



13
14
15
# File 'lib/cancan_unit_test/cancan/controller_resource.rb', line 13

def self.show_warnings
  @show_warnings ||= false
end

.show_warnings=(value) ⇒ Object



9
10
11
# File 'lib/cancan_unit_test/cancan/controller_resource.rb', line 9

def self.show_warnings= value
  @show_warnings = value
end

Instance Method Details

#_shim_load_and_authorize_resourceObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cancan_unit_test/cancan/controller_resource.rb', line 17

def _shim_load_and_authorize_resource
  model_name = resource_class.model_name.underscore

  stub_finder = StubFinder.new(@controller, :load_and_authorize_resource)

  singleton_stub = stub_finder.find_by_singleton(model_name.to_sym, @options)
  collection_stub = stub_finder.find_by_collection(model_name.to_sym, @options)

  if (singleton_stub || collection_stub)
    self.resource_instance = singleton_stub.call if singleton_stub
    self.collection_instance = collection_stub.call if collection_stub
  else
    warn_about_missing_stub(model_name) if ControllerResource.show_warnings
    _original_load_and_authorize_resource
  end
end