goca-spree-core 3.1.14.rails.5.0 → 3.1.14.rails.5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +1 -1
  3. data/app/models/application_record.rb +3 -0
  4. data/app/models/spree/app_configuration.rb +7 -0
  5. data/app/models/spree/base.rb +1 -1
  6. data/app/models/spree/calculator.rb +1 -1
  7. data/app/models/spree/country.rb +1 -1
  8. data/app/models/spree/credit_card.rb +5 -2
  9. data/app/models/spree/gateway/bogus.rb +11 -11
  10. data/app/models/spree/gateway/bogus_simple.rb +4 -4
  11. data/app/models/spree/gateway.rb +1 -1
  12. data/app/models/spree/image.rb +2 -2
  13. data/app/models/spree/inventory_unit.rb +6 -10
  14. data/app/models/spree/line_item.rb +3 -3
  15. data/app/models/spree/order_contents.rb +4 -2
  16. data/app/models/spree/payment/processing.rb +1 -1
  17. data/app/models/spree/preferences/store.rb +3 -3
  18. data/app/models/spree/product/scopes.rb +13 -13
  19. data/app/models/spree/product.rb +2 -2
  20. data/app/models/spree/promotion/rules/taxon.rb +1 -1
  21. data/app/models/spree/promotion.rb +1 -1
  22. data/app/models/spree/promotion_handler/cart.rb +1 -14
  23. data/app/models/spree/promotion_handler/page.rb +2 -2
  24. data/app/models/spree/refund_reason.rb +1 -1
  25. data/app/models/spree/reimbursement_type.rb +5 -1
  26. data/app/models/spree/return_item.rb +1 -1
  27. data/app/models/spree/stock/inventory_unit_builder.rb +1 -1
  28. data/app/models/spree/stock_movement.rb +11 -6
  29. data/app/models/spree/store.rb +1 -0
  30. data/app/models/spree/store_credit.rb +1 -1
  31. data/app/models/spree/taxon.rb +2 -2
  32. data/app/models/spree/variant.rb +7 -4
  33. data/app/models/spree/zone.rb +2 -2
  34. data/app/validators/db_maximum_length_validator.rb +5 -1
  35. data/config/initializers/friendly_id.rb +0 -81
  36. data/db/default/spree/countries.rb +1 -1
  37. data/db/default/spree/roles.rb +2 -2
  38. data/db/default/spree/states.rb +1 -1
  39. data/lib/generators/spree/custom_user/custom_user_generator.rb +1 -1
  40. data/lib/generators/spree/custom_user/templates/authentication_helpers.rb.tt +3 -3
  41. data/lib/generators/spree/custom_user/templates/migration.rb.tt +2 -2
  42. data/lib/generators/spree/dummy/dummy_generator.rb +11 -11
  43. data/lib/generators/spree/dummy/templates/rails/application.rb +1 -1
  44. data/lib/generators/spree/dummy/templates/rails/database.yml +9 -6
  45. data/lib/generators/spree/dummy/templates/rails/test.rb +1 -1
  46. data/lib/generators/spree/install/install_generator.rb +10 -10
  47. data/lib/spree/core/controller_helpers/respond_with.rb +1 -1
  48. data/lib/spree/core/delegate_belongs_to.rb +2 -2
  49. data/lib/spree/core/importer/product.rb +2 -2
  50. data/lib/spree/core/product_duplicator.rb +1 -1
  51. data/lib/spree/core/product_filters.rb +1 -1
  52. data/lib/spree/core/search/base.rb +1 -1
  53. data/lib/spree/core/version.rb +1 -1
  54. data/lib/spree/i18n/initializer.rb +1 -1
  55. data/lib/spree/localized_number.rb +3 -0
  56. data/lib/spree/permitted_attributes.rb +1 -1
  57. data/lib/spree/testing_support/caching.rb +3 -3
  58. data/lib/spree/testing_support/controller_requests.rb +4 -4
  59. data/lib/spree/testing_support/kernel.rb +18 -0
  60. data/lib/spree/testing_support/order_walkthrough.rb +4 -4
  61. data/lib/tasks/core.rake +2 -2
  62. data/spree_core.gemspec +2 -2
  63. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aba6863b91a645fcee9334b81d398c7137988e17
