Permalink
Browse files

Fix rubocop Issues: Lint/UnusedBlockArgument

  • Loading branch information...
1 parent 0d833ec commit 0cc96fa16e16808df7d5a8da83e3e001affc4607 @zorafuchs zorafuchs committed Dec 20, 2016
View
@@ -36,17 +36,6 @@ Lint/ShadowingOuterLocalVariable:
# Offense count: 16
# Cop supports --auto-correct.
-# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
-Lint/UnusedBlockArgument:
- Exclude:
- - 'lib/cancan/controller_resource.rb'
- - 'lib/cancan/model_adapters/mongoid_adapter.rb'
- - 'spec/cancan/ability_spec.rb'
- - 'spec/cancan/controller_additions_spec.rb'
- - 'spec/cancan/controller_resource_spec.rb'
-
-# Offense count: 16
-# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
Lint/UnusedMethodArgument:
Exclude:
@@ -98,7 +98,7 @@ def assign_attributes(resource)
end
def initial_attributes
- current_ability.attributes_for(@params[:action].to_sym, resource_class).delete_if do |key, value|
+ current_ability.attributes_for(@params[:action].to_sym, resource_class).delete_if do |key, _value|
resource_params && resource_params.include?(key)
end
end
@@ -6,7 +6,7 @@ def self.for_class?(model_class)
end
def self.override_conditions_hash_matching?(subject, conditions)
- conditions.any? do |k,v|
+ conditions.any? do |k,_v|
key_is_not_symbol = lambda { !k.kind_of?(Symbol) }
subject_value_is_array = lambda do
subject.respond_to?(k) && subject.send(k).is_a?(Array)
@@ -17,7 +17,7 @@
it 'passes true to `can?` when non false/nil is returned in block' do
@ability.can :read, :all
- @ability.can :read, Symbol do |sym|
+ @ability.can :read, Symbol do |_sym|
'foo' # TODO test that sym is nil when no instance is passed
end
expect(@ability.can?(:read, :some_symbol)).to be(true)
@@ -79,7 +79,7 @@
it 'does not call block when only class is passed, only return true' do
@block_called = false
- @ability.can :preview, :all do |object|
+ @ability.can :preview, :all do |_object|
@block_called = true
end
expect(@ability.can?(:preview, Hash)).to be(true)
@@ -441,7 +441,7 @@ class Container < Hash; end
it 'knows when block is used in conditions' do
@ability.can :read, :foo
expect(@ability).to_not have_block(:read, :foo)
- @ability.can :read, :foo do |foo|
+ @ability.can :read, :foo do |_foo|
false
end
expect(@ability).to have_block(:read, :foo)
@@ -33,14 +33,14 @@
it 'load_and_authorize_resource setups a before filter which passes call to ControllerResource' do
expect(cancan_resource_class = double).to receive(:load_and_authorize_resource)
allow(CanCan::ControllerResource).to receive(:new).with(@controller, nil, foo: :bar) {cancan_resource_class }
- expect(@controller_class).to receive(callback_action(:before_action)).with({}) { |options, &block| block.call(@controller) }
+ expect(@controller_class).to receive(callback_action(:before_action)).with({}) { |_options, &block| block.call(@controller) }
@controller_class.load_and_authorize_resource foo: :bar
end
it 'load_and_authorize_resource properly passes first argument as the resource name' do
expect(cancan_resource_class = double).to receive(:load_and_authorize_resource)
allow(CanCan::ControllerResource).to receive(:new).with(@controller, :project, foo: :bar) {cancan_resource_class}
- expect(@controller_class).to receive(callback_action(:before_action)).with({}) { |options, &block| block.call(@controller) }
+ expect(@controller_class).to receive(callback_action(:before_action)).with({}) { |_options, &block| block.call(@controller) }
@controller_class.load_and_authorize_resource :project, foo: :bar
end
@@ -52,49 +52,49 @@
it 'authorize_resource setups a before filter which passes call to ControllerResource' do
expect(cancan_resource_class = double).to receive(:authorize_resource)
allow(CanCan::ControllerResource).to receive(:new).with(@controller, nil, foo: :bar) {cancan_resource_class}
- expect(@controller_class).to receive(callback_action(:before_action)).with(except: :show, if: true) { |options, &block| block.call(@controller) }
+ expect(@controller_class).to receive(callback_action(:before_action)).with(except: :show, if: true) { |_options, &block| block.call(@controller) }
@controller_class.authorize_resource foo: :bar, except: :show, if: true
end
it 'load_resource setups a before filter which passes call to ControllerResource' do
expect(cancan_resource_class = double).to receive(:load_resource)
allow(CanCan::ControllerResource).to receive(:new).with(@controller, nil, foo: :bar) {cancan_resource_class}
- expect(@controller_class).to receive(callback_action(:before_action)).with(only: [:show, :index], unless: false) { |options, &block| block.call(@controller) }
+ expect(@controller_class).to receive(callback_action(:before_action)).with(only: [:show, :index], unless: false) { |_options, &block| block.call(@controller) }
@controller_class.load_resource foo: :bar, only: [:show, :index], unless: false
end
it 'skip_authorization_check setups a before filter which sets @_authorized to true' do
- expect(@controller_class).to receive(callback_action(:before_action)).with(:filter_options) { |options, &block| block.call(@controller) }
+ expect(@controller_class).to receive(callback_action(:before_action)).with(:filter_options) { |_options, &block| block.call(@controller) }
@controller_class.skip_authorization_check(:filter_options)
expect(@controller.instance_variable_get(:@_authorized)).to be(true)
end
it 'check_authorization triggers AuthorizationNotPerformed in after filter' do
- expect(@controller_class).to receive(callback_action(:after_action)).with(only: [:test]) { |options, &block| block.call(@controller) }
+ expect(@controller_class).to receive(callback_action(:after_action)).with(only: [:test]) { |_options, &block| block.call(@controller) }
expect {
@controller_class.check_authorization(only: [:test])
}.to raise_error(CanCan::AuthorizationNotPerformed)
end
it 'check_authorization does not trigger AuthorizationNotPerformed when :if is false' do
allow(@controller).to receive(:check_auth?) { false }
- allow(@controller_class).to receive(callback_action(:after_action)).with({}) { |options, &block| block.call(@controller) }
+ allow(@controller_class).to receive(callback_action(:after_action)).with({}) { |_options, &block| block.call(@controller) }
expect {
@controller_class.check_authorization(if: :check_auth?)
}.not_to raise_error
end
it 'check_authorization does not trigger AuthorizationNotPerformed when :unless is true' do
allow(@controller).to receive(:engine_controller?) { true }
- expect(@controller_class).to receive(callback_action(:after_action)).with({}) { |options, &block| block.call(@controller) }
+ expect(@controller_class).to receive(callback_action(:after_action)).with({}) { |_options, &block| block.call(@controller) }
expect {
@controller_class.check_authorization(unless: :engine_controller?)
}.not_to raise_error
end
it 'check_authorization does not raise error when @_authorized is set' do
@controller.instance_variable_set(:@_authorized, true)
- expect(@controller_class).to receive(callback_action(:after_action)).with(only: [:test]) { |options, &block| block.call(@controller) }
+ expect(@controller_class).to receive(callback_action(:after_action)).with(only: [:test]) { |_options, &block| block.call(@controller) }
expect {
@controller_class.check_authorization(only: [:test])
}.not_to raise_error
@@ -155,7 +155,7 @@ class HiddenModel < ::Model; end
end
it 'accepts the specified proc for sanitizing input' do
- resource = CanCan::ControllerResource.new(controller, {param_method: Proc.new { |c| {custom: 'params'}}})
+ resource = CanCan::ControllerResource.new(controller, {param_method: Proc.new { |_c| {custom: 'params'}}})
expect(resource.send('resource_params')).to eq(custom: 'params')
end
@@ -209,7 +209,7 @@ class HiddenModel < ::Model; end
it 'does not use accessible_by when defining abilities through a block' do
allow(Model).to receive(:accessible_by).with(ability) { :found_models }
- ability.can(:read, Model) { |p| false }
+ ability.can(:read, Model) { |_p| false }
resource = CanCan::ControllerResource.new(controller)
resource.load_resource
expect(controller.instance_variable_get(:@model)).to be_nil

0 comments on commit 0cc96fa

Please sign in to comment.