solidus_core 2.10.0.beta1 → 2.10.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (142) 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_methods.rb +2 -2
  6. data/app/models/spree/address.rb +11 -15
  7. data/app/models/spree/adjustment.rb +11 -0
  8. data/app/models/spree/calculator/price_sack.rb +1 -1
  9. data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
  10. data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
  11. data/app/models/spree/calculator/tiered_percent.rb +6 -6
  12. data/app/models/spree/carton.rb +1 -1
  13. data/app/models/spree/credit_card.rb +2 -2
  14. data/app/models/spree/inventory_unit.rb +1 -19
  15. data/app/models/spree/line_item.rb +1 -1
  16. data/app/models/spree/order.rb +3 -2
  17. data/app/models/spree/order/checkout.rb +1 -1
  18. data/app/models/spree/order/payments.rb +2 -2
  19. data/app/models/spree/order_capturing.rb +2 -2
  20. data/app/models/spree/order_taxation.rb +2 -2
  21. data/app/models/spree/payment.rb +4 -41
  22. data/app/models/spree/payment/processing.rb +2 -2
  23. data/app/models/spree/payment_method.rb +2 -2
  24. data/app/models/spree/product.rb +3 -3
  25. data/app/models/spree/product/scopes.rb +9 -8
  26. data/app/models/spree/promotion.rb +27 -12
  27. data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
  28. data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
  29. data/app/models/spree/promotion/rules/option_value.rb +2 -2
  30. data/app/models/spree/promotion/rules/product.rb +3 -3
  31. data/app/models/spree/promotion_action.rb +1 -1
  32. data/app/models/spree/promotion_chooser.rb +2 -2
  33. data/app/models/spree/promotion_code.rb +9 -8
  34. data/app/models/spree/promotion_code/batch_builder.rb +3 -3
  35. data/app/models/spree/promotion_rule.rb +1 -1
  36. data/app/models/spree/refund.rb +2 -2
  37. data/app/models/spree/reimbursement.rb +3 -11
  38. data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
  39. data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
  40. data/app/models/spree/return_authorization.rb +1 -7
  41. data/app/models/spree/return_item.rb +3 -42
  42. data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
  43. data/app/models/spree/shipment.rb +4 -38
  44. data/app/models/spree/shipping_calculator.rb +0 -4
  45. data/app/models/spree/shipping_method.rb +1 -1
  46. data/app/models/spree/state.rb +1 -1
  47. data/app/models/spree/stock/differentiator.rb +1 -1
  48. data/app/models/spree/stock/package.rb +1 -1
  49. data/app/models/spree/stock_item.rb +1 -1
  50. data/app/models/spree/stock_quantities.rb +13 -12
  51. data/app/models/spree/tax_calculator/default.rb +0 -4
  52. data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
  53. data/app/models/spree/tax_rate.rb +4 -0
  54. data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
  55. data/app/models/spree/user_last_url_storer.rb +46 -0
  56. data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
  57. data/app/models/spree/variant.rb +9 -9
  58. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
  59. data/app/models/spree/zone.rb +1 -1
  60. data/config/initializers/money.rb +2 -0
  61. data/config/locales/en.yml +12 -0
  62. data/lib/generators/spree/install/install_generator.rb +3 -0
  63. data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
  64. data/lib/spree/app_configuration.rb +18 -3
  65. data/lib/spree/core.rb +12 -0
  66. data/lib/spree/core/controller_helpers/auth.rb +1 -13
  67. data/lib/spree/core/controller_helpers/strong_parameters.rb +21 -7
  68. data/lib/spree/core/engine.rb +2 -2
  69. data/lib/spree/core/environment_extension.rb +9 -0
  70. data/lib/spree/core/importer/order.rb +27 -26
  71. data/lib/spree/core/product_filters.rb +15 -15
  72. data/lib/spree/core/role_configuration.rb +2 -2
  73. data/lib/spree/core/search/variant.rb +1 -1
  74. data/lib/spree/core/state_machines.rb +78 -0
  75. data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
  76. data/lib/spree/core/state_machines/payment.rb +61 -0
  77. data/lib/spree/core/state_machines/reimbursement.rb +33 -0
  78. data/lib/spree/core/state_machines/return_authorization.rb +32 -0
  79. data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
  80. data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
  81. data/lib/spree/core/state_machines/shipment.rb +58 -0
  82. data/lib/spree/core/stock_configuration.rb +1 -0
  83. data/lib/spree/core/validators/email.rb +1 -8
  84. data/lib/spree/core/version.rb +1 -1
  85. data/lib/spree/money.rb +2 -2
  86. data/lib/spree/permission_sets/user_management.rb +3 -0
  87. data/lib/spree/permitted_attributes.rb +78 -9
  88. data/lib/spree/preferences/static_model_preferences.rb +2 -2
  89. data/lib/spree/testing_support/dummy_app.rb +4 -1
  90. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
  91. data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
  92. data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
  93. data/lib/spree/testing_support/factories/user_factory.rb +4 -1
  94. data/solidus_core.gemspec +4 -4
  95. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +8 -1
  96. data/spec/lib/spree/core/environment_extension_spec.rb +12 -1
  97. data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
  98. data/spec/lib/spree/core/validators/email_spec.rb +18 -18
  99. data/spec/lib/spree/permitted_attributes_spec.rb +41 -0
  100. data/spec/models/spree/ability_spec.rb +1 -1
  101. data/spec/models/spree/address_spec.rb +23 -0
  102. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
  103. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
  104. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
  105. data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
  106. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
  107. data/spec/models/spree/carton_spec.rb +8 -0
  108. data/spec/models/spree/classification_spec.rb +21 -9
  109. data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
  110. data/spec/models/spree/concerns/user_methods_spec.rb +2 -1
  111. data/spec/models/spree/order_merger_spec.rb +3 -3
  112. data/spec/models/spree/order_spec.rb +8 -15
  113. data/spec/models/spree/order_updater_spec.rb +4 -3
  114. data/spec/models/spree/payment_create_spec.rb +4 -14
  115. data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
  116. data/spec/models/spree/preference_spec.rb +4 -4
  117. data/spec/models/spree/preferences/preferable_spec.rb +3 -3
  118. data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
  119. data/spec/models/spree/promotion/rules/taxon_spec.rb +1 -0
  120. data/spec/models/spree/promotion_rule_spec.rb +6 -6
  121. data/spec/models/spree/promotion_spec.rb +73 -52
  122. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
  123. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
  124. data/spec/models/spree/returns_calculator_spec.rb +2 -2
  125. data/spec/models/spree/shipping_calculator_spec.rb +1 -13
  126. data/spec/models/spree/shipping_method_spec.rb +32 -0
  127. data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
  128. data/spec/models/spree/stock/differentiator_spec.rb +2 -2
  129. data/spec/models/spree/stock/estimator_spec.rb +3 -3
  130. data/spec/models/spree/stock/package_spec.rb +28 -28
  131. data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
  132. data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
  133. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
  134. data/spec/models/spree/stock_quantities_spec.rb +1 -1
  135. data/spec/models/spree/store_credit_spec.rb +1 -1
  136. data/spec/models/spree/tax_rate_spec.rb +1 -0
  137. data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
  138. data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
  139. data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
  140. metadata +41 -35
  141. data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -162
  142. data/spec/models/spree/order/updating_spec.rb +0 -18