4
- data.tar.gz: b39ff84eb8f8b960d47fe18095344fc0c909273f
3
+ metadata.gz: 382329a7b83ef77945ce49e6ad3d27d4e2e53606
4
+ data.tar.gz: 768251611329f7710e3356481aafb09678b2b898
5
5
  SHA512:
6
- metadata.gz: dac8ef26d94c18eaede8001b3dbb693a97134e661b86578d9bd3e258bb052e69949a9c39e38a8a95294e710048ce0ba85f2b411e7c10cd914346211c60bad60c
7
- data.tar.gz: ef075cdcc94e6c1d9cebeec9b05d4277652d8b00087847bc9ec6081c1d8e8f53dd86dbe7946dcb698f66a008cc6c80101c1d7689743391d5f46afa2295268680
6
+ metadata.gz: 32dd49043108fb116003998969739efe4933b4e843cf4815ac86858f934288319d24bb63af3d0e5a5f5a0dbb553a7d3d30baab84691dc55014b62dad33828520
7
+ data.tar.gz: 6f88cc72fb4fb4da976ce8b06f91b0a47a2fe8243002e6d06d9f52dfb36c7c5ed0750958fd93b849d2bdddacfa104fdda4656511ff0fe2c7d996ed3b37bf976d
@@ -41,7 +41,7 @@ module Spree
41
41
  object = instance_variable_get('@'+controller_name.singularize)
42
42
  meta = {}
43
43
 
44
- if object.kind_of? ActiveRecord::Base
44
+ if object.kind_of? ApplicationRecord
45
45
  meta[:keywords] = object.meta_keywords if object[:meta_keywords].present?
46
46
  meta[:description] = object.meta_description if object[:meta_description].present?
47
47
  end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -58,6 +58,13 @@ module Spree
58
58
  preference :tax_using_ship_address, :boolean, default: true
59
59
  preference :track_inventory_levels, :boolean, default: true # Determines whether to track on_hand values for variants / products.
60
60
 
61
+ preference :admin_products_per_page, :integer, default: Kaminari.config.default_per_page
62
+ preference :admin_orders_per_page, :integer, default: Kaminari.config.default_per_page
63
+ preference :admin_properties_per_page, :integer, default: Kaminari.config.default_per_page
64
+ preference :admin_promotions_per_page, :integer, default: Kaminari.config.default_per_page
65
+ preference :admin_customer_returns_per_page, :integer, default: Kaminari.config.default_per_page
66
+ preference :admin_users_per_page, :integer, default: Kaminari.config.default_per_page
67
+
61
68
  # Store credits configurations
62
69
  preference :non_expiring_credit_types, :array, default: []
63
70
  preference :credit_to_new_allocation, :boolean, default: false
@@ -1,4 +1,4 @@
1
- class Spree::Base < ActiveRecord::Base
1
+ class Spree::Base < ApplicationRecord
2
2
  include Spree::Preferences::Preferable
3
3
  serialize :preferences, Hash
4
4
 
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  class Calculator < Spree::Base
3
3
  # Conditional check for backwards compatibilty since acts as paranoid was added late https://github.com/spree/spree/issues/5858
4
- if ActiveRecord::Base.connected? && connection.data_source_exists?(:spree_calculators) && connection.column_exists?(:spree_calculators, :deleted_at)
4
+ if connection.data_source_exists?(:spree_calculators) && connection.column_exists?(:spree_calculators, :deleted_at)
5
5
  acts_as_paranoid
6
6
  end
7
7
 
@@ -33,7 +33,7 @@ module Spree
33
33
  def ensure_not_default
34
34
  if id.eql?(Spree::Config[:default_country_id])
35
35
  errors.add(:base, Spree.t(:default_country_cannot_be_deleted))
36
- false
36
+ throw(:abort)
37
37
  end
38
38
  end
39
39
  end
@@ -1,5 +1,7 @@
1
1
  module Spree
2
2
  class CreditCard < Spree::Base
3
+ include ActiveMerchant::Billing::CreditCardMethods
4
+
3
5
  belongs_to :payment_method
