solidus_core 2.9.0 → 2.10.0

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 (219) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +4 -4
  3. data/app/helpers/spree/products_helper.rb +2 -1
  4. data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
  5. data/app/models/concerns/spree/user_address_book.rb +2 -2
  6. data/app/models/concerns/spree/user_methods.rb +2 -2
  7. data/app/models/spree/address.rb +13 -17
  8. data/app/models/spree/adjustment.rb +20 -9
  9. data/app/models/spree/asset.rb +1 -1
  10. data/app/models/spree/base.rb +0 -2
  11. data/app/models/spree/calculator/price_sack.rb +1 -1
  12. data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
  13. data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
  14. data/app/models/spree/calculator/tiered_percent.rb +6 -6
  15. data/app/models/spree/calculator.rb +1 -1
  16. data/app/models/spree/carton.rb +3 -3
  17. data/app/models/spree/classification.rb +2 -2
  18. data/app/models/spree/credit_card.rb +4 -4
  19. data/app/models/spree/customer_return.rb +1 -1
  20. data/app/models/spree/image/paperclip_attachment.rb +1 -1
  21. data/app/models/spree/inventory_unit.rb +5 -23
  22. data/app/models/spree/line_item.rb +4 -4
  23. data/app/models/spree/line_item_action.rb +2 -2
  24. data/app/models/spree/log_entry.rb +1 -1
  25. data/app/models/spree/option_value.rb +1 -1
  26. data/app/models/spree/option_values_variant.rb +2 -2
  27. data/app/models/spree/order/checkout.rb +1 -1
  28. data/app/models/spree/order/payments.rb +2 -2
  29. data/app/models/spree/order.rb +11 -10
  30. data/app/models/spree/order_cancellations.rb +1 -1
  31. data/app/models/spree/order_capturing.rb +2 -2
  32. data/app/models/spree/order_contents.rb +2 -2
  33. data/app/models/spree/order_mutex.rb +1 -1
  34. data/app/models/spree/order_promotion.rb +3 -3
  35. data/app/models/spree/order_shipping.rb +1 -1
  36. data/app/models/spree/order_taxation.rb +3 -3
  37. data/app/models/spree/payment/processing.rb +3 -3
  38. data/app/models/spree/payment.rb +8 -45
  39. data/app/models/spree/payment_capture_event.rb +1 -1
  40. data/app/models/spree/payment_method/bogus_credit_card.rb +1 -1
  41. data/app/models/spree/payment_method.rb +5 -2
  42. data/app/models/spree/payment_source.rb +1 -1
  43. data/app/models/spree/price.rb +2 -2
  44. data/app/models/spree/product/scopes.rb +218 -210
  45. data/app/models/spree/product.rb +5 -5
  46. data/app/models/spree/product_option_type.rb +2 -2
  47. data/app/models/spree/product_promotion_rule.rb +2 -2
  48. data/app/models/spree/product_property.rb +2 -2
  49. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
  50. data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
  51. data/app/models/spree/promotion/rules/option_value.rb +2 -2
  52. data/app/models/spree/promotion/rules/product.rb +3 -3
  53. data/app/models/spree/promotion.rb +28 -13
  54. data/app/models/spree/promotion_action.rb +2 -2
  55. data/app/models/spree/promotion_chooser.rb +2 -2
  56. data/app/models/spree/promotion_code/batch_builder.rb +3 -3
  57. data/app/models/spree/promotion_code.rb +11 -10
  58. data/app/models/spree/promotion_code_batch.rb +1 -1
  59. data/app/models/spree/promotion_rule.rb +2 -2
  60. data/app/models/spree/promotion_rule_role.rb +2 -2
  61. data/app/models/spree/promotion_rule_store.rb +2 -2
  62. data/app/models/spree/promotion_rule_taxon.rb +2 -2
  63. data/app/models/spree/promotion_rule_user.rb +2 -2
  64. data/app/models/spree/refund.rb +5 -5
  65. data/app/models/spree/reimbursement/credit.rb +2 -2
  66. data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
  67. data/app/models/spree/reimbursement.rb +5 -13
  68. data/app/models/spree/reimbursement_tax_calculator.rb +1 -1
  69. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
  70. data/app/models/spree/return_authorization.rb +4 -10
  71. data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
  72. data/app/models/spree/return_item.rb +13 -52
  73. data/app/models/spree/role_user.rb +2 -2
  74. data/app/models/spree/shipment.rb +7 -41
  75. data/app/models/spree/shipping_calculator.rb +0 -4
  76. data/app/models/spree/shipping_manifest.rb +3 -3
  77. data/app/models/spree/shipping_method.rb +2 -2
  78. data/app/models/spree/shipping_method_category.rb +2 -2
  79. data/app/models/spree/shipping_method_stock_location.rb +2 -2
  80. data/app/models/spree/shipping_method_zone.rb +2 -2
  81. data/app/models/spree/shipping_rate.rb +2 -2
  82. data/app/models/spree/shipping_rate_tax.rb +2 -2
  83. data/app/models/spree/state.rb +2 -2
  84. data/app/models/spree/state_change.rb +2 -2
  85. data/app/models/spree/stock/differentiator.rb +1 -1
  86. data/app/models/spree/stock/package.rb +1 -1
  87. data/app/models/spree/stock_item.rb +3 -3
  88. data/app/models/spree/stock_location.rb +2 -2
  89. data/app/models/spree/stock_movement.rb +2 -2
  90. data/app/models/spree/stock_quantities.rb +13 -12
  91. data/app/models/spree/store_credit.rb +8 -8
  92. data/app/models/spree/store_credit_event.rb +3 -3
  93. data/app/models/spree/store_payment_method.rb +2 -2
  94. data/app/models/spree/store_shipping_method.rb +2 -2
  95. data/app/models/spree/tax_calculator/default.rb +0 -4
  96. data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
  97. data/app/models/spree/tax_rate.rb +5 -1
  98. data/app/models/spree/tax_rate_tax_category.rb +2 -2
  99. data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
  100. data/app/models/spree/unit_cancel.rb +5 -2
  101. data/app/models/spree/user_address.rb +2 -2
  102. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
  103. data/app/models/spree/user_last_url_storer.rb +46 -0
  104. data/app/models/spree/user_stock_location.rb +2 -2
  105. data/app/models/spree/variant/scopes.rb +37 -29
  106. data/app/models/spree/variant.rb +10 -10
  107. data/app/models/spree/variant_property_rule.rb +1 -1
  108. data/app/models/spree/variant_property_rule_condition.rb +2 -2
  109. data/app/models/spree/variant_property_rule_value.rb +2 -2
  110. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
  111. data/app/models/spree/wallet_payment_source.rb +2 -2
  112. data/app/models/spree/zone.rb +1 -1
  113. data/app/models/spree/zone_member.rb +2 -2
  114. data/config/initializers/inflections.rb +5 -0
  115. data/config/initializers/money.rb +2 -0
  116. data/config/locales/en.yml +34 -3
  117. data/lib/generators/spree/dummy/dummy_generator.rb +2 -0
  118. data/lib/generators/spree/install/install_generator.rb +3 -0
  119. data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
  120. data/lib/spree/app_configuration.rb +18 -3
  121. data/lib/spree/core/controller_helpers/auth.rb +1 -13
  122. data/lib/spree/core/engine.rb +2 -2
  123. data/lib/spree/core/environment_extension.rb +9 -0
  124. data/lib/spree/core/importer/order.rb +28 -28
  125. data/lib/spree/core/importer/product.rb +2 -2
  126. data/lib/spree/core/product_filters.rb +15 -15
  127. data/lib/spree/core/role_configuration.rb +2 -2
  128. data/lib/spree/core/search/variant.rb +1 -1
  129. data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
  130. data/lib/spree/core/state_machines/payment.rb +61 -0
  131. data/lib/spree/core/state_machines/reimbursement.rb +33 -0
  132. data/lib/spree/core/state_machines/return_authorization.rb +32 -0
  133. data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
  134. data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
  135. data/lib/spree/core/state_machines/shipment.rb +58 -0
  136. data/lib/spree/core/state_machines.rb +78 -0
  137. data/lib/spree/core/stock_configuration.rb +1 -0
  138. data/lib/spree/core/validators/email.rb +1 -8
  139. data/lib/spree/core/version.rb +1 -1
  140. data/lib/spree/core.rb +12 -0
  141. data/lib/spree/money.rb +2 -2
  142. data/lib/spree/permission_sets/default_customer.rb +1 -1
  143. data/lib/spree/permission_sets/user_management.rb +3 -0
  144. data/lib/spree/permitted_attributes.rb +3 -3
  145. data/lib/spree/preferences/static_model_preferences.rb +2 -2
  146. data/lib/spree/testing_support/dummy_app/rake_tasks.rb +6 -2
  147. data/lib/spree/testing_support/dummy_app.rb +4 -1
  148. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
  149. data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
  150. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  151. data/lib/spree/testing_support/preferences.rb +54 -15
  152. data/solidus_core.gemspec +6 -6
  153. data/spec/lib/search/base_spec.rb +5 -1
  154. data/spec/lib/search/variant_spec.rb +1 -1
  155. data/spec/lib/spree/core/environment_extension_spec.rb +12 -1
  156. data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
  157. data/spec/lib/spree/core/validators/email_spec.rb +18 -18
  158. data/spec/lib/spree/event_spec.rb +15 -3
  159. data/spec/models/spree/address_spec.rb +23 -0
  160. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +1 -1
  161. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
  162. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
  163. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
  164. data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
  165. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
  166. data/spec/models/spree/carton_spec.rb +10 -2
  167. data/spec/models/spree/classification_spec.rb +21 -9
  168. data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
  169. data/spec/models/spree/concerns/user_methods_spec.rb +5 -4
  170. data/spec/models/spree/credit_card_spec.rb +2 -2
  171. data/spec/models/spree/customer_return_spec.rb +1 -1
  172. data/spec/models/spree/order/checkout_spec.rb +1 -1
  173. data/spec/models/spree/order/outstanding_balance_integration_spec.rb +5 -5
  174. data/spec/models/spree/order/payment_spec.rb +1 -1
  175. data/spec/models/spree/order_contents_spec.rb +1 -1
  176. data/spec/models/spree/order_inventory_spec.rb +3 -3
  177. data/spec/models/spree/order_merger_spec.rb +3 -3
  178. data/spec/models/spree/order_shipping_spec.rb +1 -1
  179. data/spec/models/spree/order_spec.rb +14 -21
  180. data/spec/models/spree/order_updater_spec.rb +4 -3
  181. data/spec/models/spree/payment_create_spec.rb +6 -16
  182. data/spec/models/spree/payment_spec.rb +12 -12
  183. data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
  184. data/spec/models/spree/preference_spec.rb +4 -4
  185. data/spec/models/spree/preferences/preferable_spec.rb +3 -3
  186. data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
  187. data/spec/models/spree/promotion/rules/first_repeat_purchase_since_spec.rb +2 -2
  188. data/spec/models/spree/promotion/rules/nth_order_spec.rb +2 -2
  189. data/spec/models/spree/promotion_rule_spec.rb +6 -6
  190. data/spec/models/spree/promotion_spec.rb +71 -54
  191. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +3 -3
  192. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
  193. data/spec/models/spree/return_item_spec.rb +11 -11
  194. data/spec/models/spree/returns_calculator_spec.rb +2 -2
  195. data/spec/models/spree/shipment_spec.rb +6 -6
  196. data/spec/models/spree/shipping_calculator_spec.rb +1 -13
  197. data/spec/models/spree/shipping_method_spec.rb +32 -0
  198. data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
  199. data/spec/models/spree/stock/differentiator_spec.rb +2 -2
  200. data/spec/models/spree/stock/estimator_spec.rb +3 -3
  201. data/spec/models/spree/stock/inventory_units_finalizer_spec.rb +4 -4
  202. data/spec/models/spree/stock/package_spec.rb +28 -28
  203. data/spec/models/spree/stock/quantifier_spec.rb +3 -3
  204. data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
  205. data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
  206. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
  207. data/spec/models/spree/stock_quantities_spec.rb +1 -1
  208. data/spec/models/spree/store_credit_spec.rb +8 -8
  209. data/spec/models/spree/tax_category_spec.rb +1 -1
  210. data/spec/models/spree/tax_rate_spec.rb +1 -0
  211. data/spec/models/spree/taxon_spec.rb +2 -2
  212. data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
  213. data/spec/models/spree/unit_cancel_spec.rb +5 -0
  214. data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
  215. data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
  216. data/spec/models/spree/user_spec.rb +3 -3
  217. metadata +46 -41
  218. data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -148
  219. data/spec/models/spree/order/updating_spec.rb +0 -18
