mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Autocorrect Style/HashConversion offenses
This commit is contained in:
@@ -508,20 +508,6 @@ Style/ClassAndModuleChildren:
|
||||
- 'lib/open_food_network/locking.rb'
|
||||
- 'spec/models/spree/payment_method_spec.rb'
|
||||
|
||||
# Offense count: 10
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
# Configuration parameters: AllowSplatArgument.
|
||||
Style/HashConversion:
|
||||
Exclude:
|
||||
- 'app/controllers/admin/column_preferences_controller.rb'
|
||||
- 'app/controllers/admin/variant_overrides_controller.rb'
|
||||
- 'app/controllers/spree/admin/products_controller.rb'
|
||||
- 'app/models/product_import/product_importer.rb'
|
||||
- 'app/serializers/api/admin/exchange_serializer.rb'
|
||||
- 'app/services/variants_stock_levels.rb'
|
||||
- 'spec/controllers/admin/inventory_items_controller_spec.rb'
|
||||
- 'spec/controllers/admin/variant_overrides_controller_spec.rb'
|
||||
|
||||
# Offense count: 13
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
# Configuration parameters: AllowedReceivers.
|
||||
|
||||
@@ -40,8 +40,8 @@ module Admin
|
||||
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
collection_attributes = Hash[permitted_params[:column_preferences].
|
||||
each_with_index.map { |cp, i| [i, cp] }]
|
||||
collection_attributes = permitted_params[:column_preferences].
|
||||
each_with_index.to_h { |cp, i| [i, cp] }
|
||||
collection_attributes.select!{ |_i, cp|
|
||||
cp[:action_name] == permitted_params[:action_name]
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ module Admin
|
||||
end
|
||||
|
||||
def load_collection
|
||||
collection_hash = Hash[variant_overrides_params.each_with_index.map { |vo, i| [i, vo] }]
|
||||
collection_hash = variant_overrides_params.each_with_index.to_h { |vo, i| [i, vo] }
|
||||
|
||||
# Reset count_on_hand when switching to producer settings:
|
||||
collection_hash.each_value do |vo|
|
||||
|
||||
@@ -134,9 +134,9 @@ module Spree
|
||||
end
|
||||
|
||||
def product_set_from_params
|
||||
collection_hash = Hash[products_bulk_params[:products].each_with_index.map { |p, i|
|
||||
[i, p]
|
||||
} ]
|
||||
collection_hash = products_bulk_params[:products].each_with_index.to_h { |p, i|
|
||||
[i, p]
|
||||
}
|
||||
Sets::ProductSet.new(collection_attributes: collection_hash)
|
||||
end
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ module ProductImport
|
||||
|
||||
def build_entries_from_rows(rows, offset = 0)
|
||||
rows.each_with_index.inject([]) do |entries, (row, i)|
|
||||
row_data = Hash[[headers, row].transpose]
|
||||
row_data = [headers, row].transpose.to_h
|
||||
entry = SpreadsheetEntry.new(row_data)
|
||||
entry.line_number = offset + i + 2
|
||||
entries.push entry
|
||||
|
||||
@@ -11,7 +11,7 @@ module Api
|
||||
|
||||
def variants
|
||||
variants = object.incoming? ? visible_incoming_variants : visible_outgoing_variants
|
||||
Hash[object.variants.merge(variants).map { |v| [v.id, true] }]
|
||||
object.variants.merge(variants).to_h { |v| [v.id, true] }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -25,17 +25,15 @@ class VariantsStockLevels
|
||||
private
|
||||
|
||||
def variant_stock_levels(line_items)
|
||||
Hash[
|
||||
line_items.map do |line_item|
|
||||
variant = scoped_variant(line_item.order.distributor, line_item.variant)
|
||||
line_items.to_h do |line_item|
|
||||
variant = scoped_variant(line_item.order.distributor, line_item.variant)
|
||||
|
||||
[variant.id,
|
||||
{ quantity: line_item.quantity,
|
||||
max_quantity: line_item.max_quantity,
|
||||
on_hand: variant.on_hand,
|
||||
on_demand: variant.on_demand }]
|
||||
end
|
||||
]
|
||||
[variant.id,
|
||||
{ quantity: line_item.quantity,
|
||||
max_quantity: line_item.max_quantity,
|
||||
on_hand: variant.on_hand,
|
||||
on_demand: variant.on_demand }]
|
||||
end
|
||||
end
|
||||
|
||||
def scoped_variant(distributor, variant)
|
||||
|
||||
@@ -68,7 +68,7 @@ RSpec.describe Admin::InventoryItemsController, type: :controller do
|
||||
|
||||
it "returns an error message" do
|
||||
expect{ spree_post :create, bad_params }.to change{ InventoryItem.count }.by(0)
|
||||
expect(response.body).to eq Hash[:errors, ["Visible must be true or false"]].to_json
|
||||
expect(response.body).to eq { :errors => ["Visible must be true or false"] }.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -134,7 +134,7 @@ RSpec.describe Admin::InventoryItemsController, type: :controller do
|
||||
|
||||
it "returns an error message" do
|
||||
expect{ spree_put :update, bad_params }.to change{ InventoryItem.count }.by(0)
|
||||
expect(response.body).to eq Hash[:errors, ["Visible must be true or false"]].to_json
|
||||
expect(response.body).to eq { :errors => ["Visible must be true or false"] }.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -60,7 +60,7 @@ RSpec.describe Admin::VariantOverridesController, type: :controller do
|
||||
put :bulk_update, as: format, params: { variant_overrides: variant_override_params }
|
||||
expect(assigns[:hubs]).to eq [hub]
|
||||
expect(assigns[:producers]).to eq [variant.supplier]
|
||||
expect(assigns[:hub_permissions]).to eq Hash[hub.id, [variant.supplier.id]]
|
||||
expect(assigns[:hub_permissions]).to eq({ hub.id => [variant.supplier.id] })
|
||||
expect(assigns[:inventory_items]).to eq [inventory_item]
|
||||
end
|
||||
|
||||
@@ -163,7 +163,7 @@ RSpec.describe Admin::VariantOverridesController, type: :controller do
|
||||
put(:bulk_reset, params:)
|
||||
expect(assigns[:hubs]).to eq [hub]
|
||||
expect(assigns[:producers]).to eq [producer]
|
||||
expect(assigns[:hub_permissions]).to eq Hash[hub.id, [producer.id]]
|
||||
expect(assigns[:hub_permissions]).to eq({ hub.id => [producer.id] })
|
||||
expect(assigns[:inventory_items]).to eq []
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user