@@ -30,8 +30,8 @@ module Spree
30
30
  end
31
31
 
32
32
  def initialize
33
- @store = Hash.new do |h, klass|
34
- h[klass] = {}
33
+ @store = Hash.new do |data, klass|
34
+ data[klass] = {}
35
35
  end
36
36
  end
37
37
 
@@ -13,6 +13,7 @@ Rails.env = 'test'
13
13
  require 'solidus_core'
14
14
 
15
15
  RAILS_52_OR_ABOVE = Gem::Version.new(Rails.version) >= Gem::Version.new('5.2')
16
+ RAILS_6_OR_ABOVE = Gem::Version.new(Rails.version) >= Gem::Version.new('6.0')
16
17
 
17
18
  # @private
18
19
  class ApplicationController < ActionController::Base
@@ -64,7 +65,9 @@ module DummyApp
64
65
 
65
66
  if RAILS_52_OR_ABOVE
66
67
  config.action_controller.default_protect_from_forgery = true
67
- config.active_record.sqlite3.represent_boolean_as_integer = true
68
+ unless RAILS_6_OR_ABOVE
69
+ config.active_record.sqlite3.represent_boolean_as_integer = true
70
+ end
68
71
  end
69
72
 
70
73
  # Avoid issues if an old spec/dummy still exists
@@ -9,6 +9,7 @@ FactoryBot.define do
9
9
  factory :inventory_unit, class: 'Spree::InventoryUnit' do
10
10
  transient do
11
11
  order { nil }
12
+ stock_location { nil }
12
13
  end
13
14
 
14
15
  variant
@@ -20,7 +21,13 @@ FactoryBot.define do
20
21
  end
21
22
  end
22
23
  state { 'on_hand' }
23
- shipment { build(:shipment, state: 'pending', order: line_item.order) }
24
+ shipment do
25
+ if stock_location
26
+ build(:shipment, state: 'pending', order: line_item.order, stock_location: stock_location)
27
+ else
28
+ build(:shipment, state: 'pending', order: line_item.order)
29
+ end
30
+ end
24
31
  # return_authorization
25
32
  end
26
33
  end
@@ -27,8 +27,15 @@ FactoryBot.define do
27
27
  Spree::Promotion::Actions::CreateItemAdjustments.create!(calculator: calculator, promotion: promotion)
28
28
  end
29
29
  end
30
+
30
31
  factory :promotion_with_item_adjustment, traits: [:with_line_item_adjustment]