data/solidus_core.gemspec CHANGED
@@ -17,27 +17,27 @@ Gem::Specification.new do |s|
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.require_path = 'lib'
19
19
 
20
- s.required_ruby_version = '>= 2.2.2'
20
+ s.required_ruby_version = '>= 2.4.0'
21
21
  s.required_rubygems_version = '>= 1.8.23'
22
22
 
23
23
  %w[
24
24
  actionmailer actionpack actionview activejob activemodel activerecord
25
25
  activesupport railties
26
26
  ].each do |rails_dep|
27
- s.add_dependency rails_dep, ['>= 5.1', '< 5.3.x']
27
+ s.add_dependency rails_dep, ['>= 5.1', '< 7.0.x']
28
28
  end
29
29
 
30
30
  s.add_dependency 'activemerchant', '~> 1.66'
31
31
  s.add_dependency 'acts_as_list', '~> 0.3'
32
- s.add_dependency 'awesome_nested_set', '~> 3.0', '>= 3.0.1'
33
- s.add_dependency 'cancancan', '~> 2.2'
32
+ s.add_dependency 'awesome_nested_set', '~> 3.2'
33
+ s.add_dependency 'cancancan', ['>= 2.2', '< 4.0']
34
34
  s.add_dependency 'carmen', '~> 1.1.0'
