spree_core 3.0.5 → 3.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/Rakefile +30 -0
- data/app/assets/javascripts/spree.js.coffee.erb +1 -1
- data/app/models/spree/ability.rb +1 -1
- data/app/models/spree/base.rb +3 -1
- data/app/models/spree/order_updater.rb +2 -1
- data/app/models/spree/price.rb +7 -12
- data/app/models/spree/product.rb +3 -2
- data/app/models/spree/reimbursement.rb +1 -1
- data/app/models/spree/state.rb +2 -0
- data/app/models/spree/zone.rb +1 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/testing_support/shoulda_matcher_configuration.rb +6 -0
- data/script/rails +9 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +137 -0
- data/spec/helpers/products_helper_spec.rb +224 -0
- data/spec/lib/calculated_adjustments_spec.rb +7 -0
- data/spec/lib/i18n_spec.rb +123 -0
- data/spec/lib/search/base_spec.rb +86 -0
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +101 -0
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +95 -0
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +17 -0
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +16 -0
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +39 -0
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +22 -0
- data/spec/lib/spree/core/importer/order_spec.rb +502 -0
- data/spec/lib/spree/core/validators/email_spec.rb +53 -0
- data/spec/lib/spree/localized_number_spec.rb +38 -0
- data/spec/lib/spree/migrations_spec.rb +34 -0
- data/spec/lib/spree/money_spec.rb +122 -0
- data/spec/lib/tasks/exchanges_spec.rb +136 -0
- data/spec/mailers/order_mailer_spec.rb +124 -0
- data/spec/mailers/reimbursement_mailer_spec.rb +47 -0
- data/spec/mailers/shipment_mailer_spec.rb +63 -0
- data/spec/mailers/test_mailer_spec.rb +24 -0
- data/spec/models/spree/ability_spec.rb +246 -0
- data/spec/models/spree/address_spec.rb +291 -0
- data/spec/models/spree/adjustable/adjustments_updater_spec.rb +286 -0
- data/spec/models/spree/adjustment_spec.rb +163 -0
- data/spec/models/spree/app_configuration_spec.rb +23 -0
- data/spec/models/spree/asset_spec.rb +25 -0
- data/spec/models/spree/calculator/default_tax_spec.rb +127 -0
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +25 -0
- data/spec/models/spree/calculator/flat_rate_spec.rb +47 -0
- data/spec/models/spree/calculator/flexi_rate_spec.rb +41 -0
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +15 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +30 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +51 -0
- data/spec/models/spree/calculator/shipping.rb +8 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +23 -0
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +13 -0
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +52 -0
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +20 -0
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +29 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +40 -0
- data/spec/models/spree/calculator/tiered_percent_spec.rb +51 -0
- data/spec/models/spree/calculator_spec.rb +69 -0
- data/spec/models/spree/classification_spec.rb +93 -0
- data/spec/models/spree/concerns/display_money_spec.rb +43 -0
- data/spec/models/spree/country_spec.rb +18 -0
- data/spec/models/spree/credit_card_spec.rb +324 -0
- data/spec/models/spree/customer_return_spec.rb +262 -0
- data/spec/models/spree/exchange_spec.rb +75 -0
- data/spec/models/spree/gateway/bogus_simple.rb +20 -0
- data/spec/models/spree/gateway/bogus_spec.rb +13 -0
- data/spec/models/spree/gateway_spec.rb +54 -0
- data/spec/models/spree/image_spec.rb +5 -0
- data/spec/models/spree/inventory_unit_spec.rb +242 -0
- data/spec/models/spree/line_item_spec.rb +267 -0
- data/spec/models/spree/option_type_spec.rb +14 -0
- data/spec/models/spree/option_value_spec.rb +13 -0
- data/spec/models/spree/order/address_spec.rb +50 -0
- data/spec/models/spree/order/adjustments_spec.rb +29 -0
- data/spec/models/spree/order/callbacks_spec.rb +42 -0
- data/spec/models/spree/order/checkout_spec.rb +764 -0
- data/spec/models/spree/order/currency_updater_spec.rb +32 -0
- data/spec/models/spree/order/finalizing_spec.rb +117 -0
- data/spec/models/spree/order/helpers_spec.rb +5 -0
- data/spec/models/spree/order/payment_spec.rb +214 -0
- data/spec/models/spree/order/risk_assessment_spec.rb +84 -0
- data/spec/models/spree/order/shipments_spec.rb +43 -0
- data/spec/models/spree/order/state_machine_spec.rb +216 -0
- data/spec/models/spree/order/tax_spec.rb +84 -0
- data/spec/models/spree/order/totals_spec.rb +24 -0
- data/spec/models/spree/order/updating_spec.rb +18 -0
- data/spec/models/spree/order/validations_spec.rb +15 -0
- data/spec/models/spree/order_contents_spec.rb +256 -0
- data/spec/models/spree/order_inventory_spec.rb +228 -0
- data/spec/models/spree/order_merger_spec.rb +133 -0
- data/spec/models/spree/order_spec.rb +954 -0
- data/spec/models/spree/order_updater_spec.rb +283 -0
- data/spec/models/spree/payment/gateway_options_spec.rb +119 -0
- data/spec/models/spree/payment_method_spec.rb +95 -0
- data/spec/models/spree/payment_spec.rb +926 -0
- data/spec/models/spree/preference_spec.rb +80 -0
- data/spec/models/spree/preferences/configuration_spec.rb +30 -0
- data/spec/models/spree/preferences/preferable_spec.rb +348 -0
- data/spec/models/spree/preferences/scoped_store_spec.rb +58 -0
- data/spec/models/spree/preferences/store_spec.rb +46 -0
- data/spec/models/spree/price_spec.rb +42 -0
- data/spec/models/spree/product/scopes_spec.rb +148 -0
- data/spec/models/spree/product_duplicator_spec.rb +103 -0
- data/spec/models/spree/product_filter_spec.rb +26 -0
- data/spec/models/spree/product_option_type_spec.rb +5 -0
- data/spec/models/spree/product_property_spec.rb +11 -0
- data/spec/models/spree/product_spec.rb +474 -0
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +50 -0
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +148 -0
- data/spec/models/spree/promotion/actions/create_line_items_spec.rb +86 -0
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +36 -0
- data/spec/models/spree/promotion/rules/first_order_spec.rb +75 -0
- data/spec/models/spree/promotion/rules/item_total_spec.rb +282 -0
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +42 -0
- data/spec/models/spree/promotion/rules/option_value_spec.rb +90 -0
- data/spec/models/spree/promotion/rules/product_spec.rb +143 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +102 -0
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +27 -0
- data/spec/models/spree/promotion/rules/user_spec.rb +37 -0
- data/spec/models/spree/promotion_action_spec.rb +10 -0
- data/spec/models/spree/promotion_category_spec.rb +17 -0
- data/spec/models/spree/promotion_handler/cart_spec.rb +102 -0
- data/spec/models/spree/promotion_handler/coupon_spec.rb +323 -0
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +48 -0
- data/spec/models/spree/promotion_handler/page_spec.rb +44 -0
- data/spec/models/spree/promotion_rule_spec.rb +29 -0
- data/spec/models/spree/promotion_spec.rb +603 -0
- data/spec/models/spree/property_spec.rb +5 -0
- data/spec/models/spree/prototype_spec.rb +5 -0
- data/spec/models/spree/refund_spec.rb +195 -0
- data/spec/models/spree/reimbursement/credit_spec.rb +36 -0
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +140 -0
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +83 -0
- data/spec/models/spree/reimbursement_performer_spec.rb +30 -0
- data/spec/models/spree/reimbursement_spec.rb +215 -0
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +51 -0
- data/spec/models/spree/reimbursement_type/credit_spec.rb +53 -0
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +46 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +55 -0
- data/spec/models/spree/return_authorization_spec.rb +250 -0
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +77 -0
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +58 -0
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +61 -0
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +32 -0
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +29 -0
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +35 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +65 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +43 -0
- data/spec/models/spree/return_item_spec.rb +682 -0
- data/spec/models/spree/returns_calculator_spec.rb +14 -0
- data/spec/models/spree/shipment_spec.rb +740 -0
- data/spec/models/spree/shipping_calculator_spec.rb +45 -0
- data/spec/models/spree/shipping_category_spec.rb +5 -0
- data/spec/models/spree/shipping_method_spec.rb +88 -0
- data/spec/models/spree/shipping_rate_spec.rb +141 -0
- data/spec/models/spree/state_spec.rb +18 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +36 -0
- data/spec/models/spree/stock/content_item_spec.rb +22 -0
- data/spec/models/spree/stock/coordinator_spec.rb +51 -0
- data/spec/models/spree/stock/differentiator_spec.rb +39 -0
- data/spec/models/spree/stock/estimator_spec.rb +154 -0
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +38 -0
- data/spec/models/spree/stock/package_spec.rb +194 -0
- data/spec/models/spree/stock/packer_spec.rb +70 -0
- data/spec/models/spree/stock/prioritizer_spec.rb +125 -0
- data/spec/models/spree/stock/quantifier_spec.rb +97 -0
- data/spec/models/spree/stock/splitter/backordered_spec.rb +29 -0
- data/spec/models/spree/stock/splitter/base_spec.rb +21 -0
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +47 -0
- data/spec/models/spree/stock/splitter/weight_spec.rb +32 -0
- data/spec/models/spree/stock_item_spec.rb +410 -0
- data/spec/models/spree/stock_location_spec.rb +243 -0
- data/spec/models/spree/stock_movement_spec.rb +56 -0
- data/spec/models/spree/stock_transfer_spec.rb +50 -0
- data/spec/models/spree/store_spec.rb +50 -0
- data/spec/models/spree/tax_category_spec.rb +27 -0
- data/spec/models/spree/tax_rate_spec.rb +382 -0
- data/spec/models/spree/taxon_spec.rb +74 -0
- data/spec/models/spree/taxonomy_spec.rb +18 -0
- data/spec/models/spree/tracker_spec.rb +21 -0
- data/spec/models/spree/user_spec.rb +130 -0
- data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +24 -0
- data/spec/models/spree/variant_spec.rb +523 -0
- data/spec/models/spree/zone_spec.rb +444 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/support/big_decimal.rb +5 -0
- data/spec/support/concerns/adjustment_source_spec.rb +23 -0
- data/spec/support/concerns/default_price_spec.rb +28 -0
- data/spec/support/rake.rb +13 -0
- data/spec/support/test_gateway.rb +2 -0
- data/spree_core.gemspec +48 -0
- metadata +185 -4
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EmailValidator do
|
4
|
+
|
5
|
+
class Tester
|
6
|
+
include ActiveModel::Validations
|
7
|
+
attr_accessor :email_address
|
8
|
+
validates :email_address, email: true
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:valid_emails) {[
|
12
|
+
'valid@email.com',
|
13
|
+
'valid@email.com.uk',
|
14
|
+
'e@email.com',
|
15
|
+
'valid+email@email.com',
|
16
|
+
'valid-email@email.com',
|
17
|
+
'valid_email@email.com',
|
18
|
+
'validemail_@email.com',
|
19
|
+
'valid.email@email.com'
|
20
|
+
]}
|
21
|
+
let(:invalid_emails) {[
|
22
|
+
'',
|
23
|
+
' ',
|
24
|
+
'invalid email@email.com',
|
25
|
+
'invalidemail @email.com',
|
26
|
+
'invalidemail@email..com',
|
27
|
+
'.invalid.email@email.com',
|
28
|
+
'invalid.email.@email.com',
|
29
|
+
'@email.com',
|
30
|
+
'.@email.com',
|
31
|
+
'invalidemailemail.com',
|
32
|
+
'@invalid.email@email.com',
|
33
|
+
'invalid@email@email.com',
|
34
|
+
'invalid.email@@email.com'
|
35
|
+
]}
|
36
|
+
|
37
|
+
it 'validates valid email addresses' do
|
38
|
+
tester = Tester.new
|
39
|
+
valid_emails.each do |email|
|
40
|
+
tester.email_address = email
|
41
|
+
expect(tester.valid?).to be true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'validates invalid email addresses' do
|
46
|
+
tester = Tester.new
|
47
|
+
invalid_emails.each do |email|
|
48
|
+
tester.email_address = email
|
49
|
+
expect(tester.valid?).to be false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::LocalizedNumber do
|
4
|
+
|
5
|
+
context ".parse" do
|
6
|
+
before do
|
7
|
+
I18n.enforce_available_locales = false
|
8
|
+
I18n.locale = I18n.default_locale
|
9
|
+
I18n.backend.store_translations(:de, { :number => { :currency => { :format => { :delimiter => '.', :separator => ',' } } } })
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
I18n.locale = I18n.default_locale
|
14
|
+
I18n.enforce_available_locales = true
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with decimal point" do
|
18
|
+
it "captures the proper amount for a formatted price" do
|
19
|
+
expect(subject.class.parse('1,599.99')).to eql 1599.99
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with decimal comma" do
|
24
|
+
it "captures the proper amount for a formatted price" do
|
25
|
+
I18n.locale = :de
|
26
|
+
expect(subject.class.parse('1.599,99')).to eql 1599.99
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with a numeric price" do
|
31
|
+
it "uses the price as is" do
|
32
|
+
I18n.locale = :de
|
33
|
+
expect(subject.class.parse(1599.99)).to eql 1599.99
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe Migrations do
|
5
|
+
let(:app_migrations) { [".", "34_add_title.rb", "52_add_text.rb"] }
|
6
|
+
let(:engine_migrations) { [".", "334_create_orders.spree.rb", "777_create_products.spree.rb"] }
|
7
|
+
|
8
|
+
let(:config) { double("Config", root: "dir") }
|
9
|
+
|
10
|
+
subject { described_class.new(config, "spree") }
|
11
|
+
|
12
|
+
before do
|
13
|
+
expect(File).to receive(:exists?).with("config/spree.yml").and_return true
|
14
|
+
expect(File).to receive(:directory?).with("db/migrate").and_return true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "warns about missing migrations" do
|
18
|
+
expect(Dir).to receive(:entries).with("db/migrate").and_return app_migrations
|
19
|
+
expect(Dir).to receive(:entries).with("dir/db/migrate").and_return engine_migrations
|
20
|
+
|
21
|
+
silence_stream(STDOUT) {
|
22
|
+
expect(subject.check).to eq true
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
context "no missing migrations" do
|
27
|
+
it "says nothing" do
|
28
|
+
expect(Dir).to receive(:entries).with("dir/db/migrate").and_return engine_migrations
|
29
|
+
expect(Dir).to receive(:entries).with("db/migrate").and_return (app_migrations + engine_migrations)
|
30
|
+
expect(subject.check).to eq nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Spree::Money do
|
5
|
+
before do
|
6
|
+
configure_spree_preferences do |config|
|
7
|
+
config.currency = "USD"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "formats correctly" do
|
12
|
+
money = Spree::Money.new(10)
|
13
|
+
expect(money.to_s).to eq("$10.00")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can get cents" do
|
17
|
+
money = Spree::Money.new(10)
|
18
|
+
expect(money.cents).to eq(1000)
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with currency" do
|
22
|
+
it "passed in option" do
|
23
|
+
money = Spree::Money.new(10, :with_currency => true, :html => false)
|
24
|
+
expect(money.to_s).to eq("$10.00 USD")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "hide cents" do
|
29
|
+
it "hides cents suffix" do
|
30
|
+
money = Spree::Money.new(10, no_cents: true)
|
31
|
+
expect(money.to_s).to eq("$10")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "shows cents suffix" do
|
35
|
+
money = Spree::Money.new(10)
|
36
|
+
expect(money.to_s).to eq("$10.00")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "currency parameter" do
|
41
|
+
context "when currency is specified in Canadian Dollars" do
|
42
|
+
it "uses the currency param over the global configuration" do
|
43
|
+
money = Spree::Money.new(10, :currency => 'CAD', :with_currency => true, :html => false)
|
44
|
+
expect(money.to_s).to eq("$10.00 CAD")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when currency is specified in Japanese Yen" do
|
49
|
+
it "uses the currency param over the global configuration" do
|
50
|
+
money = Spree::Money.new(100, :currency => 'JPY', :html => false)
|
51
|
+
expect(money.to_s).to eq("¥100")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "symbol positioning" do
|
57
|
+
it "passed in option" do
|
58
|
+
money = Spree::Money.new(10, :symbol_position => :after, :html => false)
|
59
|
+
expect(money.to_s).to eq("10.00 $")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "sign before symbol" do
|
64
|
+
it "defaults to -$10.00" do
|
65
|
+
money = Spree::Money.new(-10)
|
66
|
+
expect(money.to_s).to eq("-$10.00")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "passed in option" do
|
70
|
+
money = Spree::Money.new(-10, :sign_before_symbol => false)
|
71
|
+
expect(money.to_s).to eq("$-10.00")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "JPY" do
|
76
|
+
before do
|
77
|
+
configure_spree_preferences do |config|
|
78
|
+
config.currency = "JPY"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "formats correctly" do
|
83
|
+
money = Spree::Money.new(1000, :html => false)
|
84
|
+
expect(money.to_s).to eq("¥1,000")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "EUR" do
|
89
|
+
before do
|
90
|
+
configure_spree_preferences do |config|
|
91
|
+
config.currency = "EUR"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Regression test for #2634
|
96
|
+
it "formats as plain by default" do
|
97
|
+
money = Spree::Money.new(10, symbol_position: :after)
|
98
|
+
expect(money.to_s).to eq("10.00 €")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "formats as HTML if asked (nicely) to" do
|
102
|
+
money = Spree::Money.new(10, symbol_position: :after)
|
103
|
+
# The HTML'ified version of "10.00 €"
|
104
|
+
expect(money.to_html).to eq("10.00 €")
|
105
|
+
end
|
106
|
+
|
107
|
+
it "formats as HTML with currency" do
|
108
|
+
money = Spree::Money.new(10, symbol_position: :after, with_currency: true)
|
109
|
+
# The HTML'ified version of "10.00 €"
|
110
|
+
expect(money.to_html).to eq("10.00 € <span class=\"currency\">EUR</span>")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#as_json" do
|
115
|
+
let(:options) { double('options') }
|
116
|
+
|
117
|
+
it "returns the expected string" do
|
118
|
+
money = Spree::Money.new(10)
|
119
|
+
expect(money.as_json(options)).to eq("$10.00")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,136 @@
|
|
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
|
@@ -0,0 +1,124 @@
|
|
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 => %Q{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
|
+
|
85
|
+
context "pt-BR locale" do
|
86
|
+
before do
|
87
|
+
I18n.enforce_available_locales = false
|
88
|
+
pt_br_confirm_mail = { :spree => { :order_mailer => { :confirm_email => { :dear_customer => 'Caro Cliente,' } } } }
|
89
|
+
pt_br_cancel_mail = { :spree => { :order_mailer => { :cancel_email => { :order_summary_canceled => 'Resumo da Pedido [CANCELADA]' } } } }
|
90
|
+
I18n.backend.store_translations :'pt-BR', pt_br_confirm_mail
|
91
|
+
I18n.backend.store_translations :'pt-BR', pt_br_cancel_mail
|
92
|
+
I18n.locale = :'pt-BR'
|
93
|
+
end
|
94
|
+
|
95
|
+
after do
|
96
|
+
I18n.locale = I18n.default_locale
|
97
|
+
I18n.enforce_available_locales = true
|
98
|
+
end
|
99
|
+
|
100
|
+
context "confirm_email" do
|
101
|
+
specify do
|
102
|
+
confirmation_email = Spree::OrderMailer.confirm_email(order)
|
103
|
+
expect(confirmation_email).to have_body_text("Caro Cliente,")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "cancel_email" do
|
108
|
+
specify do
|
109
|
+
cancel_email = Spree::OrderMailer.cancel_email(order)
|
110
|
+
expect(cancel_email).to have_body_text("Resumo da Pedido [CANCELADA]")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "with preference :send_core_emails set to false" do
|
117
|
+
it "sends no email" do
|
118
|
+
Spree::Config.set(:send_core_emails, false)
|
119
|
+
message = Spree::OrderMailer.confirm_email(order)
|
120
|
+
expect(message.body).to be_blank
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|