solidus_core 2.7.4 → 2.8.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/README.md +19 -17
- data/app/assets/images/logo/solidus.svg +18 -0
- data/app/assets/javascripts/spree.js.erb +2 -2
- data/app/helpers/spree/base_helper.rb +1 -7
- data/app/helpers/spree/taxons_helper.rb +2 -2
- data/app/mailers/spree/carton_mailer.rb +4 -4
- data/app/models/spree/calculator/flat_percent_item_total.rb +4 -1
- data/app/models/spree/calculator/shipping/flat_percent_item_total.rb +5 -3
- data/app/models/spree/calculator/tiered_percent.rb +2 -1
- data/app/models/spree/country.rb +8 -0
- data/app/models/spree/fulfilment_changer.rb +9 -1
- data/app/models/spree/gallery/product_gallery.rb +18 -0
- data/app/models/spree/gallery/variant_gallery.rb +21 -0
- data/app/models/spree/image.rb +11 -1
- data/app/models/spree/inventory_unit.rb +8 -0
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/order.rb +0 -4
- data/app/models/spree/order_cancellations.rb +31 -10
- data/app/models/spree/order_contents.rb +1 -5
- data/app/models/spree/order_inventory.rb +5 -4
- data/app/models/spree/product.rb +9 -0
- data/app/models/spree/product/scopes.rb +3 -4
- data/app/models/spree/promotion.rb +1 -6
- data/app/models/spree/promotion_handler/coupon.rb +15 -0
- data/app/models/spree/reimbursement.rb +21 -6
- data/app/models/spree/reimbursement_performer.rb +12 -6
- data/app/models/spree/reimbursement_type.rb +1 -1
- data/app/models/spree/reimbursement_type/credit.rb +5 -2
- data/app/models/spree/reimbursement_type/exchange.rb +1 -1
- data/app/models/spree/reimbursement_type/original_payment.rb +1 -1
- data/app/models/spree/reimbursement_type/reimbursement_helpers.rb +6 -6
- data/app/models/spree/reimbursement_type/store_credit.rb +18 -3
- data/app/models/spree/shipment.rb +11 -11
- data/app/models/spree/stock/allocator/base.rb +19 -0
- data/app/models/spree/stock/allocator/on_hand_first.rb +42 -0
- data/app/models/spree/stock/content_item.rb +1 -1
- data/app/models/spree/stock/inventory_units_finalizer.rb +47 -0
- data/app/models/spree/stock/location_sorter/base.rb +38 -0
- data/app/models/spree/stock/location_sorter/default_first.rb +15 -0
- data/app/models/spree/stock/location_sorter/unsorted.rb +14 -0
- data/app/models/spree/stock/simple_coordinator.rb +24 -10
- data/app/models/spree/stock_location.rb +2 -0
- data/app/models/spree/store_credit.rb +4 -12
- data/app/models/spree/store_credit_event.rb +2 -2
- data/app/models/spree/store_credit_reason.rb +11 -0
- data/app/models/spree/taxon.rb +8 -3
- data/app/models/spree/unit_cancel.rb +3 -0
- data/app/models/spree/variant.rb +18 -7
- data/config/initializers/money.rb +5 -0
- data/config/locales/en.yml +661 -527
- data/db/default/spree/store_credit.rb +1 -1
- data/db/default/spree/zones.rb +2 -2
- data/db/migrate/20180710170104_create_spree_store_credit_reasons_table.rb +42 -0
- data/db/migrate/20190106184413_remove_code_from_spree_promotions.rb +41 -0
- data/lib/generators/spree/dummy/templates/rails/test.rb +0 -3
- data/lib/generators/spree/install/install_generator.rb +2 -2
- data/lib/generators/spree/install/templates/config/initializers/spree.rb.tt +2 -2
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/solidus/migrations/promotions_with_code_handlers.rb +66 -0
- data/lib/spree/app_configuration.rb +20 -4
- data/lib/spree/core/controller_helpers/common.rb +1 -1
- data/lib/spree/core/stock_configuration.rb +12 -0
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/i18n.rb +4 -0
- data/lib/spree/money.rb +13 -11
- data/lib/spree/permission_sets.rb +0 -1
- data/lib/spree/permission_sets/promotion_management.rb +1 -0
- data/lib/spree/testing_support/dummy_app.rb +13 -2
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/backend/all.js +1 -1
- data/lib/spree/testing_support/dummy_app/assets/javascripts/spree/frontend/all.js +1 -1
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +5 -5
- data/lib/spree/testing_support/factories/{store_credit_update_reason_factory.rb → store_credit_reason_factory.rb} +1 -1
- data/lib/spree/testing_support/partial_double_verification.rb +13 -0
- data/lib/spree/testing_support/shared_examples/gallery.rb +18 -0
- data/spec/helpers/products_helper_spec.rb +10 -8
- data/spec/helpers/taxons_helper_spec.rb +3 -1
- data/spec/lib/i18n_spec.rb +5 -0
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +6 -2
- data/spec/lib/spree/core/stock_configuration_spec.rb +19 -0
- data/spec/lib/spree/core/testing_support/factories/store_credit_reason_factory_spec.rb +14 -0
- data/spec/lib/spree/money_spec.rb +12 -13
- data/spec/migrate/20190106184413_remove_code_from_spree_promotions_spec.rb +136 -0
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +10 -1
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +18 -6
- data/spec/models/spree/calculator/tiered_percent_spec.rb +7 -1
- data/spec/models/spree/country_spec.rb +76 -0
- data/spec/models/spree/customer_return_spec.rb +2 -1
- data/spec/models/spree/fulfilment_changer_spec.rb +33 -0
- data/spec/models/spree/gallery/product_gallery_spec.rb +21 -0
- data/spec/models/spree/gallery/variant_gallery_spec.rb +21 -0
- data/spec/models/spree/inventory_unit_spec.rb +1 -4
- data/spec/models/spree/order/checkout_spec.rb +6 -6
- data/spec/models/spree/order/finalizing_spec.rb +1 -20
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +2 -1
- data/spec/models/spree/order/updating_spec.rb +1 -1
- data/spec/models/spree/order_cancellations_spec.rb +55 -14
- data/spec/models/spree/order_inventory_spec.rb +12 -5
- data/spec/models/spree/order_merger_spec.rb +6 -3
- data/spec/models/spree/order_spec.rb +3 -7
- data/spec/models/spree/order_updater_spec.rb +3 -8
- data/spec/models/spree/payment/cancellation_spec.rb +4 -3
- data/spec/models/spree/payment_spec.rb +1 -17
- data/spec/models/spree/permission_sets/promotion_management_spec.rb +2 -0
- data/spec/models/spree/product_spec.rb +10 -1
- data/spec/models/spree/promotion_handler/coupon_spec.rb +62 -8
- data/spec/models/spree/promotion_spec.rb +24 -10
- data/spec/models/spree/refund_spec.rb +2 -1
- data/spec/models/spree/reimbursement_performer_spec.rb +5 -4
- data/spec/models/spree/reimbursement_spec.rb +26 -2
- data/spec/models/spree/reimbursement_type/credit_spec.rb +2 -1
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +2 -1
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +2 -1
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +14 -2
- data/spec/models/spree/return_item_spec.rb +1 -1
- data/spec/models/spree/shipment_spec.rb +20 -13
- data/spec/models/spree/shipping_calculator_spec.rb +13 -3
- data/spec/models/spree/stock/allocator/on_hand_first_spec.rb +146 -0
- data/spec/models/spree/stock/content_item_spec.rb +70 -0
- data/spec/models/spree/stock/estimator_spec.rb +5 -2
- data/spec/models/spree/stock/inventory_units_finalizer_spec.rb +34 -0
- data/spec/models/spree/stock/location_sorter/default_first_spec.rb +20 -0
- data/spec/models/spree/stock/location_sorter/unsorted_spec.rb +19 -0
- data/spec/models/spree/stock/simple_coordinator_spec.rb +17 -0
- data/spec/models/spree/store_credit_event_spec.rb +12 -12
- data/spec/models/spree/store_credit_spec.rb +2 -2
- data/spec/models/spree/unit_cancel_spec.rb +20 -1
- data/spec/models/spree/variant_spec.rb +46 -24
- data/spec/spec_helper.rb +1 -0
- metadata +30 -9
- data/.yardopts +0 -1
- data/app/models/spree/store_credit_update_reason.rb +0 -4
- data/lib/spree/permission_sets/report_display.rb +0 -11
- data/spec/lib/spree/core/testing_support/factories/store_credit_update_reason_factory_spec.rb +0 -14
- data/spec/models/spree/permission_sets/report_display_spec.rb +0 -25
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'spree/testing_support/factories/store_credit_factory'
|
|
4
|
-
require 'spree/testing_support/factories/
|
|
4
|
+
require 'spree/testing_support/factories/store_credit_reason_factory'
|
|
5
5
|
|
|
6
6
|
FactoryBot.define do
|
|
7
7
|
factory :store_credit_event, class: 'Spree::StoreCreditEvent' do
|
|
@@ -18,13 +18,13 @@ FactoryBot.define do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
factory :store_credit_adjustment_event do
|
|
21
|
-
action
|
|
22
|
-
|
|
21
|
+
action { Spree::StoreCredit::ADJUSTMENT_ACTION }
|
|
22
|
+
store_credit_reason { create(:store_credit_reason) }
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
factory :store_credit_invalidate_event do
|
|
26
|
-
action
|
|
27
|
-
|
|
26
|
+
action { Spree::StoreCredit::INVALIDATE_ACTION }
|
|
27
|
+
store_credit_reason { create(:store_credit_reason) }
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.configure do |config|
|
|
4
|
+
config.mock_with :rspec do |c|
|
|
5
|
+
c.verify_partial_doubles = true
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
config.around(:each, partial_double_verification: false) do |example|
|
|
9
|
+
without_partial_double_verification do
|
|
10
|
+
example.run
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.shared_examples 'a gallery' do
|
|
4
|
+
describe '#images' do
|
|
5
|
+
subject { gallery.images }
|
|
6
|
+
|
|
7
|
+
it { is_expected.to be_empty }
|
|
8
|
+
|
|
9
|
+
context 'there are images' do
|
|
10
|
+
include_context 'has multiple images'
|
|
11
|
+
|
|
12
|
+
it 'has the associated images' do
|
|
13
|
+
expect(subject.map { |picture| picture.id }).
|
|
14
|
+
to match_array([first_image.id, second_image.id])
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -15,7 +15,9 @@ module Spree
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
before do
|
|
18
|
-
|
|
18
|
+
without_partial_double_verification do
|
|
19
|
+
allow(helper).to receive(:current_pricing_options) { pricing_options }
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
context "#variant_price_diff" do
|
|
@@ -31,7 +33,7 @@ module Spree
|
|
|
31
33
|
context "when variant is more than master" do
|
|
32
34
|
let(:variant_price) { 15 }
|
|
33
35
|
|
|
34
|
-
it { is_expected.to eq("(Add:
|
|
36
|
+
it { is_expected.to eq("(Add: <span class=\"money-currency-symbol\">$</span><span class=\"money-whole\">5</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span>)") }
|
|
35
37
|
# Regression test for https://github.com/spree/spree/issues/2737
|
|
36
38
|
it { is_expected.to be_html_safe }
|
|
37
39
|
end
|
|
@@ -39,7 +41,7 @@ module Spree
|
|
|
39
41
|
context "when variant is less than master" do
|
|
40
42
|
let(:product_price) { 15 }
|
|
41
43
|
|
|
42
|
-
it { is_expected.to eq("(Subtract:
|
|
44
|
+
it { is_expected.to eq("(Subtract: <span class=\"money-currency-symbol\">$</span><span class=\"money-whole\">5</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span>)") }
|
|
43
45
|
end
|
|
44
46
|
end
|
|
45
47
|
|
|
@@ -56,13 +58,13 @@ module Spree
|
|
|
56
58
|
context "when variant is more than master" do
|
|
57
59
|
let(:variant_price) { 150 }
|
|
58
60
|
|
|
59
|
-
it { is_expected.to eq("(Add:
|
|
61
|
+
it { is_expected.to eq("(Add: <span class=\"money-currency-symbol\">¥</span><span class=\"money-whole\">50</span>)") }
|
|
60
62
|
end
|
|
61
63
|
|
|
62
64
|
context "when variant is less than master" do
|
|
63
65
|
let(:product_price) { 150 }
|
|
64
66
|
|
|
65
|
-
it { is_expected.to eq("(Subtract:
|
|
67
|
+
it { is_expected.to eq("(Subtract: <span class=\"money-currency-symbol\">¥</span><span class=\"money-whole\">50</span>)") }
|
|
66
68
|
end
|
|
67
69
|
end
|
|
68
70
|
end
|
|
@@ -79,8 +81,8 @@ module Spree
|
|
|
79
81
|
|
|
80
82
|
context "when currency is default" do
|
|
81
83
|
it "should return the variant price if the price is different than master" do
|
|
82
|
-
expect(helper.variant_price(variant)).to eq("
|
|
83
|
-
expect(helper.variant_price(variant_2)).to eq("
|
|
84
|
+
expect(helper.variant_price(variant)).to eq("<span class=\"money-currency-symbol\">$</span><span class=\"money-whole\">15</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span>")
|
|
85
|
+
expect(helper.variant_price(variant_2)).to eq("<span class=\"money-currency-symbol\">$</span><span class=\"money-whole\">20</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span>")
|
|
84
86
|
end
|
|
85
87
|
end
|
|
86
88
|
|
|
@@ -95,7 +97,7 @@ module Spree
|
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
it "should return the variant price if the price is different than master" do
|
|
98
|
-
expect(helper.variant_price(variant)).to eq("
|
|
100
|
+
expect(helper.variant_price(variant)).to eq("<span class=\"money-currency-symbol\">¥</span><span class=\"money-whole\">150</span>")
|
|
99
101
|
end
|
|
100
102
|
end
|
|
101
103
|
|
|
@@ -8,7 +8,9 @@ RSpec.describe Spree::TaxonsHelper, type: :helper do
|
|
|
8
8
|
Spree::Config.pricing_options_class.new(currency: currency)
|
|
9
9
|
end
|
|
10
10
|
before do
|
|
11
|
-
|
|
11
|
+
without_partial_double_verification do
|
|
12
|
+
allow(helper).to receive(:current_pricing_options) { pricing_options }
|
|
13
|
+
end
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
describe "#taxon_preview" do
|
data/spec/lib/i18n_spec.rb
CHANGED
|
@@ -30,23 +30,28 @@ RSpec.describe "i18n" do
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
it "translates within the spree scope" do
|
|
33
|
+
expect(Spree::Deprecation).to receive(:warn).twice
|
|
33
34
|
expect(Spree.t(:foo)).to eql("bar")
|
|
34
35
|
expect(Spree.translate(:foo)).to eql("bar")
|
|
35
36
|
end
|
|
36
37
|
|
|
37
38
|
it "prepends a string scope" do
|
|
39
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
38
40
|
expect(Spree.t(:foo, scope: "bar")).to eql("bar within bar scope")
|
|
39
41
|
end
|
|
40
42
|
|
|
41
43
|
it "prepends to an array scope" do
|
|
44
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
42
45
|
expect(Spree.t(:foo, scope: ["bar"])).to eql("bar within bar scope")
|
|
43
46
|
end
|
|
44
47
|
|
|
45
48
|
it "returns two translations" do
|
|
49
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
46
50
|
expect(Spree.t([:foo, 'bar.foo'])).to eql(["bar", "bar within bar scope"])
|
|
47
51
|
end
|
|
48
52
|
|
|
49
53
|
it "returns reasonable string for missing translations" do
|
|
54
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
50
55
|
expect(Spree.t(:missing_entry)).to include("<span")
|
|
51
56
|
end
|
|
52
57
|
|
|
@@ -55,11 +55,15 @@ RSpec.describe Spree::Core::ControllerHelpers::Auth, type: :controller do
|
|
|
55
55
|
|
|
56
56
|
describe '#try_spree_current_user' do
|
|
57
57
|
it 'calls spree_current_user when define spree_current_user method' do
|
|
58
|
-
|
|
58
|
+
without_partial_double_verification do
|
|
59
|
+
expect(controller).to receive(:spree_current_user)
|
|
60
|
+
end
|
|
59
61
|
controller.try_spree_current_user
|
|
60
62
|
end
|
|
61
63
|
it 'calls current_spree_user when define current_spree_user method' do
|
|
62
|
-
|
|
64
|
+
without_partial_double_verification do
|
|
65
|
+
expect(controller).to receive(:current_spree_user)
|
|
66
|
+
end
|
|
63
67
|
controller.try_spree_current_user
|
|
64
68
|
end
|
|
65
69
|
it 'returns nil' do
|
|
@@ -20,6 +20,7 @@ RSpec.describe Spree::Core::StockConfiguration do
|
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
|
+
|
|
23
24
|
describe '#estimator_class' do
|
|
24
25
|
let(:stock_configuration) { described_class.new }
|
|
25
26
|
subject { stock_configuration.estimator_class }
|
|
@@ -37,4 +38,22 @@ RSpec.describe Spree::Core::StockConfiguration do
|
|
|
37
38
|
end
|
|
38
39
|
end
|
|
39
40
|
end
|
|
41
|
+
|
|
42
|
+
describe '#location_sorter_class' do
|
|
43
|
+
let(:stock_configuration) { described_class.new }
|
|
44
|
+
subject { stock_configuration.location_sorter_class }
|
|
45
|
+
|
|
46
|
+
it "returns Spree::Stock::LocationSorter::Unsorted" do
|
|
47
|
+
is_expected.to be ::Spree::Stock::LocationSorter::Unsorted
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "with another constant name assiged" do
|
|
51
|
+
MySorter = Class.new
|
|
52
|
+
before { stock_configuration.location_sorter_class = MySorter.to_s }
|
|
53
|
+
|
|
54
|
+
it "returns the constant" do
|
|
55
|
+
is_expected.to be MySorter
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
40
59
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails_helper'
|
|
4
|
+
require 'spree/testing_support/factories/store_credit_reason_factory'
|
|
5
|
+
|
|
6
|
+
RSpec.describe 'store credit reason factory' do
|
|
7
|
+
let(:factory_class) { Spree::StoreCreditReason }
|
|
8
|
+
|
|
9
|
+
describe 'store credit reason' do
|
|
10
|
+
let(:factory) { :store_credit_reason }
|
|
11
|
+
|
|
12
|
+
it_behaves_like 'a working factory'
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require '
|
|
4
|
-
require 'spree/money'
|
|
3
|
+
require 'rails_helper'
|
|
5
4
|
|
|
6
5
|
RSpec.describe Spree::Money do
|
|
7
6
|
before do
|
|
@@ -97,7 +96,7 @@ RSpec.describe Spree::Money do
|
|
|
97
96
|
|
|
98
97
|
context "with currency" do
|
|
99
98
|
it "passed in option" do
|
|
100
|
-
money = Spree::Money.new(10, with_currency: true,
|
|
99
|
+
money = Spree::Money.new(10, with_currency: true, html_wrap: false)
|
|
101
100
|
expect(money.to_s).to eq("$10.00 USD")
|
|
102
101
|
end
|
|
103
102
|
end
|
|
@@ -117,14 +116,14 @@ RSpec.describe Spree::Money do
|
|
|
117
116
|
context "currency parameter" do
|
|
118
117
|
context "when currency is specified in Canadian Dollars" do
|
|
119
118
|
it "uses the currency param over the global configuration" do
|
|
120
|
-
money = Spree::Money.new(10, currency: 'CAD', with_currency: true,
|
|
119
|
+
money = Spree::Money.new(10, currency: 'CAD', with_currency: true, html_wrap: false)
|
|
121
120
|
expect(money.to_s).to eq("$10.00 CAD")
|
|
122
121
|
end
|
|
123
122
|
end
|
|
124
123
|
|
|
125
124
|
context "when currency is specified in Japanese Yen" do
|
|
126
125
|
it "uses the currency param over the global configuration" do
|
|
127
|
-
money = Spree::Money.new(100, currency: 'JPY',
|
|
126
|
+
money = Spree::Money.new(100, currency: 'JPY', html_wrap: false)
|
|
128
127
|
expect(money.to_s).to eq("¥100")
|
|
129
128
|
end
|
|
130
129
|
end
|
|
@@ -132,12 +131,12 @@ RSpec.describe Spree::Money do
|
|
|
132
131
|
|
|
133
132
|
context "symbol positioning" do
|
|
134
133
|
it "passed in option" do
|
|
135
|
-
money = Spree::Money.new(10,
|
|
134
|
+
money = Spree::Money.new(10, format: '%n %u', html_wrap: false)
|
|
136
135
|
expect(money.to_s).to eq("10.00 $")
|
|
137
136
|
end
|
|
138
137
|
|
|
139
138
|
it "config option" do
|
|
140
|
-
money = Spree::Money.new(10,
|
|
139
|
+
money = Spree::Money.new(10, format: '%n %u', html_wrap: false)
|
|
141
140
|
expect(money.to_s).to eq("10.00 $")
|
|
142
141
|
end
|
|
143
142
|
end
|
|
@@ -162,7 +161,7 @@ RSpec.describe Spree::Money do
|
|
|
162
161
|
end
|
|
163
162
|
|
|
164
163
|
it "formats correctly" do
|
|
165
|
-
money = Spree::Money.new(1000,
|
|
164
|
+
money = Spree::Money.new(1000, html_wrap: false)
|
|
166
165
|
expect(money.to_s).to eq("¥1,000")
|
|
167
166
|
end
|
|
168
167
|
end
|
|
@@ -176,20 +175,20 @@ RSpec.describe Spree::Money do
|
|
|
176
175
|
|
|
177
176
|
# Regression test for https://github.com/spree/spree/issues/2634
|
|
178
177
|
it "formats as plain by default" do
|
|
179
|
-
money = Spree::Money.new(10,
|
|
178
|
+
money = Spree::Money.new(10, format: '%n %u')
|
|
180
179
|
expect(money.to_s).to eq("10.00 €")
|
|
181
180
|
end
|
|
182
181
|
|
|
183
182
|
it "formats as HTML if asked (nicely) to" do
|
|
184
|
-
money = Spree::Money.new(10,
|
|
183
|
+
money = Spree::Money.new(10, format: '%n %u')
|
|
185
184
|
# The HTML'ified version of "10.00 €"
|
|
186
|
-
expect(money.to_html).to eq("10
|
|
185
|
+
expect(money.to_html).to eq("<span class=\"money-whole\">10</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span> <span class=\"money-currency-symbol\">€</span>")
|
|
187
186
|
end
|
|
188
187
|
|
|
189
188
|
it "formats as HTML with currency" do
|
|
190
|
-
money = Spree::Money.new(10,
|
|
189
|
+
money = Spree::Money.new(10, format: '%n %u', with_currency: true)
|
|
191
190
|
# The HTML'ified version of "10.00 €"
|
|
192
|
-
expect(money.to_html).to eq("10
|
|
191
|
+
expect(money.to_html).to eq("<span class=\"money-whole\">10</span><span class=\"money-decimal-mark\">.</span><span class=\"money-decimal\">00</span> <span class=\"money-currency-symbol\">€</span> <span class=\"money-currency\">EUR</span>")
|
|
193
192
|
end
|
|
194
193
|
end
|
|
195
194
|
|
|
@@ -0,0 +1,136 @@
|
|
|
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 ActiveRecord::Base.connection.respond_to?(:migration_context)
|
|
10
|
+
# Rails >= 5.2
|
|
11
|
+
ActiveRecord::MigrationContext.new(migrations_paths).migrations
|
|
12
|
+
else
|
|
13
|
+
ActiveRecord::Migrator.migrations(migrations_paths)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
let(:previous_version) { 20180710170104 }
|
|
17
|
+
let(:current_version) { 20190106184413 }
|
|
18
|
+
|
|
19
|
+
subject { ActiveRecord::Migrator.new(:up, migrations, current_version).migrate }
|
|
20
|
+
|
|
21
|
+
# This is needed for MySQL since it is not able to rollback to the previous
|
|
22
|
+
# state when database schema changes within that transaction.
|
|
23
|
+
before(:all) { self.use_transactional_tests = false }
|
|
24
|
+
after(:all) { self.use_transactional_tests = true }
|
|
25
|
+
|
|
26
|
+
around do |example|
|
|
27
|
+
DatabaseCleaner.clean_with(:truncation)
|
|
28
|
+
# Silence migrations output in specs report.
|
|
29
|
+
ActiveRecord::Migration.suppress_messages do
|
|
30
|
+
# Migrate back to the previous version
|
|
31
|
+
ActiveRecord::Migrator.new(:down, migrations, previous_version).migrate
|
|
32
|
+
# If other tests using Spree::Promotion ran before this one, Rails has
|
|
33
|
+
# stored information about table's columns and we need to reset those
|
|
34
|
+
# since the migration changed the database structure.
|
|
35
|
+
Spree::Promotion.reset_column_information
|
|
36
|
+
|
|
37
|
+
example.run
|
|
38
|
+
|
|
39
|
+
# Re-update column information after the migration has been executed
|
|
40
|
+
# again in the example. This will make the promotion attributes cache
|
|
41
|
+
# ready for other tests.
|
|
42
|
+
Spree::Promotion.reset_column_information
|
|
43
|
+
end
|
|
44
|
+
DatabaseCleaner.clean_with(:truncation)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context 'when there are no promotions with code' do
|
|
48
|
+
it 'does not call any promotion with code handler' do
|
|
49
|
+
expect(described_class).not_to receive(:promotions_with_code_handler)
|
|
50
|
+
|
|
51
|
+
subject
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'when there are promotions with code' do
|
|
56
|
+
let(:promotion_with_code) { create(:promotion) }
|
|
57
|
+
|
|
58
|
+
before do
|
|
59
|
+
# We can't set code via factory since `code=` is currently raising
|
|
60
|
+
# an error, see more at:
|
|
61
|
+
# https://github.com/solidusio/solidus/blob/cf96b03eb9e80002b69736e082fd485c870ab5d9/core/app/models/spree/promotion.rb#L65
|
|
62
|
+
promotion_with_code.update_column(:code, 'Just An Old Promo Code')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context 'with the deafult handler (Solidus::Migrations::PromotionWithCodeHandlers::RaiseException)' do
|
|
66
|
+
it 'raise a StandardError exception' do
|
|
67
|
+
expect { subject }.to raise_error(StandardError)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context 'changing the default handler' do
|
|
72
|
+
before do
|
|
73
|
+
allow(described_class)
|
|
74
|
+
.to receive(:promotions_with_code_handler)
|
|
75
|
+
.and_return(promotions_with_code_handler)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context 'to Solidus::Migrations::PromotionWithCodeHandlers::MoveToSpreePromotionCode' do
|
|
79
|
+
let(:promotions_with_code_handler) { Solidus::Migrations::PromotionWithCodeHandlers::MoveToSpreePromotionCode }
|
|
80
|
+
|
|
81
|
+
context 'when there are no Spree::PromotionCode with the same value' do
|
|
82
|
+
it 'moves the code into a Spree::PromotionCode' do
|
|
83
|
+
migration_context = double('a migration context')
|
|
84
|
+
allow_any_instance_of(promotions_with_code_handler)
|
|
85
|
+
.to receive(:migration_context)
|
|
86
|
+
.and_return(migration_context)
|
|
87
|
+
|
|
88
|
+
expect(migration_context)
|
|
89
|
+
.to receive(:say)
|
|
90
|
+
.with("Creating Spree::PromotionCode with value 'just an old promo code' for Spree::Promotion with id '#{promotion_with_code.id}'")
|
|
91
|
+
|
|
92
|
+
expect { subject }
|
|
93
|
+
.to change { Spree::PromotionCode.all.size }
|
|
94
|
+
.from(0)
|
|
95
|
+
.to(1)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
context 'when there is a Spree::PromotionCode with the same value' do
|
|
100
|
+
context 'associated with the same promotion' do
|
|
101
|
+
let!(:existing_promotion_code) { create(:promotion_code, value: 'just an old promo code', promotion: promotion_with_code) }
|
|
102
|
+
|
|
103
|
+
it 'does not create a new Spree::PromotionCode' do
|
|
104
|
+
expect { subject }.not_to change { Spree::PromotionCode.all.size }
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context 'associated with another promotion' do
|
|
109
|
+
let!(:existing_promotion_code) { create(:promotion_code, value: 'just an old promo code') }
|
|
110
|
+
|
|
111
|
+
it 'raises an exception' do
|
|
112
|
+
expect { subject }.to raise_error(StandardError)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
context 'to Solidus::Migrations::PromotionWithCodeHandlers::DoNothing' do
|
|
119
|
+
let(:promotions_with_code_handler) { Solidus::Migrations::PromotionWithCodeHandlers::DoNothing }
|
|
120
|
+
|
|
121
|
+
it 'just prints a message' do
|
|
122
|
+
migration_context = double('a migration context')
|
|
123
|
+
allow_any_instance_of(promotions_with_code_handler)
|
|
124
|
+
.to receive(:migration_context)
|
|
125
|
+
.and_return(migration_context)
|
|
126
|
+
|
|
127
|
+
expect(migration_context)
|
|
128
|
+
.to receive(:say)
|
|
129
|
+
.with("Code 'Just An Old Promo Code' is going to be removed from Spree::Promotion with id '#{promotion_with_code.id}'")
|
|
130
|
+
|
|
131
|
+
subject
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|