35
35
  s.add_dependency 'discard', '~> 1.0'
36
36
  s.add_dependency 'friendly_id', '~> 5.0'
37
37
  s.add_dependency 'kaminari-activerecord', '~> 1.1'
38
38
  s.add_dependency 'monetize', '~> 1.8'
39
- s.add_dependency 'paperclip', ['>= 4.2', '< 6']
39
+ s.add_dependency 'paperclip', '>= 4.2'
40
40
  s.add_dependency 'paranoia', '~> 2.4'
41
41
  s.add_dependency 'ransack', '~> 2.0'
42
- s.add_dependency 'state_machines-activerecord', '~> 0.4'
42
+ s.add_dependency 'state_machines-activerecord', '~> 0.6'
43
43
  end
@@ -60,7 +60,11 @@ RSpec.describe Spree::Core::Search::Base do
60
60
  search: { "price_range_any" => ["Under $10.00", "$10.00 - $15.00"] } }
61
61
  searcher = Spree::Core::Search::Base.new(params)
62
62
  expect(searcher.send(:get_base_scope).to_sql).to match /<= 10/
63
- expect(searcher.send(:get_base_scope).to_sql).to match /between 10 and 15/i
63
+ if Rails.gem_version >= Gem::Version.new('6.0.0')
64
+ expect(searcher.send(:get_base_scope).to_sql).to match /between 10\.0 and 15\.0/i
65
+ else
66
+ expect(searcher.send(:get_base_scope).to_sql).to match /between 10 and 15/i
67
+ end
64
68
  expect(searcher.retrieve_products.count).to eq(2)
