spree_core 3.1.5 → 3.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/spree/ransackable_attributes.rb +6 -1
- data/app/models/concerns/spree/user_methods.rb +10 -0
- data/app/models/spree/legacy_user.rb +0 -8
- data/app/models/spree/order.rb +1 -1
- data/app/models/spree/product.rb +8 -0
- data/app/models/spree/product/scopes.rb +7 -3
- data/app/models/spree/stock_transfer.rb +1 -1
- data/config/locales/en.yml +2 -0
- data/lib/spree/core/version.rb +1 -1
- data/spree_core.gemspec +2 -2
- metadata +11 -208
- 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 -296
- 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 -291
- 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 -51
- 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 -55
- 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 -225
- data/spec/models/spree/line_item_spec.rb +0 -327
- 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 -782
- 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 -211
- 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 -238
- data/spec/models/spree/order_merger_spec.rb +0 -135
- data/spec/models/spree/order_spec.rb +0 -967
- 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 -348
- 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 -22
- data/spec/models/spree/product_spec.rb +0 -540
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -50
- 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/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 -644
- 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 -7
- 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 -740
- 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 -51
- 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 -194
- 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 -428
- data/spec/models/spree/stock_location_spec.rb +0 -243
- data/spec/models/spree/stock_movement_spec.rb +0 -56
- 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 -542
- data/spec/models/spree/taxon_spec.rb +0 -74
- 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 -795
- data/spec/models/spree/zone_member_spec.rb +0 -38
- data/spec/models/spree/zone_spec.rb +0 -470
- data/spec/spec_helper.rb +0 -77
- 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
- data/spec/validators/db_maximum_length_validator_spec.rb +0 -22
@@ -1,136 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "exchanges:charge_unreturned_items" do
|
4
|
-
include_context "rake"
|
5
|
-
|
6
|
-
describe '#prerequisites' do
|
7
|
-
it { expect(subject.prerequisites).to include("environment") }
|
8
|
-
end
|
9
|
-
|
10
|
-
context "there are no unreturned items" do
|
11
|
-
it { expect { subject.invoke }.not_to change { Spree::Order.count } }
|
12
|
-
end
|
13
|
-
|
14
|
-
context "there are unreturned items" do
|
15
|
-
let!(:order) { create(:shipped_order, line_items_count: 2) }
|
16
|
-
let(:return_item_1) { create(:exchange_return_item, inventory_unit: order.inventory_units.first) }
|
17
|
-
let(:return_item_2) { create(:exchange_return_item, inventory_unit: order.inventory_units.last) }
|
18
|
-
let!(:rma) { create(:return_authorization, order: order, return_items: [return_item_1, return_item_2]) }
|
19
|
-
let!(:tax_rate) { create(:tax_rate, zone: order.tax_zone, tax_category: return_item_2.exchange_variant.tax_category) }
|
20
|
-
|
21
|
-
before do
|
22
|
-
@original_expedited_exchanges_pref = Spree::Config[:expedited_exchanges]
|
23
|
-
Spree::Config[:expedited_exchanges] = true
|
24
|
-
Spree::StockItem.update_all(count_on_hand: 10)
|
25
|
-
rma.save!
|
26
|
-
Spree::Shipment.last.ship!
|
27
|
-
return_item_1.receive!
|
28
|
-
Timecop.travel travel_time
|
29
|
-
end
|
30
|
-
|
31
|
-
after do
|
32
|
-
Timecop.return
|
33
|
-
Spree::Config[:expedited_exchanges] = @original_expedited_exchanges_pref
|
34
|
-
end
|
35
|
-
|
36
|
-
context "fewer than the config allowed days have passed" do
|
37
|
-
let(:travel_time) { (Spree::Config[:expedited_exchanges_days_window] - 1).days }
|
38
|
-
|
39
|
-
it "does not create a new order" do
|
40
|
-
expect { subject.invoke }.not_to change { Spree::Order.count }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "more than the config allowed days have passed" do
|
45
|
-
|
46
|
-
let(:travel_time) { (Spree::Config[:expedited_exchanges_days_window] + 1).days }
|
47
|
-
|
48
|
-
it "creates a new completed order" do
|
49
|
-
expect { subject.invoke }.to change { Spree::Order.count }
|
50
|
-
expect(Spree::Order.last).to be_completed
|
51
|
-
end
|
52
|
-
|
53
|
-
it "moves the shipment for the unreturned items to the new order" do
|
54
|
-
subject.invoke
|
55
|
-
new_order = Spree::Order.last
|
56
|
-
expect(new_order.shipments.count).to eq 1
|
57
|
-
expect(return_item_2.reload.exchange_shipment.order).to eq Spree::Order.last
|
58
|
-
end
|
59
|
-
|
60
|
-
it "creates line items on the order for the unreturned items" do
|
61
|
-
subject.invoke
|
62
|
-
expect(Spree::Order.last.line_items.map(&:variant)).to eq [return_item_2.exchange_variant]
|
63
|
-
end
|
64
|
-
|
65
|
-
it "associates the exchanges inventory units with the new line items" do
|
66
|
-
subject.invoke
|
67
|
-
expect(return_item_2.reload.exchange_inventory_unit.try(:line_item).try(:order)).to eq Spree::Order.last
|
68
|
-
end
|
69
|
-
|
70
|
-
it "uses the credit card from the previous order" do
|
71
|
-
subject.invoke
|
72
|
-
new_order = Spree::Order.last
|
73
|
-
expect(new_order.credit_cards).to be_present
|
74
|
-
expect(new_order.credit_cards.first).to eq order.valid_credit_cards.first
|
75
|
-
end
|
76
|
-
|
77
|
-
it "authorizes the order for the full amount of the unreturned items including taxes" do
|
78
|
-
expect { subject.invoke }.to change { Spree::Payment.count }.by(1)
|
79
|
-
new_order = Spree::Order.last
|
80
|
-
expected_amount = return_item_2.reload.exchange_variant.price + new_order.additional_tax_total + new_order.included_tax_total
|
81
|
-
expect(new_order.total).to eq expected_amount
|
82
|
-
payment = new_order.payments.first
|
83
|
-
expect(payment.amount).to eq expected_amount
|
84
|
-
expect(payment).to be_pending
|
85
|
-
expect(new_order.item_total).to eq return_item_2.reload.exchange_variant.price
|
86
|
-
end
|
87
|
-
|
88
|
-
it "does not attempt to create a new order for the item more than once" do
|
89
|
-
subject.invoke
|
90
|
-
subject.reenable
|
91
|
-
expect { subject.invoke }.not_to change { Spree::Order.count }
|
92
|
-
end
|
93
|
-
|
94
|
-
it "associates the store of the original order with the exchange order" do
|
95
|
-
allow_any_instance_of(Spree::Order).to receive(:store_id).and_return(123)
|
96
|
-
|
97
|
-
expect(Spree::Order).to receive(:create!).once.with(hash_including({store_id: 123})) { |attrs| Spree::Order.new(attrs.except(:store_id)).tap(&:save!) }
|
98
|
-
subject.invoke
|
99
|
-
end
|
100
|
-
|
101
|
-
context "there is no card from the previous order" do
|
102
|
-
let!(:credit_card) { create(:credit_card, user: order.user, default: true, gateway_customer_profile_id: "BGS-123") }
|
103
|
-
before { allow_any_instance_of(Spree::Order).to receive(:valid_credit_cards) { [] } }
|
104
|
-
|
105
|
-
it "attempts to use the user's default card" do
|
106
|
-
expect { subject.invoke }.to change { Spree::Payment.count }.by(1)
|
107
|
-
new_order = Spree::Order.last
|
108
|
-
expect(new_order.credit_cards).to be_present
|
109
|
-
expect(new_order.credit_cards.first).to eq credit_card
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "it is unable to authorize the credit card" do
|
114
|
-
before { allow_any_instance_of(Spree::Payment).to receive(:authorize!).and_raise(RuntimeError) }
|
115
|
-
|
116
|
-
it "raises an error with the order" do
|
117
|
-
expect { subject.invoke }.to raise_error(UnableToChargeForUnreturnedItems)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "the exchange inventory unit is not shipped" do
|
122
|
-
before { return_item_2.reload.exchange_inventory_unit.update_columns(state: "on hand") }
|
123
|
-
it "does not create a new order" do
|
124
|
-
expect { subject.invoke }.not_to change { Spree::Order.count }
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
context "the exchange inventory unit has been returned" do
|
129
|
-
before { return_item_2.reload.exchange_inventory_unit.update_columns(state: "returned") }
|
130
|
-
it "does not create a new order" do
|
131
|
-
expect { subject.invoke }.not_to change { Spree::Order.count }
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'email_spec'
|
3
|
-
|
4
|
-
describe Spree::OrderMailer, type: :mailer do
|
5
|
-
include EmailSpec::Helpers
|
6
|
-
include EmailSpec::Matchers
|
7
|
-
|
8
|
-
before { create(:store) }
|
9
|
-
|
10
|
-
let(:order) do
|
11
|
-
order = stub_model(Spree::Order)
|
12
|
-
product = stub_model(Spree::Product, name: %{The "BEST" product})
|
13
|
-
variant = stub_model(Spree::Variant, product: product)
|
14
|
-
price = stub_model(Spree::Price, variant: variant, amount: 5.00)
|
15
|
-
line_item = stub_model(Spree::LineItem, variant: variant, order: order, quantity: 1, price: 4.99)
|
16
|
-
allow(variant).to receive_messages(default_price: price)
|
17
|
-
allow(order).to receive_messages(line_items: [line_item])
|
18
|
-
order
|
19
|
-
end
|
20
|
-
|
21
|
-
context ":from not set explicitly" do
|
22
|
-
it "falls back to spree config" do
|
23
|
-
message = Spree::OrderMailer.confirm_email(order)
|
24
|
-
expect(message.from).to eq([Spree::Store.current.mail_from_address])
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
it "doesn't aggressively escape double quotes in confirmation body" do
|
29
|
-
confirmation_email = Spree::OrderMailer.confirm_email(order)
|
30
|
-
expect(confirmation_email.body).not_to include(""")
|
31
|
-
end
|
32
|
-
|
33
|
-
it "confirm_email accepts an order id as an alternative to an Order object" do
|
34
|
-
expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
|
35
|
-
expect {
|
36
|
-
Spree::OrderMailer.confirm_email(order.id).body
|
37
|
-
}.not_to raise_error
|
38
|
-
end
|
39
|
-
|
40
|
-
it "cancel_email accepts an order id as an alternative to an Order object" do
|
41
|
-
expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
|
42
|
-
expect {
|
43
|
-
cancel_email = Spree::OrderMailer.cancel_email(order.id).body
|
44
|
-
}.not_to raise_error
|
45
|
-
end
|
46
|
-
|
47
|
-
context "only shows eligible adjustments in emails" do
|
48
|
-
before do
|
49
|
-
create(:adjustment, order: order, eligible: true, label: "Eligible Adjustment")
|
50
|
-
create(:adjustment, order: order, eligible: false, label: "Ineligible Adjustment")
|
51
|
-
end
|
52
|
-
|
53
|
-
let!(:confirmation_email) { Spree::OrderMailer.confirm_email(order) }
|
54
|
-
let!(:cancel_email) { Spree::OrderMailer.cancel_email(order) }
|
55
|
-
|
56
|
-
specify do
|
57
|
-
expect(confirmation_email.body).not_to include("Ineligible Adjustment")
|
58
|
-
end
|
59
|
-
|
60
|
-
specify do
|
61
|
-
expect(cancel_email.body).not_to include("Ineligible Adjustment")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context "displays unit costs from line item" do
|
66
|
-
# Regression test for #2772
|
67
|
-
|
68
|
-
# Tests mailer view spree/order_mailer/confirm_email.text.erb
|
69
|
-
specify do
|
70
|
-
confirmation_email = Spree::OrderMailer.confirm_email(order)
|
71
|
-
expect(confirmation_email).to have_body_text("4.99")
|
72
|
-
expect(confirmation_email).to_not have_body_text("5.00")
|
73
|
-
end
|
74
|
-
|
75
|
-
# Tests mailer view spree/order_mailer/cancel_email.text.erb
|
76
|
-
specify do
|
77
|
-
cancel_email = Spree::OrderMailer.cancel_email(order)
|
78
|
-
expect(cancel_email).to have_body_text("4.99")
|
79
|
-
expect(cancel_email).to_not have_body_text("5.00")
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "emails must be translatable" do
|
84
|
-
context "pt-BR locale" do
|
85
|
-
before do
|
86
|
-
I18n.enforce_available_locales = false
|
87
|
-
pt_br_confirm_mail = { spree: { order_mailer: { confirm_email: { dear_customer: 'Caro Cliente,' } } } }
|
88
|
-
pt_br_cancel_mail = { spree: { order_mailer: { cancel_email: { order_summary_canceled: 'Resumo da Pedido [CANCELADA]' } } } }
|
89
|
-
I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail
|
90
|
-
I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail
|
91
|
-
I18n.locale = :'pt-BR'
|
92
|
-
end
|
93
|
-
|
94
|
-
after do
|
95
|
-
I18n.locale = I18n.default_locale
|
96
|
-
I18n.enforce_available_locales = true
|
97
|
-
end
|
98
|
-
|
99
|
-
context "confirm_email" do
|
100
|
-
specify do
|
101
|
-
confirmation_email = Spree::OrderMailer.confirm_email(order)
|
102
|
-
expect(confirmation_email).to have_body_text("Caro Cliente,")
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context "cancel_email" do
|
107
|
-
specify do
|
108
|
-
cancel_email = Spree::OrderMailer.cancel_email(order)
|
109
|
-
expect(cancel_email).to have_body_text("Resumo da Pedido [CANCELADA]")
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context "with preference :send_core_emails set to false" do
|
116
|
-
it "sends no email" do
|
117
|
-
Spree::Config.set(:send_core_emails, false)
|
118
|
-
message = Spree::OrderMailer.confirm_email(order)
|
119
|
-
expect(message.body).to be_blank
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'email_spec'
|
3
|
-
|
4
|
-
describe Spree::ReimbursementMailer, :type => :mailer do
|
5
|
-
include EmailSpec::Helpers
|
6
|
-
include EmailSpec::Matchers
|
7
|
-
|
8
|
-
let(:reimbursement) { create(:reimbursement) }
|
9
|
-
|
10
|
-
context ":from not set explicitly" do
|
11
|
-
it "falls back to spree config" do
|
12
|
-
message = Spree::ReimbursementMailer.reimbursement_email(reimbursement)
|
13
|
-
expect(message.from).to eq [Spree::Store.current.mail_from_address]
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
it "accepts a reimbursement id as an alternative to a Reimbursement object" do
|
18
|
-
expect(Spree::Reimbursement).to receive(:find).with(reimbursement.id).and_return(reimbursement)
|
19
|
-
|
20
|
-
expect {
|
21
|
-
Spree::ReimbursementMailer.reimbursement_email(reimbursement.id).body
|
22
|
-
}.not_to raise_error
|
23
|
-
end
|
24
|
-
|
25
|
-
context "emails must be translatable" do
|
26
|
-
context "reimbursement_email" do
|
27
|
-
context "pt-BR locale" do
|
28
|
-
before do
|
29
|
-
I18n.enforce_available_locales = false
|
30
|
-
pt_br_shipped_email = { :spree => { :reimbursement_mailer => { :reimbursement_email => { :dear_customer => 'Caro Cliente,' } } } }
|
31
|
-
I18n.backend.store_translations :'pt-BR', pt_br_shipped_email
|
32
|
-
I18n.locale = :'pt-BR'
|
33
|
-
end
|
34
|
-
|
35
|
-
after do
|
36
|
-
I18n.locale = I18n.default_locale
|
37
|
-
I18n.enforce_available_locales = true
|
38
|
-
end
|
39
|
-
|
40
|
-
specify do
|
41
|
-
reimbursement_email = Spree::ReimbursementMailer.reimbursement_email(reimbursement)
|
42
|
-
expect(reimbursement_email.body).to include("Caro Cliente,")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'email_spec'
|
3
|
-
|
4
|
-
describe Spree::ShipmentMailer, type: :mailer do
|
5
|
-
include EmailSpec::Helpers
|
6
|
-
include EmailSpec::Matchers
|
7
|
-
|
8
|
-
before { create(:store) }
|
9
|
-
|
10
|
-
let(:order) { stub_model(Spree::Order, number: 'R12345') }
|
11
|
-
let(:shipping_method) { stub_model(Spree::ShippingMethod, name: 'USPS') }
|
12
|
-
let(:product) { stub_model(Spree::Product, name: %{The "BEST" product}, sku: 'SKU0001') }
|
13
|
-
let(:variant) { stub_model(Spree::Variant, product: product) }
|
14
|
-
let(:line_item) { stub_model(Spree::LineItem, variant: variant, order: order, quantity: 1, price: 5) }
|
15
|
-
let(:shipment) do
|
16
|
-
shipment = stub_model(Spree::Shipment)
|
17
|
-
allow(shipment).to receive_messages(line_items: [line_item], order: order)
|
18
|
-
allow(shipment).to receive_messages(tracking_url: "http://track.com/me")
|
19
|
-
allow(shipment).to receive_messages(shipping_method: shipping_method)
|
20
|
-
shipment
|
21
|
-
end
|
22
|
-
|
23
|
-
context ":from not set explicitly" do
|
24
|
-
it "falls back to spree config" do
|
25
|
-
message = Spree::ShipmentMailer.shipped_email(shipment)
|
26
|
-
expect(message.from).to eq([Spree::Store.current.mail_from_address])
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Regression test for #2196
|
31
|
-
it "doesn't include out of stock in the email body" do
|
32
|
-
shipment_email = Spree::ShipmentMailer.shipped_email(shipment)
|
33
|
-
expect(shipment_email.body).not_to include(%Q{Out of Stock})
|
34
|
-
end
|
35
|
-
|
36
|
-
it "shipment_email accepts an shipment id as an alternative to an Shipment object" do
|
37
|
-
expect(Spree::Shipment).to receive(:find).with(shipment.id).and_return(shipment)
|
38
|
-
expect {
|
39
|
-
Spree::ShipmentMailer.shipped_email(shipment.id).body
|
40
|
-
}.not_to raise_error
|
41
|
-
end
|
42
|
-
|
43
|
-
context "emails must be translatable" do
|
44
|
-
context "shipped_email" do
|
45
|
-
context "pt-BR locale" do
|
46
|
-
before do
|
47
|
-
I18n.enforce_available_locales = false
|
48
|
-
pt_br_shipped_email = { spree: { shipment_mailer: { shipped_email: { dear_customer: 'Caro Cliente,' } } } }
|
49
|
-
I18n.backend.store_translations :'pt-BR', pt_br_shipped_email
|
50
|
-
I18n.locale = :'pt-BR'
|
51
|
-
end
|
52
|
-
|
53
|
-
after do
|
54
|
-
I18n.locale = I18n.default_locale
|
55
|
-
I18n.enforce_available_locales = true
|
56
|
-
end
|
57
|
-
|
58
|
-
specify do
|
59
|
-
shipped_email = Spree::ShipmentMailer.shipped_email(shipment)
|
60
|
-
expect(shipped_email).to have_body_text("Caro Cliente,")
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "shipped_email" do
|
67
|
-
let(:shipped_email) { Spree::ShipmentMailer.shipped_email(shipment) }
|
68
|
-
|
69
|
-
specify do
|
70
|
-
expect(shipped_email).to have_body_text(order.number)
|
71
|
-
end
|
72
|
-
|
73
|
-
specify do
|
74
|
-
expect(shipped_email).to have_body_text(shipping_method.name)
|
75
|
-
end
|
76
|
-
|
77
|
-
specify do
|
78
|
-
expect(shipped_email).to have_body_text("href=\"#{shipment.tracking_url}\"")
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'email_spec'
|
3
|
-
|
4
|
-
describe Spree::TestMailer, :type => :mailer do
|
5
|
-
include EmailSpec::Helpers
|
6
|
-
include EmailSpec::Matchers
|
7
|
-
|
8
|
-
before { create(:store) }
|
9
|
-
|
10
|
-
let(:user) { create(:user) }
|
11
|
-
|
12
|
-
context ":from not set explicitly" do
|
13
|
-
it "falls back to spree config" do
|
14
|
-
message = Spree::TestMailer.test_email('test@example.com')
|
15
|
-
expect(message.from).to eq([Spree::Store.current.mail_from_address])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it "confirm_email accepts a user id as an alternative to a User object" do
|
20
|
-
expect {
|
21
|
-
Spree::TestMailer.test_email('test@example.com')
|
22
|
-
}.not_to raise_error
|
23
|
-
end
|
24
|
-
|
25
|
-
context "action mailer host" do
|
26
|
-
it "falls back to spree store url" do
|
27
|
-
ActionMailer::Base.default_url_options = {}
|
28
|
-
Spree::TestMailer.test_email('test@example.com').deliver_now
|
29
|
-
expect(ActionMailer::Base.default_url_options[:host]).to eq(Spree::Store.current.url)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "uses developer set host" do
|
33
|
-
ActionMailer::Base.default_url_options[:host] = 'test.test'
|
34
|
-
Spree::TestMailer.test_email('test@example.com').deliver_now
|
35
|
-
expect(ActionMailer::Base.default_url_options[:host]).to eq('test.test')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
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).allow_nil }
|
8
|
-
end
|
9
|
-
end
|
@@ -1,251 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'cancan/matchers'
|
3
|
-
require 'spree/testing_support/ability_helpers'
|
4
|
-
require 'spree/testing_support/bar_ability'
|
5
|
-
|
6
|
-
# Fake ability for testing registration of additional abilities
|
7
|
-
class FooAbility
|
8
|
-
include CanCan::Ability
|
9
|
-
|
10
|
-
def initialize(user)
|
11
|
-
# allow anyone to perform index on Order
|
12
|
-
can :index, Spree::Order
|
13
|
-
# allow anyone to update an Order with id of 1
|
14
|
-
can :update, Spree::Order do |order|
|
15
|
-
order.id == 1
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe Spree::Ability, :type => :model do
|
21
|
-
let(:user) { build(:user) }
|
22
|
-
let(:ability) { Spree::Ability.new(user) }
|
23
|
-
let(:token) { nil }
|
24
|
-
|
25
|
-
after(:each) {
|
26
|
-
Spree::Ability.abilities = Set.new
|
27
|
-
}
|
28
|
-
|
29
|
-
context 'register_ability' do
|
30
|
-
it 'should add the ability to the list of abilties' do
|
31
|
-
Spree::Ability.register_ability(FooAbility)
|
32
|
-
expect(Spree::Ability.new(user).abilities).not_to be_empty
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should apply the registered abilities permissions' do
|
36
|
-
Spree::Ability.register_ability(FooAbility)
|
37
|
-
expect(Spree::Ability.new(user).can?(:update, mock_model(Spree::Order, :id => 1))).to be true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context '#abilities_to_register' do
|
42
|
-
it 'adds the ability to the list of abilities' do
|
43
|
-
allow_any_instance_of(Spree::Ability).to receive(:abilities_to_register) { [FooAbility] }
|
44
|
-
expect(Spree::Ability.new(user).abilities).to include FooAbility
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'applies the registered abilities permissions' do
|
48
|
-
allow_any_instance_of(Spree::Ability).to receive(:abilities_to_register) { [FooAbility] }
|
49
|
-
expect(Spree::Ability.new(user).can?(:update, mock_model(Spree::Order, id: 1))).to be true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context 'for general resource' do
|
54
|
-
let(:resource) { Object.new }
|
55
|
-
|
56
|
-
context 'with admin user' do
|
57
|
-
before(:each) { allow(user).to receive(:has_spree_role?).and_return(true) }
|
58
|
-
it_should_behave_like 'access granted'
|
59
|
-
it_should_behave_like 'index allowed'
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'with customer' do
|
63
|
-
it_should_behave_like 'access denied'
|
64
|
-
it_should_behave_like 'no index allowed'
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'for admin protected resources' do
|
69
|
-
let(:resource) { Object.new }
|
70
|
-
let(:resource_shipment) { Spree::Shipment.new }
|
71
|
-
let(:resource_product) { Spree::Product.new }
|
72
|
-
let(:resource_user) { create :user }
|
73
|
-
let(:resource_order) { Spree::Order.new }
|
74
|
-
let(:fakedispatch_user) { Spree.user_class.create }
|
75
|
-
let(:fakedispatch_ability) { Spree::Ability.new(fakedispatch_user) }
|
76
|
-
|
77
|
-
context 'with admin user' do
|
78
|
-
it 'should be able to admin' do
|
79
|
-
user.spree_roles << Spree::Role.find_or_create_by(name: 'admin')
|
80
|
-
expect(ability).to be_able_to :admin, resource
|
81
|
-
expect(ability).to be_able_to :index, resource_order
|
82
|
-
expect(ability).to be_able_to :show, resource_product
|
83
|
-
expect(ability).to be_able_to :create, resource_user
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'with fakedispatch user' do
|
88
|
-
it 'should be able to admin on the order and shipment pages' do
|
89
|
-
user.spree_roles << Spree::Role.find_or_create_by(name: 'bar')
|
90
|
-
|
91
|
-
Spree::Ability.register_ability(BarAbility)
|
92
|
-
|
93
|
-
expect(ability).not_to be_able_to :admin, resource
|
94
|
-
|
95
|
-
expect(ability).to be_able_to :admin, resource_order
|
96
|
-
expect(ability).to be_able_to :index, resource_order
|
97
|
-
expect(ability).not_to be_able_to :update, resource_order
|
98
|
-
# ability.should_not be_able_to :create, resource_order # Fails
|
99
|
-
|
100
|
-
expect(ability).to be_able_to :admin, resource_shipment
|
101
|
-
expect(ability).to be_able_to :index, resource_shipment
|
102
|
-
expect(ability).to be_able_to :create, resource_shipment
|
103
|
-
|
104
|
-
expect(ability).not_to be_able_to :admin, resource_product
|
105
|
-
expect(ability).not_to be_able_to :update, resource_product
|
106
|
-
# ability.should_not be_able_to :show, resource_product # Fails
|
107
|
-
|
108
|
-
expect(ability).not_to be_able_to :admin, resource_user
|
109
|
-
expect(ability).not_to be_able_to :update, resource_user
|
110
|
-
expect(ability).to be_able_to :update, user
|
111
|
-
# ability.should_not be_able_to :create, resource_user # Fails
|
112
|
-
# It can create new users if is has access to the :admin, User!!
|
113
|
-
|
114
|
-
# TODO change the Ability class so only users and customers get the extra premissions?
|
115
|
-
|
116
|
-
Spree::Ability.remove_ability(BarAbility)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context 'with customer' do
|
121
|
-
it 'should not be able to admin' do
|
122
|
-
expect(ability).not_to be_able_to :admin, resource
|
123
|
-
expect(ability).not_to be_able_to :admin, resource_order
|
124
|
-
expect(ability).not_to be_able_to :admin, resource_product
|
125
|
-
expect(ability).not_to be_able_to :admin, resource_user
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
context 'as Guest User' do
|
131
|
-
|
132
|
-
context 'for Country' do
|
133
|
-
let(:resource) { Spree::Country.new }
|
134
|
-
context 'requested by any user' do
|
135
|
-
it_should_behave_like 'read only'
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'for OptionType' do
|
140
|
-
let(:resource) { Spree::OptionType.new }
|
141
|
-
context 'requested by any user' do
|
142
|
-
it_should_behave_like 'read only'
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'for OptionValue' do
|
147
|
-
let(:resource) { Spree::OptionType.new }
|
148
|
-
context 'requested by any user' do
|
149
|
-
it_should_behave_like 'read only'
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'for Order' do
|
154
|
-
let(:resource) { Spree::Order.new }
|
155
|
-
|
156
|
-
context 'requested by same user' do
|
157
|
-
before(:each) { resource.user = user }
|
158
|
-
it_should_behave_like 'access granted'
|
159
|
-
it_should_behave_like 'no index allowed'
|
160
|
-
end
|
161
|
-
|
162
|
-
context 'requested by other user' do
|
163
|
-
before(:each) { resource.user = Spree.user_class.new }
|
164
|
-
it_should_behave_like 'create only'
|
165
|
-
end
|
166
|
-
|
167
|
-
context 'requested with proper token' do
|
168
|
-
let(:token) { 'TOKEN123' }
|
169
|
-
before(:each) { allow(resource).to receive_messages guest_token: token }
|
170
|
-
it_should_behave_like 'access granted'
|
171
|
-
it_should_behave_like 'no index allowed'
|
172
|
-
end
|
173
|
-
|
174
|
-
context 'requested with inproper token' do
|
175
|
-
let(:token) { 'FAIL' }
|
176
|
-
before(:each) { allow(resource).to receive_messages guest_token: token }
|
177
|
-
it_should_behave_like 'create only'
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
context 'for Product' do
|
182
|
-
let(:resource) { Spree::Product.new }
|
183
|
-
context 'requested by any user' do
|
184
|
-
it_should_behave_like 'read only'
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
context 'for ProductProperty' do
|
189
|
-
let(:resource) { Spree::Product.new }
|
190
|
-
context 'requested by any user' do
|
191
|
-
it_should_behave_like 'read only'
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
context 'for Property' do
|
196
|
-
let(:resource) { Spree::Product.new }
|
197
|
-
context 'requested by any user' do
|
198
|
-
it_should_behave_like 'read only'
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
context 'for State' do
|
203
|
-
let(:resource) { Spree::State.new }
|
204
|
-
context 'requested by any user' do
|
205
|
-
it_should_behave_like 'read only'
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
context 'for Taxons' do
|
210
|
-
let(:resource) { Spree::Taxon.new }
|
211
|
-
context 'requested by any user' do
|
212
|
-
it_should_behave_like 'read only'
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
context 'for Taxonomy' do
|
217
|
-
let(:resource) { Spree::Taxonomy.new }
|
218
|
-
context 'requested by any user' do
|
219
|
-
it_should_behave_like 'read only'
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
context 'for User' do
|
224
|
-
context 'requested by same user' do
|
225
|
-
let(:resource) { user }
|
226
|
-
it_should_behave_like 'access granted'
|
227
|
-
it_should_behave_like 'no index allowed'
|
228
|
-
end
|
229
|
-
context 'requested by other user' do
|
230
|
-
let(:resource) { create(:user) }
|
231
|
-
it_should_behave_like 'create only'
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
context 'for Variant' do
|
236
|
-
let(:resource) { Spree::Variant.new }
|
237
|
-
context 'requested by any user' do
|
238
|
-
it_should_behave_like 'read only'
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
context 'for Zone' do
|
243
|
-
let(:resource) { Spree::Zone.new }
|
244
|
-
context 'requested by any user' do
|
245
|
-
it_should_behave_like 'read only'
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|
250
|
-
|
251
|
-
end
|