solidus_core 2.10.0.beta1 → 2.10.5
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.
- checksums.yaml +4 -4
- data/app/helpers/spree/base_helper.rb +4 -4
- data/app/helpers/spree/products_helper.rb +2 -1
- data/app/jobs/spree/promotion_code_batch_job.rb +2 -2
- data/app/models/concerns/spree/user_methods.rb +2 -2
- data/app/models/spree/address.rb +11 -15
- data/app/models/spree/adjustment.rb +11 -0
- data/app/models/spree/calculator/price_sack.rb +1 -1
- data/app/models/spree/calculator/shipping/flexi_rate.rb +2 -2
- data/app/models/spree/calculator/tiered_flat_rate.rb +5 -5
- data/app/models/spree/calculator/tiered_percent.rb +6 -6
- data/app/models/spree/carton.rb +1 -1
- data/app/models/spree/credit_card.rb +2 -2
- data/app/models/spree/inventory_unit.rb +1 -19
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/order.rb +3 -2
- data/app/models/spree/order/checkout.rb +1 -1
- data/app/models/spree/order/payments.rb +2 -2
- data/app/models/spree/order_capturing.rb +2 -2
- data/app/models/spree/order_taxation.rb +2 -2
- data/app/models/spree/payment.rb +4 -41
- data/app/models/spree/payment/processing.rb +2 -2
- data/app/models/spree/payment_method.rb +2 -2
- data/app/models/spree/product.rb +3 -3
- data/app/models/spree/product/scopes.rb +9 -8
- data/app/models/spree/promotion.rb +27 -12
- data/app/models/spree/promotion/actions/create_quantity_adjustments.rb +1 -1
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
- data/app/models/spree/promotion/rules/option_value.rb +2 -2
- data/app/models/spree/promotion/rules/product.rb +3 -3
- data/app/models/spree/promotion_action.rb +1 -1
- data/app/models/spree/promotion_chooser.rb +2 -2
- data/app/models/spree/promotion_code.rb +9 -8
- data/app/models/spree/promotion_code/batch_builder.rb +3 -3
- data/app/models/spree/promotion_rule.rb +1 -1
- data/app/models/spree/refund.rb +2 -2
- data/app/models/spree/reimbursement.rb +3 -11
- data/app/models/spree/reimbursement/reimbursement_type_engine.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +2 -2
- data/app/models/spree/return_authorization.rb +1 -7
- data/app/models/spree/return_item.rb +3 -42
- data/app/models/spree/return_item/eligibility_validator/default.rb +1 -1
- data/app/models/spree/shipment.rb +4 -38
- data/app/models/spree/shipping_calculator.rb +0 -4
- data/app/models/spree/shipping_method.rb +1 -1
- data/app/models/spree/state.rb +1 -1
- data/app/models/spree/stock/differentiator.rb +1 -1
- data/app/models/spree/stock/package.rb +1 -1
- data/app/models/spree/stock_item.rb +1 -1
- data/app/models/spree/stock_quantities.rb +13 -12
- data/app/models/spree/tax_calculator/default.rb +0 -4
- data/app/models/spree/tax_calculator/shipping_rate.rb +0 -3
- data/app/models/spree/tax_rate.rb +4 -0
- data/app/models/spree/taxon/paperclip_attachment.rb +13 -0
- data/app/models/spree/user_last_url_storer.rb +46 -0
- data/app/models/spree/user_last_url_storer/rules/authentication_rule.rb +36 -0
- data/app/models/spree/variant.rb +9 -9
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +1 -1
- data/app/models/spree/zone.rb +1 -1
- data/config/initializers/money.rb +2 -0
- data/config/locales/en.yml +12 -0
- data/lib/generators/spree/install/install_generator.rb +3 -0
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +8 -0
- data/lib/spree/app_configuration.rb +18 -3
- data/lib/spree/core.rb +12 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -13
- data/lib/spree/core/controller_helpers/strong_parameters.rb +21 -7
- data/lib/spree/core/engine.rb +2 -2
- data/lib/spree/core/environment_extension.rb +9 -0
- data/lib/spree/core/importer/order.rb +27 -26
- data/lib/spree/core/product_filters.rb +15 -15
- data/lib/spree/core/role_configuration.rb +2 -2
- data/lib/spree/core/search/variant.rb +1 -1
- data/lib/spree/core/state_machines.rb +78 -0
- data/lib/spree/core/state_machines/inventory_unit.rb +42 -0
- data/lib/spree/core/state_machines/payment.rb +61 -0
- data/lib/spree/core/state_machines/reimbursement.rb +33 -0
- data/lib/spree/core/state_machines/return_authorization.rb +32 -0
- data/lib/spree/core/state_machines/return_item/acceptance_status.rb +51 -0
- data/lib/spree/core/state_machines/return_item/reception_status.rb +42 -0
- data/lib/spree/core/state_machines/shipment.rb +58 -0
- data/lib/spree/core/stock_configuration.rb +1 -0
- data/lib/spree/core/validators/email.rb +1 -8
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/money.rb +2 -2
- data/lib/spree/permission_sets/user_management.rb +3 -0
- data/lib/spree/permitted_attributes.rb +78 -9
- data/lib/spree/preferences/static_model_preferences.rb +2 -2
- data/lib/spree/testing_support/dummy_app.rb +4 -1
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +8 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +7 -0
- data/lib/spree/testing_support/factories/stock_package_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +4 -1
- data/solidus_core.gemspec +4 -4
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +8 -1
- data/spec/lib/spree/core/environment_extension_spec.rb +12 -1
- data/spec/lib/spree/core/stock_configuration_spec.rb +36 -0
- data/spec/lib/spree/core/validators/email_spec.rb +18 -18
- data/spec/lib/spree/permitted_attributes_spec.rb +41 -0
- data/spec/models/spree/ability_spec.rb +1 -1
- data/spec/models/spree/address_spec.rb +23 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +2 -2
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +1 -1
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +24 -15
- data/spec/models/spree/carton_spec.rb +8 -0
- data/spec/models/spree/classification_spec.rb +21 -9
- data/spec/models/spree/concerns/user_address_book_spec.rb +4 -4
- data/spec/models/spree/concerns/user_methods_spec.rb +2 -1
- data/spec/models/spree/order_merger_spec.rb +3 -3
- data/spec/models/spree/order_spec.rb +8 -15
- data/spec/models/spree/order_updater_spec.rb +4 -3
- data/spec/models/spree/payment_create_spec.rb +4 -14
- data/spec/models/spree/permission_sets/user_management_spec.rb +2 -0
- data/spec/models/spree/preference_spec.rb +4 -4
- data/spec/models/spree/preferences/preferable_spec.rb +3 -3
- data/spec/models/spree/preferences/statically_configurable_spec.rb +2 -2
- data/spec/models/spree/promotion/rules/taxon_spec.rb +1 -0
- data/spec/models/spree/promotion_rule_spec.rb +6 -6
- data/spec/models/spree/promotion_spec.rb +73 -52
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +1 -1
- data/spec/models/spree/returns_calculator_spec.rb +2 -2
- data/spec/models/spree/shipping_calculator_spec.rb +1 -13
- data/spec/models/spree/shipping_method_spec.rb +32 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +2 -2
- data/spec/models/spree/stock/differentiator_spec.rb +2 -2
- data/spec/models/spree/stock/estimator_spec.rb +3 -3
- data/spec/models/spree/stock/package_spec.rb +28 -28
- data/spec/models/spree/stock/simple_coordinator_spec.rb +11 -11
- data/spec/models/spree/stock/splitter/base_spec.rb +4 -4
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +7 -7
- data/spec/models/spree/stock_quantities_spec.rb +1 -1
- data/spec/models/spree/store_credit_spec.rb +1 -1
- data/spec/models/spree/tax_rate_spec.rb +1 -0
- data/spec/models/spree/taxons/paperclip_attachment_spec.rb +29 -0
- data/spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb +31 -0
- data/spec/models/spree/user_last_url_storer_spec.rb +60 -0
- metadata +41 -35
- data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -162
- data/spec/models/spree/order/updating_spec.rb +0 -18
|
@@ -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
|
|
|
@@ -34,9 +34,21 @@ module Spree
|
|
|
34
34
|
|
|
35
35
|
context "removing product from taxon" do
|
|
36
36
|
before :each do
|
|
37
|
-
|
|
38
|
-
expect(
|
|
39
|
-
taxon_with_5_products.products.destroy(
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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 { |
|
|
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 { |
|
|
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
|
-
|
|
195
|
-
expect(
|
|
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
|
|
@@ -95,6 +95,7 @@ RSpec.describe Spree::UserMethods do
|
|
|
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)
|
|
@@ -77,13 +77,13 @@ module Spree
|
|
|
77
77
|
|
|
78
78
|
context "2 equal line items" do
|
|
79
79
|
before do
|
|
80
|
-
@
|
|
81
|
-
@
|
|
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(@
|
|
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)
|
|
@@ -366,26 +366,19 @@ RSpec.describe Spree::Order, type: :model do
|
|
|
366
366
|
end
|
|
367
367
|
end
|
|
368
368
|
|
|
369
|
-
context "
|
|
370
|
-
|
|
371
|
-
Spree::Order.class_eval do
|
|
372
|
-
register_update_hook :add_awesome_sauce
|
|
373
|
-
end
|
|
374
|
-
end
|
|
369
|
+
context ".register_update_hook", partial_double_verification: false do
|
|
370
|
+
let(:order) { create(:order) }
|
|
375
371
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
end
|
|
372
|
+
before { Spree::Order.register_update_hook :foo }
|
|
373
|
+
after { Spree::Order.update_hooks.clear }
|
|
379
374
|
|
|
380
|
-
it "calls
|
|
381
|
-
order
|
|
382
|
-
expect(order).to receive(:add_awesome_sauce)
|
|
375
|
+
it "calls hooks during #recalculate" do
|
|
376
|
+
expect(order).to receive :foo
|
|
383
377
|
order.recalculate
|
|
384
378
|
end
|
|
385
379
|
|
|
386
|
-
it "calls hook during finalize" do
|
|
387
|
-
order
|
|
388
|
-
expect(order).to receive(:add_awesome_sauce)
|
|
380
|
+
it "calls hook during #finalize!" do
|
|
381
|
+
expect(order).to receive :foo
|
|
389
382
|
order.finalize!
|
|
390
383
|
end
|
|
391
384
|
end
|
|
@@ -158,7 +158,8 @@ module Spree
|
|
|
158
158
|
amount: -500,
|
|
159
159
|
finalized: true,
|
|
160
160
|
label: 'Some other credit')
|
|
161
|
-
|
|
161
|
+
|
|
162
|
+
line_item.adjustments.each { |item| item.update_column(:eligible, true) }
|
|
162
163
|
|
|
163
164
|
order.recalculate
|
|
164
165
|
|
|
@@ -172,7 +173,7 @@ module Spree
|
|
|
172
173
|
create_adjustment('Promotion A', -200)
|
|
173
174
|
create_adjustment('Promotion B', -200)
|
|
174
175
|
end
|
|
175
|
-
line_item.adjustments.each { |
|
|
176
|
+
line_item.adjustments.each { |item| item.update_column(:eligible, true) }
|
|
176
177
|
|
|
177
178
|
order.recalculate
|
|
178
179
|
|
|
@@ -186,7 +187,7 @@ module Spree
|
|
|
186
187
|
create_adjustment('Promotion A', -200)
|
|
187
188
|
create_adjustment('Promotion B', -200)
|
|
188
189
|
end
|
|
189
|
-
line_item.adjustments.each { |
|
|
190
|
+
line_item.adjustments.each { |item| item.update_column(:eligible, true) }
|
|
190
191
|
|
|
191
192
|
order.recalculate
|
|
192
193
|
|
|
@@ -156,20 +156,10 @@ module Spree
|
|
|
156
156
|
context "unpermitted" do
|
|
157
157
|
let(:attributes) { ActionController::Parameters.new(valid_attributes) }
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
payment_method: nil,
|
|
164
|
-
source: nil
|
|
165
|
-
)
|
|
166
|
-
end
|
|
167
|
-
else
|
|
168
|
-
it "raises an exception" do
|
|
169
|
-
expect {
|
|
170
|
-
new_payment
|
|
171
|
-
}.to raise_exception(ActionController::UnfilteredParameters)
|
|
172
|
-
end
|
|
159
|
+
it "raises an exception" do
|
|
160
|
+
expect {
|
|
161
|
+
new_payment
|
|
162
|
+
}.to raise_exception(ActionController::UnfilteredParameters)
|
|
173
163
|
end
|
|
174
164
|
end
|
|
175
165
|
|
|
@@ -25,11 +25,13 @@ RSpec.describe Spree::PermissionSets::UserManagement do
|
|
|
25
25
|
context 'when the user does not have a role' do
|
|
26
26
|
let(:user) { create(:user) }
|
|
27
27
|
it { is_expected.to be_able_to(:update_email, user) }
|
|
28
|
+
it { is_expected.to be_able_to(:update_password, user) }
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
context 'when the user has a role' do
|
|
31
32
|
let(:user) { create(:user, spree_roles: [create(:role)]) }
|
|
32
33
|
it { is_expected.not_to be_able_to(:update_email, user) }
|
|
34
|
+
it { is_expected.not_to be_able_to(:update_password, user) }
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
it { is_expected.not_to be_able_to(:delete, Spree.user_class) }
|
|
@@ -12,10 +12,10 @@ RSpec.describe Spree::Preference, type: :model do
|
|
|
12
12
|
|
|
13
13
|
describe "type coversion for values" do
|
|
14
14
|
def round_trip_preference(key, value)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
element = Spree::Preference.new
|
|
16
|
+
element.value = value
|
|
17
|
+
element.key = key
|
|
18
|
+
element.save
|
|
19
19
|
|
|
20
20
|
Spree::Preference.find_by(key: key)
|
|
21
21
|
end
|
|
@@ -272,9 +272,9 @@ RSpec.describe Spree::Preferences::Preferable, type: :model do
|
|
|
272
272
|
before(:all) do
|
|
273
273
|
class CreatePrefTest < ActiveRecord::Migration[4.2]
|
|
274
274
|
def self.up
|
|
275
|
-
create_table :pref_tests do |
|
|
276
|
-
|
|
277
|
-
|
|
275
|
+
create_table :pref_tests do |item|
|
|
276
|
+
item.string :col
|
|
277
|
+
item.text :preferences
|
|
278
278
|
end
|
|
279
279
|
end
|
|
280
280
|
|
|
@@ -17,13 +17,13 @@ module Spree
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "validates unique rules for a promotion" do
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
promotion_one = TestRule.new
|
|
21
|
+
promotion_one.promotion_id = 1
|
|
22
|
+
promotion_one.save
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
expect(
|
|
24
|
+
promotion_two = TestRule.new
|
|
25
|
+
promotion_two.promotion_id = 1
|
|
26
|
+
expect(promotion_two).not_to be_valid
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "generates its own partial path" do
|
|
@@ -434,12 +434,12 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
434
434
|
end
|
|
435
435
|
|
|
436
436
|
context 'when expires_at date is not already reached' do
|
|
437
|
-
let(:expires_at) { Time.current + 1.
|
|
437
|
+
let(:expires_at) { Time.current + 1.day }
|
|
438
438
|
it { is_expected.to be_falsey }
|
|
439
439
|
end
|
|
440
440
|
|
|
441
441
|
context 'when expires_at date is in the past' do
|
|
442
|
-
let(:expires_at) { Time.current - 1.
|
|
442
|
+
let(:expires_at) { Time.current - 1.day }
|
|
443
443
|
it { is_expected.to be_truthy }
|
|
444
444
|
end
|
|
445
445
|
end
|
|
@@ -454,12 +454,12 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
454
454
|
end
|
|
455
455
|
|
|
456
456
|
context 'when expires_at date is not already reached' do
|
|
457
|
-
let(:expires_at) { Time.current + 1.
|
|
457
|
+
let(:expires_at) { Time.current + 1.day }
|
|
458
458
|
it { is_expected.to be_truthy }
|
|
459
459
|
end
|
|
460
460
|
|
|
461
461
|
context 'when expires_at date is in the past' do
|
|
462
|
-
let(:expires_at) { Time.current - 1.
|
|
462
|
+
let(:expires_at) { Time.current - 1.day }
|
|
463
463
|
it { is_expected.to be_falsey }
|
|
464
464
|
end
|
|
465
465
|
end
|
|
@@ -569,76 +569,69 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
569
569
|
|
|
570
570
|
context "#eligible?" do
|
|
571
571
|
subject do
|
|
572
|
-
promotion.eligible?(promotable)
|
|
572
|
+
promotion.eligible?(promotable, promotion_code: promotion.codes.first)
|
|
573
573
|
end
|
|
574
574
|
|
|
575
|
-
|
|
575
|
+
shared_examples "a promotable" do
|
|
576
|
+
context "when empty" do
|
|
577
|
+
it { is_expected.to be true }
|
|
578
|
+
end
|
|
576
579
|
|
|
577
|
-
|
|
580
|
+
context "when promotion is expired" do
|
|
581
|
+
before { promotion.expires_at = Time.current - 10.days }
|
|
578
582
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
it { is_expected.to be false }
|
|
582
|
-
end
|
|
583
|
+
it { is_expected.to be false }
|
|
584
|
+
end
|
|
583
585
|
|
|
584
|
-
|
|
585
|
-
|
|
586
|
+
context "when promotion's usage limit is exceeded" do
|
|
587
|
+
before do
|
|
588
|
+
promotion.usage_limit = 1
|
|
589
|
+
create(:completed_order_with_promotion, promotion: promotion)
|
|
590
|
+
end
|
|
586
591
|
|
|
587
|
-
|
|
588
|
-
FactoryBot.create(
|
|
589
|
-
:completed_order_with_promotion,
|
|
590
|
-
promotion: promotion
|
|
591
|
-
)
|
|
592
|
-
promotion.usage_limit = 1
|
|
592
|
+
it { is_expected.to be false }
|
|
593
593
|
end
|
|
594
594
|
|
|
595
|
-
|
|
596
|
-
|
|
595
|
+
context "when promotion code's usage limit is exceeded" do
|
|
596
|
+
before do
|
|
597
|
+
promotion.per_code_usage_limit = 1
|
|
598
|
+
create(:completed_order_with_promotion, promotion: promotion)
|
|
599
|
+
promotion.codes.first.adjustments.update_all(eligible: true)
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
it { is_expected.to be false }
|
|
597
603
|
end
|
|
598
|
-
end
|
|
599
604
|
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
605
|
+
context "when promotion is at last usage on the same order" do
|
|
606
|
+
let(:order) { create(:completed_order_with_promotion, promotion: promotion) }
|
|
607
|
+
let(:promotable) { order }
|
|
603
608
|
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
promotion: promotion
|
|
608
|
-
)
|
|
609
|
-
promotion_code.adjustments.update_all(eligible: true)
|
|
610
|
-
end
|
|
609
|
+
before do
|
|
610
|
+
promotion.usage_limit = 1
|
|
611
|
+
end
|
|
611
612
|
|
|
612
|
-
|
|
613
|
-
expect(promotion.eligible?(promotable, promotion_code: promotion_code)).to eq(false)
|
|
613
|
+
it { is_expected.to be true }
|
|
614
614
|
end
|
|
615
|
-
end
|
|
616
615
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
616
|
+
context "when promotion code is at last usage on the same order" do
|
|
617
|
+
let(:order) { create(:completed_order_with_promotion, promotion: promotion) }
|
|
618
|
+
let(:promotable) { order }
|
|
620
619
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
620
|
+
before do
|
|
621
|
+
promotion.per_code_usage_limit = 1
|
|
622
|
+
end
|
|
624
623
|
|
|
625
|
-
context "and product is promotionable" do
|
|
626
|
-
let(:promotionable) { true }
|
|
627
624
|
it { is_expected.to be true }
|
|
628
625
|
end
|
|
629
|
-
|
|
630
|
-
context "and product is not promotionable" do
|
|
631
|
-
let(:promotionable) { false }
|
|
632
|
-
it { is_expected.to be false }
|
|
633
|
-
end
|
|
634
626
|
end
|
|
635
627
|
|
|
636
628
|
context "when promotable is a Spree::Order" do
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
end
|
|
629
|
+
let(:promotion) { create(:promotion, :with_order_adjustment) }
|
|
630
|
+
let(:promotable) { create :order }
|
|
640
631
|
|
|
641
|
-
|
|
632
|
+
it_behaves_like "a promotable"
|
|
633
|
+
|
|
634
|
+
context "when it contains items" do
|
|
642
635
|
let!(:line_item) { create(:line_item, order: promotable) }
|
|
643
636
|
let!(:line_item2) { create(:line_item, order: promotable) }
|
|
644
637
|
|
|
@@ -646,6 +639,7 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
646
639
|
before do
|
|
647
640
|
line_item.product.update_column(:promotionable, false)
|
|
648
641
|
end
|
|
642
|
+
|
|
649
643
|
it { is_expected.to be false }
|
|
650
644
|
end
|
|
651
645
|
|
|
@@ -654,6 +648,7 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
654
648
|
line_item.product.update_column(:promotionable, false)
|
|
655
649
|
line_item2.product.update_column(:promotionable, false)
|
|
656
650
|
end
|
|
651
|
+
|
|
657
652
|
it { is_expected.to be false }
|
|
658
653
|
end
|
|
659
654
|
|
|
@@ -662,6 +657,32 @@ RSpec.describe Spree::Promotion, type: :model do
|
|
|
662
657
|
end
|
|
663
658
|
end
|
|
664
659
|
end
|
|
660
|
+
|
|
661
|
+
context "when promotable is a Spree::LineItem" do
|
|
662
|
+
let(:promotion) { create(:promotion, :with_line_item_adjustment) }
|
|
663
|
+
let(:promotable) { create(:line_item) }
|
|
664
|
+
|
|
665
|
+
it_behaves_like "a promotable"
|
|
666
|
+
|
|
667
|
+
context "and product is promotionable" do
|
|
668
|
+
before { promotable.product.promotionable = true }
|
|
669
|
+
|
|
670
|
+
it { is_expected.to be true }
|
|
671
|
+
end
|
|
672
|
+
|
|
673
|
+
context "and product is not promotionable" do
|
|
674
|
+
before { promotable.product.promotionable = false }
|
|
675
|
+
|
|
676
|
+
it { is_expected.to be false }
|
|
677
|
+
end
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
context "when promotable is a Spree::Shipment" do
|
|
681
|
+
let(:promotion) { create(:promotion, :with_free_shipping) }
|
|
682
|
+
let(:promotable) { create(:shipment) }
|
|
683
|
+
|
|
684
|
+
it_behaves_like "a promotable"
|
|
685
|
+
end
|
|
665
686
|
end
|
|
666
687
|
|
|
667
688
|
context "#eligible_rules" do
|