solidus_core 2.10.0.beta1 → 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.
- 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 +8 -7
- 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/engine.rb +2 -2
- data/lib/spree/core/environment_extension.rb +9 -0
- data/lib/spree/core/importer/order.rb +26 -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 +3 -3
- 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/solidus_core.gemspec +2 -2
- 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/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_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 +17 -12
- data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +0 -162
- data/spec/models/spree/order/updating_spec.rb +0 -18
|
@@ -9,12 +9,12 @@ module Spree
|
|
|
9
9
|
let(:stock_location) { mock_model(Spree::StockLocation) }
|
|
10
10
|
|
|
11
11
|
it 'continues to splitter chain' do
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
splitter_one = Base.new(stock_location)
|
|
13
|
+
splitter_two = Base.new(stock_location, splitter_one)
|
|
14
14
|
packages = []
|
|
15
15
|
|
|
16
|
-
expect(
|
|
17
|
-
|
|
16
|
+
expect(splitter_one).to receive(:split).with(packages)
|
|
17
|
+
splitter_two.split(packages)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
end
|
|
@@ -29,15 +29,15 @@ module Spree
|
|
|
29
29
|
subject { described_class.new(stock_location) }
|
|
30
30
|
|
|
31
31
|
it 'splits each package by shipping category' do
|
|
32
|
-
|
|
33
|
-
4.times {
|
|
34
|
-
8.times {
|
|
32
|
+
package_one = Package.new(stock_location)
|
|
33
|
+
4.times { package_one.add inventory_unit1 }
|
|
34
|
+
8.times { package_one.add inventory_unit2 }
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
6.times {
|
|
38
|
-
9.times {
|
|
36
|
+
package_two = Package.new(stock_location)
|
|
37
|
+
6.times { package_two.add inventory_unit1 }
|
|
38
|
+
9.times { package_two.add inventory_unit2, :backordered }
|
|
39
39
|
|
|
40
|
-
packages = subject.split([
|
|
40
|
+
packages = subject.split([package_one, package_two])
|
|
41
41
|
expect(packages[0].quantity).to eq 4
|
|
42
42
|
expect(packages[1].quantity).to eq 8
|
|
43
43
|
expect(packages[2].quantity).to eq 6
|
|
@@ -777,7 +777,7 @@ RSpec.describe Spree::StoreCredit do
|
|
|
777
777
|
let!(:store_credits) do
|
|
778
778
|
[
|
|
779
779
|
create(:store_credit, user: user, amount: store_credit_amount),
|
|
780
|
-
create(:store_credit, user: user, amount: additional_store_credit_amount)
|
|
780
|
+
create(:store_credit, user: user.reload, amount: additional_store_credit_amount)
|
|
781
781
|
]
|
|
782
782
|
end
|
|
783
783
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe "Spree::Taxon::PaperclipAttachment", type: :model do
|
|
6
|
+
describe "#destroy_attachment" do
|
|
7
|
+
let(:taxon) { create(:taxon) }
|
|
8
|
+
|
|
9
|
+
context "when trying to destroy a valid attachment definition" do
|
|
10
|
+
context "and taxon has a file attached " do
|
|
11
|
+
it "removes the attachment" do
|
|
12
|
+
taxon.update(icon: File.new(Rails.root.join('..', '..', 'spec', 'fixtures', 'thinking-cat.jpg')))
|
|
13
|
+
expect(taxon.destroy_attachment(:icon)).to be_truthy
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
context "and the taxon does not have any file attached yet" do
|
|
17
|
+
it "returns false" do
|
|
18
|
+
expect(taxon.destroy_attachment(:icon)).to be_falsey
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "when trying to destroy an invalid attachment" do
|
|
24
|
+
it 'returns false' do
|
|
25
|
+
expect(taxon.destroy_attachment(:foo)).to be_falsey
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Spree::UserLastUrlStorer::Rules::AuthenticationRule do
|
|
6
|
+
describe '#match?' do
|
|
7
|
+
let(:login_path) { '/sign_in' }
|
|
8
|
+
let(:request) { double(fullpath: fullpath) }
|
|
9
|
+
let(:controller) do
|
|
10
|
+
double(
|
|
11
|
+
request: request,
|
|
12
|
+
spree_login_path: login_path,
|
|
13
|
+
controller_name: 'controller_double'
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
subject { described_class.match?(controller) }
|
|
18
|
+
|
|
19
|
+
context 'when the request full path is an authentication route' do
|
|
20
|
+
let!(:fullpath) { login_path }
|
|
21
|
+
|
|
22
|
+
it { is_expected.to be true }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context 'when the request full path is not an authentication route' do
|
|
26
|
+
let!(:fullpath) { '/products/baseball-cap' }
|
|
27
|
+
|
|
28
|
+
it { is_expected.to be false }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Spree::UserLastUrlStorer do
|
|
6
|
+
subject { described_class.new(controller) }
|
|
7
|
+
|
|
8
|
+
let(:fullpath) { '/products/baseball-cap' }
|
|
9
|
+
let(:session) { {} }
|
|
10
|
+
let(:request) { double(fullpath: fullpath) }
|
|
11
|
+
let(:controller) do
|
|
12
|
+
instance_double(
|
|
13
|
+
ApplicationController,
|
|
14
|
+
request: request,
|
|
15
|
+
session: session,
|
|
16
|
+
controller_name: 'app_controller_double'
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
module CustomRule
|
|
21
|
+
def self.match?(_controller)
|
|
22
|
+
true
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
after :each do
|
|
27
|
+
described_class.rules.delete('CustomRule')
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '::rules' do
|
|
31
|
+
it 'includes default rules' do
|
|
32
|
+
rule = Spree::UserLastUrlStorer::Rules::AuthenticationRule
|
|
33
|
+
expect(described_class.rules).to include(rule)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'can add new rules' do
|
|
37
|
+
described_class.rules << CustomRule
|
|
38
|
+
expect(described_class.rules).to include(CustomRule)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe '#store_location' do
|
|
43
|
+
context 'when at least one rule matches' do
|
|
44
|
+
it 'does not set the path value into the session' do
|
|
45
|
+
described_class.rules << CustomRule
|
|
46
|
+
subject.store_location
|
|
47
|
+
expect(session[:spree_user_return_to]).to be_nil
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context 'when no rule matches' do
|
|
52
|
+
it 'sets the path value into the session' do
|
|
53
|
+
described_class.rules << CustomRule
|
|
54
|
+
described_class.rules.delete('CustomRule')
|
|
55
|
+
subject.store_location
|
|
56
|
+
expect(session[:spree_user_return_to]).to eql fullpath
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solidus_core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.10.0
|
|
4
|
+
version: 2.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Solidus Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-01-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionmailer
|
|
@@ -309,9 +309,6 @@ dependencies:
|
|
|
309
309
|
- - ">="
|
|
310
310
|
- !ruby/object:Gem::Version
|
|
311
311
|
version: '4.2'
|
|
312
|
-
- - "<"
|
|
313
|
-
- !ruby/object:Gem::Version
|
|
314
|
-
version: '6'
|
|
315
312
|
type: :runtime
|
|
316
313
|
prerelease: false
|
|
317
314
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -319,9 +316,6 @@ dependencies:
|
|
|
319
316
|
- - ">="
|
|
320
317
|
- !ruby/object:Gem::Version
|
|
321
318
|
version: '4.2'
|
|
322
|
-
- - "<"
|
|
323
|
-
- !ruby/object:Gem::Version
|
|
324
|
-
version: '6'
|
|
325
319
|
- !ruby/object:Gem::Dependency
|
|
326
320
|
name: paranoia
|
|
327
321
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -619,6 +613,8 @@ files:
|
|
|
619
613
|
- app/models/spree/unit_cancel.rb
|
|
620
614
|
- app/models/spree/user_address.rb
|
|
621
615
|
- app/models/spree/user_class_handle.rb
|
|
616
|
+
- app/models/spree/user_last_url_storer.rb
|
|
617
|
+
- app/models/spree/user_last_url_storer/rules/authentication_rule.rb
|
|
622
618
|
- app/models/spree/user_stock_location.rb
|
|
623
619
|
- app/models/spree/validations/db_maximum_length_validator.rb
|
|
624
620
|
- app/models/spree/variant.rb
|
|
@@ -742,6 +738,14 @@ files:
|
|
|
742
738
|
- lib/spree/core/role_configuration.rb
|
|
743
739
|
- lib/spree/core/search/base.rb
|
|
744
740
|
- lib/spree/core/search/variant.rb
|
|
741
|
+
- lib/spree/core/state_machines.rb
|
|
742
|
+
- lib/spree/core/state_machines/inventory_unit.rb
|
|
743
|
+
- lib/spree/core/state_machines/payment.rb
|
|
744
|
+
- lib/spree/core/state_machines/reimbursement.rb
|
|
745
|
+
- lib/spree/core/state_machines/return_authorization.rb
|
|
746
|
+
- lib/spree/core/state_machines/return_item/acceptance_status.rb
|
|
747
|
+
- lib/spree/core/state_machines/return_item/reception_status.rb
|
|
748
|
+
- lib/spree/core/state_machines/shipment.rb
|
|
745
749
|
- lib/spree/core/stock_configuration.rb
|
|
746
750
|
- lib/spree/core/validators/email.rb
|
|
747
751
|
- lib/spree/core/version.rb
|
|
@@ -981,7 +985,6 @@ files:
|
|
|
981
985
|
- spec/mailers/promotion_code_batch_mailer_spec.rb
|
|
982
986
|
- spec/mailers/reimbursement_mailer_spec.rb
|
|
983
987
|
- spec/mailers/test_mailer_spec.rb
|
|
984
|
-
- spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb
|
|
985
988
|
- spec/models/spree/ability_spec.rb
|
|
986
989
|
- spec/models/spree/address_spec.rb
|
|
987
990
|
- spec/models/spree/adjustment_reason_spec.rb
|
|
@@ -1038,7 +1041,6 @@ files:
|
|
|
1038
1041
|
- spec/models/spree/order/risk_assessment_spec.rb
|
|
1039
1042
|
- spec/models/spree/order/state_machine_spec.rb
|
|
1040
1043
|
- spec/models/spree/order/totals_spec.rb
|
|
1041
|
-
- spec/models/spree/order/updating_spec.rb
|
|
1042
1044
|
- spec/models/spree/order/validations_spec.rb
|
|
1043
1045
|
- spec/models/spree/order_cancellations_spec.rb
|
|
1044
1046
|
- spec/models/spree/order_capturing_spec.rb
|
|
@@ -1186,7 +1188,10 @@ files:
|
|
|
1186
1188
|
- spec/models/spree/tax_rate_spec.rb
|
|
1187
1189
|
- spec/models/spree/taxon_spec.rb
|
|
1188
1190
|
- spec/models/spree/taxonomy_spec.rb
|
|
1191
|
+
- spec/models/spree/taxons/paperclip_attachment_spec.rb
|
|
1189
1192
|
- spec/models/spree/unit_cancel_spec.rb
|
|
1193
|
+
- spec/models/spree/user_last_url_storer/rules/authentication_rule_spec.rb
|
|
1194
|
+
- spec/models/spree/user_last_url_storer_spec.rb
|
|
1190
1195
|
- spec/models/spree/user_spec.rb
|
|
1191
1196
|
- spec/models/spree/validations/db_maximum_length_validator_spec.rb
|
|
1192
1197
|
- spec/models/spree/variant/price_selector_spec.rb
|
|
@@ -1223,14 +1228,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
1223
1228
|
requirements:
|
|
1224
1229
|
- - ">="
|
|
1225
1230
|
- !ruby/object:Gem::Version
|
|
1226
|
-
version: 2.
|
|
1231
|
+
version: 2.4.0
|
|
1227
1232
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1228
1233
|
requirements:
|
|
1229
1234
|
- - ">="
|
|
1230
1235
|
- !ruby/object:Gem::Version
|
|
1231
1236
|
version: 1.8.23
|
|
1232
1237
|
requirements: []
|
|
1233
|
-
rubygems_version: 3.0.
|
|
1238
|
+
rubygems_version: 3.0.3
|
|
1234
1239
|
signing_key:
|
|
1235
1240
|
specification_version: 4
|
|
1236
1241
|
summary: Essential models, mailers, and classes for the Solidus e-commerce project.
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rails_helper'
|
|
4
|
-
require Spree::Core::Engine.root.join('db/migrate/20190106184413_remove_code_from_spree_promotions.rb')
|
|
5
|
-
|
|
6
|
-
RSpec.describe RemoveCodeFromSpreePromotions do
|
|
7
|
-
let(:migrations_paths) { ActiveRecord::Migrator.migrations_paths }
|
|
8
|
-
let(:migrations) do
|
|
9
|
-
if Rails.gem_version >= Gem::Version.new('6.0.0')
|
|
10
|
-
ActiveRecord::MigrationContext.new(
|
|
11
|
-
migrations_paths,
|
|
12
|
-
ActiveRecord::SchemaMigration
|
|
13
|
-
).migrations
|
|
14
|
-
elsif Rails.gem_version >= Gem::Version.new('5.2.0')
|
|
15
|
-
ActiveRecord::MigrationContext.new(migrations_paths).migrations
|
|
16
|
-
else
|
|
17
|
-
ActiveRecord::Migrator.migrations(migrations_paths)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
let(:previous_version) { 20180710170104 }
|
|
21
|
-
let(:current_version) { 20190106184413 }
|
|
22
|
-
|
|
23
|
-
subject do
|
|
24
|
-
if Rails.gem_version >= Gem::Version.new('6.0.0')
|
|
25
|
-
ActiveRecord::Migrator.new(:up, migrations, ActiveRecord::SchemaMigration, current_version).migrate
|
|
26
|
-
else
|
|
27
|
-
ActiveRecord::Migrator.new(:up, migrations, current_version).migrate
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# This is needed for MySQL since it is not able to rollback to the previous
|
|
32
|
-
# state when database schema changes within that transaction.
|
|
33
|
-
before(:all) { self.use_transactional_tests = false }
|
|
34
|
-
after(:all) { self.use_transactional_tests = true }
|
|
35
|
-
|
|
36
|
-
around do |example|
|
|
37
|
-
DatabaseCleaner.clean_with(:truncation)
|
|
38
|
-
# Silence migrations output in specs report.
|
|
39
|
-
ActiveRecord::Migration.suppress_messages do
|
|
40
|
-
# Migrate back to the previous version
|
|
41
|
-
if Rails.gem_version >= Gem::Version.new('6.0.0')
|
|
42
|
-
ActiveRecord::Migrator.new(:down, migrations, ActiveRecord::SchemaMigration, previous_version).migrate
|
|
43
|
-
else
|
|
44
|
-
ActiveRecord::Migrator.new(:down, migrations, previous_version).migrate
|
|
45
|
-
end
|
|
46
|
-
# If other tests using Spree::Promotion ran before this one, Rails has
|
|
47
|
-
# stored information about table's columns and we need to reset those
|
|
48
|
-
# since the migration changed the database structure.
|
|
49
|
-
Spree::Promotion.reset_column_information
|
|
50
|
-
|
|
51
|
-
example.run
|
|
52
|
-
|
|
53
|
-
# Re-update column information after the migration has been executed
|
|
54
|
-
# again in the example. This will make the promotion attributes cache
|
|
55
|
-
# ready for other tests.
|
|
56
|
-
Spree::Promotion.reset_column_information
|
|
57
|
-
end
|
|
58
|
-
DatabaseCleaner.clean_with(:truncation)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
let(:promotion_with_code) { create(:promotion) }
|
|
62
|
-
|
|
63
|
-
before do
|
|
64
|
-
# We can't set code via factory since `code=` is currently raising
|
|
65
|
-
# an error, see more at:
|
|
66
|
-
# https://github.com/solidusio/solidus/blob/cf96b03eb9e80002b69736e082fd485c870ab5d9/core/app/models/spree/promotion.rb#L65
|
|
67
|
-
promotion_with_code.update_column(:code, code)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
context 'when there are no promotions with code' do
|
|
71
|
-
let(:code) { '' }
|
|
72
|
-
|
|
73
|
-
it 'does not call any promotion with code handler' do
|
|
74
|
-
expect(described_class).not_to receive(:promotions_with_code_handler)
|
|
75
|
-
|
|
76
|
-
subject
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
context 'when there are promotions with code' do
|
|
81
|
-
let(:code) { 'Just An Old Promo Code' }
|
|
82
|
-
|
|
83
|
-
context 'with the deafult handler (Solidus::Migrations::PromotionWithCodeHandlers::RaiseException)' do
|
|
84
|
-
it 'raise a StandardError exception' do
|
|
85
|
-
expect { subject }.to raise_error(StandardError)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
context 'changing the default handler' do
|
|
90
|
-
before do
|
|
91
|
-
allow(described_class)
|
|
92
|
-
.to receive(:promotions_with_code_handler)
|
|
93
|
-
.and_return(promotions_with_code_handler)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
context 'to Solidus::Migrations::PromotionWithCodeHandlers::MoveToSpreePromotionCode' do
|
|
97
|
-
let(:promotions_with_code_handler) { Solidus::Migrations::PromotionWithCodeHandlers::MoveToSpreePromotionCode }
|
|
98
|
-
|
|
99
|
-
context 'when there are no Spree::PromotionCode with the same value' do
|
|
100
|
-
it 'moves the code into a Spree::PromotionCode' do
|
|
101
|
-
migration_context = double('a migration context')
|
|
102
|
-
allow_any_instance_of(promotions_with_code_handler)
|
|
103
|
-
.to receive(:migration_context)
|
|
104
|
-
.and_return(migration_context)
|
|
105
|
-
|
|
106
|
-
expect(migration_context)
|
|
107
|
-
.to receive(:say)
|
|
108
|
-
.with("Creating Spree::PromotionCode with value 'just an old promo code' for Spree::Promotion with id '#{promotion_with_code.id}'")
|
|
109
|
-
|
|
110
|
-
expect { subject }
|
|
111
|
-
.to change { Spree::PromotionCode.all.size }
|
|
112
|
-
.from(0)
|
|
113
|
-
.to(1)
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
context 'with promotions with type set (legacy feature)' do
|
|
118
|
-
let(:promotion_with_code) { create(:promotion, type: 'Spree::Promotion') }
|
|
119
|
-
|
|
120
|
-
it 'does not raise a STI error' do
|
|
121
|
-
expect { subject }.not_to raise_error
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
context 'when there is a Spree::PromotionCode with the same value' do
|
|
126
|
-
context 'associated with the same promotion' do
|
|
127
|
-
let!(:existing_promotion_code) { create(:promotion_code, value: 'just an old promo code', promotion: promotion_with_code) }
|
|
128
|
-
|
|
129
|
-
it 'does not create a new Spree::PromotionCode' do
|
|
130
|
-
expect { subject }.not_to change { Spree::PromotionCode.all.size }
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
context 'associated with another promotion' do
|
|
135
|
-
let!(:existing_promotion_code) { create(:promotion_code, value: 'just an old promo code') }
|
|
136
|
-
|
|
137
|
-
it 'raises an exception' do
|
|
138
|
-
expect { subject }.to raise_error(StandardError)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
context 'to Solidus::Migrations::PromotionWithCodeHandlers::DoNothing' do
|
|
145
|
-
let(:promotions_with_code_handler) { Solidus::Migrations::PromotionWithCodeHandlers::DoNothing }
|
|
146
|
-
|
|
147
|
-
it 'just prints a message' do
|
|
148
|
-
migration_context = double('a migration context')
|
|
149
|
-
allow_any_instance_of(promotions_with_code_handler)
|
|
150
|
-
.to receive(:migration_context)
|
|
151
|
-
.and_return(migration_context)
|
|
152
|
-
|
|
153
|
-
expect(migration_context)
|
|
154
|
-
.to receive(:say)
|
|
155
|
-
.with("Code 'Just An Old Promo Code' is going to be removed from Spree::Promotion with id '#{promotion_with_code.id}'")
|
|
156
|
-
|
|
157
|
-
subject
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
end
|