4
6
  belongs_to :user, class_name: Spree.user_class, foreign_key: 'user_id'
5
7
  has_many :payments, as: :source
@@ -15,7 +17,8 @@ module Spree
15
17
  attr_reader :number
16
18
  attr_accessor :encrypted_data,
17
19
  :imported,
18
- :verification_value
20
+ :verification_value,
21
+ :manual_entry
19
22
 
20
23
  with_options if: :require_card_numbers?, on: :create do
21
24
  validates :month, :year, numericality: { only_integer: true }
@@ -23,7 +26,7 @@ module Spree
23
26
  validates :name, presence: true
24
27
  end
25
28
 
26
- scope :with_payment_profile, -> { where('gateway_customer_profile_id IS NOT NULL') }
29
+ scope :with_payment_profile, -> { where.not(gateway_customer_profile_id: nil) }
27
30
  scope :default, -> { where(default: true) }
28
31
 
29
32
  # needed for some of the ActiveMerchant gateways (eg. SagePay)
@@ -21,43 +21,43 @@ module Spree
21
21
  return if payment.source.has_payment_profile?
22
22
  # simulate the storage of credit card profile using remote service
23
23
  if success = VALID_CCS.include?(payment.source.number)
24
- payment.source.update_attributes(:gateway_customer_profile_id => generate_profile_id(success))
24
+ payment.source.update_attributes(gateway_customer_profile_id: generate_profile_id(success))
25
25
  end
26
26
  end
27
27
 
28
28
  def authorize(money, credit_card, options = {})
29
29
  profile_id = credit_card.gateway_customer_profile_id
30
30
  if VALID_CCS.include? credit_card.number or (profile_id and profile_id.starts_with? 'BGS-')
31
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'D' })
31
+ ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'D' })
32
32
  else
33
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { :message => 'Bogus Gateway: Forced failure' }, :test => true)
33
+ ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { message: 'Bogus Gateway: Forced failure' }, test: true)
34
34
  end
35
35
  end
36
36
 
37
37
  def purchase(money, credit_card, options = {})
38
38
  profile_id = credit_card.gateway_customer_profile_id
39
39
  if VALID_CCS.include? credit_card.number or (profile_id and profile_id.starts_with? 'BGS-')
40
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'M' })
40
+ ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'M' })
41
41
  else
42
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', :message => 'Bogus Gateway: Forced failure', :test => true)
42
+ ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', message: 'Bogus Gateway: Forced failure', test: true)
43
43
  end
44
44
  end
45
45
 
46
46
  def credit(money, credit_card, response_code, options = {})
47
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345')
47
+ ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
48
48
  end
49
49
 
50
50
  def capture(money, authorization, gateway_options)
51
51
  if authorization == '12345'
52
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true)
52
+ ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true)
53
53
  else
54
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', :error => 'Bogus Gateway: Forced failure', :test => true)
54
+ ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', error: 'Bogus Gateway: Forced failure', test: true)
55
55
  end
56
56
 
57
57
  end
58
58
 
59
59
  def void(response_code, credit_card, options = {})
60
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345')
60
+ ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345')
61
61
  end
62
62
 
63
63
  def cancel(_response_code)
@@ -82,8 +82,8 @@ module Spree
82
82
  record = true
83
83
  prefix = success ? 'BGS' : 'FAIL'
84
84
  while record
85
- random = "#{prefix}-#{Array.new(6){rand(6)}.join}"
86
- record = CreditCard.where(:gateway_customer_profile_id => random).first
85
+ random = "#{ prefix }-#{ Array.new(6) { rand(6) }.join }"
86
+ record = CreditCard.find_by(gateway_customer_profile_id: random)
87
87
  end
88
88
  random
89
89
  end
@@ -8,17 +8,17 @@ module Spree
8
8
 
9
9
  def authorize(money, credit_card, options = {})
10
10
  if VALID_CCS.include? credit_card.number
11
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
11
+ ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'A' })
12
12
  else
13
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { :message => 'Bogus Gateway: Forced failure' }, :test => true)
13
+ ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', { message: 'Bogus Gateway: Forced failure' }, test: true)
14
14
  end
15
15
  end
16
16
 