65
69
  end
66
70
 
@@ -85,7 +85,7 @@ module Spree
85
85
  example.run
86
86
  described_class.search_terms = search_terms
87
87
  end
88
- before { variant.update_attributes!(weight: 5000) }
88
+ before { variant.update!(weight: 5000) }
89
89
 
90
90
  it { assert_found("5000", variant) }
91
91
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
  require 'spree/core/environment_extension'
5
5
 
6
6
  RSpec.describe Spree::Core::EnvironmentExtension do
7
- let(:base) { Class.new }
7
+ let(:base) { Class.new { def self.to_s; 'ExampleClass'; end } }
8
8
  subject! { base.include(described_class).new }
9
9
 
10
10
  describe '.add_class_set' do
@@ -32,4 +32,15 @@ RSpec.describe Spree::Core::EnvironmentExtension do
32
32
  end
33
33
  end
34
34
  end
35
+
36
+ describe '#add_class' do
37
+ it 'is deprecated' do
38
+ expect(Spree::Deprecation).to receive(:warn) do |message, _caller|
39
+ expect(message).to include('ExampleClass.add_class_set(:foo)')
40
+ end
41
+ expect(base).to receive(:add_class_set).with(:foo)
42
+
43
+ base.new.add_class(:foo)
44
+ end
45
+ end
35
46
  end
@@ -39,6 +39,24 @@ RSpec.describe Spree::Core::StockConfiguration do
39
39
  end
40
40
  end
41
41
 
42
+ describe '#location_filter_class' do
43
+ let(:stock_configuration) { described_class.new }
44
+ subject { stock_configuration.location_filter_class }
45
+
46
+ it "returns Spree::Stock::LocationFilter::Active" do
47
+ is_expected.to be ::Spree::Stock::LocationFilter::Active
48
+ end
49
+
50
+ context "with another constant name assiged" do
51
+ MyFilter = Class.new
52
+ before { stock_configuration.location_filter_class = MyFilter.to_s }
53
+
54
+ it "returns the constant" do
55
+ is_expected.to be MyFilter
56
+ end
57
+ end
58
+ end
59
+
42
60
  describe '#location_sorter_class' do
43
61
  let(:stock_configuration) { described_class.new }
44
62
  subject { stock_configuration.location_sorter_class }
@@ -56,4 +74,22 @@ RSpec.describe Spree::Core::StockConfiguration do
56
74
  end
57
75
  end
58
76
  end
77
+
78
+ describe '#allocator_class' do
79
+ let(:stock_configuration) { described_class.new }
80
+ subject { stock_configuration.allocator_class }
81
+
82
+ it "returns Spree::Stock::Allocator::OnHandFirst" do
83
+ is_expected.to be ::Spree::Stock::Allocator::OnHandFirst
84
+ end
85
+
86
+ context "with another constant name assiged" do
87
+ MyAllocator = Class.new
88
+ before { stock_configuration.allocator_class = MyAllocator.to_s }
89
+
90
+ it "returns the constant" do
91
+ is_expected.to be MyAllocator
92
+ end
93
+ end
94
+ end
59
95
  end
@@ -12,27 +12,27 @@ RSpec.describe Spree::EmailValidator do
12
12
 
13
13
  let(:valid_emails) {
14
14
  [
15
- 'valid@email.com',
16
- 'valid@email.com.uk',
17
- 'e@email.com',
18
- 'valid+email@email.com',
19
- 'valid-email@email.com',
20
- 'valid_email@email.com',
21
- 'valid.email@email.com'
22
- ]
15
+ 'valid@email.com',
16
+ 'valid@email.com.uk',
17
+ 'e@email.com',
18
+ 'valid+email@email.com',
19
+ 'valid-email@email.com',
20
+ 'valid_email@email.com',
21
+ 'valid.email@email.com'
22
+ ]
23
23
  }
24
24
  let(:invalid_emails) {
25
25
  [
26
- 'invalid email@email.com',
27
- '.invalid.email@email.com',
28
- 'invalid.email.@email.com',
29
- '@email.com',
30
- '.@email.com',
31
- 'invalidemailemail.com',
32
- '@invalid.email@email.com',
33
- 'invalid@email@email.com',
34
- 'invalid.email@@email.com'
35
- ]
26
+ 'invalid email@email.com',
27
+ '.invalid.email@email.com',
28
+ 'invalid.email.@email.com',
29
+ '@email.com',
30
+ '.@email.com',
31
+ 'invalidemailemail.com',
32
+ '@invalid.email@email.com',
33
+ 'invalid@email@email.com',
34
+ 'invalid.email@@email.com'
35
+ ]
36
36
  }
