spree_core 3.2.1 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spree/core/version.rb +1 -1
- data/spree_core.gemspec +1 -1
- metadata +3 -206
- data/spec/fixtures/microdata.html +0 -22
- data/spec/fixtures/microdata_itemref.html +0 -15
- data/spec/fixtures/microdata_no_itemscope.html +0 -20
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +0 -200
- data/spec/helpers/products_helper_spec.rb +0 -289
- data/spec/lib/calculated_adjustments_spec.rb +0 -7
- data/spec/lib/i18n_spec.rb +0 -123
- data/spec/lib/search/base_spec.rb +0 -86
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
- data/spec/lib/spree/core/importer/order_spec.rb +0 -605
- data/spec/lib/spree/core/number_generator_spec.rb +0 -175
- data/spec/lib/spree/core/token_generator_spec.rb +0 -24
- data/spec/lib/spree/core/validators/email_spec.rb +0 -53
- data/spec/lib/spree/core_spec.rb +0 -23
- data/spec/lib/spree/localized_number_spec.rb +0 -48
- data/spec/lib/spree/migrations_spec.rb +0 -36
- data/spec/lib/spree/money_spec.rb +0 -122
- data/spec/lib/tasks/exchanges_spec.rb +0 -136
- data/spec/mailers/order_mailer_spec.rb +0 -122
- data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
- data/spec/mailers/shipment_mailer_spec.rb +0 -81
- data/spec/mailers/test_mailer_spec.rb +0 -38
- data/spec/models/option_type_prototype_spec.rb +0 -9
- data/spec/models/spree/ability_spec.rb +0 -251
- data/spec/models/spree/address_spec.rb +0 -402
- data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
- data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
- data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
- data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
- data/spec/models/spree/adjustment_spec.rb +0 -189
- data/spec/models/spree/app_configuration_spec.rb +0 -26
- data/spec/models/spree/asset_spec.rb +0 -28
- data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
- data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
- data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
- data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
- data/spec/models/spree/calculator/shipping.rb +0 -8
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
- data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
- data/spec/models/spree/calculator_spec.rb +0 -69
- data/spec/models/spree/classification_spec.rb +0 -93
- data/spec/models/spree/concerns/display_money_spec.rb +0 -43
- data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
- data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
- data/spec/models/spree/country_spec.rb +0 -55
- data/spec/models/spree/credit_card_spec.rb +0 -328
- data/spec/models/spree/customer_return_spec.rb +0 -240
- data/spec/models/spree/exchange_spec.rb +0 -75
- data/spec/models/spree/gateway/bogus_simple.rb +0 -20
- data/spec/models/spree/gateway/bogus_spec.rb +0 -13
- data/spec/models/spree/gateway_spec.rb +0 -61
- data/spec/models/spree/image_spec.rb +0 -8
- data/spec/models/spree/inventory_unit_spec.rb +0 -256
- data/spec/models/spree/line_item_spec.rb +0 -346
- data/spec/models/spree/option_type_spec.rb +0 -14
- data/spec/models/spree/option_value_spec.rb +0 -18
- data/spec/models/spree/order/address_spec.rb +0 -50
- data/spec/models/spree/order/adjustments_spec.rb +0 -29
- data/spec/models/spree/order/callbacks_spec.rb +0 -42
- data/spec/models/spree/order/checkout_spec.rb +0 -770
- data/spec/models/spree/order/currency_updater_spec.rb +0 -32
- data/spec/models/spree/order/finalizing_spec.rb +0 -114
- data/spec/models/spree/order/helpers_spec.rb +0 -5
- data/spec/models/spree/order/payment_spec.rb +0 -214
- data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
- data/spec/models/spree/order/shipments_spec.rb +0 -43
- data/spec/models/spree/order/state_machine_spec.rb +0 -212
- data/spec/models/spree/order/store_credit_spec.rb +0 -426
- data/spec/models/spree/order/tax_spec.rb +0 -84
- data/spec/models/spree/order/totals_spec.rb +0 -24
- data/spec/models/spree/order/updating_spec.rb +0 -18
- data/spec/models/spree/order/validations_spec.rb +0 -15
- data/spec/models/spree/order_contents_spec.rb +0 -297
- data/spec/models/spree/order_inventory_spec.rb +0 -239
- data/spec/models/spree/order_merger_spec.rb +0 -135
- data/spec/models/spree/order_spec.rb +0 -1046
- data/spec/models/spree/order_updater_spec.rb +0 -305
- data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
- data/spec/models/spree/payment/store_credit_spec.rb +0 -60
- data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
- data/spec/models/spree/payment_method_spec.rb +0 -103
- data/spec/models/spree/payment_spec.rb +0 -919
- data/spec/models/spree/preference_spec.rb +0 -80
- data/spec/models/spree/preferences/configuration_spec.rb +0 -30
- data/spec/models/spree/preferences/preferable_spec.rb +0 -344
- data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
- data/spec/models/spree/preferences/store_spec.rb +0 -46
- data/spec/models/spree/price_spec.rb +0 -128
- data/spec/models/spree/product/scopes_spec.rb +0 -183
- data/spec/models/spree/product_duplicator_spec.rb +0 -103
- data/spec/models/spree/product_filter_spec.rb +0 -26
- data/spec/models/spree/product_option_type_spec.rb +0 -9
- data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
- data/spec/models/spree/product_property_spec.rb +0 -26
- data/spec/models/spree/product_spec.rb +0 -629
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
- data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
- data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
- data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
- data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
- data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
- data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
- data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
- data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
- data/spec/models/spree/promotion_action_spec.rb +0 -10
- data/spec/models/spree/promotion_category_spec.rb +0 -17
- data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
- data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
- data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
- data/spec/models/spree/promotion_rule_spec.rb +0 -29
- data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
- data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
- data/spec/models/spree/promotion_spec.rb +0 -679
- data/spec/models/spree/property_prototype_spec.rb +0 -9
- data/spec/models/spree/property_spec.rb +0 -5
- data/spec/models/spree/prototype_spec.rb +0 -5
- data/spec/models/spree/prototype_taxon_spec.rb +0 -9
- data/spec/models/spree/refund_reason_spec.rb +0 -20
- data/spec/models/spree/refund_spec.rb +0 -195
- data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
- data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
- data/spec/models/spree/reimbursement_spec.rb +0 -188
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
- data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
- data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
- data/spec/models/spree/return_authorization_spec.rb +0 -230
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
- data/spec/models/spree/return_item_spec.rb +0 -731
- data/spec/models/spree/returns_calculator_spec.rb +0 -14
- data/spec/models/spree/role_spec.rb +0 -7
- data/spec/models/spree/shipment_spec.rb +0 -742
- data/spec/models/spree/shipping_calculator_spec.rb +0 -45
- data/spec/models/spree/shipping_category_spec.rb +0 -19
- data/spec/models/spree/shipping_method_spec.rb +0 -95
- data/spec/models/spree/shipping_rate_spec.rb +0 -140
- data/spec/models/spree/state_spec.rb +0 -29
- data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
- data/spec/models/spree/stock/content_item_spec.rb +0 -31
- data/spec/models/spree/stock/coordinator_spec.rb +0 -61
- data/spec/models/spree/stock/differentiator_spec.rb +0 -39
- data/spec/models/spree/stock/estimator_spec.rb +0 -202
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
- data/spec/models/spree/stock/package_spec.rb +0 -182
- data/spec/models/spree/stock/packer_spec.rb +0 -70
- data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
- data/spec/models/spree/stock/quantifier_spec.rb +0 -126
- data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
- data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
- data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
- data/spec/models/spree/stock_item_spec.rb +0 -432
- data/spec/models/spree/stock_location_spec.rb +0 -243
- data/spec/models/spree/stock_movement_spec.rb +0 -120
- data/spec/models/spree/stock_transfer_spec.rb +0 -50
- data/spec/models/spree/store_credit_event_spec.rb +0 -101
- data/spec/models/spree/store_credit_spec.rb +0 -786
- data/spec/models/spree/store_spec.rb +0 -78
- data/spec/models/spree/tax_category_spec.rb +0 -32
- data/spec/models/spree/tax_rate_spec.rb +0 -561
- data/spec/models/spree/taxon_spec.rb +0 -85
- data/spec/models/spree/taxonomy_spec.rb +0 -18
- data/spec/models/spree/tracker_spec.rb +0 -21
- data/spec/models/spree/user_spec.rb +0 -203
- data/spec/models/spree/variant_spec.rb +0 -818
- data/spec/models/spree/zone_member_spec.rb +0 -38
- data/spec/models/spree/zone_spec.rb +0 -472
- data/spec/spec_helper.rb +0 -79
- data/spec/support/big_decimal.rb +0 -5
- data/spec/support/concerns/adjustment_source.rb +0 -23
- data/spec/support/concerns/default_price.rb +0 -37
- data/spec/support/rake.rb +0 -13
- data/spec/support/test_gateway.rb +0 -2
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::Adjustable::Adjuster::Tax, type: :model do
|
4
|
-
let(:order) { create :order_with_line_items, line_items_count: 1 }
|
5
|
-
let(:line_item) { order.line_items.first }
|
6
|
-
|
7
|
-
let(:subject) { Spree::Adjustable::AdjustmentsUpdater.new(line_item) }
|
8
|
-
let(:order_subject) { Spree::Adjustable::AdjustmentsUpdater.new(order) }
|
9
|
-
|
10
|
-
context "taxes with promotions" do
|
11
|
-
let!(:tax_rate) do
|
12
|
-
create(:tax_rate, amount: 0.05)
|
13
|
-
end
|
14
|
-
|
15
|
-
let!(:promotion) do
|
16
|
-
Spree::Promotion.create(name: "$10 off")
|
17
|
-
end
|
18
|
-
|
19
|
-
let!(:promotion_action) do
|
20
|
-
calculator = Spree::Calculator::FlatRate.new(preferred_amount: 10)
|
21
|
-
Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator,
|
22
|
-
promotion: promotion)
|
23
|
-
end
|
24
|
-
|
25
|
-
before do
|
26
|
-
line_item.price = 20
|
27
|
-
line_item.tax_category = tax_rate.tax_category
|
28
|
-
line_item.save
|
29
|
-
create(:adjustment, order: order, source: promotion_action, adjustable: line_item)
|
30
|
-
end
|
31
|
-
|
32
|
-
context "tax included in price" do
|
33
|
-
before do
|
34
|
-
create(:adjustment,
|
35
|
-
source: tax_rate,
|
36
|
-
adjustable: line_item,
|
37
|
-
order: order,
|
38
|
-
included: true)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "tax has no bearing on final price" do
|
42
|
-
subject.update
|
43
|
-
line_item.reload
|
44
|
-
expect(line_item.included_tax_total).to eq(0.5)
|
45
|
-
expect(line_item.additional_tax_total).to eq(0)
|
46
|
-
expect(line_item.promo_total).to eq(-10)
|
47
|
-
expect(line_item.adjustment_total).to eq(-10)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "tax linked to order" do
|
51
|
-
order_subject.update
|
52
|
-
order.reload
|
53
|
-
expect(order.included_tax_total).to eq(0.5)
|
54
|
-
expect(order.additional_tax_total).to eq(00)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "tax excluded from price" do
|
59
|
-
before do
|
60
|
-
create(:adjustment,
|
61
|
-
source: tax_rate,
|
62
|
-
adjustable: line_item,
|
63
|
-
order: order,
|
64
|
-
included: false)
|
65
|
-
end
|
66
|
-
|
67
|
-
it "tax applies to line item" do
|
68
|
-
subject.update
|
69
|
-
line_item.reload
|
70
|
-
# Taxable amount is: $20 (base) - $10 (promotion) = $10
|
71
|
-
# Tax rate is 5% (of $10).
|
72
|
-
expect(line_item.included_tax_total).to eq(0)
|
73
|
-
expect(line_item.additional_tax_total).to eq(0.5)
|
74
|
-
expect(line_item.promo_total).to eq(-10)
|
75
|
-
expect(line_item.adjustment_total).to eq(-9.5)
|
76
|
-
end
|
77
|
-
|
78
|
-
it "tax linked to order" do
|
79
|
-
order_subject.update
|
80
|
-
order.reload
|
81
|
-
expect(order.included_tax_total).to eq(0)
|
82
|
-
expect(order.additional_tax_total).to eq(0.5)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Spree
|
4
|
-
module Adjustable
|
5
|
-
describe AdjustmentsUpdater do
|
6
|
-
let(:order) { create :order_with_line_items, line_items_count: 1 }
|
7
|
-
let(:line_item) { order.line_items.first }
|
8
|
-
|
9
|
-
let(:subject) { AdjustmentsUpdater.new(line_item) }
|
10
|
-
let(:order_subject) { AdjustmentsUpdater.new(order) }
|
11
|
-
|
12
|
-
describe '#update' do
|
13
|
-
it "updates all linked adjusters" do
|
14
|
-
tax_rate = create(:tax_rate, amount: 0.05)
|
15
|
-
create(:adjustment, order: order, source: tax_rate, adjustable: line_item)
|
16
|
-
line_item.price = 10
|
17
|
-
line_item.tax_category = tax_rate.tax_category
|
18
|
-
|
19
|
-
subject.update
|
20
|
-
expect(line_item.adjustment_total).to eq(0.5)
|
21
|
-
expect(line_item.additional_tax_total).to eq(0.5)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,189 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
|
4
|
-
require 'spec_helper'
|
5
|
-
|
6
|
-
describe Spree::Adjustment, type: :model do
|
7
|
-
|
8
|
-
let(:order) { Spree::Order.new }
|
9
|
-
|
10
|
-
before do
|
11
|
-
allow(order).to receive(:update_with_updater!)
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:adjustment) { Spree::Adjustment.create!(label: 'Adjustment', adjustable: order, order: order, amount: 5) }
|
15
|
-
|
16
|
-
describe 'scopes' do
|
17
|
-
describe '.for_complete_order' do
|
18
|
-
let(:complete_order) { Spree::Order.create! completed_at: Time.current }
|
19
|
-
let(:incomplete_order) { Spree::Order.create! completed_at: nil }
|
20
|
-
let(:adjustment_for_complete_order) { Spree::Adjustment.create!(label: 'Adjustment', adjustable: complete_order, order: complete_order, amount: 5) }
|
21
|
-
let(:adjustment_for_incomplete_order) { Spree::Adjustment.create!(label: 'Adjustment', adjustable: incomplete_order, order: incomplete_order, amount: 5) }
|
22
|
-
|
23
|
-
subject { Spree::Adjustment.for_complete_order }
|
24
|
-
|
25
|
-
it { is_expected.to include(adjustment_for_complete_order) }
|
26
|
-
it { is_expected.to_not include(adjustment_for_incomplete_order) }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe '.for_incomplete_order' do
|
30
|
-
let(:complete_order) { Spree::Order.create! completed_at: Time.current }
|
31
|
-
let(:incomplete_order) { Spree::Order.create! completed_at: nil }
|
32
|
-
let(:adjustment_for_complete_order) { Spree::Adjustment.create!(label: 'Adjustment', adjustable: complete_order, order: complete_order, amount: 5) }
|
33
|
-
let(:adjustment_for_incomplete_order) { Spree::Adjustment.create!(label: 'Adjustment', adjustable: incomplete_order, order: incomplete_order, amount: 5) }
|
34
|
-
|
35
|
-
subject { Spree::Adjustment.for_incomplete_order }
|
36
|
-
|
37
|
-
it { is_expected.to_not include(adjustment_for_complete_order) }
|
38
|
-
it { is_expected.to include(adjustment_for_incomplete_order) }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context '#create & #destroy' do
|
43
|
-
let(:adjustment) { Spree::Adjustment.new(label: "Adjustment", amount: 5, order: order, adjustable: create(:line_item)) }
|
44
|
-
|
45
|
-
it 'calls #update_adjustable_adjustment_total' do
|
46
|
-
expect(adjustment).to receive(:update_adjustable_adjustment_total).twice
|
47
|
-
adjustment.save
|
48
|
-
adjustment.destroy
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context '#save' do
|
53
|
-
let(:order) { Spree::Order.create! }
|
54
|
-
let!(:adjustment) { Spree::Adjustment.create(label: "Adjustment", amount: 5, order: order, adjustable: order) }
|
55
|
-
|
56
|
-
it 'touches the adjustable' do
|
57
|
-
expect(adjustment.adjustable).to receive(:touch)
|
58
|
-
adjustment.amount = 3
|
59
|
-
adjustment.save
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe 'non_tax scope' do
|
64
|
-
subject do
|
65
|
-
Spree::Adjustment.non_tax.to_a
|
66
|
-
end
|
67
|
-
|
68
|
-
let!(:tax_adjustment) { create(:adjustment, order: order, source: create(:tax_rate)) }
|
69
|
-
let!(:non_tax_adjustment_with_source) { create(:adjustment, order: order, source_type: 'Spree::Order', source_id: nil) }
|
70
|
-
let!(:non_tax_adjustment_without_source) { create(:adjustment, order: order, source: nil) }
|
71
|
-
|
72
|
-
it 'select non-tax adjustments' do
|
73
|
-
expect(subject).to_not include tax_adjustment
|
74
|
-
expect(subject).to include non_tax_adjustment_with_source
|
75
|
-
expect(subject).to include non_tax_adjustment_without_source
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe 'competing_promos scope' do
|
80
|
-
before do
|
81
|
-
allow_any_instance_of(Spree::Adjustment).to receive(:update_adjustable_adjustment_total).and_return(true)
|
82
|
-
end
|
83
|
-
|
84
|
-
subject do
|
85
|
-
Spree::Adjustment.competing_promos.to_a
|
86
|
-
end
|
87
|
-
|
88
|
-
let!(:promotion_adjustment) { create(:adjustment, order: order, source_type: 'Spree::PromotionAction', source_id: nil) }
|
89
|
-
let!(:custom_adjustment_with_source) { create(:adjustment, order: order, source_type: 'Custom', source_id: nil) }
|
90
|
-
let!(:non_promotion_adjustment_with_source) { create(:adjustment, order: order, source_type: 'Spree::Order', source_id: nil) }
|
91
|
-
let!(:non_promotion_adjustment_without_source) { create(:adjustment, order: order, source: nil) }
|
92
|
-
|
93
|
-
context 'no custom source_types have been added to competing_promos' do
|
94
|
-
before { Spree::Adjustment.competing_promos_source_types = ['Spree::PromotionAction'] }
|
95
|
-
|
96
|
-
it 'selects promotion adjustments by default' do
|
97
|
-
expect(subject).to include promotion_adjustment
|
98
|
-
expect(subject).to_not include custom_adjustment_with_source
|
99
|
-
expect(subject).to_not include non_promotion_adjustment_with_source
|
100
|
-
expect(subject).to_not include non_promotion_adjustment_without_source
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context 'a custom source_type has been added to competing_promos' do
|
105
|
-
before { Spree::Adjustment.competing_promos_source_types = ['Spree::PromotionAction', 'Custom'] }
|
106
|
-
|
107
|
-
it 'selects adjustments with registered source_types' do
|
108
|
-
expect(subject).to include promotion_adjustment
|
109
|
-
expect(subject).to include custom_adjustment_with_source
|
110
|
-
expect(subject).to_not include non_promotion_adjustment_with_source
|
111
|
-
expect(subject).to_not include non_promotion_adjustment_without_source
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
|
117
|
-
context "adjustment state" do
|
118
|
-
let(:adjustment) { create(:adjustment, order: order, state: 'open') }
|
119
|
-
|
120
|
-
context "#closed?" do
|
121
|
-
it "is true when adjustment state is closed" do
|
122
|
-
adjustment.state = "closed"
|
123
|
-
expect(adjustment).to be_closed
|
124
|
-
end
|
125
|
-
|
126
|
-
it "is false when adjustment state is open" do
|
127
|
-
adjustment.state = "open"
|
128
|
-
expect(adjustment).to_not be_closed
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context '#currency' do
|
134
|
-
it 'returns the globally configured currency' do
|
135
|
-
expect(adjustment.currency).to eq 'USD'
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context "#display_amount" do
|
140
|
-
before { adjustment.amount = 10.55 }
|
141
|
-
|
142
|
-
it "shows the amount" do
|
143
|
-
expect(adjustment.display_amount.to_s).to eq "$10.55"
|
144
|
-
end
|
145
|
-
|
146
|
-
context "with currency set to JPY" do
|
147
|
-
context "when adjustable is set to an order" do
|
148
|
-
before do
|
149
|
-
expect(order).to receive(:currency).and_return('JPY')
|
150
|
-
adjustment.adjustable = order
|
151
|
-
end
|
152
|
-
|
153
|
-
it "displays in JPY" do
|
154
|
-
expect(adjustment.display_amount.to_s).to eq "¥11"
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
context "when adjustable is nil" do
|
159
|
-
it "displays in the default currency" do
|
160
|
-
expect(adjustment.display_amount.to_s).to eq "$10.55"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context '#update!' do
|
167
|
-
context "when adjustment is closed" do
|
168
|
-
before { expect(adjustment).to receive(:closed?).and_return(true) }
|
169
|
-
|
170
|
-
it "does not update the adjustment" do
|
171
|
-
expect(adjustment).to_not receive(:update_column)
|
172
|
-
adjustment.update!
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
context "when adjustment is open" do
|
177
|
-
before { expect(adjustment).to receive(:closed?).and_return(false) }
|
178
|
-
|
179
|
-
it "updates the amount" do
|
180
|
-
expect(adjustment).to receive(:adjustable).and_return(double("Adjustable")).at_least(1).times
|
181
|
-
expect(adjustment).to receive(:source).and_return(double("Source")).at_least(1).times
|
182
|
-
expect(adjustment.source).to receive("compute_amount").with(adjustment.adjustable).and_return(5)
|
183
|
-
expect(adjustment).to receive(:update_columns).with(amount: 5, updated_at: kind_of(Time))
|
184
|
-
adjustment.update!
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::AppConfiguration, type: :model do
|
4
|
-
let (:prefs) { Rails.application.config.spree.preferences }
|
5
|
-
|
6
|
-
it "should be available from the environment" do
|
7
|
-
prefs.layout = "my/layout"
|
8
|
-
expect(prefs.layout).to eq "my/layout"
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should be available as Spree::Config for legacy access" do
|
12
|
-
Spree::Config.layout = "my/layout"
|
13
|
-
expect(Spree::Config.layout).to eq "my/layout"
|
14
|
-
end
|
15
|
-
|
16
|
-
it "uses base searcher class by default" do
|
17
|
-
prefs.searcher_class = nil
|
18
|
-
expect(prefs.searcher_class).to eq Spree::Core::Search::Base
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'admin_path' do
|
22
|
-
it { expect(Spree::Config).to have_preference(:admin_path) }
|
23
|
-
it { expect(Spree::Config.preferred_admin_path_type).to eq(:string) }
|
24
|
-
it { expect(Spree::Config.preferred_admin_path_default).to eq('/admin') }
|
25
|
-
end
|
26
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::Asset, type: :model do
|
4
|
-
describe "#viewable" do
|
5
|
-
it "touches association" do
|
6
|
-
Timecop.scale(3600) do
|
7
|
-
|
8
|
-
product = create(:custom_product)
|
9
|
-
asset = Spree::Asset.create! { |a| a.viewable = product.master }
|
10
|
-
|
11
|
-
expect do
|
12
|
-
asset.touch
|
13
|
-
end.to change { product.reload.updated_at }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe "#acts_as_list scope" do
|
19
|
-
it "should start from first position for different viewables" do
|
20
|
-
asset1 = Spree::Asset.create(viewable_type: 'Spree::Image', viewable_id: 1)
|
21
|
-
asset2 = Spree::Asset.create(viewable_type: 'Spree::LineItem', viewable_id: 1)
|
22
|
-
|
23
|
-
expect(asset1.position).to eq 1
|
24
|
-
expect(asset2.position).to eq 1
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::Calculator::DefaultTax, type: :model do
|
4
|
-
let!(:country) { create(:country) }
|
5
|
-
let!(:zone) { create(:zone, name: "Country Zone", default_tax: true, zone_members: []) }
|
6
|
-
let!(:tax_category) { create(:tax_category, tax_rates: []) }
|
7
|
-
let!(:rate) { create(:tax_rate, tax_category: tax_category, amount: 0.05, included_in_price: included_in_price) }
|
8
|
-
let(:included_in_price) { false }
|
9
|
-
let!(:calculator) { Spree::Calculator::DefaultTax.new(calculable: rate) }
|
10
|
-
let!(:order) { create(:order) }
|
11
|
-
let!(:line_item) { create(:line_item, price: 10, quantity: 3, tax_category: tax_category) }
|
12
|
-
let!(:shipment) { create(:shipment, cost: 15) }
|
13
|
-
|
14
|
-
context "#compute" do
|
15
|
-
context "when given an order" do
|
16
|
-
let!(:line_item_1) { line_item }
|
17
|
-
let!(:line_item_2) { create(:line_item, price: 10, quantity: 3, tax_category: tax_category) }
|
18
|
-
|
19
|
-
before do
|
20
|
-
allow(order).to receive_messages line_items: [line_item_1, line_item_2]
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when no line items match the tax category" do
|
24
|
-
before do
|
25
|
-
line_item_1.tax_category = nil
|
26
|
-
line_item_2.tax_category = nil
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should be 0" do
|
30
|
-
expect(calculator.compute(order)).to eq(0)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context "when one item matches the tax category" do
|
35
|
-
before do
|
36
|
-
line_item_1.tax_category = tax_category
|
37
|
-
line_item_2.tax_category = nil
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should be equal to the item total * rate" do
|
41
|
-
expect(calculator.compute(order)).to eq(1.5)
|
42
|
-
end
|
43
|
-
|
44
|
-
context "correctly rounds to within two decimal places" do
|
45
|
-
before do
|
46
|
-
line_item_1.price = 10.333
|
47
|
-
line_item_1.quantity = 1
|
48
|
-
end
|
49
|
-
|
50
|
-
specify do
|
51
|
-
# Amount is 0.51665, which will be rounded to...
|
52
|
-
expect(calculator.compute(order)).to eq(0.52)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when more than one item matches the tax category" do
|
58
|
-
it "should be equal to the sum of the item totals * rate" do
|
59
|
-
expect(calculator.compute(order)).to eq(3)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
context "when tax is included in price" do
|
64
|
-
let(:included_in_price) { true }
|
65
|
-
|
66
|
-
it "will return the deducted amount from the totals" do
|
67
|
-
# total price including 5% tax = $60
|
68
|
-
# ex pre-tax = $57.14
|
69
|
-
# 57.14 + %5 = 59.997 (or "close enough" to $60)
|
70
|
-
# 60 - 57.14 = $2.86
|
71
|
-
expect(calculator.compute(order).to_f).to eql 2.86
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "when tax is included in price" do
|
77
|
-
let(:included_in_price) { true }
|
78
|
-
context "when the variant matches the tax category" do
|
79
|
-
context "when line item is discounted" do
|
80
|
-
before do
|
81
|
-
line_item.taxable_adjustment_total = -1
|
82
|
-
Spree::TaxRate.store_pre_tax_amount(line_item, [rate])
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should be equal to the item's discounted total * rate" do
|
86
|
-
expect(calculator.compute(line_item)).to eql 1.38
|
87
|
-
end
|
88
|
-
end
|
89
|
-
it "should be equal to the item's full price * rate" do
|
90
|
-
Spree::TaxRate.store_pre_tax_amount(line_item, [rate])
|
91
|
-
expect(calculator.compute(line_item)).to eql 1.43
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when tax is not included in price" do
|
97
|
-
context "when the line item is discounted" do
|
98
|
-
before { line_item.taxable_adjustment_total = -1 }
|
99
|
-
|
100
|
-
it "should be equal to the item's pre-tax total * rate" do
|
101
|
-
expect(calculator.compute(line_item)).to eq(1.45)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
context "when the variant matches the tax category" do
|
106
|
-
it "should be equal to the item pre-tax total * rate" do
|
107
|
-
expect(calculator.compute(line_item)).to eq(1.50)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context "when given a shipment" do
|
113
|
-
it "should be 5% of 15" do
|
114
|
-
expect(calculator.compute(shipment)).to eq(0.75)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "takes discounts into consideration" do
|
118
|
-
shipment.promo_total = -1
|
119
|
-
# 5% of 14
|
120
|
-
expect(calculator.compute(shipment)).to eq(0.7)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when given a line_item" do
|
126
|
-
let(:rate) { create(:tax_rate, amount: 0.07, included_in_price: true) }
|
127
|
-
let(:line_item) { create(:line_item, quantity: 50, price: 8.50) }
|
128
|
-
|
129
|
-
subject do
|
130
|
-
Spree::Calculator::DefaultTax.new(calculable: rate).
|
131
|
-
compute_line_item(line_item)
|
132
|
-
end
|
133
|
-
|
134
|
-
describe "#compute_line_item" do
|
135
|
-
it "computes the line item right" do
|
136
|
-
Spree::TaxRate.store_pre_tax_amount(line_item, [rate])
|
137
|
-
expect(subject).to eq(27.80)
|
138
|
-
end
|
139
|
-
|
140
|
-
context "with a 40$ promo" do
|
141
|
-
before do
|
142
|
-
allow(line_item).to receive(:taxable_adjustment_total).and_return(BigDecimal.new("-40"))
|
143
|
-
Spree::TaxRate.store_pre_tax_amount(line_item, [rate])
|
144
|
-
end
|
145
|
-
|
146
|
-
it "computes the line item right" do
|
147
|
-
expect(subject).to eq(25.19)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|