Fix simepl rubocop issues

This commit is contained in:
Luis Ramos
2020-08-06 10:23:08 +01:00
parent 0b053c18af
commit e89eb8f76c
4 changed files with 21 additions and 12 deletions

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Spree
class StockLocation < ActiveRecord::Base
has_many :stock_items, dependent: :delete_all
@@ -6,22 +8,22 @@ module Spree
belongs_to :state, class_name: 'Spree::State'
belongs_to :country, class_name: 'Spree::Country'
validates_presence_of :name
validates :name, presence: true
scope :active, -> { where(active: true) }
after_create :create_stock_items, :if => "self.propagate_all_variants?"
after_create :create_stock_items, if: "self.propagate_all_variants?"
# Wrapper for creating a new stock item respecting the backorderable config
def propagate_variant(variant)
self.stock_items.create!(variant: variant, backorderable: self.backorderable_default)
stock_items.create!(variant: variant, backorderable: backorderable_default)
end
# Return either an existing stock item or create a new one. Useful in
# scenarios where the user might not know whether there is already a stock
# item for a given variant
def set_up_stock_item(variant)
self.stock_item(variant) || propagate_variant(variant)
stock_item(variant) || propagate_variant(variant)
end
def stock_item(variant)
@@ -57,8 +59,9 @@ module Spree
end
private
def create_stock_items
Variant.find_each { |variant| self.propagate_variant(variant) }
end
def create_stock_items
Variant.find_each { |variant| propagate_variant(variant) }
end
end
end

View File

@@ -1,9 +1,10 @@
# frozen_string_literal: true
module Spree
class StockMovement < ActiveRecord::Base
belongs_to :stock_item, class_name: 'Spree::StockItem'
belongs_to :originator, polymorphic: true
after_create :update_stock_item_quantity
validates :stock_item, presence: true
@@ -16,10 +17,11 @@ module Spree
end
private
def update_stock_item_quantity
return unless Spree::Config[:track_inventory_levels]
stock_item.adjust_count_on_hand quantity
end
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
module Spree
@@ -102,7 +104,7 @@ module Spree
end
it 'finds a count_on_hand for a variant' do
subject.count_on_hand(variant).should eq 10
subject.count_on_hand(variant).should eq 10
end
it 'finds determines if you a variant is backorderable' do
@@ -128,8 +130,8 @@ module Spree
end
it 'can be deactivated' do
create(:stock_location, :active => true)
create(:stock_location, :active => false)
create(:stock_location, active: true)
create(:stock_location, active: false)
Spree::StockLocation.active.count.should eq 1
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'spec_helper'
describe Spree::StockMovement do