spree_core 3.3.0.rc1 → 3.3.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/spree/base_helper.rb +1 -1
- data/app/mailers/spree/base_mailer.rb +5 -0
- data/app/models/spree/ability.rb +4 -1
- data/app/models/spree/image.rb +6 -2
- data/app/models/spree/order.rb +10 -9
- data/app/models/spree/order/payments.rb +1 -1
- data/app/models/spree/payment_method/store_credit.rb +4 -0
- data/app/models/spree/shipment.rb +2 -0
- data/app/views/spree/shared/_base_mailer_header.html.erb +5 -1
- data/app/views/spree/shared/_mailer_line_item.html.erb +5 -1
- data/config/routes.rb +0 -3
- data/lib/spree/core/components.rb +17 -0
- data/lib/spree/core/controller_helpers/auth.rb +3 -1
- data/lib/spree/core/engine.rb +1 -0
- data/lib/spree/core/validators/email.rb +1 -5
- data/lib/spree/core/version.rb +1 -1
- data/spree_core.gemspec +1 -1
- metadata +4 -204
- data/lib/spree/testing_support/shoulda_matcher_configuration.rb +0 -6
- 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 -607
- data/spec/lib/spree/core/number_generator_spec.rb +0 -139
- data/spec/lib/spree/core/token_generator_spec.rb +0 -24
- data/spec/lib/spree/core/validators/email_spec.rb +0 -54
- data/spec/lib/spree/core_spec.rb +0 -23
- data/spec/lib/spree/localized_number_spec.rb +0 -54
- 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 -52
- data/spec/mailers/shipment_mailer_spec.rb +0 -81
- data/spec/mailers/test_mailer_spec.rb +0 -38
- 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 -348
- data/spec/models/spree/option_type_prototype_spec.rb +0 -9
- 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 -457
- 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 -332
- data/spec/models/spree/order_inventory_spec.rb +0 -247
- data/spec/models/spree/order_merger_spec.rb +0 -135
- data/spec/models/spree/order_spec.rb +0 -1067
- 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 -108
- data/spec/models/spree/payment_spec.rb +0 -922
- 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 -174
- data/spec/models/spree/product_duplicator_spec.rb +0 -102
- 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 -626
- 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 -674
- 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 -734
- 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 -744
- 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 -125
- 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 -42
- 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 -37
- 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 -465
- 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 -798
- 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 -93
- 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 -82
- 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,348 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::LineItem, 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
|
-
before { create(:store) }
|
8
|
-
|
9
|
-
describe 'Validations' do
|
10
|
-
it { expect(line_item).to validate_numericality_of(:quantity).only_integer.with_message(Spree.t('validation.must_be_int')) }
|
11
|
-
it { expect(line_item).to validate_presence_of(:order) }
|
12
|
-
|
13
|
-
describe 'ensure_proper_currency' do
|
14
|
-
context 'order is present' do
|
15
|
-
context "when line_item's currency matches with order's" do
|
16
|
-
it { expect(line_item).to be_valid }
|
17
|
-
end
|
18
|
-
|
19
|
-
context "when line_item's currency does not matches with order's" do
|
20
|
-
before do
|
21
|
-
line_item.currency = "Invalid Currency"
|
22
|
-
end
|
23
|
-
|
24
|
-
it { expect(line_item).not_to be_valid }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '#ensure_valid_quantity' do
|
31
|
-
context 'quantity.nil?' do
|
32
|
-
before do
|
33
|
-
line_item.quantity = nil
|
34
|
-
line_item.valid?
|
35
|
-
end
|
36
|
-
|
37
|
-
it { expect(line_item.quantity).to be_zero }
|
38
|
-
end
|
39
|
-
|
40
|
-
context 'quantity < 0' do
|
41
|
-
before do
|
42
|
-
line_item.quantity = -1
|
43
|
-
line_item.valid?
|
44
|
-
end
|
45
|
-
|
46
|
-
it { expect(line_item.quantity).to be_zero }
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'quantity = 0' do
|
50
|
-
before do
|
51
|
-
line_item.quantity = 0
|
52
|
-
line_item.valid?
|
53
|
-
end
|
54
|
-
|
55
|
-
it { expect(line_item.quantity).to be_zero }
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'quantity > 0' do
|
59
|
-
let(:original_quantity) { 1 }
|
60
|
-
|
61
|
-
before do
|
62
|
-
line_item.quantity = original_quantity
|
63
|
-
line_item.valid?
|
64
|
-
end
|
65
|
-
|
66
|
-
it { expect(line_item.quantity).to eq(original_quantity) }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context '#save' do
|
71
|
-
it 'touches the order' do
|
72
|
-
expect(line_item.order).to receive(:touch)
|
73
|
-
line_item.touch
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context "#discontinued" do
|
78
|
-
it "fetches discontinued products" do
|
79
|
-
line_item.product.discontinue!
|
80
|
-
expect(line_item.reload.product).to be_a Spree::Product
|
81
|
-
end
|
82
|
-
|
83
|
-
it "fetches discontinued variants" do
|
84
|
-
line_item.variant.discontinue!
|
85
|
-
expect(line_item.reload.variant).to be_a Spree::Variant
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
context "#destroy" do
|
90
|
-
let!(:line_item) { order.line_items.first }
|
91
|
-
it "returns inventory when a line item is destroyed" do
|
92
|
-
is_expected.to callback(:verify_order_inventory).before(:destroy)
|
93
|
-
end
|
94
|
-
|
95
|
-
it "deletes inventory units" do
|
96
|
-
expect { line_item.destroy }.to change { line_item.inventory_units.count }.from(1).to(0)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "#save" do
|
101
|
-
context "line item changes" do
|
102
|
-
before do
|
103
|
-
line_item.quantity = line_item.quantity + 1
|
104
|
-
end
|
105
|
-
|
106
|
-
it "triggers adjustment total recalculation" do
|
107
|
-
expect(line_item).to receive(:update_tax_charge) # Regression test for https://github.com/spree/spree/issues/4671
|
108
|
-
expect(line_item).to receive(:recalculate_adjustments)
|
109
|
-
line_item.save
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "line item does not change" do
|
114
|
-
it "does not trigger adjustment total recalculation" do
|
115
|
-
expect(line_item).not_to receive(:recalculate_adjustments)
|
116
|
-
line_item.save
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context "target_shipment is provided" do
|
121
|
-
it "verifies inventory" do
|
122
|
-
line_item.target_shipment = Spree::Shipment.new
|
123
|
-
expect_any_instance_of(Spree::OrderInventory).to receive(:verify)
|
124
|
-
line_item.save
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "#create" do
|
130
|
-
let(:variant) { create(:variant) }
|
131
|
-
|
132
|
-
before do
|
133
|
-
create(:tax_rate, zone: order.tax_zone, tax_category: variant.tax_category)
|
134
|
-
end
|
135
|
-
|
136
|
-
context "when order has a tax zone" do
|
137
|
-
before do
|
138
|
-
expect(order.tax_zone).to be_present
|
139
|
-
end
|
140
|
-
|
141
|
-
it "creates a tax adjustment" do
|
142
|
-
order.contents.add(variant)
|
143
|
-
line_item = order.find_line_item_by_variant(variant)
|
144
|
-
expect(line_item.adjustments.tax.count).to eq(1)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context "when order does not have a tax zone" do
|
149
|
-
before do
|
150
|
-
order.bill_address = nil
|
151
|
-
order.ship_address = nil
|
152
|
-
order.save
|
153
|
-
expect(order.reload.tax_zone).to be_nil
|
154
|
-
end
|
155
|
-
|
156
|
-
it "does not create a tax adjustment" do
|
157
|
-
order.contents.add(variant)
|
158
|
-
line_item = order.find_line_item_by_variant(variant)
|
159
|
-
expect(line_item.adjustments.tax.count).to eq(0)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# Test for #3391
|
165
|
-
context '#copy_price' do
|
166
|
-
it "copies over a variant's prices" do
|
167
|
-
line_item.price = nil
|
168
|
-
line_item.cost_price = nil
|
169
|
-
line_item.currency = nil
|
170
|
-
line_item.copy_price
|
171
|
-
variant = line_item.variant
|
172
|
-
expect(line_item.price).to eq(variant.price)
|
173
|
-
expect(line_item.cost_price).to eq(variant.cost_price)
|
174
|
-
expect(line_item.currency).to eq(variant.currency)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
# test for copying prices when the vat changes
|
179
|
-
context "#update_price" do
|
180
|
-
it "copies over a variants differing price for another vat zone" do
|
181
|
-
expect(line_item.variant).to receive(:price_including_vat_for).and_return(12)
|
182
|
-
line_item.price = 10
|
183
|
-
line_item.update_price
|
184
|
-
expect(line_item.price).to eq(12)
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
# Test for #3481
|
189
|
-
context '#copy_tax_category' do
|
190
|
-
it "copies over a variant's tax category" do
|
191
|
-
line_item.tax_category = nil
|
192
|
-
line_item.copy_tax_category
|
193
|
-
expect(line_item.tax_category).to eq(line_item.variant.tax_category)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe '#discounted_amount' do
|
198
|
-
it "returns the amount minus any discounts" do
|
199
|
-
line_item.price = 10
|
200
|
-
line_item.quantity = 2
|
201
|
-
line_item.taxable_adjustment_total = -5
|
202
|
-
expect(line_item.discounted_amount).to eq(15)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe '.currency' do
|
207
|
-
it 'returns the globally configured currency' do
|
208
|
-
line_item.currency == 'USD'
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
describe "#discounted_money" do
|
213
|
-
it "should return a money object with the discounted amount" do
|
214
|
-
expect(line_item.discounted_money.to_s).to eq "$10.00"
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
describe "#money" do
|
219
|
-
before do
|
220
|
-
line_item.price = 3.50
|
221
|
-
line_item.quantity = 2
|
222
|
-
end
|
223
|
-
|
224
|
-
it "returns a Spree::Money representing the total for this line item" do
|
225
|
-
expect(line_item.money.to_s).to eq("$7.00")
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
describe '#single_money' do
|
230
|
-
before do
|
231
|
-
line_item.price = 3.50
|
232
|
-
line_item.quantity = 2
|
233
|
-
end
|
234
|
-
|
235
|
-
it "returns a Spree::Money representing the price for one variant" do
|
236
|
-
expect(line_item.single_money.to_s).to eq("$3.50")
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
context "has inventory (completed order so items were already unstocked)" do
|
241
|
-
let(:order) { Spree::Order.create(email: 'spree@example.com') }
|
242
|
-
let(:variant) { create(:variant) }
|
243
|
-
|
244
|
-
context "nothing left on stock" do
|
245
|
-
before do
|
246
|
-
variant.stock_items.update_all count_on_hand: 5, backorderable: false
|
247
|
-
order.contents.add(variant, 5)
|
248
|
-
order.create_proposed_shipments
|
249
|
-
order.finalize!
|
250
|
-
order.reload
|
251
|
-
end
|
252
|
-
|
253
|
-
it "allows to decrease item quantity" do
|
254
|
-
line_item = order.line_items.first
|
255
|
-
line_item.quantity -= 1
|
256
|
-
line_item.target_shipment = order.shipments.first
|
257
|
-
line_item.valid?
|
258
|
-
|
259
|
-
expect(line_item.errors_on(:quantity).size).to eq(0)
|
260
|
-
end
|
261
|
-
|
262
|
-
it "doesnt allow to increase item quantity" do
|
263
|
-
line_item = order.line_items.first
|
264
|
-
line_item.quantity += 2
|
265
|
-
line_item.target_shipment = order.shipments.first
|
266
|
-
line_item.valid?
|
267
|
-
|
268
|
-
expect(line_item.errors_on(:quantity).size).to eq(1)
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
context "2 items left on stock" do
|
273
|
-
before do
|
274
|
-
variant.stock_items.update_all count_on_hand: 7, backorderable: false
|
275
|
-
order.contents.add(variant, 5)
|
276
|
-
order.create_proposed_shipments
|
277
|
-
order.finalize!
|
278
|
-
order.reload
|
279
|
-
end
|
280
|
-
|
281
|
-
it "allows to increase quantity up to stock availability" do
|
282
|
-
line_item = order.line_items.first
|
283
|
-
line_item.quantity += 2
|
284
|
-
line_item.target_shipment = order.shipments.first
|
285
|
-
line_item.valid?
|
286
|
-
|
287
|
-
expect(line_item.errors_on(:quantity).size).to eq(0)
|
288
|
-
end
|
289
|
-
|
290
|
-
it "doesnt allow to increase quantity over stock availability" do
|
291
|
-
line_item = order.line_items.first
|
292
|
-
line_item.quantity += 3
|
293
|
-
line_item.target_shipment = order.shipments.first
|
294
|
-
line_item.valid?
|
295
|
-
|
296
|
-
expect(line_item.errors_on(:quantity).size).to eq(1)
|
297
|
-
end
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
context "currency same as order.currency" do
|
302
|
-
it "is a valid line item" do
|
303
|
-
line_item = order.line_items.first
|
304
|
-
line_item.currency = order.currency
|
305
|
-
line_item.valid?
|
306
|
-
|
307
|
-
expect(line_item.error_on(:currency).size).to eq(0)
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
context "currency different than order.currency" do
|
312
|
-
it "is not a valid line item" do
|
313
|
-
line_item = order.line_items.first
|
314
|
-
line_item.currency = "no currency"
|
315
|
-
line_item.valid?
|
316
|
-
|
317
|
-
expect(line_item.error_on(:currency).size).to eq(1)
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
describe "#options=" do
|
322
|
-
it "can handle updating a blank line item with no order" do
|
323
|
-
line_item.options = { price: 123 }
|
324
|
-
end
|
325
|
-
|
326
|
-
it "updates the data provided in the options" do
|
327
|
-
line_item.options = { price: 123 }
|
328
|
-
expect(line_item.price).to eq 123
|
329
|
-
end
|
330
|
-
|
331
|
-
it "updates the price based on the options provided" do
|
332
|
-
expect(line_item).to receive(:gift_wrap=).with(true)
|
333
|
-
expect(line_item.variant).to receive(:gift_wrap_price_modifier_amount_in).with("USD", true).and_return 1.99
|
334
|
-
line_item.options = { gift_wrap: true }
|
335
|
-
expect(line_item.price).to eq 21.98
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
describe "precision of pre_tax_amount" do
|
340
|
-
let(:line_item) { create :line_item, pre_tax_amount: 4.2051 }
|
341
|
-
|
342
|
-
it "keeps four digits of precision even when reloading" do
|
343
|
-
# prevent it from updating pre_tax_amount
|
344
|
-
allow_any_instance_of(Spree::LineItem).to receive(:update_tax_charge)
|
345
|
-
expect(line_item.reload.pre_tax_amount).to eq(4.2051)
|
346
|
-
end
|
347
|
-
end
|
348
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::OptionTypePrototype do
|
4
|
-
describe 'Validations' do
|
5
|
-
it { is_expected.to validate_presence_of(:prototype) }
|
6
|
-
it { is_expected.to validate_presence_of(:option_type) }
|
7
|
-
it { is_expected.to validate_uniqueness_of(:prototype_id).scoped_to(:option_type_id) }
|
8
|
-
end
|
9
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::OptionType, type: :model do
|
4
|
-
context "touching" do
|
5
|
-
it "should touch a product" do
|
6
|
-
product_option_type = create(:product_option_type)
|
7
|
-
option_type = product_option_type.option_type
|
8
|
-
product = product_option_type.product
|
9
|
-
product.update_column(:updated_at, 1.day.ago)
|
10
|
-
option_type.touch
|
11
|
-
expect(product.reload.updated_at).to be_within(3.seconds).of(Time.current)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::OptionValue, type: :model do
|
4
|
-
describe 'delegate' do
|
5
|
-
it { is_expected.to delegate_method(:name).to(:option_type).with_prefix }
|
6
|
-
it { is_expected.to delegate_method(:presentation).to(:option_type).with_prefix }
|
7
|
-
end
|
8
|
-
|
9
|
-
context "touching" do
|
10
|
-
it "should touch a variant" do
|
11
|
-
variant = create(:variant)
|
12
|
-
option_value = variant.option_values.first
|
13
|
-
variant.update_column(:updated_at, 1.day.ago)
|
14
|
-
option_value.touch
|
15
|
-
expect(variant.reload.updated_at).to be_within(3.seconds).of(Time.current)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::Order, type: :model do
|
4
|
-
let(:order) { Spree::Order.new }
|
5
|
-
|
6
|
-
context 'validation' do
|
7
|
-
context "when @use_billing is populated" do
|
8
|
-
before do
|
9
|
-
order.bill_address = stub_model(Spree::Address)
|
10
|
-
order.ship_address = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
context "with true" do
|
14
|
-
before { order.use_billing = true }
|
15
|
-
|
16
|
-
it "clones the bill address to the ship address" do
|
17
|
-
order.valid?
|
18
|
-
expect(order.ship_address).to eq(order.bill_address)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context "with 'true'" do
|
23
|
-
before { order.use_billing = 'true' }
|
24
|
-
|
25
|
-
it "clones the bill address to the shipping" do
|
26
|
-
order.valid?
|
27
|
-
expect(order.ship_address).to eq(order.bill_address)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "with '1'" do
|
32
|
-
before { order.use_billing = '1' }
|
33
|
-
|
34
|
-
it "clones the bill address to the shipping" do
|
35
|
-
order.valid?
|
36
|
-
expect(order.ship_address).to eq(order.bill_address)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "with something other than a 'truthful' value" do
|
41
|
-
before { order.use_billing = '0' }
|
42
|
-
|
43
|
-
it "does not clone the bill address to the shipping" do
|
44
|
-
order.valid?
|
45
|
-
expect(order.ship_address).to be_nil
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::Order do
|
4
|
-
context "when an order has an adjustment that zeroes the total, but another adjustment for shipping that raises it above zero" do
|
5
|
-
let!(:persisted_order) { create(:order) }
|
6
|
-
let!(:line_item) { create(:line_item) }
|
7
|
-
let!(:shipping_method) do
|
8
|
-
sm = create(:shipping_method)
|
9
|
-
sm.calculator.preferred_amount = 10
|
10
|
-
sm.save
|
11
|
-
sm
|
12
|
-
end
|
13
|
-
|
14
|
-
before do
|
15
|
-
# Don't care about available payment methods in this test
|
16
|
-
allow(persisted_order).to receive_messages(has_available_payment: false)
|
17
|
-
persisted_order.line_items << line_item
|
18
|
-
create(:adjustment, amount: -line_item.amount, label: "Promotion", adjustable: line_item, order: persisted_order)
|
19
|
-
persisted_order.state = 'delivery'
|
20
|
-
persisted_order.save # To ensure new state_change event
|
21
|
-
end
|
22
|
-
|
23
|
-
it "transitions from delivery to payment" do
|
24
|
-
allow(persisted_order).to receive_messages(payment_required?: true)
|
25
|
-
persisted_order.next!
|
26
|
-
expect(persisted_order.state).to eq("payment")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|