solidus_core 1.3.2 → 1.4.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/app/helpers/spree/base_helper.rb +6 -2
- data/app/mailers/spree/base_mailer.rb +1 -1
- data/app/mailers/spree/carton_mailer.rb +1 -1
- data/app/mailers/spree/order_mailer.rb +2 -2
- data/app/mailers/spree/reimbursement_mailer.rb +7 -7
- data/app/mailers/spree/test_mailer.rb +3 -2
- data/app/models/concerns/spree/user_payment_source.rb +1 -1
- data/app/models/spree/address.rb +14 -4
- data/app/models/spree/adjustment.rb +11 -19
- data/app/models/spree/app_configuration.rb +23 -1
- data/app/models/spree/base.rb +9 -0
- data/app/models/spree/country.rb +2 -2
- data/app/models/spree/exchange.rb +1 -1
- data/app/models/spree/gateway.rb +1 -1
- data/app/models/spree/item_adjustments.rb +7 -0
- data/app/models/spree/line_item.rb +1 -13
- data/app/models/spree/order/checkout.rb +19 -16
- data/app/models/spree/order/payments.rb +0 -2
- data/app/models/spree/order.rb +7 -21
- data/app/models/spree/order_contents.rb +60 -4
- data/app/models/spree/order_merger.rb +2 -4
- data/app/models/spree/order_shipping.rb +1 -1
- data/app/models/spree/order_update_attributes.rb +0 -2
- data/app/models/spree/order_updater.rb +14 -11
- data/app/models/spree/payment.rb +2 -3
- data/app/models/spree/payment_create.rb +5 -2
- data/app/models/spree/payment_method/store_credit.rb +6 -5
- data/app/models/spree/product/scopes.rb +2 -1
- data/app/models/spree/product.rb +2 -5
- data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -3
- data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
- data/app/models/spree/promotion/rules/option_value.rb +2 -3
- data/app/models/spree/promotion/rules/product.rb +9 -3
- data/app/models/spree/promotion/rules/taxon.rb +33 -7
- data/app/models/spree/promotion/rules/user.rb +2 -3
- data/app/models/spree/promotion.rb +16 -6
- data/app/models/spree/promotion_handler/coupon.rb +1 -1
- data/app/models/spree/shipment.rb +12 -16
- data/app/models/spree/stock/estimator.rb +1 -1
- data/app/models/spree/stock/package.rb +0 -1
- data/app/models/spree/stock_item.rb +2 -6
- data/app/models/spree/store.rb +2 -1
- data/app/models/spree/tax_rate.rb +1 -1
- data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +29 -0
- data/app/models/spree/wallet/default_payment_builder.rb +26 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +46 -0
- data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +1 -1
- data/app/views/spree/shared/_base_mailer_footer.html.erb +1 -20
- data/app/views/spree/shared/_base_mailer_header.html.erb +1 -31
- data/config/initializers/spree_user.rb +1 -1
- data/config/locales/en.yml +58 -34
- data/db/migrate/20130414000512_update_name_fields_on_spree_credit_cards.rb +1 -1
- data/db/migrate/20140601011216_set_shipment_total_for_users_upgrading.rb +15 -3
- data/db/migrate/20160527070401_rename_shipment_address_field.rb +7 -0
- data/db/migrate/20160616232103_remove_user_id_from_promotion_rules.rb +11 -0
- data/db/migrate/20160718205341_add_payment_id_index_to_spree_refunds.rb +5 -0
- data/db/migrate/20160718205859_add_reimbursement_id_index_to_spree_refunds.rb +5 -0
- data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
- data/lib/generators/spree/dummy/templates/rails/database.yml +3 -1
- data/lib/generators/spree/dummy/templates/rails/test.rb +4 -2
- data/lib/generators/spree/install/install_generator.rb +6 -16
- data/lib/spree/core/controller_helpers/auth.rb +1 -1
- data/lib/spree/core/controller_helpers/common.rb +1 -1
- data/lib/spree/core/controller_helpers/order.rb +2 -2
- data/lib/spree/core/current_store.rb +5 -1
- data/lib/spree/core/delegate_belongs_to.rb +1 -1
- data/lib/spree/core/routes.rb +6 -32
- data/lib/spree/core/search/base.rb +2 -2
- data/lib/spree/core/stock_configuration.rb +6 -0
- data/lib/spree/core/version.rb +2 -2
- data/lib/spree/core.rb +2 -1
- data/lib/spree/i18n.rb +7 -0
- data/lib/spree/mailer_previews/carton_preview.rb +2 -1
- data/lib/spree/mailer_previews/order_preview.rb +8 -3
- data/lib/spree/mailer_previews/reimbursement_preview.rb +11 -0
- data/lib/spree/migrations.rb +13 -7
- data/lib/spree/permitted_attributes.rb +1 -1
- data/lib/spree/testing_support/capybara_ext.rb +6 -1
- data/lib/spree/testing_support/common_rake.rb +3 -7
- data/lib/spree/testing_support/controller_requests.rb +8 -0
- data/lib/spree/testing_support/factories/order_factory.rb +30 -8
- data/lib/spree/testing_support/factories/payment_factory.rb +1 -1
- data/lib/spree/testing_support/factories/product_factory.rb +6 -0
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -0
- data/lib/tasks/migrations/copy_shipped_shipments_to_cartons.rake +3 -1
- data/solidus_core.gemspec +3 -3
- data/spec/helpers/base_helper_spec.rb +18 -2
- data/spec/lib/i18n_spec.rb +4 -0
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +16 -4
- data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +75 -59
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +1 -1
- data/spec/lib/spree/core/importer/order_spec.rb +4 -2
- data/spec/lib/spree/core/stock_configuration_spec.rb +17 -0
- data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +195 -0
- data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +6 -0
- data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +6 -0
- data/spec/lib/spree/migrations_spec.rb +3 -9
- data/spec/lib/tasks/migrations/copy_shipped_shipments_to_cartons_spec.rb +1 -1
- data/spec/mailers/carton_mailer_spec.rb +1 -1
- data/spec/mailers/order_mailer_spec.rb +2 -2
- data/spec/mailers/reimbursement_mailer_spec.rb +1 -1
- data/spec/models/spree/address_spec.rb +22 -0
- data/spec/models/spree/adjustment_spec.rb +0 -10
- data/spec/models/spree/carton_spec.rb +1 -1
- data/spec/models/spree/country_spec.rb +9 -1
- data/spec/models/spree/gateway/bogus_spec.rb +1 -1
- data/spec/models/spree/item_adjustments_spec.rb +33 -0
- data/spec/models/spree/line_item_spec.rb +2 -21
- data/spec/models/spree/order/checkout_spec.rb +32 -45
- data/spec/models/spree/order/payment_spec.rb +1 -16
- data/spec/models/spree/order_cancellations_spec.rb +8 -3
- data/spec/models/spree/order_contents_spec.rb +48 -0
- data/spec/models/spree/order_merger_spec.rb +8 -5
- data/spec/models/spree/order_shipping_spec.rb +3 -4
- data/spec/models/spree/order_spec.rb +23 -59
- data/spec/models/spree/order_update_attributes_spec.rb +1 -5
- data/spec/models/spree/order_updater_spec.rb +39 -11
- data/spec/models/spree/payment_create_spec.rb +61 -0
- data/spec/models/spree/payment_method/store_credit_spec.rb +23 -10
- data/spec/models/spree/payment_spec.rb +17 -4
- data/spec/models/spree/product_spec.rb +1 -1
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +8 -13
- data/spec/models/spree/promotion/rules/product_spec.rb +33 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +52 -8
- data/spec/models/spree/promotion_spec.rb +18 -12
- data/spec/models/spree/return_authorization_spec.rb +0 -16
- data/spec/models/spree/shipment_spec.rb +57 -36
- data/spec/models/spree/stock/coordinator_spec.rb +0 -5
- data/spec/models/spree/stock/package_spec.rb +0 -1
- data/spec/models/spree/stock_item_spec.rb +35 -145
- data/spec/models/spree/store_spec.rb +24 -10
- data/spec/models/spree/tax_rate_spec.rb +2 -2
- data/spec/models/spree/user_spec.rb +1 -1
- data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +20 -12
- data/spec/support/concerns/working_factories.rb +4 -0
- metadata +30 -10
- data/config/routes.rb +0 -1
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
class FakeController < ApplicationController
|
|
4
|
-
include Spree::Core::ControllerHelpers::PaymentParameters
|
|
5
|
-
end
|
|
6
|
-
|
|
7
3
|
describe Spree::Core::ControllerHelpers::PaymentParameters, type: :controller do
|
|
8
|
-
controller(
|
|
4
|
+
controller(ApplicationController) do
|
|
5
|
+
include Spree::Core::ControllerHelpers::PaymentParameters
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
let(:params_hash) { subject.permit!.to_h.deep_symbolize_keys }
|
|
9
|
+
|
|
10
|
+
shared_examples "unpermitted params" do
|
|
11
|
+
it "is unpermitted ActionController::Parameters" do
|
|
12
|
+
expect(subject).to be_a(ActionController::Parameters)
|
|
13
|
+
expect(subject).not_to be_permitted
|
|
14
|
+
expect(subject.to_h).to eq({})
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
shared_examples "unchanged params" do
|
|
19
|
+
let!(:original_param_hash) { params.dup.permit!.to_h.deep_symbolize_keys }
|
|
20
|
+
|
|
21
|
+
it 'returns the original hash' do
|
|
22
|
+
expect(params_hash).to eq(original_param_hash)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it_behaves_like "unpermitted params"
|
|
26
|
+
end
|
|
9
27
|
|
|
10
28
|
describe '#move_payment_source_into_payments_attributes' do
|
|
11
29
|
subject do
|
|
@@ -36,45 +54,45 @@ describe Spree::Core::ControllerHelpers::PaymentParameters, type: :controller do
|
|
|
36
54
|
let(:credit_card_2_params) { attributes_for(:credit_card, name: 'Jordan2') }
|
|
37
55
|
|
|
38
56
|
it 'produces the expected hash' do
|
|
39
|
-
expect(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
other_param: 2
|
|
51
|
-
)
|
|
57
|
+
expect(params_hash).to eq(
|
|
58
|
+
order: {
|
|
59
|
+
payments_attributes: [
|
|
60
|
+
{
|
|
61
|
+
payment_method_id: payment_method_1.id.to_s,
|
|
62
|
+
source_attributes: credit_card_1_params
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
other_order_param: 1
|
|
66
|
+
},
|
|
67
|
+
other_param: 2
|
|
52
68
|
)
|
|
53
69
|
end
|
|
54
70
|
|
|
71
|
+
it_behaves_like "unpermitted params"
|
|
72
|
+
|
|
55
73
|
context 'when payment_source is missing' do
|
|
56
74
|
before { params.delete(:payment_source) }
|
|
57
|
-
|
|
75
|
+
it_behaves_like "unchanged params"
|
|
58
76
|
end
|
|
59
77
|
|
|
60
78
|
context 'when order params are missing' do
|
|
61
79
|
before { params.delete(:order) }
|
|
62
|
-
|
|
80
|
+
it_behaves_like "unchanged params"
|
|
63
81
|
end
|
|
64
82
|
|
|
65
83
|
context 'when payment_attributes are missing' do
|
|
66
84
|
before { params[:order].delete(:payments_attributes) }
|
|
67
|
-
|
|
85
|
+
it_behaves_like "unchanged params"
|
|
68
86
|
end
|
|
69
87
|
|
|
70
88
|
context 'when the payment_method_id is missing' do
|
|
71
89
|
before { params[:order][:payments_attributes][0].delete(:payment_method_id) }
|
|
72
|
-
|
|
90
|
+
it_behaves_like "unchanged params"
|
|
73
91
|
end
|
|
74
92
|
|
|
75
93
|
context 'when the payment_method_id does not match a payments source' do
|
|
76
94
|
before { params[:order][:payments_attributes][0][:payment_method_id] = -1 }
|
|
77
|
-
|
|
95
|
+
it_behaves_like "unchanged params"
|
|
78
96
|
end
|
|
79
97
|
end
|
|
80
98
|
|
|
@@ -95,14 +113,35 @@ describe Spree::Core::ControllerHelpers::PaymentParameters, type: :controller do
|
|
|
95
113
|
end
|
|
96
114
|
|
|
97
115
|
it 'produces the expected hash' do
|
|
98
|
-
expect(
|
|
99
|
-
|
|
116
|
+
expect(params_hash).to eq(
|
|
117
|
+
order: {
|
|
118
|
+
payments_attributes: [
|
|
119
|
+
{
|
|
120
|
+
source_attributes: {
|
|
121
|
+
existing_card_id: '123',
|
|
122
|
+
verification_value: '456'
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
other_order_param: 1
|
|
127
|
+
},
|
|
128
|
+
other_param: 2
|
|
129
|
+
)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it_behaves_like "unpermitted params"
|
|
133
|
+
|
|
134
|
+
context 'when cvc_confirm is missing' do
|
|
135
|
+
before { params.delete(:cvc_confirm) }
|
|
136
|
+
|
|
137
|
+
it 'produces the expected hash' do
|
|
138
|
+
expect(params_hash).to eq(
|
|
100
139
|
order: {
|
|
101
140
|
payments_attributes: [
|
|
102
141
|
{
|
|
103
142
|
source_attributes: {
|
|
104
143
|
existing_card_id: '123',
|
|
105
|
-
verification_value:
|
|
144
|
+
verification_value: nil
|
|
106
145
|
}
|
|
107
146
|
}
|
|
108
147
|
],
|
|
@@ -110,40 +149,19 @@ describe Spree::Core::ControllerHelpers::PaymentParameters, type: :controller do
|
|
|
110
149
|
},
|
|
111
150
|
other_param: 2
|
|
112
151
|
)
|
|
113
|
-
)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
context 'when cvc_confirm is missing' do
|
|
117
|
-
before { params.delete(:cvc_confirm) }
|
|
118
|
-
|
|
119
|
-
it 'produces the expected hash' do
|
|
120
|
-
expect(subject).to eq(
|
|
121
|
-
ActionController::Parameters.new(
|
|
122
|
-
order: {
|
|
123
|
-
payments_attributes: [
|
|
124
|
-
{
|
|
125
|
-
source_attributes: {
|
|
126
|
-
existing_card_id: '123',
|
|
127
|
-
verification_value: nil
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
],
|
|
131
|
-
other_order_param: 1
|
|
132
|
-
},
|
|
133
|
-
other_param: 2
|
|
134
|
-
)
|
|
135
|
-
)
|
|
136
152
|
end
|
|
153
|
+
|
|
154
|
+
it_behaves_like "unpermitted params"
|
|
137
155
|
end
|
|
138
156
|
|
|
139
157
|
context 'when order params are missing' do
|
|
140
158
|
before { params.delete(:order) }
|
|
141
|
-
|
|
159
|
+
it_behaves_like "unchanged params"
|
|
142
160
|
end
|
|
143
161
|
|
|
144
162
|
context 'when existing_card is missing' do
|
|
145
163
|
before { params[:order].delete(:existing_card) }
|
|
146
|
-
|
|
164
|
+
it_behaves_like "unchanged params"
|
|
147
165
|
end
|
|
148
166
|
end
|
|
149
167
|
|
|
@@ -164,14 +182,12 @@ describe Spree::Core::ControllerHelpers::PaymentParameters, type: :controller do
|
|
|
164
182
|
let(:order) { create(:order_with_line_items, line_items_price: 101.00, line_items_count: 1, shipment_cost: 0) }
|
|
165
183
|
|
|
166
184
|
it 'produces the expected hash' do
|
|
167
|
-
expect(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
other_param: 2
|
|
174
|
-
)
|
|
185
|
+
expect(params_hash).to eq(
|
|
186
|
+
order: {
|
|
187
|
+
payments_attributes: [{ amount: 101 }],
|
|
188
|
+
other_order_param: 1
|
|
189
|
+
},
|
|
190
|
+
other_param: 2
|
|
175
191
|
)
|
|
176
192
|
end
|
|
177
193
|
end
|
|
@@ -123,8 +123,10 @@ module Spree
|
|
|
123
123
|
params = { line_items_attributes: line_items }
|
|
124
124
|
|
|
125
125
|
expect {
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
Spree::Deprecation.silence do
|
|
127
|
+
Importer::Order.import(user, params)
|
|
128
|
+
end
|
|
129
|
+
}.to raise_exception ActiveRecord::RecordInvalid
|
|
128
130
|
end
|
|
129
131
|
|
|
130
132
|
it 'can build an order from API with variant sku' do
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
RSpec.describe Spree::Core::StockConfiguration do
|
|
4
|
+
describe '#coordinator_class' do
|
|
5
|
+
let(:stock_configuration) { described_class.new }
|
|
6
|
+
subject { stock_configuration.coordinator_class }
|
|
7
|
+
|
|
8
|
+
it "returns Spree::Stock::Coordinator" do
|
|
9
|
+
is_expected.to be ::Spree::Stock::Coordinator
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "with another constant name assiged" do
|
|
13
|
+
MyCoordinator = Class.new
|
|
14
|
+
before { stock_configuration.coordinator_class = MyCoordinator.to_s }
|
|
15
|
+
|
|
16
|
+
it "returns the constant" do
|
|
17
|
+
is_expected.to be MyCoordinator
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
4
21
|
describe '#estimator_class' do
|
|
5
22
|
let(:stock_configuration) { described_class.new }
|
|
6
23
|
subject { stock_configuration.estimator_class }
|
|
@@ -8,41 +8,236 @@ RSpec.describe 'order factory' do
|
|
|
8
8
|
let(:factory) { :order }
|
|
9
9
|
|
|
10
10
|
it_behaves_like 'a working factory'
|
|
11
|
+
|
|
12
|
+
it "has the expected attributes" do
|
|
13
|
+
order = create(factory)
|
|
14
|
+
aggregate_failures do
|
|
15
|
+
expect(order.bill_address).to be_present
|
|
16
|
+
expect(order.ship_address).to be_present
|
|
17
|
+
expect(order.user).to be_present
|
|
18
|
+
expect(order.email).to be_present
|
|
19
|
+
expect(order.email).to eq(order.user.email)
|
|
20
|
+
expect(order.state).to eq "cart"
|
|
21
|
+
expect(order.store).to be_present
|
|
22
|
+
expect(order).not_to be_completed
|
|
23
|
+
end
|
|
24
|
+
end
|
|
11
25
|
end
|
|
12
26
|
|
|
13
27
|
describe 'order with totals' do
|
|
14
28
|
let(:factory) { :order_with_totals }
|
|
15
29
|
|
|
16
30
|
it_behaves_like 'a working factory'
|
|
31
|
+
|
|
32
|
+
it "has the expected attributes" do
|
|
33
|
+
order = create(factory)
|
|
34
|
+
aggregate_failures do
|
|
35
|
+
# This factory is terrbily named
|
|
36
|
+
expect(order.total).to eq 0
|
|
37
|
+
expect(order.line_items.count).to eq 1
|
|
38
|
+
end
|
|
39
|
+
end
|
|
17
40
|
end
|
|
18
41
|
|
|
19
42
|
describe 'order with line items' do
|
|
20
43
|
let(:factory) { :order_with_line_items }
|
|
21
44
|
|
|
22
45
|
it_behaves_like 'a working factory'
|
|
46
|
+
|
|
47
|
+
it "has the expected attributes" do
|
|
48
|
+
order = create(factory)
|
|
49
|
+
aggregate_failures do
|
|
50
|
+
expect(order.line_items.count).to eq 1
|
|
51
|
+
expect(order.line_items[0]).to have_attributes(
|
|
52
|
+
quantity: 1,
|
|
53
|
+
price: 10
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
expect(order.shipments.count).to eq 1
|
|
57
|
+
expect(order.shipments[0]).to have_attributes(
|
|
58
|
+
amount: 100
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
expect(order.shipments[0].inventory_units.count).to eq(1)
|
|
62
|
+
expect(order.shipments[0].inventory_units[0]).to have_attributes(
|
|
63
|
+
order: order,
|
|
64
|
+
shipment: order.shipments[0],
|
|
65
|
+
line_item: order.line_items[0],
|
|
66
|
+
variant: order.line_items[0].variant,
|
|
67
|
+
state: 'on_hand'
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
expect(order).to have_attributes(
|
|
71
|
+
item_total: 10,
|
|
72
|
+
ship_total: 100,
|
|
73
|
+
total: 110,
|
|
74
|
+
state: 'cart' # this isn't realistic
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe 'order ready to complete' do
|
|
81
|
+
let(:factory) { :order_ready_to_complete }
|
|
82
|
+
|
|
83
|
+
it_behaves_like 'a working factory'
|
|
84
|
+
|
|
85
|
+
it "is completable" do
|
|
86
|
+
order = create(factory)
|
|
87
|
+
|
|
88
|
+
expect { order.complete! }.to change {
|
|
89
|
+
order.complete?
|
|
90
|
+
}.from(false).to(true)
|
|
91
|
+
end
|
|
23
92
|
end
|
|
24
93
|
|
|
25
94
|
describe 'completed order with totals' do
|
|
26
95
|
let(:factory) { :completed_order_with_totals }
|
|
27
96
|
|
|
28
97
|
it_behaves_like 'a working factory'
|
|
98
|
+
|
|
99
|
+
it "has the expected attributes" do
|
|
100
|
+
order = create(factory)
|
|
101
|
+
aggregate_failures do
|
|
102
|
+
expect(order).to be_completed
|
|
103
|
+
expect(order).to have_attributes(
|
|
104
|
+
item_total: 10,
|
|
105
|
+
ship_total: 100,
|
|
106
|
+
total: 110,
|
|
107
|
+
state: 'complete'
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
29
111
|
end
|
|
30
112
|
|
|
31
113
|
describe 'completed order with pending payment' do
|
|
32
114
|
let(:factory) { :completed_order_with_pending_payment }
|
|
33
115
|
|
|
34
116
|
it_behaves_like 'a working factory'
|
|
117
|
+
|
|
118
|
+
it "has the expected attributes" do
|
|
119
|
+
order = create(factory)
|
|
120
|
+
aggregate_failures do
|
|
121
|
+
expect(order).to be_completed
|
|
122
|
+
expect(order).to have_attributes(
|
|
123
|
+
payment_state: 'balance_due',
|
|
124
|
+
total: 110,
|
|
125
|
+
payment_total: 0 # payment is still pending
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
expect(order.payments.count).to eq 1
|
|
129
|
+
expect(order.payments[0]).to have_attributes(
|
|
130
|
+
amount: 110,
|
|
131
|
+
state: 'pending'
|
|
132
|
+
)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
35
135
|
end
|
|
36
136
|
|
|
37
137
|
describe 'order ready to ship' do
|
|
38
138
|
let(:factory) { :order_ready_to_ship }
|
|
39
139
|
|
|
40
140
|
it_behaves_like 'a working factory'
|
|
141
|
+
|
|
142
|
+
it "has the expected attributes" do
|
|
143
|
+
order = create(factory)
|
|
144
|
+
aggregate_failures do
|
|
145
|
+
expect(order).to be_completed
|
|
146
|
+
expect(order).to have_attributes(
|
|
147
|
+
total: 110,
|
|
148
|
+
payment_total: 110,
|
|
149
|
+
payment_state: "paid",
|
|
150
|
+
shipment_state: "ready"
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
expect(order.payments.count).to eq 1
|
|
154
|
+
expect(order.payments[0]).to have_attributes(
|
|
155
|
+
amount: 110,
|
|
156
|
+
state: 'completed'
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
expect(order.shipments.count).to eq 1
|
|
160
|
+
expect(order.shipments[0]).to have_attributes(
|
|
161
|
+
state: 'ready'
|
|
162
|
+
)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
it "can be shipped" do
|
|
167
|
+
order = create(factory)
|
|
168
|
+
order.shipments[0].ship
|
|
169
|
+
aggregate_failures do
|
|
170
|
+
expect(order.shipment_state).to eq "shipped"
|
|
171
|
+
expect(order.shipments[0]).to be_shipped
|
|
172
|
+
end
|
|
173
|
+
end
|
|
41
174
|
end
|
|
42
175
|
|
|
43
176
|
describe 'shipped order' do
|
|
44
177
|
let(:factory) { :shipped_order }
|
|
45
178
|
|
|
46
179
|
it_behaves_like 'a working factory'
|
|
180
|
+
|
|
181
|
+
it "has the expected attributes" do
|
|
182
|
+
order = create(factory)
|
|
183
|
+
aggregate_failures do
|
|
184
|
+
expect(order).to be_completed
|
|
185
|
+
expect(order).to have_attributes(
|
|
186
|
+
total: 110,
|
|
187
|
+
payment_total: 110,
|
|
188
|
+
payment_state: "paid"
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
expect(order.payments.count).to eq 1
|
|
192
|
+
expect(order.payments[0]).to have_attributes(
|
|
193
|
+
amount: 110,
|
|
194
|
+
state: 'completed'
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
expect(order.shipments.count).to eq 1
|
|
198
|
+
expect(order.shipments[0]).to have_attributes(
|
|
199
|
+
state: 'shipped'
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
expect(order.cartons.count).to eq 1
|
|
203
|
+
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
describe 'completed order with promotion' do
|
|
208
|
+
let(:factory) { :completed_order_with_promotion }
|
|
209
|
+
|
|
210
|
+
it_behaves_like 'a working factory'
|
|
211
|
+
|
|
212
|
+
it "has the expected attributes" do
|
|
213
|
+
order = create(factory)
|
|
214
|
+
aggregate_failures do
|
|
215
|
+
expect(order).to be_completed
|
|
216
|
+
expect(order).to be_complete
|
|
217
|
+
|
|
218
|
+
expect(order.order_promotions.count).to eq(1)
|
|
219
|
+
order_promotion = order.order_promotions[0]
|
|
220
|
+
expect(order_promotion.promotion_code.promotion).to eq order_promotion.promotion
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
context 'with a promotion with an action' do
|
|
225
|
+
let(:promotion) { create(:promotion, :with_line_item_adjustment) }
|
|
226
|
+
it "has the expected attributes" do
|
|
227
|
+
order = create(factory, promotion: promotion)
|
|
228
|
+
aggregate_failures do
|
|
229
|
+
expect(order).to be_completed
|
|
230
|
+
expect(order).to be_complete
|
|
231
|
+
|
|
232
|
+
expect(order.line_items[0].adjustments.count).to eq 1
|
|
233
|
+
adjustment = order.line_items[0].adjustments[0]
|
|
234
|
+
expect(adjustment).to have_attributes(
|
|
235
|
+
amount: -10,
|
|
236
|
+
eligible: true,
|
|
237
|
+
order_id: order.id
|
|
238
|
+
)
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
47
242
|
end
|
|
48
243
|
end
|
|
@@ -8,6 +8,12 @@ RSpec.describe 'payment factory' do
|
|
|
8
8
|
let(:factory) { :payment }
|
|
9
9
|
|
|
10
10
|
it_behaves_like 'a working factory'
|
|
11
|
+
|
|
12
|
+
it "assigns the Order's user to the created Credit Card" do
|
|
13
|
+
payment = create(factory)
|
|
14
|
+
expect(payment.source.user).to be_present
|
|
15
|
+
expect(payment.source.user).to eq payment.order.user
|
|
16
|
+
end
|
|
11
17
|
end
|
|
12
18
|
|
|
13
19
|
describe 'check payment' do
|
|
@@ -12,24 +12,18 @@ module Spree
|
|
|
12
12
|
|
|
13
13
|
subject { described_class.new(config, "spree") }
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
expect(File).to receive(:directory?).with(app_dir).and_return true
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "warns about missing migrations" do
|
|
15
|
+
it "detects missing migrations" do
|
|
20
16
|
expect(Dir).to receive(:entries).with(app_dir).and_return app_migrations
|
|
21
17
|
expect(Dir).to receive(:entries).with(engine_dir).and_return engine_migrations
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
expect(subject.check).to eq true
|
|
25
|
-
}
|
|
19
|
+
expect(subject.missing_migrations.size).to eq 2
|
|
26
20
|
end
|
|
27
21
|
|
|
28
22
|
context "no missing migrations" do
|
|
29
23
|
it "says nothing" do
|
|
30
24
|
expect(Dir).to receive(:entries).with(engine_dir).and_return engine_migrations
|
|
31
25
|
expect(Dir).to receive(:entries).with(app_dir).and_return(app_migrations + engine_migrations)
|
|
32
|
-
expect(subject.
|
|
26
|
+
expect(subject.missing_migrations.size).to eq 0
|
|
33
27
|
end
|
|
34
28
|
end
|
|
35
29
|
end
|
|
@@ -49,7 +49,7 @@ describe 'spree:migrations:copy_shipped_shipments_to_cartons' do
|
|
|
49
49
|
|
|
50
50
|
expect(carton.number).to eq "C#{shipped_shipment.number}"
|
|
51
51
|
expect(carton.stock_location).to eq shipped_shipment.stock_location
|
|
52
|
-
expect(carton.address).to eq shipped_shipment.
|
|
52
|
+
expect(carton.address).to eq shipped_shipment.order.ship_address
|
|
53
53
|
expect(carton.shipping_method).to eq shipped_shipment.shipping_method
|
|
54
54
|
expect(carton.tracking).to eq shipped_shipment.tracking
|
|
55
55
|
expect(carton.shipped_at).to eq shipped_shipment.shipped_at
|
|
@@ -18,7 +18,7 @@ describe Spree::CartonMailer do
|
|
|
18
18
|
|
|
19
19
|
context "deprecated signature" do
|
|
20
20
|
it do
|
|
21
|
-
|
|
21
|
+
Spree::Deprecation.silence do
|
|
22
22
|
mail = Spree::CartonMailer.shipped_email(carton.id)
|
|
23
23
|
expect(mail.subject).to include "Shipment Notification"
|
|
24
24
|
end
|
|
@@ -30,14 +30,14 @@ describe Spree::OrderMailer, type: :mailer do
|
|
|
30
30
|
|
|
31
31
|
it "confirm_email accepts an order id as an alternative to an Order object" do
|
|
32
32
|
expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
|
|
33
|
-
|
|
33
|
+
Spree::Deprecation.silence do
|
|
34
34
|
Spree::OrderMailer.confirm_email(order.id).body
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
it "cancel_email accepts an order id as an alternative to an Order object" do
|
|
39
39
|
expect(Spree::Order).to receive(:find).with(order.id).and_return(order)
|
|
40
|
-
|
|
40
|
+
Spree::Deprecation.silence do
|
|
41
41
|
Spree::OrderMailer.cancel_email(order.id).body
|
|
42
42
|
end
|
|
43
43
|
end
|
|
@@ -30,7 +30,7 @@ describe Spree::ReimbursementMailer, type: :mailer do
|
|
|
30
30
|
|
|
31
31
|
specify do
|
|
32
32
|
reimbursement_email = Spree::ReimbursementMailer.reimbursement_email(reimbursement)
|
|
33
|
-
expect(reimbursement_email
|
|
33
|
+
expect(reimbursement_email).to have_body_text("Caro Cliente,")
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|
|
@@ -308,6 +308,28 @@ describe Spree::Address, type: :model do
|
|
|
308
308
|
end
|
|
309
309
|
end
|
|
310
310
|
|
|
311
|
+
describe '.taxation_attributes' do
|
|
312
|
+
context 'both taxation and non-taxation attributes are present ' do
|
|
313
|
+
let(:address) { stub_model(Spree::Address, firstname: 'Michael', lastname: 'Jackson', state_id: 1, country_id: 2, zipcode: '12345') }
|
|
314
|
+
|
|
315
|
+
it 'removes the non-taxation attributes' do
|
|
316
|
+
expect(address.taxation_attributes).not_to eq('firstname' => 'Michael', 'lastname' => 'Jackson')
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
it 'returns only the taxation attributes' do
|
|
320
|
+
expect(address.taxation_attributes).to eq('state_id' => 1, 'country_id' => 2, 'zipcode' => '12345')
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
context 'taxation attributes are blank' do
|
|
325
|
+
let(:address) { stub_model(Spree::Address, firstname: 'Michael', lastname: 'Jackson') }
|
|
326
|
+
|
|
327
|
+
it 'returns a subset of the attributes with the correct keys and nil values' do
|
|
328
|
+
expect(address.taxation_attributes).to eq('state_id' => nil, 'country_id' => nil, 'zipcode' => nil)
|
|
329
|
+
end
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
|
|
311
333
|
context '#country_iso=' do
|
|
312
334
|
let(:address) { build(:address, country_id: nil) }
|
|
313
335
|
let(:country) { create(:country, iso: 'ZW') }
|
|
@@ -10,16 +10,6 @@ describe Spree::Adjustment, type: :model do
|
|
|
10
10
|
|
|
11
11
|
let(:adjustment) { Spree::Adjustment.create!(label: 'Adjustment', adjustable: order, order: order, amount: 5) }
|
|
12
12
|
|
|
13
|
-
context '#create & #destroy' do
|
|
14
|
-
let(:adjustment) { Spree::Adjustment.new(label: "Adjustment", amount: 5, order: order, adjustable: line_item) }
|
|
15
|
-
|
|
16
|
-
it 'calls #update_adjustable_adjustment_total' do
|
|
17
|
-
expect(adjustment).to receive(:update_adjustable_adjustment_total).twice
|
|
18
|
-
adjustment.save
|
|
19
|
-
adjustment.destroy
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
13
|
context '#save' do
|
|
24
14
|
let(:adjustment) { Spree::Adjustment.create(label: "Adjustment", amount: 5, order: order, adjustable: line_item) }
|
|
25
15
|
|
|
@@ -57,7 +57,7 @@ describe Spree::Carton do
|
|
|
57
57
|
subject { carton.shipment_numbers }
|
|
58
58
|
let(:shipment) { carton.shipments.first }
|
|
59
59
|
|
|
60
|
-
it "returns a list of the
|
|
60
|
+
it "returns a list of the shipment numbers it is associated to" do
|
|
61
61
|
expect(subject).to eq [shipment.number]
|
|
62
62
|
end
|
|
63
63
|
end
|
|
@@ -14,8 +14,12 @@ describe Spree::Country, type: :model do
|
|
|
14
14
|
Spree::Config[:default_country_id] = 2
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
+
subject(:default_country) do
|
|
18
|
+
Spree::Deprecation.silence { described_class.default }
|
|
19
|
+
end
|
|
20
|
+
|
|
17
21
|
it 'emits a deprecation warning' do
|
|
18
|
-
expect(
|
|
22
|
+
expect(Spree::Deprecation).to receive(:warn)
|
|
19
23
|
default_country
|
|
20
24
|
end
|
|
21
25
|
|
|
@@ -29,6 +33,10 @@ describe Spree::Country, type: :model do
|
|
|
29
33
|
Spree::Config[:default_country_id] = 0
|
|
30
34
|
end
|
|
31
35
|
|
|
36
|
+
subject(:default_country) do
|
|
37
|
+
Spree::Deprecation.silence { described_class.default }
|
|
38
|
+
end
|
|
39
|
+
|
|
32
40
|
it 'loads the country configured by the ISO code' do
|
|
33
41
|
expect(default_country).to eq(Spree::Country.find(2))
|
|
34
42
|
end
|
|
@@ -6,7 +6,7 @@ module Spree
|
|
|
6
6
|
let!(:cc) { create(:credit_card, payment_method: bogus, gateway_customer_profile_id: "BGS-RERTERT") }
|
|
7
7
|
|
|
8
8
|
it "disable recurring contract by destroying payment source" do
|
|
9
|
-
|
|
9
|
+
Spree::Deprecation.silence do
|
|
10
10
|
bogus.disable_customer_profile(cc)
|
|
11
11
|
end
|
|
12
12
|
expect(cc.gateway_customer_profile_id).to be_nil
|