37
37
 
38
38
  it 'validates valid email addresses' do
@@ -18,14 +18,26 @@ RSpec.describe Spree::Event do
18
18
  before do
19
19
  # ActiveSupport::Notifications does not provide an interface to clean all
20
20
  # subscribers at once, so some low level brittle code is required
21
- @old_subscribers = notifier.instance_variable_get('@subscribers').dup
21
+ if Rails.gem_version >= Gem::Version.new('6.0.0')
22
+ @old_string_subscribers = notifier.instance_variable_get('@string_subscribers').dup
23
+ @old_other_subscribers = notifier.instance_variable_get('@other_subscribers').dup
24
+ notifier.instance_variable_get('@string_subscribers').clear
25
+ notifier.instance_variable_get('@other_subscribers').clear
26
+ else
27
+ @old_subscribers = notifier.instance_variable_get('@subscribers').dup
28
+ notifier.instance_variable_get('@subscribers').clear
29
+ end
22
30
  @old_listeners = notifier.instance_variable_get('@listeners_for').dup
23
- notifier.instance_variable_get('@subscribers').clear
24
31
  notifier.instance_variable_get('@listeners_for').clear
25
32
  end
26
33
 
27
34
  after do
28
- notifier.instance_variable_set '@subscribers', @old_subscribers
35
+ if Rails.gem_version >= Gem::Version.new('6.0.0')
36
+ notifier.instance_variable_set '@string_subscribers', @old_string_subscribers
37
+ notifier.instance_variable_set '@other_subscribers', @old_other_subscribers
38
+ else
39
+ notifier.instance_variable_set '@subscribers', @old_subscribers
40
+ end
29
41
  notifier.instance_variable_set '@listeners_for', @old_listeners
30
42
  end
31
43
 
@@ -152,6 +152,29 @@ RSpec.describe Spree::Address, type: :model do
152
152
  it "sets up a new record with Spree::Config[:default_country_iso]" do
153
153
  expect(Spree::Address.build_default.country).to eq default_country
154
154
  end
155
+
156
+ it 'accepts other attributes' do
157
+ address = Spree::Address.build_default(first_name: 'Ryan')
158
+
159
+ expect(address.country).to eq default_country
160
+ expect(address.first_name).to eq 'Ryan'
161
+ end
162
+
163
+ it 'accepts a block' do
164
+ address = Spree::Address.build_default do |record|
165
+ record.first_name = 'Ryan'
166
+ end
167
+
168
+ expect(address.country).to eq default_country
169
+ expect(address.first_name).to eq 'Ryan'
170
+ end
171
+
172
+ it 'can override the country' do
173
+ another_country = build :country
174
+ address = Spree::Address.build_default(country: another_country)
175
+
176
+ expect(address.country).to eq another_country
177
+ end
155
178
  end
156
179
 
157
180
  # Regression test for https://github.com/spree/spree/issues/1142
@@ -36,7 +36,7 @@ RSpec.describe Spree::Calculator::Returns::DefaultRefundAmount, type: :model do
36
36
  source_type: 'Spree::Order'
37
37
  )
38
38
 
39
- order.adjustments.first.update_attributes(amount: adjustment_amount)
39
+ order.adjustments.first.update(amount: adjustment_amount)
40
40
  end
41
41
 
42
42
  it 'will return the line item amount deducted of refund' do
@@ -25,7 +25,7 @@ module Spree
25
25
  )
26
26
  end
27
27
 
28
- subject { FlatPercentItemTotal.new(preferred_flat_percent: 10) }
28
+ subject { described_class.new(preferred_flat_percent: 10) }
29
29
 
30
30
  it "should round result correctly" do
31
31
  expect(subject.compute(package)).to eq(4.04)
@@ -6,7 +6,7 @@ require 'shared_examples/calculator_shared_examples'
6
6
  module Spree
7
7
  module Calculator::Shipping
8
8
  RSpec.describe FlatRate, type: :model do
9
- subject { Calculator::Shipping::FlatRate.new(preferred_amount: 4.00) }
9
+ subject { described_class.new(preferred_amount: 4.00) }
10
10
 
11
11
  it_behaves_like 'a calculator with a description'
12
12
 
@@ -15,7 +15,7 @@ module Spree
15
15
  build(:stock_package, variants_contents: { variant1 => 4, variant2 => 6 })
16
16
  end
17
17
 
18
- let(:subject) { FlexiRate.new }
18
+ let(:subject) { described_class.new }
19
19
 
20
20
  context "compute" do
21
21
  it "should compute amount correctly when all fees are 0" do
@@ -46,7 +46,7 @@ module Spree
46
46
  end
47
47
 
48
48
  it "should allow creation of new object with all the attributes" do