17
17
  def purchase(money, credit_card, options = {})
18
18
  if VALID_CCS.include? credit_card.number
19
- ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, :test => true, :authorization => '12345', :avs_result => { :code => 'A' })
19
+ ActiveMerchant::Billing::Response.new(true, 'Bogus Gateway: Forced success', {}, test: true, authorization: '12345', avs_result: { code: 'A' })
20
20
  else
21
- ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', :message => 'Bogus Gateway: Forced failure', :test => true)
21
+ ActiveMerchant::Billing::Response.new(false, 'Bogus Gateway: Forced failure', message: 'Bogus Gateway: Forced failure', test: true)
22
22
  end
23
23
  end
24
24
 
@@ -17,7 +17,7 @@ module Spree
17
17
  gateway_options = options
18
18
  gateway_options.delete :login if gateway_options.has_key?(:login) and gateway_options[:login].nil?
19
19
  if gateway_options[:server]
20
- ActiveMerchant::Billing::Base.gateway_mode = gateway_options[:server].to_sym
20
+ ActiveMerchant::Billing::Base.mode = gateway_options[:server].to_sym
21
21
  end
22
22
  @provider ||= provider_class.new(gateway_options)
23
23
  end
@@ -9,8 +9,8 @@ module Spree
9
9
  path: ':rails_root/public/spree/products/:id/:style/:basename.:extension',
10
10
  convert_options: { all: '-strip -auto-orient -colorspace sRGB' }
11
11
  validates_attachment :attachment,
12
- :presence => true,
13
- :content_type => { :content_type => %w(image/jpeg image/jpg image/png image/gif) }
12
+ presence: true,
13
+ content_type: { content_type: %w(image/jpeg image/jpg image/png image/gif) }
14
14
 
15
15
  # save the w,h of the original image (from which others can be calculated)
16
16
  # we need to look at the write-queue for images which have not been saved yet
@@ -4,7 +4,7 @@ module Spree
4
4
  with_options inverse_of: :inventory_units do
5
5
  belongs_to :variant, class_name: "Spree::Variant"
6
6
  belongs_to :order, class_name: "Spree::Order"
7
- belongs_to :shipment, class_name: "Spree::Shipment", touch: true
7
+ belongs_to :shipment, class_name: "Spree::Shipment", touch: true, optional: true
8
8
  belongs_to :return_authorization, class_name: "Spree::ReturnAuthorization"
9
9
  belongs_to :line_item, class_name: "Spree::LineItem"
10
10
  end
@@ -14,13 +14,14 @@ module Spree
14
14
 
15
15
  scope :backordered, -> { where state: 'backordered' }
16
16
  scope :on_hand, -> { where state: 'on_hand' }
17
+ scope :on_hand_or_backordered, -> { where state: ['backordered', 'on_hand'] }
17
18
  scope :shipped, -> { where state: 'shipped' }
18
19
  scope :returned, -> { where state: 'returned' }
19
20
  scope :backordered_per_variant, ->(stock_item) do
20
21
  includes(:shipment, :order)
21
- .where("spree_shipments.state != 'canceled'").references(:shipment)
22
+ .where.not(spree_shipments: { state: 'canceled' })
22
23
  .where(variant_id: stock_item.variant_id)
23
- .where('spree_orders.completed_at is not null')
24
+ .where.not(spree_orders: { completed_at: nil })
24
25
  .backordered.order("spree_orders.completed_at ASC")
25
26
  end
26
27
 
@@ -52,13 +53,8 @@ module Spree
52
53
  end
53
54
  end
54
55
 
55
- def self.finalize_units!(inventory_units)
56
- inventory_units.map do |iu|
57
- iu.update_columns(
58
- pending: false,
59
- updated_at: Time.current,
60
- )
61
- end
56
+ def self.finalize_units!
57
+ update_all(pending: false, updated_at: Time.current)
62
58
  end
63
59
 
64
60
  def find_stock_item
@@ -16,12 +16,12 @@ module Spree
16
16
  before_validation :copy_price
17
17
  before_validation :copy_tax_category
18
18
 
19
- validates :variant, presence: true
19
+ validates :variant, :order, presence: true
20
20
  validates :quantity, numericality: { only_integer: true, message: Spree.t('validation.must_be_int') }
