solidus_core 2.2.2 → 2.3.0.beta1
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 +4 -7
- data/app/assets/javascripts/spree.js.erb +2 -2
- data/app/helpers/spree/base_helper.rb +3 -4
- data/app/models/spree/address.rb +1 -1
- data/app/models/spree/adjustment.rb +3 -1
- data/app/models/spree/app_configuration.rb +43 -0
- data/app/models/spree/billing_integration.rb +2 -2
- data/app/models/spree/calculator/default_tax.rb +3 -1
- data/app/models/spree/calculator/distributed_amount.rb +24 -0
- data/app/models/spree/calculator/free_shipping.rb +0 -1
- data/app/models/spree/calculator/tiered_flat_rate.rb +17 -3
- data/app/models/spree/calculator/tiered_percent.rb +18 -3
- data/app/models/spree/distributed_amounts_handler.rb +43 -0
- data/app/models/spree/gateway/bogus.rb +7 -83
- data/app/models/spree/gateway/bogus_simple.rb +7 -20
- data/app/models/spree/gateway.rb +8 -58
- data/app/models/spree/image.rb +1 -1
- data/app/models/spree/line_item.rb +1 -1
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/order/checkout.rb +1 -4
- data/app/models/spree/order/number_generator.rb +43 -0
- data/app/models/spree/order.rb +33 -38
- data/app/models/spree/order_contents.rb +1 -1
- data/app/models/spree/order_taxation.rb +79 -0
- data/app/models/spree/order_update_attributes.rb +0 -2
- data/app/models/spree/order_updater.rb +55 -33
- data/app/models/spree/payment.rb +0 -1
- data/app/models/spree/payment_method/bogus_credit_card.rb +87 -0
- data/app/models/spree/payment_method/check.rb +14 -6
- data/app/models/spree/payment_method/credit_card.rb +41 -0
- data/app/models/spree/payment_method/simple_bogus_credit_card.rb +24 -0
- data/app/models/spree/payment_method/store_credit.rb +5 -13
- data/app/models/spree/payment_method.rb +126 -40
- data/app/models/spree/preferences/preferable.rb +5 -1
- data/app/models/spree/preferences/store.rb +2 -2
- data/app/models/spree/product/scopes.rb +14 -1
- data/app/models/spree/product.rb +10 -4
- data/app/models/spree/promotion_action.rb +4 -0
- data/app/models/spree/promotion_code/batch_builder.rb +3 -2
- data/app/models/spree/promotion_rule.rb +4 -0
- data/app/models/spree/role.rb +2 -0
- data/app/models/spree/role_user.rb +2 -0
- data/app/models/spree/shipment.rb +4 -2
- data/app/models/spree/shipping_method.rb +3 -1
- data/app/models/spree/shipping_rate.rb +1 -1
- data/app/models/spree/state.rb +10 -2
- data/app/models/spree/stock_item.rb +3 -3
- data/app/models/spree/store.rb +5 -0
- data/app/models/spree/store_credit.rb +2 -2
- data/app/models/spree/store_credit_event.rb +1 -1
- data/app/models/spree/store_selector/by_server_name.rb +30 -0
- data/app/models/spree/store_selector/legacy.rb +48 -0
- data/app/models/spree/tax/item_tax.rb +20 -0
- data/app/models/spree/tax/order_adjuster.rb +2 -14
- data/app/models/spree/tax/order_tax.rb +18 -0
- data/app/models/spree/tax/shipping_rate_taxer.rb +4 -13
- data/app/models/spree/tax/tax_helpers.rb +5 -3
- data/app/models/spree/tax_calculator/default.rb +83 -0
- data/app/models/spree/tax_calculator/shipping_rate.rb +46 -0
- data/app/models/spree/tax_category.rb +9 -1
- data/app/models/spree/tax_rate.rb +31 -7
- data/app/models/spree/tax_rate_tax_category.rb +6 -0
- data/app/models/spree/taxon.rb +1 -1
- data/app/models/spree/variant.rb +1 -1
- data/app/views/spree/{shipment_mailer → carton_mailer}/shipped_email.html.erb +3 -3
- data/app/views/spree/order_mailer/cancel_email.html.erb +3 -3
- data/app/views/spree/order_mailer/confirm_email.html.erb +2 -2
- data/app/views/spree/order_mailer/inventory_cancellation_email.html.erb +26 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +2 -2
- data/app/views/spree/test_mailer/test_email.html.erb +2 -2
- data/config/locales/en.yml +66 -57
- data/db/default/spree/refund_reasons.rb +1 -0
- data/db/default/spree/shipping_categories.rb +1 -0
- data/db/default/spree/stock_locations.rb +2 -0
- data/db/default/spree/stores.rb +3 -4
- data/db/migrate/20170412103617_transform_tax_rate_category_relation.rb +48 -0
- data/db/migrate/20170422134804_add_roles_unique_constraints.rb +6 -0
- data/db/migrate/20170522143442_add_time_range_to_tax_rate.rb +6 -0
- data/db/migrate/20170608074534_rename_bogus_gateways.rb +13 -0
- data/lib/generators/spree/custom_user/custom_user_generator.rb +1 -1
- data/lib/generators/spree/dummy/dummy_generator.rb +10 -4
- data/lib/generators/spree/dummy/templates/rails/database.yml +12 -12
- data/lib/generators/spree/install/install_generator.rb +5 -5
- data/lib/generators/spree/install/templates/config/initializers/{spree.rb → solidus.rb} +0 -0
- data/lib/solidus/migrations/rename_gateways.rb +39 -0
- data/lib/spree/core/controller_helpers/auth.rb +1 -1
- data/lib/spree/core/controller_helpers/order.rb +10 -5
- data/lib/spree/core/controller_helpers/store.rb +1 -9
- data/lib/spree/core/current_store.rb +6 -14
- data/lib/spree/core/engine.rb +4 -3
- data/lib/spree/core/importer/order.rb +4 -4
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/core.rb +0 -1
- data/lib/spree/localized_number.rb +2 -1
- data/lib/spree/permitted_attributes.rb +12 -6
- data/lib/spree/testing_support/capybara_ext.rb +0 -1
- data/lib/spree/testing_support/factories/adjustment_factory.rb +5 -1
- data/lib/spree/testing_support/factories/order_factory.rb +26 -24
- data/lib/spree/testing_support/factories/payment_factory.rb +4 -0
- data/lib/spree/testing_support/factories/payment_method_factory.rb +3 -3
- data/lib/spree/testing_support/factories/shipment_factory.rb +7 -3
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_factory.rb +3 -1
- data/lib/tasks/migrations/copy_order_bill_address_to_credit_card.rake +0 -4
- data/lib/tasks/migrations/migrate_user_addresses.rake +2 -2
- data/lib/tasks/migrations/rename_gateways.rake +19 -0
- data/solidus_core.gemspec +2 -3
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +32 -6
- data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +0 -1
- data/spec/lib/spree/core/current_store_spec.rb +6 -11
- data/spec/lib/spree/core/price_migrator_spec.rb +4 -4
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +199 -91
- data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +18 -0
- data/spec/lib/spree/localized_number_spec.rb +6 -0
- data/spec/mailers/carton_mailer_spec.rb +3 -3
- data/spec/models/spree/address_spec.rb +3 -3
- data/spec/models/spree/adjustment_spec.rb +71 -27
- data/spec/models/spree/calculator/default_tax_spec.rb +72 -1
- data/spec/models/spree/calculator/distributed_amount_spec.rb +32 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +20 -1
- data/spec/models/spree/calculator/tiered_percent_spec.rb +20 -1
- data/spec/models/spree/distributed_amounts_handler_spec.rb +79 -0
- data/spec/models/spree/gateway/bogus_simple.rb +7 -13
- data/spec/models/spree/gateway/bogus_spec.rb +8 -4
- data/spec/models/spree/gateway_spec.rb +6 -105
- data/spec/models/spree/image_spec.rb +23 -0
- data/spec/models/spree/order/checkout_spec.rb +3 -18
- data/spec/models/spree/order/number_generator_spec.rb +45 -0
- data/spec/models/spree/order/outstanding_balance_integration_spec.rb +135 -0
- data/spec/models/spree/order/payment_spec.rb +7 -2
- data/spec/models/spree/order/state_machine_spec.rb +4 -2
- data/spec/models/spree/order_capturing_spec.rb +8 -8
- data/spec/models/spree/order_contents_spec.rb +8 -1
- data/spec/models/spree/order_shipping_spec.rb +5 -1
- data/spec/models/spree/order_spec.rb +156 -83
- data/spec/models/spree/order_taxation_spec.rb +126 -0
- data/spec/models/spree/order_update_attributes_spec.rb +1 -5
- data/spec/models/spree/order_updater_spec.rb +20 -21
- data/spec/models/spree/payment_create_spec.rb +14 -6
- data/spec/models/spree/payment_method/bogus_credit_card_spec.rb +8 -0
- data/spec/models/spree/payment_method/check_spec.rb +78 -0
- data/spec/models/spree/payment_method/credit_card_spec.rb +66 -0
- data/spec/models/spree/payment_method/simple_bogus_credit_card_spec.rb +18 -0
- data/spec/models/spree/payment_method_spec.rb +47 -2
- data/spec/models/spree/payment_spec.rb +6 -8
- data/spec/models/spree/preference_spec.rb +1 -1
- data/spec/models/spree/price_spec.rb +1 -1
- data/spec/models/spree/product/scopes_spec.rb +46 -0
- data/spec/models/spree/promotion_action_spec.rb +4 -0
- data/spec/models/spree/promotion_code/batch_builder_spec.rb +25 -3
- data/spec/models/spree/promotion_code_batch_spec.rb +0 -6
- data/spec/models/spree/promotion_handler/coupon_spec.rb +1 -1
- data/spec/models/spree/promotion_rule_spec.rb +5 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +1 -1
- data/spec/models/spree/shipment_spec.rb +24 -3
- data/spec/models/spree/shipping_rate_spec.rb +5 -5
- data/spec/models/spree/state_spec.rb +31 -4
- data/spec/models/spree/stock/coordinator_spec.rb +24 -0
- data/spec/models/spree/stock/estimator_spec.rb +1 -1
- data/spec/models/spree/store_selector/by_server_name_spec.rb +26 -0
- data/spec/models/spree/store_selector/legacy_spec.rb +44 -0
- data/spec/models/spree/store_spec.rb +10 -2
- data/spec/models/spree/tax/order_adjuster_spec.rb +11 -21
- data/spec/models/spree/tax/shipping_rate_taxer_spec.rb +10 -3
- data/spec/models/spree/tax/taxation_integration_spec.rb +43 -8
- data/spec/models/spree/tax_calculator/default_spec.rb +54 -0
- data/spec/models/spree/tax_rate_spec.rb +92 -0
- data/spec/models/spree/variant/vat_price_generator_spec.rb +4 -4
- data/spec/models/spree/variant_spec.rb +8 -2
- data/spec/spec_helper.rb +2 -1
- data/spec/support/test_gateway.rb +1 -1
- metadata +45 -24
- data/app/models/spree/tax/item_adjuster.rb +0 -51
- data/spec/models/spree/tax/item_adjuster_spec.rb +0 -82
|
@@ -11,8 +11,8 @@ describe Spree::CartonMailer do
|
|
|
11
11
|
# Regression test for https://github.com/spree/spree/issues/2196
|
|
12
12
|
it "doesn't include out of stock in the email body" do
|
|
13
13
|
shipment_email = Spree::CartonMailer.shipped_email(order: order, carton: carton)
|
|
14
|
-
expect(shipment_email
|
|
15
|
-
expect(shipment_email
|
|
14
|
+
expect(shipment_email).not_to have_body_text(%{Out of Stock})
|
|
15
|
+
expect(shipment_email).to have_body_text(%{Your order has been shipped})
|
|
16
16
|
expect(shipment_email.subject).to eq "#{order.store.name} Shipment Notification ##{order.number}"
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -38,7 +38,7 @@ describe Spree::CartonMailer do
|
|
|
38
38
|
|
|
39
39
|
specify do
|
|
40
40
|
shipped_email = Spree::CartonMailer.shipped_email(order: order, carton: carton)
|
|
41
|
-
expect(shipped_email
|
|
41
|
+
expect(shipped_email).to have_body_text("Caro Cliente,")
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
end
|
|
@@ -21,7 +21,7 @@ describe Spree::Address, type: :model do
|
|
|
21
21
|
let(:address) { build(:address, country: country) }
|
|
22
22
|
|
|
23
23
|
before do
|
|
24
|
-
allow(country.states).to receive_messages
|
|
24
|
+
allow(country.states).to receive_messages with_name_or_abbr: [state]
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
context 'address does not require state' do
|
|
@@ -151,10 +151,10 @@ describe Spree::Address, type: :model do
|
|
|
151
151
|
context "zipcode not required" do
|
|
152
152
|
before { allow(address).to receive_messages require_zipcode?: false }
|
|
153
153
|
|
|
154
|
-
it "shows no errors when
|
|
154
|
+
it "shows no errors when zipcode is blank" do
|
|
155
155
|
address.zipcode = ""
|
|
156
156
|
address.valid?
|
|
157
|
-
expect(address.errors[:zipcode]
|
|
157
|
+
expect(address.errors[:zipcode]).to be_blank
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
end
|
|
@@ -79,54 +79,98 @@ describe Spree::Adjustment, type: :model do
|
|
|
79
79
|
end
|
|
80
80
|
|
|
81
81
|
context '#update!' do
|
|
82
|
-
let(:adjustment) { Spree::Adjustment.create!(label: 'Adjustment', order: order, adjustable: order, amount: 5, finalized: finalized, source: source) }
|
|
83
|
-
let(:source) { mock_model(Spree::TaxRate, compute_amount: 10) }
|
|
84
|
-
|
|
85
82
|
subject { adjustment.update! }
|
|
83
|
+
let(:adjustment) do
|
|
84
|
+
line_item.adjustments.create!(
|
|
85
|
+
label: 'Adjustment',
|
|
86
|
+
order: order,
|
|
87
|
+
adjustable: order,
|
|
88
|
+
amount: 5,
|
|
89
|
+
finalized: finalized,
|
|
90
|
+
source: source,
|
|
91
|
+
)
|
|
92
|
+
end
|
|
93
|
+
let(:order) { create(:order_with_line_items, line_items_price: 100) }
|
|
94
|
+
let(:line_item) { order.line_items.to_a.first }
|
|
86
95
|
|
|
87
|
-
context "when adjustment is
|
|
96
|
+
context "when adjustment is finalized" do
|
|
88
97
|
let(:finalized) { true }
|
|
89
98
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
99
|
+
context 'with a promotion adjustment' do
|
|
100
|
+
let(:source) { promotion.actions.first! }
|
|
101
|
+
let(:promotion) { create(:promotion, :with_line_item_adjustment, adjustment_rate: 7) }
|
|
102
|
+
|
|
103
|
+
it 'does not update the adjustment' do
|
|
104
|
+
expect { subject }.not_to change { adjustment.amount }
|
|
105
|
+
end
|
|
93
106
|
end
|
|
94
|
-
end
|
|
95
107
|
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
context 'with a tax adjustment' do
|
|
109
|
+
let(:source) { mock_model(Spree::TaxRate, compute_amount: 10) }
|
|
98
110
|
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
it 'updates the adjustment' do
|
|
112
|
+
expect { subject }.to change { adjustment.amount }.from(5).to(10)
|
|
113
|
+
end
|
|
101
114
|
end
|
|
102
115
|
|
|
103
|
-
context
|
|
104
|
-
let(:
|
|
105
|
-
let(:promo_start_date) { nil }
|
|
106
|
-
let(:promotion_code) { promotion.codes.first }
|
|
107
|
-
let(:order) { create(:order_with_line_items, line_items_count: 1) }
|
|
116
|
+
context 'with a sourceless adjustment' do
|
|
117
|
+
let(:source) { nil }
|
|
108
118
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
order.adjustments.first
|
|
119
|
+
it 'does nothing' do
|
|
120
|
+
expect { subject }.not_to change { adjustment.amount }
|
|
112
121
|
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
context "when adjustment isn't finalized" do
|
|
126
|
+
let(:finalized) { false }
|
|
127
|
+
|
|
128
|
+
context 'with a promotion adjustment' do
|
|
129
|
+
let(:source) { promotion.actions.first! }
|
|
130
|
+
let(:promotion) { create(:promotion, :with_line_item_adjustment, adjustment_rate: 7) }
|
|
113
131
|
|
|
114
|
-
context
|
|
115
|
-
it
|
|
132
|
+
context 'when the promotion is eligible' do
|
|
133
|
+
it 'updates the adjustment' do
|
|
134
|
+
expect { subject }.to change { adjustment.amount }.from(5).to(-7)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'sets the adjustment elgiible to true' do
|
|
116
138
|
subject
|
|
117
|
-
expect(adjustment.eligible).to eq
|
|
139
|
+
expect(adjustment.eligible).to eq(true)
|
|
118
140
|
end
|
|
119
141
|
end
|
|
120
142
|
|
|
121
|
-
context
|
|
122
|
-
|
|
143
|
+
context 'when the promotion is not eligible' do
|
|
144
|
+
before do
|
|
145
|
+
promotion.update!(starts_at: 1.day.from_now)
|
|
146
|
+
end
|
|
123
147
|
|
|
124
|
-
it
|
|
148
|
+
it 'zeros out the adjustment' do
|
|
149
|
+
expect { subject }.to change { adjustment.amount }.from(5).to(0)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it 'sets the adjustment elgiible to false' do
|
|
125
153
|
subject
|
|
126
|
-
expect(adjustment.eligible).to eq
|
|
154
|
+
expect(adjustment.eligible).to eq(false)
|
|
127
155
|
end
|
|
128
156
|
end
|
|
129
157
|
end
|
|
158
|
+
|
|
159
|
+
context 'with a tax adjustment' do
|
|
160
|
+
let(:source) { mock_model(Spree::TaxRate, compute_amount: 10) }
|
|
161
|
+
|
|
162
|
+
it 'updates the adjustment' do
|
|
163
|
+
expect { subject }.to change { adjustment.amount }.from(5).to(10)
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
context 'with a sourceless adjustment' do
|
|
168
|
+
let(:source) { nil }
|
|
169
|
+
|
|
170
|
+
it 'does nothing' do
|
|
171
|
+
expect { subject }.to_not change { adjustment.amount }
|
|
172
|
+
end
|
|
173
|
+
end
|
|
130
174
|
end
|
|
131
175
|
end
|
|
132
176
|
|
|
@@ -6,7 +6,13 @@ describe Spree::Calculator::DefaultTax, type: :model do
|
|
|
6
6
|
let!(:zone) { create(:zone, name: "Country Zone", default_tax: default_tax, countries: [tax_rate_country]) }
|
|
7
7
|
let(:tax_rate_country) { address.country }
|
|
8
8
|
let(:tax_category) { create(:tax_category) }
|
|
9
|
-
let
|
|
9
|
+
let(:starts_at) { nil }
|
|
10
|
+
let(:expires_at) { nil }
|
|
11
|
+
let!(:rate) do
|
|
12
|
+
create(:tax_rate, tax_categories: [tax_category], amount: 0.05,
|
|
13
|
+
included_in_price: included_in_price, zone: zone,
|
|
14
|
+
starts_at: starts_at, expires_at: expires_at)
|
|
15
|
+
end
|
|
10
16
|
let(:included_in_price) { false }
|
|
11
17
|
let(:default_tax) { false }
|
|
12
18
|
subject(:calculator) { Spree::Calculator::DefaultTax.new(calculable: rate ) }
|
|
@@ -32,6 +38,15 @@ describe Spree::Calculator::DefaultTax, type: :model do
|
|
|
32
38
|
it "should be equal to the sum of the item totals * rate" do
|
|
33
39
|
expect(calculator.compute(order)).to eq(3)
|
|
34
40
|
end
|
|
41
|
+
|
|
42
|
+
context "when rate is not in its validity period" do
|
|
43
|
+
let(:starts_at) { 1.day.from_now }
|
|
44
|
+
let(:expires_at) { 2.days.from_now }
|
|
45
|
+
|
|
46
|
+
it "should be 0" do
|
|
47
|
+
expect(calculator.compute(order)).to eq(0)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
35
50
|
end
|
|
36
51
|
|
|
37
52
|
context "when no line items match the tax category" do
|
|
@@ -52,6 +67,15 @@ describe Spree::Calculator::DefaultTax, type: :model do
|
|
|
52
67
|
expect(calculator.compute(order)).to eq(1.5)
|
|
53
68
|
end
|
|
54
69
|
|
|
70
|
+
context "when rate is not in its validity period" do
|
|
71
|
+
let(:starts_at) { 1.day.from_now }
|
|
72
|
+
let(:expires_at) { 2.days.from_now }
|
|
73
|
+
|
|
74
|
+
it "should be 0" do
|
|
75
|
+
expect(calculator.compute(order)).to eq(0)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
55
79
|
context "correctly rounds to within two decimal places" do
|
|
56
80
|
let(:line_item_one_options) { { price: 10.333, quantity: 1 } }
|
|
57
81
|
|
|
@@ -73,6 +97,15 @@ describe Spree::Calculator::DefaultTax, type: :model do
|
|
|
73
97
|
expect(calculator.compute(order).to_f).to eql 2.86
|
|
74
98
|
end
|
|
75
99
|
|
|
100
|
+
context "when rate is not in its validity period" do
|
|
101
|
+
let(:starts_at) { 1.day.from_now }
|
|
102
|
+
let(:expires_at) { 2.days.from_now }
|
|
103
|
+
|
|
104
|
+
it "should be 0" do
|
|
105
|
+
expect(calculator.compute(order)).to eq(0)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
76
109
|
context "when the order's tax address is outside the default VAT zone" do
|
|
77
110
|
let(:default_tax) { true }
|
|
78
111
|
let(:default_vat_country) { create(:country, iso: "DE") }
|
|
@@ -86,6 +119,17 @@ describe Spree::Calculator::DefaultTax, type: :model do
|
|
|
86
119
|
expect(subject.compute(order)).to eq(-2.86)
|
|
87
120
|
end
|
|
88
121
|
end
|
|
122
|
+
|
|
123
|
+
context "when rate is not in its validity period" do
|
|
124
|
+
let(:starts_at) { 1.day.from_now }
|
|
125
|
+
let(:expires_at) { 2.days.from_now }
|
|
126
|
+
|
|
127
|
+
it "should be 0" do
|
|
128
|
+
Spree::Deprecation.silence do
|
|
129
|
+
expect(calculator.compute(order)).to eq(0)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
89
133
|
end
|
|
90
134
|
end
|
|
91
135
|
end
|
|
@@ -103,6 +147,15 @@ describe Spree::Calculator::DefaultTax, type: :model do
|
|
|
103
147
|
expect(calculator.compute(item)).to eql 1.43
|
|
104
148
|
end
|
|
105
149
|
|
|
150
|
+
context "when rate is not in its validity period" do
|
|
151
|
+
let(:starts_at) { 1.day.from_now }
|
|
152
|
+
let(:expires_at) { 2.days.from_now }
|
|
153
|
+
|
|
154
|
+
it "should be 0" do
|
|
155
|
+
expect(calculator.compute(item)).to eq(0)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
106
159
|
context "when line item is discounted" do
|
|
107
160
|
let(:promo_total) { -1 }
|
|
108
161
|
|
|
@@ -135,12 +188,30 @@ describe Spree::Calculator::DefaultTax, type: :model do
|
|
|
135
188
|
it "should be equal to the item's pre-tax total * rate" do
|
|
136
189
|
expect(calculator.compute(item)).to eq(1.45)
|
|
137
190
|
end
|
|
191
|
+
|
|
192
|
+
context "when rate is not in its validity period" do
|
|
193
|
+
let(:starts_at) { 1.day.from_now }
|
|
194
|
+
let(:expires_at) { 2.days.from_now }
|
|
195
|
+
|
|
196
|
+
it "should be 0" do
|
|
197
|
+
expect(calculator.compute(item)).to eq(0)
|
|
198
|
+
end
|
|
199
|
+
end
|
|
138
200
|
end
|
|
139
201
|
|
|
140
202
|
context "when the variant matches the tax category" do
|
|
141
203
|
it "should be equal to the item pre-tax total * rate" do
|
|
142
204
|
expect(calculator.compute(item)).to eq(1.50)
|
|
143
205
|
end
|
|
206
|
+
|
|
207
|
+
context "when rate is not in its validity period" do
|
|
208
|
+
let(:starts_at) { 1.day.from_now }
|
|
209
|
+
let(:expires_at) { 2.days.from_now }
|
|
210
|
+
|
|
211
|
+
it "should be 0" do
|
|
212
|
+
expect(calculator.compute(item)).to eq(0)
|
|
213
|
+
end
|
|
214
|
+
end
|
|
144
215
|
end
|
|
145
216
|
end
|
|
146
217
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'shared_examples/calculator_shared_examples'
|
|
3
|
+
|
|
4
|
+
describe Spree::Calculator::DistributedAmount, type: :model do
|
|
5
|
+
describe "#compute_line_item" do
|
|
6
|
+
subject { calculator.compute_line_item(order.line_items.first) }
|
|
7
|
+
|
|
8
|
+
let(:calculator) { Spree::Calculator::DistributedAmount.new }
|
|
9
|
+
|
|
10
|
+
let(:order) do
|
|
11
|
+
FactoryGirl.create(
|
|
12
|
+
:order_with_line_items,
|
|
13
|
+
line_items_attributes: [{ price: 50 }, { price: 50 }, { price: 50 }]
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
before do
|
|
18
|
+
calculator.preferred_amount = 15
|
|
19
|
+
calculator.preferred_currency = currency
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "when the order currency matches the store's currency" do
|
|
23
|
+
let(:currency) { "USD" }
|
|
24
|
+
it { is_expected.to eq 5 }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "when the order currency does not match the store's currency" do
|
|
28
|
+
let(:currency) { "CAD" }
|
|
29
|
+
it { is_expected.to eq 0 }
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -57,22 +57,41 @@ describe Spree::Calculator::TieredFlatRate, type: :model do
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
describe "#compute" do
|
|
60
|
-
let(:
|
|
60
|
+
let(:order) do
|
|
61
|
+
create(
|
|
62
|
+
:order_with_line_items,
|
|
63
|
+
line_items_count: 1,
|
|
64
|
+
line_items_price: amount
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
let(:line_item) { order.line_items.first }
|
|
68
|
+
let(:preferred_currency) { "USD" }
|
|
69
|
+
|
|
61
70
|
before do
|
|
62
71
|
calculator.preferred_base_amount = 10
|
|
63
72
|
calculator.preferred_tiers = {
|
|
64
73
|
100 => 15,
|
|
65
74
|
200 => 20
|
|
66
75
|
}
|
|
76
|
+
calculator.preferred_currency = preferred_currency
|
|
67
77
|
end
|
|
78
|
+
|
|
68
79
|
subject { calculator.compute(line_item) }
|
|
80
|
+
|
|
69
81
|
context "when amount falls within the first tier" do
|
|
70
82
|
let(:amount) { 50 }
|
|
71
83
|
it { is_expected.to eq 10 }
|
|
72
84
|
end
|
|
85
|
+
|
|
73
86
|
context "when amount falls within the second tier" do
|
|
74
87
|
let(:amount) { 150 }
|
|
75
88
|
it { is_expected.to eq 15 }
|
|
76
89
|
end
|
|
90
|
+
|
|
91
|
+
context "when the order's currency does not match the calculator" do
|
|
92
|
+
let(:preferred_currency) { "CAD" }
|
|
93
|
+
let(:amount) { 50 }
|
|
94
|
+
it { is_expected.to eq 0 }
|
|
95
|
+
end
|
|
77
96
|
end
|
|
78
97
|
end
|
|
@@ -73,8 +73,15 @@ describe Spree::Calculator::TieredPercent, type: :model do
|
|
|
73
73
|
end
|
|
74
74
|
|
|
75
75
|
describe "#compute" do
|
|
76
|
-
let(:order)
|
|
76
|
+
let(:order) do
|
|
77
|
+
create(
|
|
78
|
+
:order_with_line_items,
|
|
79
|
+
line_items_count: line_item_count,
|
|
80
|
+
line_items_price: price
|
|
81
|
+
)
|
|
82
|
+
end
|
|
77
83
|
let(:price) { 10 }
|
|
84
|
+
let(:preferred_currency) { "USD" }
|
|
78
85
|
|
|
79
86
|
before do
|
|
80
87
|
calculator.preferred_base_percent = 10
|
|
@@ -82,6 +89,7 @@ describe Spree::Calculator::TieredPercent, type: :model do
|
|
|
82
89
|
20 => 15,
|
|
83
90
|
30 => 20
|
|
84
91
|
}
|
|
92
|
+
calculator.preferred_currency = preferred_currency
|
|
85
93
|
end
|
|
86
94
|
|
|
87
95
|
context "with a line item" do
|
|
@@ -123,6 +131,12 @@ describe Spree::Calculator::TieredPercent, type: :model do
|
|
|
123
131
|
it { is_expected.to eq 6.0 }
|
|
124
132
|
end
|
|
125
133
|
end
|
|
134
|
+
|
|
135
|
+
context "when the order's currency does not match the calculator" do
|
|
136
|
+
let(:preferred_currency) { "CAD" }
|
|
137
|
+
let(:line_item_count) { 1 }
|
|
138
|
+
it { is_expected.to eq 0 }
|
|
139
|
+
end
|
|
126
140
|
end
|
|
127
141
|
|
|
128
142
|
context "with an order" do
|
|
@@ -165,6 +179,11 @@ describe Spree::Calculator::TieredPercent, type: :model do
|
|
|
165
179
|
it { is_expected.to eq 6.0 }
|
|
166
180
|
end
|
|
167
181
|
end
|
|
182
|
+
|
|
183
|
+
context "when the order's currency does not match the calculator" do
|
|
184
|
+
let(:preferred_currency) { "CAD" }
|
|
185
|
+
it { is_expected.to eq 0 }
|
|
186
|
+
end
|
|
168
187
|
end
|
|
169
188
|
end
|
|
170
189
|
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
RSpec.describe Spree::DistributedAmountsHandler, type: :model do
|
|
4
|
+
let(:order) do
|
|
5
|
+
FactoryGirl.create(
|
|
6
|
+
:order_with_line_items,
|
|
7
|
+
line_items_attributes: line_items_attributes
|
|
8
|
+
)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "#amount" do
|
|
12
|
+
let(:total_amount) { 15 }
|
|
13
|
+
|
|
14
|
+
subject { described_class.new(line_item, total_amount).amount }
|
|
15
|
+
|
|
16
|
+
context "when there is only one line item" do
|
|
17
|
+
let(:line_items_attributes) { [{ price: 100 }] }
|
|
18
|
+
let(:line_item) { order.line_items.first }
|
|
19
|
+
|
|
20
|
+
it "applies the entire amount to the line item" do
|
|
21
|
+
expect(subject).to eq(15)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "when there are multiple line items" do
|
|
26
|
+
let(:line_items_attributes) do
|
|
27
|
+
[{ price: 50 }, { price: 50 }, { price: 50 }]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "and the line items are equally priced" do
|
|
31
|
+
it "evenly distributes the total amount" do
|
|
32
|
+
expect(
|
|
33
|
+
[
|
|
34
|
+
described_class.new(order.line_items[0], total_amount).amount,
|
|
35
|
+
described_class.new(order.line_items[1], total_amount).amount,
|
|
36
|
+
described_class.new(order.line_items[2], total_amount).amount
|
|
37
|
+
]
|
|
38
|
+
).to eq(
|
|
39
|
+
[5, 5, 5]
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context "and the total amount cannot be equally distributed" do
|
|
44
|
+
let(:total_amount) { 10 }
|
|
45
|
+
|
|
46
|
+
it "applies the remainder of the total amount to the last item" do
|
|
47
|
+
expect(
|
|
48
|
+
[
|
|
49
|
+
described_class.new(order.line_items[0], total_amount).amount,
|
|
50
|
+
described_class.new(order.line_items[1], total_amount).amount,
|
|
51
|
+
described_class.new(order.line_items[2], total_amount).amount
|
|
52
|
+
]
|
|
53
|
+
).to eq(
|
|
54
|
+
[3.33, 3.33, 3.34]
|
|
55
|
+
)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context "and the line items are not equally priced" do
|
|
61
|
+
let(:line_items_attributes) do
|
|
62
|
+
[{ price: 150 }, { price: 50 }, { price: 100 }]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "distributes the total amount relative to the item's price" do
|
|
66
|
+
expect(
|
|
67
|
+
[
|
|
68
|
+
described_class.new(order.line_items[0], total_amount).amount,
|
|
69
|
+
described_class.new(order.line_items[1], total_amount).amount,
|
|
70
|
+
described_class.new(order.line_items[2], total_amount).amount
|
|
71
|
+
]
|
|
72
|
+
).to eq(
|
|
73
|
+
[7.5, 2.5, 5]
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Spree::Gateway::BogusSimple
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
it "returns success with the right response code" do
|
|
9
|
-
response = subject.capture(123, '12345', {})
|
|
10
|
-
expect(response.message).to include("success")
|
|
11
|
-
end
|
|
3
|
+
describe Spree::Gateway::BogusSimple do
|
|
4
|
+
it 'is deprecated' do
|
|
5
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
6
|
+
described_class.new
|
|
7
|
+
end
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
expect(response.message).to include("failure")
|
|
16
|
-
end
|
|
9
|
+
it 'has Spree::PaymentMethod::SimpleBogusCreditCard as superclass' do
|
|
10
|
+
expect(described_class.ancestors).to include(Spree::PaymentMethod::SimpleBogusCreditCard)
|
|
17
11
|
end
|
|
18
12
|
end
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
describe Spree::Gateway::Bogus do
|
|
4
|
+
it 'is deprecated' do
|
|
5
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
6
|
+
described_class.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'has Spree::PaymentMethod::BogusCreditCard as superclass' do
|
|
10
|
+
expect(described_class.ancestors).to include(Spree::PaymentMethod::BogusCreditCard)
|
|
7
11
|
end
|
|
8
12
|
end
|
|
@@ -1,111 +1,12 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Spree::Gateway
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def authorize; 'authorize'; end
|
|
9
|
-
|
|
10
|
-
def purchase; 'purchase'; end
|
|
11
|
-
|
|
12
|
-
def capture; 'capture'; end
|
|
13
|
-
|
|
14
|
-
def void; 'void'; end
|
|
15
|
-
|
|
16
|
-
def credit; 'credit'; end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
class TestGateway < Spree::Gateway
|
|
20
|
-
def provider_class
|
|
21
|
-
Provider
|
|
22
|
-
end
|
|
3
|
+
describe Spree::Gateway do
|
|
4
|
+
it 'is deprecated' do
|
|
5
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
6
|
+
described_class.new
|
|
23
7
|
end
|
|
24
8
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
it "passes through authorize" do
|
|
29
|
-
expect(gateway.authorize).to eq 'authorize'
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it "passes through purchase" do
|
|
33
|
-
expect(gateway.purchase).to eq 'purchase'
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "passes through capture" do
|
|
37
|
-
expect(gateway.capture).to eq 'capture'
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it "passes through void" do
|
|
41
|
-
expect(gateway.void).to eq 'void'
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "passes through credit" do
|
|
45
|
-
expect(gateway.credit).to eq 'credit'
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
context "fetching payment sources" do
|
|
50
|
-
let(:store) { create :store }
|
|
51
|
-
let(:user) { create :user }
|
|
52
|
-
let(:order) { Spree::Order.create(user: user, completed_at: completed_at, store: store) }
|
|
53
|
-
|
|
54
|
-
let(:payment_method) { create(:credit_card_payment_method) }
|
|
55
|
-
|
|
56
|
-
let(:cc) do
|
|
57
|
-
create(:credit_card,
|
|
58
|
-
payment_method: payment_method,
|
|
59
|
-
gateway_customer_profile_id: "EFWE",
|
|
60
|
-
user: cc_user)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
let(:payment) do
|
|
64
|
-
create(:payment, order: order, source: cc, payment_method: payment_method)
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
context 'order is not complete and credit card user is nil' do
|
|
68
|
-
let(:cc_user) { nil }
|
|
69
|
-
let(:completed_at) { nil }
|
|
70
|
-
|
|
71
|
-
it "finds no credit cards associated to the order" do
|
|
72
|
-
expect(payment_method.reusable_sources(payment.order)).to be_empty
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
context 'order is complete but credit card user is nil' do
|
|
77
|
-
let(:cc_user) { nil }
|
|
78
|
-
let(:completed_at) { Date.yesterday }
|
|
79
|
-
|
|
80
|
-
it "finds credit cards associated on a order completed" do
|
|
81
|
-
expect(payment_method.reusable_sources(payment.order)).to eq [cc]
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
context 'order is not complete but credit card has user' do
|
|
86
|
-
let(:cc_user) { user }
|
|
87
|
-
let(:completed_at) { nil }
|
|
88
|
-
before do
|
|
89
|
-
cc_user.wallet.add(cc)
|
|
90
|
-
end
|
|
91
|
-
it "finds credit cards associated to the user" do
|
|
92
|
-
expect(payment_method.reusable_sources(payment.order)).to eq [cc]
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
context 'using preference_source' do
|
|
98
|
-
let(:klass){ Spree::Gateway::Bogus }
|
|
99
|
-
before do
|
|
100
|
-
Spree::Config.static_model_preferences.add(klass, 'test_preference_source', server: 'bar')
|
|
101
|
-
end
|
|
102
|
-
after do
|
|
103
|
-
Spree::Config.static_model_preferences.for_class(klass).clear
|
|
104
|
-
end
|
|
105
|
-
let(:payment_method){ create(:credit_card_payment_method, preference_source: 'test_preference_source') }
|
|
106
|
-
|
|
107
|
-
it "reads static preferences" do
|
|
108
|
-
expect(payment_method.options).to eq({ server: "bar" })
|
|
109
|
-
end
|
|
9
|
+
it 'has Spree::PaymentMethod::CreditCard as superclass' do
|
|
10
|
+
expect(described_class.ancestors).to include(Spree::PaymentMethod::CreditCard)
|
|
110
11
|
end
|
|
111
12
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Spree::Image, type: :model do
|
|
4
|
+
context '#save' do
|
|
5
|
+
context 'invalid attachment' do
|
|
6
|
+
let(:invalid_image) { File.open(__FILE__) }
|
|
7
|
+
subject { described_class.new(attachment: invalid_image) }
|
|
8
|
+
|
|
9
|
+
it 'returns false' do
|
|
10
|
+
expect(subject.save).to be false
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'valid attachment' do
|
|
15
|
+
let(:valid_image) { File.open(File.join('spec', 'fixtures', 'thinking-cat.jpg')) }
|
|
16
|
+
subject { described_class.new(attachment: valid_image) }
|
|
17
|
+
|
|
18
|
+
it 'returns true' do
|
|
19
|
+
expect(subject.save).to be true
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|