Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rubocop Rails/NegateInclude issues #12337

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -668,16 +668,6 @@ Rails/LexicallyScopedActionFilter:
- 'app/controllers/spree/admin/zones_controller.rb'
- 'app/controllers/spree/users_controller.rb'

# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/NegateInclude:
Exclude:
- 'app/controllers/admin/resource_controller.rb'
- 'app/models/calculator/weight.rb'
- 'app/models/product_import/spreadsheet_entry.rb'
- 'lib/spree/localized_number.rb'
- 'spec/support/matchers/table_matchers.rb'

# Offense count: 32
# This cop supports unsafe autocorrection (--autocorrect-all).
Rails/Pluck:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def collection_actions
end

def member_action?
!collection_actions.include? action
collection_actions.exclude? action
end

def new_actions
Expand Down
2 changes: 1 addition & 1 deletion app/models/calculator/weight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.description
end

def set_preference(name, value)
if name == :unit_from_list && !["kg", "lb"].include?(value)
if name == :unit_from_list && ["kg", "lb"].exclude?(value)
calculable.errors.add(:preferred_unit_from_list, I18n.t(:calculator_preferred_unit_error))
else
__send__ self.class.preference_setter_method(name), value
Expand Down
2 changes: 1 addition & 1 deletion app/models/product_import/spreadsheet_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def assign_units(attrs)
units = UnitConverter.new(attrs)

units.converted_attributes.each do |attr, value|
if respond_to?("#{attr}=") && !NON_PRODUCT_ATTRIBUTES.include?(attr)
if respond_to?("#{attr}=") && NON_PRODUCT_ATTRIBUTES.exclude?(attr)
public_send("#{attr}=", value)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/spree/localized_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def self.add_trailing_zeros(number)
private

def non_activerecord_attribute?(attribute)
table_exists? && !column_names.include?(attribute.to_s)
table_exists? && column_names.exclude?(attribute.to_s)
rescue ::ActiveRecord::NoDatabaseError
# This class is now loaded during `rake db:create` (since Rails 5.2), and not only does the
# table not exist, but the database does not even exist yet, and throws a fatal error.
Expand Down
2 changes: 1 addition & 1 deletion spec/support/matchers/table_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

match_when_negated do |node|
@row = row
!rows_under(node).include? row # Robust check of columns
rows_under(node).exclude? row # Robust check of columns
end

failure_message do |text|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
end

it "select all products" do
# replace with scroll_to method when upgrading to Capybara >= 3.13.0
checkbox_id = "order_cycle_incoming_exchange_0_select_all_variants"
page.execute_script("document.getElementById('#{checkbox_id}').scrollIntoView()")
elmnt = find_field(id: checkbox_id)
scroll_to(elmnt, align: :top)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • That's great to incorporate the latest recommended method.
  • By looking at the flaky spec, we are not getting the element bycheckbox_id
  • Like the proposed changes, I think it's worth trying to use the built-in capybara method as opposed to running the JS script for the purpose
  • Let's hope for the best now :)

check checkbox_id

expect_all_products_loaded
Expand Down
Loading