Skip to content

Commit

Permalink
Update Rubocop, enable new cops, fix offenses (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
tagliala committed Mar 4, 2024
1 parent 2ba90dd commit 1f732e2
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 156 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,15 @@ Minitest/NoAssertions:
Minitest/NoTestCases:
Enabled: true

Minitest/NonExecutableTestMethod:
Enabled: true

Minitest/NonPublicTestMethod:
Enabled: true

Minitest/RedundantMessageArgument:
Enabled: true

Minitest/RefuteEmpty:
Enabled: true

Expand Down
23 changes: 12 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ GEM
racc (~> 1.4)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.4)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
psych (5.1.1.1)
Expand Down Expand Up @@ -210,31 +210,32 @@ GEM
rake (13.1.0)
rdoc (6.6.0)
psych (>= 4.0.0)
regexp_parser (2.8.3)
regexp_parser (2.9.0)
reline (0.4.1)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.6)
rubocop (1.59.0)
rubocop (1.61.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-minitest (0.33.0)
rubocop-ast (1.31.1)
parser (>= 3.3.0.4)
rubocop-minitest (0.34.5)
rubocop (>= 1.39, < 2.0)
rubocop-performance (1.19.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-performance (1.20.2)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
simplecov (0.22.0)
Expand Down
8 changes: 4 additions & 4 deletions lib/inherited_resources/base_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def method_for_find
#
def get_resource_ivar #:nodoc:
if instance_variable_defined?(:"@#{resource_instance_name}")
instance_variable_get("@#{resource_instance_name}")
instance_variable_get(:"@#{resource_instance_name}")
else
nil
end
Expand All @@ -226,14 +226,14 @@ def get_resource_ivar #:nodoc:
# Set resource ivar based on the current resource controller.
#
def set_resource_ivar(resource) #:nodoc:
instance_variable_set("@#{resource_instance_name}", resource)
instance_variable_set(:"@#{resource_instance_name}", resource)
end

# Get collection ivar based on the current resource controller.
#
def get_collection_ivar #:nodoc:
if instance_variable_defined?(:"@#{resource_collection_name}")
instance_variable_get("@#{resource_collection_name}")
instance_variable_get(:"@#{resource_collection_name}")
else
nil
end
Expand All @@ -242,7 +242,7 @@ def get_collection_ivar #:nodoc:
# Set collection ivar based on the current resource controller.
#
def set_collection_ivar(collection) #:nodoc:
instance_variable_set("@#{resource_collection_name}", collection)
instance_variable_set(:"@#{resource_collection_name}", collection)
end

# Used to allow to specify success and failure within just one block:
Expand Down
4 changes: 2 additions & 2 deletions lib/inherited_resources/belongs_to_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def evaluate_parent(parent_symbol, parent_config, chain = nil) #:nodoc:

def get_parent_ivar(instance_name) #:nodoc:
instance_variable_defined?(:"@#{instance_name}") &&
instance_variable_get("@#{instance_name}")
instance_variable_get(:"@#{instance_name}")
end

def set_parent_instance(parent_config, chain) #:nodoc:
Expand All @@ -99,7 +99,7 @@ def set_parent_instance(parent_config, chain) #:nodoc:
parent = parent.send(parent_config[:finder], params[parent_config[:param]])
end

instance_variable_set("@#{parent_config[:instance_name]}", parent)
instance_variable_set(:"@#{parent_config[:instance_name]}", parent)
end

# Maps parents_symbols to build association chain. In this case, it
Expand Down
4 changes: 2 additions & 2 deletions lib/inherited_resources/polymorphic_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def parent_class
#
def parent
if parent_type
p = instance_variable_defined?("@#{parent_type}") && instance_variable_get("@#{parent_type}")
p || instance_variable_set("@#{parent_type}", association_chain[-1])
p = instance_variable_defined?(:"@#{parent_type}") && instance_variable_get(:"@#{parent_type}")
p || instance_variable_set(:"@#{parent_type}", association_chain[-1])
end
end

Expand Down
8 changes: 8 additions & 0 deletions test/defaults_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ def test_expose_all_painters_as_instance_variable
assert_equal [mock_painter], assigns(:malarze)
end

def test_collection_instance_variable_should_not_be_set_if_already_defined
@controller.instance_variable_set(:@malarze, [mock_painter])
Malarz.expects(:scoped).never
get :index

assert_equal [mock_painter], assigns(:malarze)
end

def test_expose_the_requested_painter_on_show
Malarz.expects(:find_by_slug).with('forty_two').returns(mock_painter)
get :show, params: { id: 'forty_two' }
Expand Down
Loading

0 comments on commit 1f732e2

Please sign in to comment.