21
21
  validates :price, numericality: true
22
22
 
23
23
  validates_with Stock::AvailabilityValidator
24
- validate :ensure_proper_currency
24
+ validate :ensure_proper_currency, if: -> { order.present? }
25
25
 
26
26
  before_destroy :update_inventory
27
27
  before_destroy :destroy_inventory_units
@@ -131,7 +131,7 @@ module Spree
131
131
  end
132
132
 
133
133
  def destroy_inventory_units
134
- inventory_units.destroy_all
134
+ throw(:abort) unless inventory_units.destroy_all
135
135
  end
136
136
 
137
137
  def update_adjustments
@@ -82,8 +82,10 @@ module Spree
82
82
  line_item.quantity += quantity.to_i
83
83
  line_item.currency = currency unless currency.nil?
84
84
  else
85
- opts = { currency: order.currency }.merge ActionController::Parameters.new(options).
86
- permit(PermittedAttributes.line_item_attributes)
85
+ opts = ActionController::Parameters.new(options.to_h)
86
+ .permit(PermittedAttributes.line_item_attributes)
87
+ .to_h
88
+ .merge( { currency: order.currency } )
87
89
  line_item = order.line_items.new(quantity: quantity,
88
90
  variant: variant,
89
91
  options: opts)
@@ -143,7 +143,7 @@ module Spree
143
143
  end
144
144
 
145
145
  def record_response(response)
146
- log_entries.create!(:details => response.to_yaml)
146
+ log_entries.create!(details: response.to_yaml)
147
147
  end
148
148
 
149
149
  def protect_from_connection_error
@@ -24,7 +24,7 @@ module Spree::Preferences
24
24
 
25
25
  def exist?(key)
26
26
  @cache.exist?(key) ||
27
- should_persist? && Spree::Preference.where(:key => key).exists?
27
+ should_persist? && Spree::Preference.where(key: key).exists?
28
28
  end
29
29
 
30
30
  def get(key)
@@ -73,7 +73,7 @@ module Spree::Preferences
73
73
  def persist(cache_key, value)
74
74
  return unless should_persist?
75
75
 
76
- preference = Spree::Preference.where(:key => cache_key).first_or_initialize
76
+ preference = Spree::Preference.where(key: cache_key).first_or_initialize
77
77
  preference.value = value
78
78
  preference.save
79
79
  end
@@ -86,7 +86,7 @@ module Spree::Preferences
86
86
  end
87
87
 
88
88
  def should_persist?
89
- @persistence && ActiveRecord::Base.connected? && Spree::Preference.table_exists?
89
+ @persistence and Spree::Preference.table_exists?
90
90
  end
91
91
 
92
92
  end
@@ -39,34 +39,34 @@ module Spree
39
39
  add_simple_scopes simple_scopes
40
40
 
41
41
  add_search_scope :ascend_by_master_price do
42
- joins(:master => :default_price).order("#{price_table_name}.amount ASC")
42
+ joins(master: :default_price).order("#{price_table_name}.amount ASC")
43
43
  end
44
44
 
45
45
  add_search_scope :descend_by_master_price do
46
- joins(:master => :default_price).order("#{price_table_name}.amount DESC")
46
+ joins(master: :default_price).order("#{price_table_name}.amount DESC")
47
47
  end
48
48
 
49
49
  add_search_scope :price_between do |low, high|
50
- joins(:master => :default_price).where(Price.table_name => { :amount => low..high })
50
+ joins(master: :default_price).where(Price.table_name => { amount: low..high })
51
51
  end
52
52
 
53
53
  add_search_scope :master_price_lte do |price|
54
- joins(:master => :default_price).where("#{price_table_name}.amount <= ?", price)
54
+ joins(master: :default_price).where("#{price_table_name}.amount <= ?", price)
55
55
  end
56
56
 
57
57
  add_search_scope :master_price_gte do |price|
58
- joins(:master => :default_price).where("#{price_table_name}.amount >= ?", price)
58
+ joins(master: :default_price).where("#{price_table_name}.amount >= ?", price)
59
59
  end
60
60
 
61
61
  # This scope selects products in taxon AND all its descendants
