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,230 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::ReturnAuthorization, type: :model do
|
4
|
-
let(:order) { create(:shipped_order) }
|
5
|
-
let(:stock_location) { create(:stock_location) }
|
6
|
-
let(:rma_reason) { create(:return_authorization_reason) }
|
7
|
-
let(:inventory_unit_1) { order.inventory_units.first }
|
8
|
-
|
9
|
-
let(:variant) { order.variants.first }
|
10
|
-
let(:return_authorization) do
|
11
|
-
Spree::ReturnAuthorization.new(order: order,
|
12
|
-
stock_location_id: stock_location.id,
|
13
|
-
return_authorization_reason_id: rma_reason.id)
|
14
|
-
end
|
15
|
-
|
16
|
-
context "save" do
|
17
|
-
let(:order) { Spree::Order.create }
|
18
|
-
|
19
|
-
it "should be invalid when order has no inventory units" do
|
20
|
-
return_authorization.save
|
21
|
-
expect(return_authorization.errors[:order]).to eq(["has no shipped units"])
|
22
|
-
end
|
23
|
-
|
24
|
-
context "expedited exchanges are configured" do
|
25
|
-
let(:order) { create(:shipped_order, line_items_count: 2) }
|
26
|
-
let(:exchange_return_item) { create(:exchange_return_item, inventory_unit: order.inventory_units.first) }
|
27
|
-
let(:return_item) { create(:return_item, inventory_unit: order.inventory_units.last) }
|
28
|
-
subject { create(:return_authorization, order: order, return_items: [exchange_return_item, return_item]) }
|
29
|
-
|
30
|
-
before do
|
31
|
-
@expediteted_exchanges_config = Spree::Config[:expedited_exchanges]
|
32
|
-
Spree::Config[:expedited_exchanges] = true
|
33
|
-
@pre_exchange_hooks = subject.class.pre_expedited_exchange_hooks
|
34
|
-
end
|
35
|
-
|
36
|
-
after do
|
37
|
-
Spree::Config[:expedited_exchanges] = @expediteted_exchanges_config
|
38
|
-
subject.class.pre_expedited_exchange_hooks = @pre_exchange_hooks
|
39
|
-
end
|
40
|
-
|
41
|
-
context "no items to exchange" do
|
42
|
-
subject { create(:return_authorization, order: order) }
|
43
|
-
|
44
|
-
it "does not create a reimbursement" do
|
45
|
-
expect{subject.save}.to_not change { Spree::Reimbursement.count }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "items to exchange" do
|
50
|
-
it "calls pre_expedited_exchange hooks with the return items to exchange" do
|
51
|
-
hook = double(:as_null_object)
|
52
|
-
expect(hook).to receive(:call).with [exchange_return_item]
|
53
|
-
subject.class.pre_expedited_exchange_hooks = [hook]
|
54
|
-
subject.save
|
55
|
-
end
|
56
|
-
|
57
|
-
it "attempts to accept all return items requiring exchange" do
|
58
|
-
expect(exchange_return_item).to receive :attempt_accept
|
59
|
-
expect(return_item).not_to receive :attempt_accept
|
60
|
-
subject.save
|
61
|
-
end
|
62
|
-
|
63
|
-
it "performs an exchange reimbursement for the exchange return items" do
|
64
|
-
subject.save
|
65
|
-
reimbursement = Spree::Reimbursement.last
|
66
|
-
expect(reimbursement.order).to eq subject.order
|
67
|
-
expect(reimbursement.return_items).to eq [exchange_return_item]
|
68
|
-
expect(exchange_return_item.reload.exchange_shipments).to be_present
|
69
|
-
end
|
70
|
-
|
71
|
-
context "the reimbursement fails" do
|
72
|
-
before do
|
73
|
-
allow_any_instance_of(Spree::Reimbursement).to receive(:save) { false }
|
74
|
-
allow_any_instance_of(Spree::Reimbursement).to receive(:errors) { double(full_messages: "foo") }
|
75
|
-
end
|
76
|
-
|
77
|
-
it "puts errors on the return authorization" do
|
78
|
-
subject.save
|
79
|
-
expect(subject.errors[:base]).to include "foo"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe 'whitelisted_ransackable_attributes' do
|
88
|
-
it { expect(Spree::ReturnAuthorization.whitelisted_ransackable_attributes).to eq(%w(memo number state)) }
|
89
|
-
end
|
90
|
-
|
91
|
-
context "#currency" do
|
92
|
-
before { allow(order).to receive(:currency) { "ABC" } }
|
93
|
-
it "returns the order currency" do
|
94
|
-
expect(return_authorization.currency).to eq("ABC")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
describe "#pre_tax_total" do
|
99
|
-
let(:pre_tax_amount_1) { 15.0 }
|
100
|
-
let!(:return_item_1) { create(:return_item, return_authorization: return_authorization, pre_tax_amount: pre_tax_amount_1) }
|
101
|
-
|
102
|
-
let(:pre_tax_amount_2) { 50.0 }
|
103
|
-
let!(:return_item_2) { create(:return_item, return_authorization: return_authorization, pre_tax_amount: pre_tax_amount_2) }
|
104
|
-
|
105
|
-
let(:pre_tax_amount_3) { 5.0 }
|
106
|
-
let!(:return_item_3) { create(:return_item, return_authorization: return_authorization, pre_tax_amount: pre_tax_amount_3) }
|
107
|
-
|
108
|
-
subject { return_authorization.pre_tax_total }
|
109
|
-
|
110
|
-
it "sums it's associated return_item's pre-tax amounts" do
|
111
|
-
expect(subject).to eq (pre_tax_amount_1 + pre_tax_amount_2 + pre_tax_amount_3)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
describe "#display_pre_tax_total" do
|
116
|
-
it "returns a Spree::Money" do
|
117
|
-
allow(return_authorization).to receive_messages(pre_tax_total: 21.22)
|
118
|
-
expect(return_authorization.display_pre_tax_total).to eq(Spree::Money.new(21.22))
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "#refundable_amount" do
|
123
|
-
let(:weighted_line_item_pre_tax_amount) { 5.0 }
|
124
|
-
let(:line_item_count) { return_authorization.order.line_items.count }
|
125
|
-
|
126
|
-
subject { return_authorization.refundable_amount }
|
127
|
-
|
128
|
-
before do
|
129
|
-
return_authorization.order.line_items.update_all(pre_tax_amount: weighted_line_item_pre_tax_amount)
|
130
|
-
return_authorization.order.update_attribute(:promo_total, promo_total)
|
131
|
-
end
|
132
|
-
|
133
|
-
context "no promotions" do
|
134
|
-
let(:promo_total) { 0.0 }
|
135
|
-
it "returns the pre-tax line item total" do
|
136
|
-
expect(subject).to eq (weighted_line_item_pre_tax_amount * line_item_count)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context "promotions" do
|
141
|
-
let(:promo_total) { -10.0 }
|
142
|
-
it "returns the pre-tax line item total minus the order level promotion value" do
|
143
|
-
expect(subject).to eq (weighted_line_item_pre_tax_amount * line_item_count) + promo_total
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
describe "#customer_returned_items?" do
|
149
|
-
before do
|
150
|
-
allow_any_instance_of(Spree::Order).to receive_messages(return!: true)
|
151
|
-
end
|
152
|
-
|
153
|
-
subject { return_authorization.customer_returned_items? }
|
154
|
-
|
155
|
-
context "has associated customer returns" do
|
156
|
-
let(:customer_return) { create(:customer_return) }
|
157
|
-
let(:return_authorization) { customer_return.return_authorizations.first }
|
158
|
-
|
159
|
-
it "returns true" do
|
160
|
-
expect(subject).to eq true
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "does not have associated customer returns" do
|
165
|
-
let(:return_authorization) { create(:return_authorization) }
|
166
|
-
|
167
|
-
it "returns false" do
|
168
|
-
expect(subject).to eq false
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
describe 'cancel_return_items' do
|
174
|
-
let(:return_authorization) { create(:return_authorization, return_items: return_items) }
|
175
|
-
let(:return_items) { [return_item] }
|
176
|
-
let(:return_item) { create(:return_item) }
|
177
|
-
|
178
|
-
subject {
|
179
|
-
return_authorization.cancel!
|
180
|
-
}
|
181
|
-
|
182
|
-
it 'cancels the associated return items' do
|
183
|
-
subject
|
184
|
-
expect(return_item.reception_status).to eq 'cancelled'
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'some return items cannot be cancelled' do
|
188
|
-
let(:return_items) { [return_item, return_item_2] }
|
189
|
-
let(:return_item_2) { create(:return_item, reception_status: 'received') }
|
190
|
-
|
191
|
-
it 'cancels those that can be cancelled' do
|
192
|
-
subject
|
193
|
-
expect(return_item.reception_status).to eq 'cancelled'
|
194
|
-
expect(return_item_2.reception_status).to eq 'received'
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
describe '#can_cancel?' do
|
200
|
-
subject { create(:return_authorization, return_items: return_items).can_cancel? }
|
201
|
-
let(:return_items) { [return_item_1, return_item_2] }
|
202
|
-
let(:return_item_1) { create(:return_item) }
|
203
|
-
let(:return_item_2) { create(:return_item) }
|
204
|
-
|
205
|
-
context 'all items can be cancelled' do
|
206
|
-
it 'returns true' do
|
207
|
-
expect(subject).to eq true
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
context 'at least one return item can be cancelled' do
|
212
|
-
let(:return_item_2) { create(:return_item, reception_status: 'received') }
|
213
|
-
|
214
|
-
it { should eq true }
|
215
|
-
end
|
216
|
-
|
217
|
-
context 'no items can be cancelled' do
|
218
|
-
let(:return_item_1) { create(:return_item, reception_status: 'received') }
|
219
|
-
let(:return_item_2) { create(:return_item, reception_status: 'received') }
|
220
|
-
|
221
|
-
it { should eq false }
|
222
|
-
end
|
223
|
-
|
224
|
-
context 'when return_authorization has no return_items' do
|
225
|
-
let(:return_items) { [] }
|
226
|
-
|
227
|
-
it { should eq true }
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::ReturnItem::EligibilityValidator::Default, type: :model do
|
4
|
-
let(:return_item) { create(:return_item) }
|
5
|
-
let(:validator) { Spree::ReturnItem::EligibilityValidator::Default.new(return_item) }
|
6
|
-
|
7
|
-
let(:time_eligibility_class) { double("TimeEligibilityValidatorClass") }
|
8
|
-
let(:rma_eligibility_class) { double("RMAEligibilityValidatorClass") }
|
9
|
-
|
10
|
-
let(:time_eligibility_instance) { double(errors: time_error) }
|
11
|
-
let(:rma_eligibility_instance) { double(errors: rma_error) }
|
12
|
-
|
13
|
-
let(:time_error) {{}}
|
14
|
-
let(:rma_error) {{}}
|
15
|
-
|
16
|
-
before do
|
17
|
-
validator.permitted_eligibility_validators = [ time_eligibility_class, rma_eligibility_class ]
|
18
|
-
|
19
|
-
expect(time_eligibility_class).to receive(:new).and_return(time_eligibility_instance)
|
20
|
-
expect(rma_eligibility_class).to receive(:new).and_return(rma_eligibility_instance)
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#eligible_for_return?" do
|
24
|
-
subject { validator.eligible_for_return? }
|
25
|
-
|
26
|
-
it "checks that all permitted eligibility validators are eligible for return" do
|
27
|
-
expect(time_eligibility_instance).to receive(:eligible_for_return?).and_return(true)
|
28
|
-
expect(rma_eligibility_instance).to receive(:eligible_for_return?).and_return(true)
|
29
|
-
|
30
|
-
expect(subject).to be true
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#requires_manual_intervention?" do
|
35
|
-
subject { validator.requires_manual_intervention? }
|
36
|
-
|
37
|
-
context "any of the permitted eligibility validators require manual intervention" do
|
38
|
-
it "returns true" do
|
39
|
-
expect(time_eligibility_instance).to receive(:requires_manual_intervention?).and_return(false)
|
40
|
-
expect(rma_eligibility_instance).to receive(:requires_manual_intervention?).and_return(true)
|
41
|
-
|
42
|
-
expect(subject).to be true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "no permitted eligibility validators require manual intervention" do
|
47
|
-
it "returns false" do
|
48
|
-
expect(time_eligibility_instance).to receive(:requires_manual_intervention?).and_return(false)
|
49
|
-
expect(rma_eligibility_instance).to receive(:requires_manual_intervention?).and_return(false)
|
50
|
-
|
51
|
-
expect(subject).to be false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "#errors" do
|
57
|
-
subject { validator.errors }
|
58
|
-
|
59
|
-
context "the validator errors are empty" do
|
60
|
-
it "returns an empty hash" do
|
61
|
-
expect(subject).to eq({})
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "the validators have errors" do
|
66
|
-
let(:time_error) { { time: time_error_text }}
|
67
|
-
let(:rma_error) { { rma: rma_error_text }}
|
68
|
-
|
69
|
-
let(:time_error_text) { "Time eligibility error" }
|
70
|
-
let(:rma_error_text) { "RMA eligibility error" }
|
71
|
-
|
72
|
-
it "gathers all errors from permitted eligibility validators into a single errors hash" do
|
73
|
-
expect(subject).to eq({time: time_error_text, rma: rma_error_text})
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::ReturnItem::EligibilityValidator::InventoryShipped do
|
4
|
-
let(:return_item) { create(:return_item) }
|
5
|
-
let(:validator) { Spree::ReturnItem::EligibilityValidator::InventoryShipped.new(return_item) }
|
6
|
-
|
7
|
-
describe "#eligible_for_return?" do
|
8
|
-
before { allow(return_item.inventory_unit).to receive(:shipped?).and_return(true) }
|
9
|
-
|
10
|
-
subject { validator.eligible_for_return? }
|
11
|
-
|
12
|
-
context "the associated inventory unit is shipped" do
|
13
|
-
it "returns true" do
|
14
|
-
expect(subject).to eq true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "the associated inventory unit is not shipped" do
|
19
|
-
before { allow(return_item.inventory_unit).to receive(:shipped?).and_return(false) }
|
20
|
-
|
21
|
-
it "returns false" do
|
22
|
-
expect(subject).to eq false
|
23
|
-
end
|
24
|
-
|
25
|
-
it "sets an error" do
|
26
|
-
subject
|
27
|
-
expect(validator.errors[:inventory_unit_shipped]).to eq Spree.t('return_item_inventory_unit_ineligible')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#requires_manual_intervention?" do
|
33
|
-
subject { validator.requires_manual_intervention? }
|
34
|
-
|
35
|
-
context "not eligible for return" do
|
36
|
-
before do
|
37
|
-
allow(return_item.inventory_unit).to receive(:shipped?).and_return(false)
|
38
|
-
validator.eligible_for_return?
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns true if errors were added' do
|
42
|
-
expect(subject).to eq true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "eligible for return" do
|
47
|
-
before do
|
48
|
-
allow(return_item.inventory_unit).to receive(:shipped?).and_return(true)
|
49
|
-
validator.eligible_for_return?
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'returns false if no errors were added' do
|
53
|
-
expect(subject).to eq false
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::ReturnItem::EligibilityValidator::NoReimbursements do
|
4
|
-
let(:validator) { Spree::ReturnItem::EligibilityValidator::NoReimbursements.new(return_item) }
|
5
|
-
|
6
|
-
describe "#eligible_for_return?" do
|
7
|
-
|
8
|
-
subject { validator.eligible_for_return? }
|
9
|
-
|
10
|
-
context "inventory unit has already been reimbursed" do
|
11
|
-
let(:reimbursement) { create(:reimbursement) }
|
12
|
-
let(:return_item) { reimbursement.return_items.last }
|
13
|
-
|
14
|
-
it "returns false" do
|
15
|
-
expect(subject).to eq false
|
16
|
-
end
|
17
|
-
|
18
|
-
it "sets an error" do
|
19
|
-
subject
|
20
|
-
expect(validator.errors[:inventory_unit_reimbursed]).to eq Spree.t('return_item_inventory_unit_reimbursed')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "inventory unit has not been reimbursed" do
|
25
|
-
let(:return_item) { create(:return_item) }
|
26
|
-
|
27
|
-
it "returns true" do
|
28
|
-
expect(subject).to eq true
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#requires_manual_intervention?" do
|
34
|
-
subject { validator.requires_manual_intervention? }
|
35
|
-
|
36
|
-
context "not eligible for return" do
|
37
|
-
let(:reimbursement) { create(:reimbursement) }
|
38
|
-
let(:return_item) { reimbursement.return_items.last }
|
39
|
-
|
40
|
-
before do
|
41
|
-
validator.eligible_for_return?
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'returns true if errors were added' do
|
45
|
-
expect(subject).to eq true
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "eligible for return" do
|
50
|
-
let(:return_item) { create(:return_item) }
|
51
|
-
|
52
|
-
before do
|
53
|
-
validator.eligible_for_return?
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'returns false if no errors were added' do
|
57
|
-
expect(subject).to eq false
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::ReturnItem::EligibilityValidator::OrderCompleted do
|
4
|
-
let(:inventory_unit) { create(:inventory_unit, order: order) }
|
5
|
-
let(:return_item) { create(:return_item, inventory_unit: inventory_unit) }
|
6
|
-
let(:validator) { Spree::ReturnItem::EligibilityValidator::OrderCompleted.new(return_item) }
|
7
|
-
|
8
|
-
describe "#eligible_for_return?" do
|
9
|
-
subject { validator.eligible_for_return? }
|
10
|
-
|
11
|
-
context "the order was completed" do
|
12
|
-
let(:order) { create(:completed_order_with_totals) }
|
13
|
-
|
14
|
-
it "returns true" do
|
15
|
-
expect(subject).to be true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
context "the order is not completed" do
|
20
|
-
let(:order) { create(:order) }
|
21
|
-
|
22
|
-
it "returns false" do
|
23
|
-
expect(subject).to be false
|
24
|
-
end
|
25
|
-
|
26
|
-
it "sets an error" do
|
27
|
-
subject
|
28
|
-
expect(validator.errors[:order_not_completed]).to eq Spree.t('return_item_order_not_completed')
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|