Skip to content

Commit

Permalink
Fix Shadowing outer local variable
Browse files Browse the repository at this point in the history
This fixes the ruby (and also rubocop) warning about shadowing
variables.
  • Loading branch information
jhawthorn committed Feb 16, 2016
1 parent cc6a59e commit e61b99c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 25 deletions.
6 changes: 3 additions & 3 deletions api/spec/requests/ransackable_attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

get "/api/variants?q[product_name_or_sku_cont]=fritos", token: user.spree_api_key

skus = JSON.parse(response.body)['variants'].map { |variant| variant['sku'] }
skus = JSON.parse(response.body)['variants'].map { |x| x['sku'] }
expect(skus).to include variant.sku
expect(skus).not_to include other_variant.sku
end
Expand All @@ -56,7 +56,7 @@

get "/api/products?q[id_eq]=#{product.id}", token: user.spree_api_key

product_names = JSON.parse(response.body)['products'].map { |product| product['name'] }
product_names = JSON.parse(response.body)['products'].map { |x| x['name'] }
expect(product_names).to include product.name
expect(product_names).not_to include other_product.name
end
Expand All @@ -69,7 +69,7 @@

get "/api/products?q[name_cont]=fritos", token: user.spree_api_key

product_names = JSON.parse(response.body)['products'].map { |product| product['name'] }
product_names = JSON.parse(response.body)['products'].map { |x| x['name'] }
expect(product_names).to include product.name
expect(product_names).not_to include other_product.name
end
Expand Down
4 changes: 2 additions & 2 deletions core/app/helpers/spree/taxons_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def taxon_preview(taxon, max = 4)
products = taxon.active_products.select("DISTINCT (spree_products.id), spree_products.*, spree_products_taxons.position").limit(max)
if products.size < max
products_arel = Spree::Product.arel_table
taxon.descendants.each do |taxon|
taxon.descendants.each do |descendent_taxon|
to_get = max - products.length
products += taxon.active_products.select("DISTINCT (spree_products.id), spree_products.*, spree_products_taxons.position").where(products_arel[:id].not_in(products.map(&:id))).limit(to_get)
products += descendent_taxon.active_products.select("DISTINCT (spree_products.id), spree_products.*, spree_products_taxons.position").where(products_arel[:id].not_in(products.map(&:id))).limit(to_get)
break if products.size >= max
end
end
Expand Down
22 changes: 13 additions & 9 deletions core/app/models/spree/order_inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ def remove(item_units, shipment = nil)
if shipment.present?
remove_from_shipment(shipment, quantity)
else
order.shipments.each do |shipment|
break if quantity == 0
quantity -= remove_from_shipment(shipment, quantity)
end
remove_from_any_shipment(quantity)
end
end

Expand All @@ -53,12 +50,12 @@ def remove(item_units, shipment = nil)
# first unshipped that already includes this variant
# first unshipped that's leaving from a stock_location that stocks this variant
def determine_target_shipment
shipment = order.shipments.detect do |shipment|
shipment.ready_or_pending? && shipment.include?(variant)
end
potential_shipments = order.shipments.select(&:ready_or_pending?)

shipment || order.shipments.detect do |shipment|
shipment.ready_or_pending? && variant.stock_location_ids.include?(shipment.stock_location_id)
potential_shipments.detect do |shipment|
shipment.include?(variant)
end || potential_shipments.detect do |shipment|
variant.stock_location_ids.include?(shipment.stock_location_id)
end
end

Expand All @@ -80,6 +77,13 @@ def add_to_shipment(shipment, quantity)
quantity
end

def remove_from_any_shipment(quantity)
order.shipments.each do |shipment|
break if quantity == 0
quantity -= remove_from_shipment(shipment, quantity)
end
end

def remove_from_shipment(shipment, quantity)
return 0 if quantity == 0 || shipment.shipped?

Expand Down
6 changes: 3 additions & 3 deletions core/app/models/spree/payment_method/store_credit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def can_void?(payment)
payment.pending?
end

def authorize(amount_in_cents, store_credit, gateway_options = {})
if store_credit.nil?
def authorize(amount_in_cents, provided_store_credit, gateway_options = {})
if provided_store_credit.nil?
ActiveMerchant::Billing::Response.new(false, Spree.t('store_credit.unable_to_find'), {}, {})
else
action = -> (store_credit) {
Expand All @@ -23,7 +23,7 @@ def authorize(amount_in_cents, store_credit, gateway_options = {})
action_originator: gateway_options[:originator]
)
}
handle_action_call(store_credit, action, :authorize)
handle_action_call(provided_store_credit, action, :authorize)
end
end

Expand Down
4 changes: 1 addition & 3 deletions core/app/models/spree/stock/coordinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ def stock_location_variant_ids
# build the final lookup hash of
# {<stock location> => <set of variant ids>, ...}
# using the previous results
hash = location_variant_ids.each_with_object({}) do |(location_id, variant_id), hash|
location_variant_ids.each_with_object({}) do |(location_id, variant_id), hash|
location = location_lookup[location_id]
hash[location] ||= Set.new
hash[location] << variant_id
end

hash
end

def unallocated_inventory_units
Expand Down
6 changes: 3 additions & 3 deletions core/lib/spree/core/importer/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def update

def set_up_options
options_attrs.each do |name|
option_type = Spree::OptionType.where(name: name).first_or_initialize do |option_type|
option_type.presentation = name
option_type.save!
option_type = Spree::OptionType.where(name: name).first_or_initialize do |ot|
ot.presentation = name
ot.save!
end

unless product.option_types.include?(option_type)
Expand Down
4 changes: 2 additions & 2 deletions core/lib/spree/testing_support/order_walkthrough.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def up_to(state)
states[0..end_state_position]
end

states_to_process.each do |state|
send(state, order)
states_to_process.each do |state_to_process|
send(state_to_process, order)
end

order
Expand Down

0 comments on commit e61b99c

Please sign in to comment.