62
62
  # If you need products only within one taxon use
63
63
  #
64
- # Spree::Product.joins(:taxons).where(Taxon.table_name => { :id => taxon.id })
64
+ # Spree::Product.joins(:taxons).where(Taxon.table_name => { id: taxon.id })
65
65
  #
66
66
  # If you're using count on the result of this scope, you must use the
67
67
  # `:distinct` option as well:
68
68
  #
69
- # Spree::Product.in_taxon(taxon).count(:distinct => true)
69
+ # Spree::Product.in_taxon(taxon).count(distinct: true)
70
70
  #
71
71
  # This is so that the count query is distinct'd:
72
72
  #
@@ -162,8 +162,8 @@ module Spree
162
162
  # there is alternative faster and more elegant solution, it has small drawback though,
163
163
  # it doesn stack with other scopes :/
164
164
  #
165
- # :joins => "LEFT OUTER JOIN (SELECT line_items.variant_id as vid, COUNT(*) as cnt FROM line_items GROUP BY line_items.variant_id) AS popularity_count ON variants.id = vid",
166
- # :order => 'COALESCE(cnt, 0) DESC'
165
+ # joins: "LEFT OUTER JOIN (SELECT line_items.variant_id as vid, COUNT(*) as cnt FROM line_items GROUP BY line_items.variant_id) AS popularity_count ON variants.id = vid",
166
+ # order: 'COALESCE(cnt, 0) DESC'
167
167
  add_search_scope :descend_by_popularity do
168
168
  joins(:master).