31
32
 
33
+ trait :with_free_shipping do
34
+ after(:create) do |promotion|
35
+ Spree::Promotion::Actions::FreeShipping.create!(promotion: promotion)
36
+ end
37
+ end
38
+
32
39
  trait :with_order_adjustment do
33
40
  transient do
34
41
  weighted_order_adjustment_amount { 10 }
@@ -17,7 +17,7 @@ FactoryBot.define do
17
17
 
18
18
  after(:build) do |package, evaluator|
19
19
  evaluator.variants_contents.each do |variant, count|
20
- package.add_multiple build_list(:inventory_unit, count, variant: variant)
20
+ package.add_multiple build_list(:inventory_unit, count, variant: variant, stock_location: evaluator.stock_location)
21
21
  end
22
22
  end
23
23
 
@@ -17,7 +17,10 @@ FactoryBot.define do
17
17
  end
18
18
 
19
19
  factory :admin_user do
20
- spree_roles { [Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')] }
20
+ after(:create) do |user, _|
21
+ admin_role = Spree::Role.find_by(name: 'admin') || create(:role, name: 'admin')
22
+ user.spree_roles << admin_role
23
+ end
21
24
  end
22
25
 
23
26
  factory :user_with_addresses do |_u|
data/solidus_core.gemspec CHANGED
@@ -17,18 +17,18 @@ 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', '< 7.0.x']
27
+ s.add_dependency rails_dep, ['>= 5.1', '< 6.1.x']
28
28
  end
29
29
 
30
30
  s.add_dependency 'activemerchant', '~> 1.66'
31
- s.add_dependency 'acts_as_list', '~> 0.3'
31
+ s.add_dependency 'acts_as_list', '< 2.0'
32
32
  s.add_dependency 'awesome_nested_set', '~> 3.2'
33
33
  s.add_dependency 'cancancan', ['>= 2.2', '< 4.0']
34
34
  s.add_dependency 'carmen', '~> 1.1.0'
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
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
42
  s.add_dependency 'state_machines-activerecord', '~> 0.6'
@@ -23,7 +23,14 @@ RSpec.describe Spree::Core::ControllerHelpers::StrongParameters, type: :controll
23
23
 
24
24
  describe '#permitted_checkout_attributes' do
25
25
  it 'returns Array class' do
26
- expect(controller.permitted_checkout_attributes.class).to eq Array
26
+ Spree::Deprecation.silence do
27
+ expect(controller.permitted_checkout_attributes.class).to eq Spree::CheckoutAdditionalAttributes
28
+ end
29
+ end
30
+
31
+ it 'is deprecated' do
32
+ expect(Spree::Deprecation).to receive(:warn)
33
+ controller.permitted_checkout_attributes
27
34
  end
28
35
  end
29
36
 
@@ -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
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ RSpec.describe Spree::PermittedAttributes do
6
+ describe ".checkout_attributes" do
7
+ subject(:permitted_attributes) { described_class }
8
+
9
+ it "when read emits a deprecation warning and return all steps attributes" do
10
+ expect(Spree::Deprecation).to receive(:warn)
11
+ all_attributes = permitted_attributes.checkout_attributes
12
+
13
+ expect(all_attributes).to include(*permitted_attributes.checkout_address_attributes)
14
+ expect(all_attributes).to include(*permitted_attributes.checkout_delivery_attributes)
15
+ expect(all_attributes).to include(*permitted_attributes.checkout_payment_attributes)
16
+ end
17
+
18
+ it "when changed emits a deprecation warning and push changes to all steps' attributes" do
19
+ expect(Spree::Deprecation).to receive(:warn).exactly(4).times
20
+ permitted_attributes.checkout_attributes.push :appended_attribute
21
+ permitted_attributes.checkout_attributes.append :appended_with_alias_attribute
22
+ permitted_attributes.checkout_attributes << :another_appended_attribute
23
+ permitted_attributes.checkout_attributes.prepend :prepended_attribute
24
+
25
+ checkout_steps_attributes = [
26
+ permitted_attributes.checkout_address_attributes,
27
+ permitted_attributes.checkout_delivery_attributes,
28
+ permitted_attributes.checkout_payment_attributes,
29
+ permitted_attributes.checkout_confirm_attributes
30
+ ]
31
+
32
+ checkout_steps_attributes.each do |step_attributes|
33
+ expect(step_attributes).to include(
34
+ :appended_attribute,
35
+ :appended_with_alias_attribute,
36
+ :another_appended_attribute,
37
+ :prepended_attribute)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -59,7 +59,7 @@ RSpec.describe Spree::Ability, type: :model do
59
59
  let(:resource) { Object.new }
60
60
 
61
61
  context 'with admin user' do
62
- let(:user) { build :admin_user }
62
+ let(:user) { create :admin_user }
63
63
  it_should_behave_like 'access granted'
64
64
  it_should_behave_like 'index allowed'
65
65
  end
@@ -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
@@ -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