Skip to content

Commit

Permalink
Remove all useless assignments
Browse files Browse the repository at this point in the history
Remove all assignments flagged by rubocop's Lint/UselessAssignment
  • Loading branch information
jhawthorn committed Feb 16, 2016
1 parent 5de8c44 commit 304fc21
Show file tree
Hide file tree
Showing 50 changed files with 82 additions and 90 deletions.
4 changes: 2 additions & 2 deletions api/app/controllers/spree/api/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def image_params

def scope
if params[:product_id]
scope = Spree::Product.friendly.find(params[:product_id])
Spree::Product.friendly.find(params[:product_id])
elsif params[:variant_id]
scope = Spree::Variant.find(params[:variant_id])
Spree::Variant.find(params[:variant_id])
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def check_option_values(option_values)

it "can retrieve a list of specific option types" do
option_type_1 = create(:option_type)
option_type_2 = create(:option_type)
create(:option_type)
api_get :index, ids: "#{option_type.id},#{option_type_1.id}"
expect(json_response.count).to eq(2)

Expand Down Expand Up @@ -90,7 +90,6 @@ def check_option_values(option_values)
end

it "can update an option type" do
original_name = option_type.name
api_put :update, id: option_type.id, option_type: {
name: "Option Type"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def check_option_values(option_values)

it "can retrieve a list of option types" do
option_value_1 = create(:option_value, option_type: option_type)
option_value_2 = create(:option_value, option_type: option_type)
create(:option_value, option_type: option_type)
api_get :index, ids: [option_value.id, option_value_1.id]
expect(json_response.count).to eq(2)
end
Expand Down Expand Up @@ -101,7 +101,6 @@ def check_option_values(option_values)
end

it "can update an option value" do
original_name = option_value.name
api_put :update, id: option_value.id, option_value: {
name: "Option Value"
}
Expand Down
2 changes: 0 additions & 2 deletions api/spec/controllers/spree/api/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ module Spree
before { order.create_proposed_shipments }

it "clears out all existing shipments on line item udpate" do
previous_shipments = order.shipments
api_put :update, id: order.to_param, order: {
line_items: {
0 => { id: line_item.id, quantity: 10 }
Expand Down Expand Up @@ -722,7 +721,6 @@ module Spree
it "can create an order without any parameters" do
api_post :create
expect(response.status).to eq(201)
order = Order.last
expect(json_response["state"]).to eq("cart")
end

Expand Down
2 changes: 1 addition & 1 deletion api/spec/controllers/spree/api/products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module Spree

context "pagination" do
it "can select the next page of products" do
second_product = create(:product)
create(:product)
api_get :index, page: 2, per_page: 1
expect(json_response["products"].first).to have_attributes(show_attributes)
expect(json_response["total_count"]).to eq(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module Spree
end

it 'can query the results through a paramter' do
expected_result = create(:stock_movement, :received, quantity: 10, stock_item: stock_item)
create(:stock_movement, :received, quantity: 10, stock_item: stock_item)
api_get :index, stock_location_id: stock_location.to_param, q: { quantity_eq: '10' }
expect(json_response['count']).to eq(1)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ module Spree
api_post :create, taxonomy: {}
expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
errors = json_response["errors"]
end

it "can destroy" do
Expand Down
1 change: 0 additions & 1 deletion api/spec/controllers/spree/api/taxons_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ module Spree
api_post :create, taxonomy_id: taxonomy.id, taxon: {}
expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
errors = json_response["errors"]

expect(taxonomy.reload.root.children.count).to eq 1
end
Expand Down
1 change: 0 additions & 1 deletion api/spec/controllers/spree/api/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ module Spree
api_post :create, user: {}, token: user.spree_api_key
expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
errors = json_response["errors"]
end

it "can update own details" do
Expand Down
2 changes: 1 addition & 1 deletion api/spec/controllers/spree/api/variants_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ module Spree

context "pagination" do
it "can select the next page of variants" do
second_variant = create(:variant)
create(:variant)
api_get :index, page: 2, per_page: 1
expect(json_response["variants"].first).to have_attributes(show_attributes)
expect(json_response["total_count"]).to eq(3)
Expand Down
4 changes: 2 additions & 2 deletions api/spec/requests/ransackable_attributes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@

context "filtering by attributes" do
it "most attributes are not filterable by default" do
product = create(:product, description: "special product")
other_product = create(:product)
create(:product, description: "special product")
create(:product)

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

Expand Down
2 changes: 1 addition & 1 deletion backend/app/controllers/spree/admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def config_locale

def lock_order
OrderMutex.with_lock!(@order) { yield }
rescue Spree::OrderMutex::LockFailed => e
rescue Spree::OrderMutex::LockFailed
flash[:error] = Spree.t(:order_mutex_admin_error)
redirect_to order_mutex_redirect_path
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def update

if should_associate_user?
requested_user = Spree.user_class.find(params[:user_id])
@order.associate_user!(Spree.user_class.find(params[:user_id]), @order.email.blank?)
@order.associate_user!(requested_user, @order.email.blank?)
end

unless @order.completed?
Expand Down
8 changes: 4 additions & 4 deletions backend/app/helpers/spree/admin/products_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ module Spree
module Admin
module ProductsHelper
def taxon_options_for(product)
options = @taxons.map do |taxon|
@taxons.map do |taxon|
selected = product.taxons.include?(taxon)
content_tag(:option,
value: taxon.id,
selected: ('selected' if selected)) do
(taxon.ancestors.pluck(:name) + [taxon.name]).join(" -> ")
end
(taxon.ancestors.pluck(:name) + [taxon.name]).join(" -> ")
end
end.join("").html_safe
end

def option_types_options_for(product)
options = @option_types.map do |option_type|
@option_types.map do |option_type|
selected = product.option_types.include?(option_type)
content_tag(:option,
value: option_type.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
describe "#cancel" do
subject { spree_post :short_ship, order_id: order.number, inventory_unit_ids: inventory_units.map(&:id) }

let(:order) { order = create(:order_ready_to_ship, number: "R100", state: "complete", line_items_count: 1) }
let(:order) { create(:order_ready_to_ship, number: "R100", state: "complete", line_items_count: 1) }
let(:referer) { "order_admin_page" }

context "no inventory unit ids are provided" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
stub_authorization!

before(:each) do
country = create(:country)
create(:country)
visit spree.admin_path
click_link "Settings"
click_link "Stock Locations"
Expand All @@ -21,7 +21,7 @@
end

it "can delete an existing stock location", js: true do
location = create(:stock_location)
create(:stock_location)
visit current_path

expect(find('#listing_stock_locations')).to have_content("NY Warehouse")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
stub_authorization!

before(:each) do
promotion = create(:promotion_with_item_adjustment,
name: "$10 off",
path: 'test',
code: "10_off",
starts_at: 1.day.ago,
expires_at: 1.day.from_now,
adjustment_rate: 10)
create(:promotion_with_item_adjustment,
name: "$10 off",
path: 'test',
code: "10_off",
starts_at: 1.day.ago,
expires_at: 1.day.from_now,
adjustment_rate: 10)

order = create(:order_with_totals)
line_item = order.line_items.first
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
context "with no stock location" do
before do
@product = create(:product, name: 'apache baseball cap', price: 10)
v = @product.variants.create!(sku: 'FOOBAR')
@product.variants.create!(sku: 'FOOBAR')
Spree::StockLocation.destroy_all
click_link "Back To Products List"
within_row(1) do
Expand Down
4 changes: 2 additions & 2 deletions backend/spec/features/admin/stock_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

describe 'create stock transfer' do
it 'can create a stock transfer' do
source_location = create(:stock_location_with_items, name: 'NY')
destination_location = create(:stock_location, name: 'SF')
create(:stock_location_with_items, name: 'NY')
create(:stock_location, name: 'SF')

visit spree.new_admin_stock_transfer_path
select "SF", from: 'stock_transfer[source_location_id]'
Expand Down
4 changes: 2 additions & 2 deletions core/app/mailers/spree/order_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def find_order(order)
end

def build_subject(subject_text, resend)
subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
subject += "#{Spree::Store.current.name} #{subject_text} ##{@order.number}"
resend_text = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
"#{resend_text}#{Spree::Store.current.name} #{subject_text} ##{@order.number}"
end
end
end
2 changes: 1 addition & 1 deletion core/app/models/spree/calculator/tiered_flat_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.description
end

def compute(object)
base, amount = preferred_tiers.sort.reverse.detect{ |b, _| object.amount >= b }
_base, amount = preferred_tiers.sort.reverse.detect{ |b, _| object.amount >= b }
amount || preferred_base_amount
end

Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/calculator/tiered_percent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.description

def compute(object)
order = object.is_a?(Order) ? object : object.order
base, percent = preferred_tiers.sort.reverse.detect{ |b, _| order.item_total >= b }
_base, percent = preferred_tiers.sort.reverse.detect{ |b, _| order.item_total >= b }
(object.amount * (percent || preferred_base_percent) / 100).round(2)
end

Expand Down
5 changes: 3 additions & 2 deletions core/app/models/spree/order_capturing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def capture_payments
private

def sorted_payments(order)
payments = order.payments.pending
payments = payments.sort_by { |p| [@sorted_payment_method_classes.index(p.payment_method.class), p.id] }
order.payments.pending.sort_by do |p|
[@sorted_payment_method_classes.index(p.payment_method.class), p.id]
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/order_inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def determine_target_shipment
shipment.ready_or_pending? && shipment.include?(variant)
end

shipment ||= order.shipments.detect do |shipment|
shipment || order.shipments.detect do |shipment|
shipment.ready_or_pending? && variant.stock_location_ids.include?(shipment.stock_location_id)
end
end
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/payment/processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def process_authorization

def process_purchase
started_processing!
result = gateway_action(source, :purchase, :complete)
gateway_action(source, :purchase, :complete)
# This won't be called if gateway_action raises a GatewayError
capture_events.create!(amount: amount)
end
Expand Down
6 changes: 3 additions & 3 deletions core/app/models/spree/product/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def self.add_search_scope(name, &block)

def self.property_conditions(property)
properties = Property.table_name
conditions = case property
when String then { "#{properties}.name" => property }
when Property then { "#{properties}.id" => property.id }
case property
when String then { "#{properties}.name" => property }
when Property then { "#{properties}.id" => property.id }
else { "#{properties}.id" => property.to_i }
end
end
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/reimbursement_type/credit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ReimbursementType::Credit < Spree::ReimbursementType
class << self
def reimburse(reimbursement, return_items, simulate)
unpaid_amount = return_items.sum(&:total).round(2, :down)
reimbursement_list, unpaid_amount = create_credits(reimbursement, unpaid_amount, simulate)
reimbursement_list, _unpaid_amount = create_credits(reimbursement, unpaid_amount, simulate)
reimbursement_list
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def reimburse(reimbursement, return_items, simulate)
unpaid_amount = return_items.sum(&:total).round(2, :down)
payments = reimbursement.order.payments.completed

refund_list, unpaid_amount = create_refunds(reimbursement, payments, unpaid_amount, simulate)
refund_list, _unpaid_amount = create_refunds(reimbursement, payments, unpaid_amount, simulate)
refund_list
end
end
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/reimbursement_type/store_credit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def reimburse(reimbursement, return_items, simulate)

# If there is any amount left to pay out to the customer, then create credit with that amount
if unpaid_amount > 0.0
reimbursement_list, unpaid_amount = create_credits(reimbursement, unpaid_amount, simulate, reimbursement_list)
reimbursement_list, _unpaid_amount = create_credits(reimbursement, unpaid_amount, simulate, reimbursement_list)
end

reimbursement_list
Expand Down
3 changes: 0 additions & 3 deletions core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,6 @@ def transfer_to_location(variant, quantity, stock_location)
end

def transfer_to_shipment(variant, quantity, shipment_to_transfer_to)
quantity_already_shipment_to_transfer_to = shipment_to_transfer_to.manifest.find{ |mi| mi.line_item.variant == variant }.try(:quantity) || 0
final_quantity = quantity + quantity_already_shipment_to_transfer_to

if quantity <= 0 || self == shipment_to_transfer_to
raise ArgumentError
end
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/variant/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def has_option(option_type, *option_values)

relation = joins(option_values: :option_type).where(option_type_conditions)

option_values_conditions = option_values.each do |option_value|
option_values.each do |option_value|
option_value_conditions = case option_value
when OptionValue then { "#{OptionValue.table_name}.name" => option_value.name }
when String then { "#{OptionValue.table_name}.name" => option_value }
Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/core/controller_helpers/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def set_user_language
# Default layout is: +app/views/spree/layouts/spree_application+
#
def get_layout
layout ||= Spree::Config[:layout]
Spree::Config[:layout]
end
end
end
Expand Down
1 change: 0 additions & 1 deletion core/lib/spree/core/importer/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def self.import(user, params)
def self.create_shipments_from_params(shipments_hash, order)
return [] unless shipments_hash

line_items = order.line_items
shipments_hash.each do |s|
shipment = Shipment.new
shipment.tracking = s[:tracking]
Expand Down
4 changes: 3 additions & 1 deletion core/lib/spree/localized_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class LocalizedNumber
def self.parse(number)
return number unless number.is_a?(String)

separator, delimiter = I18n.t([:'number.currency.format.separator', :'number.currency.format.delimiter'])
# I18n.t('number.currency.format.delimiter') could be useful here, but is
# unnecessary as it is stripped by the non_number_characters gsub.
separator = I18n.t(:'number.currency.format.separator')
non_number_characters = /[^0-9\-#{separator}]/

# strip everything else first
Expand Down
1 change: 0 additions & 1 deletion core/lib/spree/testing_support/capybara_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def select2_no_label(value, options = {})
raise "Must pass a hash containing 'from'" if !options.is_a?(Hash) || !options.key?(:from)

placeholder = options[:from]
minlength = options[:minlength] || 4

click_link placeholder

Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/testing_support/factories/zone_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
zone_members do |proxy|
zone = proxy.instance_eval { @instance }
Spree::Country.all.map do |c|
zone_member = Spree::ZoneMember.create(zoneable: c, zone: zone)
Spree::ZoneMember.create(zoneable: c, zone: zone)
end
end
end
Expand Down
Loading

0 comments on commit 304fc21

Please sign in to comment.