169
169
  order(%Q{
@@ -197,12 +197,12 @@ module Spree
197
197
  # Can't use add_search_scope for this as it needs a default argument
198
198
  def self.available(available_on = nil, currency = nil)
199
199
  available_on ||= Time.current
200
- not_discontinued.joins(master: :prices).where("#{Product.quoted_table_name}.available_on <= ?", available_on).uniq
200
+ not_discontinued.joins(master: :prices).where("#{Product.quoted_table_name}.available_on <= ?", available_on).distinct
201
201
  end
202
202
  search_scopes << :available
203
203
 
204
204
  def self.active(currency = nil)
205
- not_discontinued.available(nil, currency)
205
+ available(nil, currency)
206
206
  end
207
207
  search_scopes << :active
208
208
 
@@ -228,7 +228,7 @@ module Spree
228
228
  #
229
229
  # Don't allow sort_column, a variable coming from params,
230
230
  # to be anything but a column in the database
231
- if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' && !column_names.include?(sort_column)
231
+ if ApplicationRecord.connection.adapter_name == 'PostgreSQL' && !column_names.include?(sort_column)
232
232
  all
233
233
  else
234
234
  distinct
@@ -260,7 +260,7 @@ module Spree
260
260
  ids_or_records_or_names.flatten.map { |t|
261
261
  case t
262
262
  when Integer then Taxon.find_by(id: t)
263
- when ActiveRecord::Base then t
263
+ when ApplicationRecord then t
264
264
  when String
265
265
  Taxon.find_by(name: t) ||
266
266
  Taxon.where("#{taxons}.permalink LIKE ? OR #{taxons}.permalink = ?", "%/#{t}/", "#{t}/").first
@@ -212,7 +212,7 @@ module Spree
212
212
  end
213
213
 
214
214
  def set_property(property_name, property_value, property_presentation = property_name)
215
- ActiveRecord::Base.transaction do
215
+ ApplicationRecord.transaction do
216
216
  # Works around spree_i18n #301
217
217
  property = Property.create_with(presentation: property_presentation).find_or_create_by(name: property_name)
218
218
  product_property = ProductProperty.where(product: self, property: property).first_or_initialize
@@ -269,7 +269,7 @@ module Spree
269
269
  price: master.price
270
270
  )
271
271
  end
272
- save
272
+ throw(:abort) unless save
273
273
  end
274
274
 
275
275
  def ensure_master
@@ -44,7 +44,7 @@ module Spree
44
44
 
45
45
  # All taxons in an order
46
46
  def order_taxons(order)
47
- Spree::Taxon.joins(products: {variants_including_master: :line_items}).where(spree_line_items: {order_id: order.id}).uniq
47
+ Spree::Taxon.joins(products: {variants_including_master: :line_items}).where(spree_line_items: {order_id: order.id}).distinct
48
48
  end
49
49
 
50
50
  # ids of taxons rules and taxons rules children
@@ -30,7 +30,7 @@ module Spree
30
30
  scope :coupons, -> { where.not(code: nil) }
31
31
  scope :advertised, -> { where(advertise: true) }
32
32
  scope :applied, lambda {
33
- joins(<<-SQL).uniq
33
+ joins(<<-SQL).distinct
34
34
  INNER JOIN spree_order_promotions
35
35
  ON spree_order_promotions.promotion_id = #{table_name}.id
36
36
  SQL
@@ -31,20 +31,7 @@ module Spree
31
31
  private
32
32
 
33
33
  def promotions
34
- # AR cannot bind raw ASTs to prepared statements. There always must be a manager around.
35
- # Also Postgresql requires an aliased table for `SELECT * FROM (subexpression) AS alias`.
36
- # And Sqlite3 cannot work on outher parenthesis from `(left UNION right)`.
37
- # So this construct makes both happy.
38
- select = Arel::SelectManager.new(Promotion.arel_engine)
39
- select.from(
40
- Promotion.arel_table.create_table_alias(
41
- order.promotions.active.union(Promotion.active.where(code: nil, path: nil)),
42
- Promotion.table_name
43
- )
44
- )
45
- select.project(Arel.star)
46
-
47
- Promotion.find_by_sql(select.to_sql)
34
+ Promotion.find_by_sql("#{order.promotions.active.to_sql} UNION #{Promotion.active.where(code: nil, path: nil).to_sql}")
48
35
  end
49
36
  end
50
37
  end
@@ -10,14 +10,14 @@ module Spree
10
10
 
11
11
  def activate
12
12
  if promotion && promotion.eligible?(order)
13
- promotion.activate(:order => order)
13
+ promotion.activate(order: order)
14
14
  end
15
15
  end
16
16
 
17
17
  private
18
18
 
19
19
  def promotion
20
- @promotion ||= Promotion.active.find_by(:path => path)
20
+ @promotion ||= Promotion.active.find_by(path: path)
21
21
  end
22
22
  end
23
23
  end
@@ -7,7 +7,7 @@ module Spree
7
7
  has_many :refunds, dependent: :restrict_with_error
8
8
 
9
9
  def self.return_processing_reason
10
- find_by!(name: RETURN_PROCESSING_REASON, mutable: false)
10
+ find_by(name: RETURN_PROCESSING_REASON, mutable: false)
11
11
  end
12
12
  end
13
13
  end
@@ -2,7 +2,11 @@ module Spree
2
2
  class ReimbursementType < Spree::Base
3
3
  include Spree::NamedType
4
4
 
5
- ORIGINAL = 'original'
5
+ KINDS = %w(Spree::ReimbursementType::Credit
6
+ Spree::ReimbursementType::Exchange
7
+ Spree::ReimbursementType::OriginalPayment
8
+ Spree::ReimbursementType::StoreCredit).freeze
9
+ ORIGINAL = 'original'.freeze
6
10
 
7
11
  has_many :return_items
8
12
 
@@ -102,7 +102,7 @@ module Spree
102
102
  transition to: :manual_intervention_required, from: [:accepted, :pending, :manual_intervention_required]
103
103
  end
104
104
 
105
- after_transition any => any, :do => :persist_acceptance_status_errors
105
+ after_transition any => any, do: :persist_acceptance_status_errors
106
106
  end
107
107
 
108
108
  def self.from_inventory_unit(inventory_unit)
@@ -10,7 +10,7 @@ module Spree
10
10
  line_item.quantity.times.map do |i|
11
11
  @order.inventory_units.build(
12
12
  pending: true,
13
- variant: line_item.variant,
13
+ variant_id: line_item.variant_id,
14
14
  line_item: line_item,
15
15
  order: @order
16
16
  )
@@ -1,5 +1,10 @@
1
1
  module Spree
2
2
  class StockMovement < Spree::Base
3
+ QUANTITY_LIMITS = {
4
+ max: 2**31 - 1,
5
+ min: -2**31
6
+ }.freeze
7
+
3
8
  belongs_to :stock_item, class_name: 'Spree::StockItem', inverse_of: :stock_movements
4
9
  belongs_to :originator, polymorphic: true
5
10
 
@@ -8,11 +13,11 @@ module Spree
8
13
  with_options presence: true do
9
14
  validates :stock_item
10
15
  validates :quantity, numericality: {
11
- greater_than_or_equal_to: -2**31,
12
- less_than_or_equal_to: 2**31 - 1,
13
- only_integer: true,
14
- allow_nil: true
15
- }
16
+ greater_than_or_equal_to: QUANTITY_LIMITS[:min],
17
+ less_than_or_equal_to: QUANTITY_LIMITS[:max],
18
+ only_integer: true,
19
+ allow_nil: true
20
+ }
16
21
  end
17
22
 
18
23
  scope :recent, -> { order(created_at: :desc) }
@@ -20,7 +25,7 @@ module Spree
20
25
  self.whitelisted_ransackable_attributes = ['quantity']
21
26
 
22
27
  def readonly?
23
- !new_record?
28
+ persisted?
24
29
  end
25
30
 
26
31
  private
@@ -38,6 +38,7 @@ module Spree
38
38
  def validate_not_default
39
39
  if default
40
40
  errors.add(:base, :cannot_destroy_default_store)
41
+ throw(:abort)
41
42
  end
42
43
  end
43
44
 
@@ -238,7 +238,7 @@ module Spree
238
238
  def validate_no_amount_used
239
239
  if amount_used > 0
240
240
  errors.add(:amount_used, :greater_than_zero_restrict_delete)
241
- false
241
+ throw(:abort)
242
242
  end
243
243
  end
244
244
 
@@ -13,10 +13,10 @@ module Spree
13
13
  has_many :classifications, -> { order(:position) }, dependent: :delete_all, inverse_of: :taxon
14
14
  has_many :products, through: :classifications
15
15
 
16
- has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon'
16
+ has_many :prototype_taxons, class_name: 'Spree::PrototypeTaxon', dependent: :destroy
17
17
  has_many :prototypes, through: :prototype_taxons, class_name: 'Spree::Prototype'
18
18
 
19
- has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon'
19
+ has_many :promotion_rule_taxons, class_name: 'Spree::PromotionRuleTaxon', dependent: :destroy
20
20
  has_many :promotion_rules, through: :promotion_rule_taxons, class_name: 'Spree::PromotionRule'
21
21
 
22
22
  validates :name, presence: true
@@ -58,15 +58,18 @@ module Spree
58
58
  scope :in_stock, -> { joins(:stock_items).where('count_on_hand > ? OR track_inventory = ?', 0, false) }
59
59
 
60
60
  scope :not_discontinued, -> do
61
- variant_table_name = Variant.quoted_table_name
62
- where("#{variant_table_name}.discontinue_on IS NULL OR #{variant_table_name}.discontinue_on >= ?", Time.current)
61
+ where(
62
+ arel_table[:discontinue_on].eq(nil).or(
63
+ arel_table[:discontinue_on].gteq(Time.current)
64
+ )
65
+ )
63
66
  end
64
67
 
65
68
  scope :not_deleted, -> { where("#{Variant.quoted_table_name}.deleted_at IS NULL") }
66
69
 
67
70
  scope :for_currency_and_available_price_amount, -> (currency) do
68
71
  currency ||= Spree::Config[:currency]
69
- joins(:prices).where("spree_prices.currency = ?", currency).where("spree_prices.amount IS NOT NULL").uniq
72
+ joins(:prices).where("spree_prices.currency = ?", currency).where("spree_prices.amount IS NOT NULL").distinct
70
73
  end
71
74
 
72
75
  scope :active, -> (currency = nil) do
@@ -264,7 +267,7 @@ module Spree
264
267
  def ensure_no_line_items
265
268
  if line_items.any?
266
269
  errors.add(:base, Spree.t(:cannot_destroy_if_attached_to_line_items))
267
- return false
270
+ throw(:abort)
268
271
  end
269
272
  end
270
273