49
- FlexiRate.new(preferred_first_item: 1,
49
+ described_class.new(preferred_first_item: 1,
50
50
  preferred_additional_item: 1,
51
51
  preferred_max_items: 1)
52
52
  end
@@ -15,7 +15,7 @@ module Spree
15
15
  build(:stock_package, variants_contents: { variant1 => 5, variant2 => 3 })
16
16
  end
17
17
 
18
- subject { PerItem.new(preferred_amount: 10) }
18
+ subject { described_class.new(preferred_amount: 10) }
19
19
 
20
20
  it "correctly calculates per item shipping" do
21
21
  expect(subject.compute(package).to_f).to eq(80) # 5 x 10 + 3 x 10
@@ -5,7 +5,7 @@ require 'shared_examples/calculator_shared_examples'
5
5
 
6
6
  RSpec.describe Spree::Calculator::Shipping::PriceSack, type: :model do
7
7
  let(:calculator) do
8
- calculator = Spree::Calculator::PriceSack.new
8
+ calculator = described_class.new
9
9
  calculator.preferred_minimal_amount = 5
10
10
  calculator.preferred_normal_amount = 10
11
11
  calculator.preferred_discount_amount = 1
@@ -14,22 +14,31 @@ RSpec.describe Spree::Calculator::Shipping::PriceSack, type: :model do
14
14
 
15
15
  it_behaves_like 'a calculator with a description'
16
16
 
17
- let(:order) { stub_model(Spree::Order) }
18
- let(:shipment) { stub_model(Spree::Shipment, amount: 10) }
17
+ describe '#compute' do
18
+ subject { calculator.compute(package) }
19
+ let(:package) { build(:stock_package, variants_contents: { build(:variant) => 1 }) }
19
20
 
20
- # Regression test for https://github.com/spree/spree/issues/714 and https://github.com/spree/spree/issues/739
21
- it "computes with an order object" do
22
- calculator.compute(order)
23
- end
21
+ before do
22
+ # This hack is due to our factories not being so smart to understand
23
+ # that they should create line items with the price of the associated
24
+ # variant by default.
25
+ allow_any_instance_of(Spree::Stock::ContentItem).to receive(:price) { amount }
26
+ end
24
27
 
25
- # Regression test for https://github.com/spree/spree/issues/1156
26
- it "computes with a shipment object" do
27
- calculator.compute(shipment)
28
- end
28
+ context 'when price < minimal amount' do
29
+ let(:amount) { 2 }
30
+
31
+ it "returns the discounted amount" do
32
+ expect(subject).to eq(10)
33
+ end
34
+ end
35
+
36
+ context 'when price > minimal amount' do
37
+ let(:amount) { 6 }
29
38
 
30
- # Regression test for https://github.com/spree/spree/issues/2055
31
- it "computes the correct amount" do
32
- expect(calculator.compute(2)).to eq(calculator.preferred_normal_amount)
33
- expect(calculator.compute(6)).to eq(calculator.preferred_discount_amount)
39
+ it "returns the discounted amount" do
40
+ expect(subject).to eq(1)
41
+ end
42
+ end
34
43
  end
35
44
  end
@@ -5,6 +5,14 @@ require 'rails_helper'
5
5
  RSpec.describe Spree::Carton do
6
6
  let(:carton) { create(:carton) }
7
7
 
8
+ describe 'shipping method' do
9
+ it 'returns soft deleted shipping method' do
10
+ carton = create(:carton)
11
+ carton.shipping_method.discard
12
+ expect(carton.reload.shipping_method).to be_present
13
+ end
14
+ end
15
+
8
16
  describe "#create" do
9
17
  subject { carton }
10
18
 
@@ -73,8 +81,8 @@ RSpec.describe Spree::Carton do
73
81
  let(:email) { 'something@something.com' }
74
82
 
75
83
  before do
76
- first_order.update_attributes!(email: email)
77
- second_order.update_attributes!(email: email)
84
+ first_order.update!(email: email)
85
+ second_order.update!(email: email)
78
86
  end
79
87
 
80
88
  it "returns a unique list of the order emails it is associated to" do
@@ -34,9 +34,21 @@ module Spree
34
34
 
35
35
  context "removing product from taxon" do
36
36
  before :each do
37
- p = taxon_with_5_products.products[1]
38
- expect(p.classifications.first.position).to eq(2)
39
- taxon_with_5_products.products.destroy(p)
37
+ element = taxon_with_5_products.products[1]
38
+ expect(element.classifications.first.position).to eq(2)
39
+ taxon_with_5_products.products.destroy(element)
40
+ end
41
+
42
+ it "resets positions" do
43
+ expect positions_to_be_valid(taxon_with_5_products)
44
+ end
45
+ end
46
+
47
+ context "Discard'ing a product" do
48
+ before :each do
49
+ element = taxon_with_5_products.products[1]
50
+ expect(element.classifications.first.position).to eq(2)
51
+ element.discard
40
52
  end
41
53
 
42
54
  it "resets positions" do
@@ -59,9 +71,9 @@ module Spree
59
71
 
60
72
  context "removing taxon from product" do
61
73
  before :each do
62
- p = taxon_with_5_products.products[1]
63
- p.taxons.destroy(taxon_with_5_products)
64
- p.save!
74
+ element = taxon_with_5_products.products[1]
75
+ element.taxons.destroy(taxon_with_5_products)
76
+ element.save!
65
77
  end
66
78
 
67
79
  it "resets positions" do
@@ -71,9 +83,9 @@ module Spree
71
83
 
72
84
  context "replacing product's taxons" do
73
85
  before :each do
74
- p = taxon_with_5_products.products[1]
75
- p.taxons = []
76
- p.save!
86
+ element = taxon_with_5_products.products[1]
87
+ element.taxons = []
88
+ element.save!
77
89
  end
78
90
 
79
91
  it "resets positions" do
@@ -77,7 +77,7 @@ module Spree
77
77
  end
78
78
 
79
79
  context "and changing another address field at the same time" do
80
- let(:updated_address_attributes) { address.attributes.tap { |a| a[:first_name] = "Newbie" } }
80
+ let(:updated_address_attributes) { address.attributes.tap { |value| value[:first_name] = "Newbie" } }
81
81
 
82
82
  subject { user.save_in_address_book(updated_address_attributes, true) }
83
83
 
@@ -104,7 +104,7 @@ module Spree
104
104
  let(:address1) { create(:address) }
105
105
  let(:address2) { create(:address, firstname: "Different") }
106
106
  let(:updated_attrs) do
107
- address2.attributes.tap { |a| a[:firstname] = "Johnny" }
107
+ address2.attributes.tap { |value| value[:firstname] = "Johnny" }
108
108
  end
109
109
 
110
110
  before do
@@ -191,8 +191,8 @@ module Spree
191
191
 
192
192
  it "archives address2" do
193
193
  subject
194
- user_address2 = user.user_addresses.all_historical.find_by(address_id: address2.id)
195
- expect(user_address2.archived).to be true
194
+ user_address_two = user.user_addresses.all_historical.find_by(address_id: address2.id)
195
+ expect(user_address_two.archived).to be true
196
196
  end
197
197
 
198
198
  context "via a new address that matches an archived one" do
@@ -62,7 +62,7 @@ RSpec.describe Spree::UserMethods do
62
62
 
63
63
  describe '#available_store_credit_total' do
64
64
  subject do
65
- test_user.available_store_credit_total(currency: 'USD')
65
+ test_user.reload.available_store_credit_total(currency: 'USD')
66
66
  end
67
67
 
68
68
  context 'when the user does not have any credit' do
@@ -76,25 +76,26 @@ RSpec.describe Spree::UserMethods do
76
76
  it { is_expected.to eq(100 + 200) }
77
77
 
78
78
  context 'when some has been used' do
79
- before { credit_1.update_attributes!(amount_used: 35) }
79
+ before { credit_1.update!(amount_used: 35) }
80
80
 
81
81
  it { is_expected.to eq(100 + 200 - 35) }
82
82
 
83
83
  context 'when some has been authorized' do
84
- before { credit_1.update_attributes!(amount_authorized: 10) }
84
+ before { credit_1.update!(amount_authorized: 10) }
85
85
 
86
86
  it { is_expected.to eq(100 + 200 - 35 - 10) }
87
87
  end
88
88
  end
89
89
 
90
90
  context 'when some has been authorized' do
91
- before { credit_1.update_attributes!(amount_authorized: 10) }
91
+ before { credit_1.update!(amount_authorized: 10) }
92
92
 
93
93
  it { is_expected.to eq(100 + 200 - 10) }
94
94
  end
95
95
 
96
96
  context 'with credits of multiple currencies' do
97
97
  let!(:credit_3) { create(:store_credit, user: test_user, amount: 400, currency: 'GBP') }
98
+ before { test_user.reload }
98
99
 
99
100
  it 'separates the currencies' do
100
101
  expect(test_user.available_store_credit_total(currency: 'USD')).to eq(100 + 200)
@@ -109,10 +109,10 @@ RSpec.describe Spree::CreditCard, type: :model do
109
109
  end
110
110
 
111
111
  it "should save and update addresses through nested attributes" do
112
- persisted_card.update_attributes({ address_attributes: valid_address_attributes })
112
+ persisted_card.update({ address_attributes: valid_address_attributes })
113
113
  persisted_card.save!
114
114
  updated_attributes = { id: persisted_card.address.id, address1: "123 Main St." }
115
- persisted_card.update_attributes({ address_attributes: updated_attributes })
115
+ persisted_card.update({ address_attributes: updated_attributes })
116
116
  expect(persisted_card.address.address1).to eq "123 Main St."
117
117
  end
118
118
  end
@@ -233,7 +233,7 @@ RSpec.describe Spree::CustomerReturn, type: :model do
233
233
 
234
234
  context "it was not received" do
235
235
  before do
236
- return_item.update_attributes!(reception_status: "lost_in_transit")
236
+ return_item.update!(reception_status: "lost_in_transit")
237
237
  end
238
238
 
239
239
  it 'should not updated inventory unit to returned' do
@@ -456,7 +456,7 @@ RSpec.describe Spree::Order, type: :model do
456
456
  order.line_items << FactoryBot.create(:line_item)
457
457
  order.line_items.first.variant.stock_items.each do |si|
458
458
  si.set_count_on_hand(0)
459
- si.update_attributes(backorderable: false)
459
+ si.update(backorderable: false)
460
460
  end
461
461
 
462
462
  Spree::OrderUpdater.new(order).update
@@ -16,7 +16,7 @@ RSpec.describe "Outstanding balance integration tests" do
16
16
  let!(:order) { create(:order_with_line_items, line_items_count: 2, line_items_price: 3, shipment_cost: 13) }
17
17
  let(:item_1) { order.line_items[0] }
18
18
  let(:item_2) { order.line_items[1] }
19
- before { order.update_attributes!(state: 'complete', completed_at: Time.now) }
19
+ before { order.update!(state: 'complete', completed_at: Time.now) }
20
20
 
21
21
  subject do
22
22
  order.reload
@@ -44,11 +44,11 @@ RSpec.describe "Outstanding balance integration tests" do
44
44
  end
45
45
 
46
46
  context 'when the order is cancelled' do
47
- before { order.update_attributes!(state: "canceled") }
47
+ before { order.update!(state: "canceled") }
48
48
  it { should eq(-19) }
49
49
 
50
50
  context 'and the payment is voided' do
51
- before { payment.update_attributes!(state: "void") }
51
+ before { payment.update!(state: "void") }
52
52
  it { should eq 0 }
53
53
  end
54
54
 
@@ -116,11 +116,11 @@ RSpec.describe "Outstanding balance integration tests" do
116
116
  end
117
117
 
118
118
  context 'when the order is cancelled' do
119
- before { order.update_attributes!(state: "canceled") }
119
+ before { order.update!(state: "canceled") }
120
120
  it { should eq(-10) }
121
121
 
122
122
  context 'and the payment is voided' do
123
- before { payment.update_attributes!(state: "void") }
123
+ before { payment.update!(state: "void") }
124
124
  it { should eq 0 }
125
125
  end
126
126
 
@@ -213,7 +213,7 @@ module Spree
213
213
  end
214
214
 
215
215
  context "for canceled orders" do
216
- before { order.update_attributes(state: 'canceled') }
216
+ before { order.update(state: 'canceled') }
217
217
 
218
218
  it "it should be zero" do
219
219
  expect(order.total).to eq(110)
@@ -134,7 +134,7 @@ RSpec.describe Spree::OrderContents, type: :model do
134
134
 
135
135
  context 'when the order does not have a taxable address' do
136
136
  before do
137
- order.update_attributes!(ship_address: nil, bill_address: nil)
137
+ order.update!(ship_address: nil, bill_address: nil)
138
138
  expect(order.tax_address.country_id).to be_nil
139
139
  end
140
140
 
@@ -16,7 +16,7 @@ RSpec.describe Spree::OrderInventory, type: :model do
16
16
  let(:new_quantity) { 3 }
17
17
 
18
18
  before do
19
- line_item.update_attributes!(quantity: old_quantity)
19
+ line_item.update!(quantity: old_quantity)
20
20
 
21
21
  line_item.update_column(:quantity, new_quantity)
22
22
  subject.line_item.reload
@@ -86,7 +86,7 @@ RSpec.describe Spree::OrderInventory, type: :model do
86
86
  end
87
87
 
88
88
  context "variant doesnt track inventory" do
89
- before { variant.update_attributes!(track_inventory: false) }
89
+ before { variant.update!(track_inventory: false) }
90
90
  let(:new_quantity) { 1 }
91
91
 
92
92
  it "creates on hand inventory units" do
@@ -164,7 +164,7 @@ RSpec.describe Spree::OrderInventory, type: :model do
164
164
  let(:new_quantity) { 2 }
165
165
 
166
166
  before do
167
- line_item.update_attributes!(quantity: old_quantity)
167
+ line_item.update!(quantity: old_quantity)
168
168
 
169
169
  line_item.update_column(:quantity, new_quantity)
170
170
  subject.line_item.reload
@@ -77,13 +77,13 @@ module Spree
77
77
 
78
78
  context "2 equal line items" do
79
79
  before do
80
- @line_item_1 = order_1.contents.add(variant, 1, foos: {})
81
- @line_item_2 = order_2.contents.add(variant, 1, foos: {})
80
+ @line_item_one = order_1.contents.add(variant, 1, foos: {})
81
+ @line_item_two = order_2.contents.add(variant, 1, foos: {})
82
82
  end
83
83
 
84
84
  specify do
85
85
  without_partial_double_verification do
86
- expect(order_1).to receive(:foos_match).with(@line_item_1, kind_of(Hash)).and_return(true)
86
+ expect(order_1).to receive(:foos_match).with(@line_item_one, kind_of(Hash)).and_return(true)
87
87
  end
88
88
  subject.merge!(order_2)
89
89
  expect(order_1.line_items.count).to eq(1)
@@ -181,7 +181,7 @@ RSpec.describe Spree::OrderShipping do
181
181
  # OrderShipping#ship rather than vice versa
182
182
  context "when the tracking number is already on the shipment" do
183
183
  before do
184
- shipment.update_attributes!(tracking: 'tracking-number')
184
+ shipment.update!(tracking: 'tracking-number')
185
185
  end
186
186
 
187
187
  it "sets the tracking-number" do