solidus_core 1.3.2 → 1.4.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -0
  3. data/app/helpers/spree/base_helper.rb +6 -2
  4. data/app/mailers/spree/base_mailer.rb +1 -1
  5. data/app/mailers/spree/carton_mailer.rb +1 -1
  6. data/app/mailers/spree/order_mailer.rb +2 -2
  7. data/app/mailers/spree/reimbursement_mailer.rb +7 -7
  8. data/app/mailers/spree/test_mailer.rb +3 -2
  9. data/app/models/concerns/spree/user_payment_source.rb +1 -1
  10. data/app/models/spree/address.rb +14 -4
  11. data/app/models/spree/adjustment.rb +11 -19
  12. data/app/models/spree/app_configuration.rb +23 -1
  13. data/app/models/spree/base.rb +9 -0
  14. data/app/models/spree/country.rb +2 -2
  15. data/app/models/spree/exchange.rb +1 -1
  16. data/app/models/spree/gateway.rb +1 -1
  17. data/app/models/spree/item_adjustments.rb +7 -0
  18. data/app/models/spree/line_item.rb +1 -13
  19. data/app/models/spree/order/checkout.rb +19 -16
  20. data/app/models/spree/order/payments.rb +0 -2
  21. data/app/models/spree/order.rb +7 -21
  22. data/app/models/spree/order_contents.rb +60 -4
  23. data/app/models/spree/order_merger.rb +2 -4
  24. data/app/models/spree/order_shipping.rb +1 -1
  25. data/app/models/spree/order_update_attributes.rb +0 -2
  26. data/app/models/spree/order_updater.rb +14 -11
  27. data/app/models/spree/payment.rb +2 -3
  28. data/app/models/spree/payment_create.rb +5 -2
  29. data/app/models/spree/payment_method/store_credit.rb +6 -5
  30. data/app/models/spree/product/scopes.rb +2 -1
  31. data/app/models/spree/product.rb +2 -5
  32. data/app/models/spree/promotion/actions/create_item_adjustments.rb +5 -3
  33. data/app/models/spree/promotion/actions/free_shipping.rb +1 -1
  34. data/app/models/spree/promotion/rules/option_value.rb +2 -3
  35. data/app/models/spree/promotion/rules/product.rb +9 -3
  36. data/app/models/spree/promotion/rules/taxon.rb +33 -7
  37. data/app/models/spree/promotion/rules/user.rb +2 -3
  38. data/app/models/spree/promotion.rb +16 -6
  39. data/app/models/spree/promotion_handler/coupon.rb +1 -1
  40. data/app/models/spree/shipment.rb +12 -16
  41. data/app/models/spree/stock/estimator.rb +1 -1
  42. data/app/models/spree/stock/package.rb +0 -1
  43. data/app/models/spree/stock_item.rb +2 -6
  44. data/app/models/spree/store.rb +2 -1
  45. data/app/models/spree/tax_rate.rb +1 -1
  46. data/app/models/spree/wallet/add_payment_sources_to_wallet.rb +29 -0
  47. data/app/models/spree/wallet/default_payment_builder.rb +26 -0
  48. data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +46 -0
  49. data/app/views/spree/reimbursement_mailer/reimbursement_email.text.erb +1 -1
  50. data/app/views/spree/shared/_base_mailer_footer.html.erb +1 -20
  51. data/app/views/spree/shared/_base_mailer_header.html.erb +1 -31
  52. data/config/initializers/spree_user.rb +1 -1
  53. data/config/locales/en.yml +58 -34
  54. data/db/migrate/20130414000512_update_name_fields_on_spree_credit_cards.rb +1 -1
  55. data/db/migrate/20140601011216_set_shipment_total_for_users_upgrading.rb +15 -3
  56. data/db/migrate/20160527070401_rename_shipment_address_field.rb +7 -0
  57. data/db/migrate/20160616232103_remove_user_id_from_promotion_rules.rb +11 -0
  58. data/db/migrate/20160718205341_add_payment_id_index_to_spree_refunds.rb +5 -0
  59. data/db/migrate/20160718205859_add_reimbursement_id_index_to_spree_refunds.rb +5 -0
  60. data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
  61. data/lib/generators/spree/dummy/templates/rails/database.yml +3 -1
  62. data/lib/generators/spree/dummy/templates/rails/test.rb +4 -2
  63. data/lib/generators/spree/install/install_generator.rb +6 -16
  64. data/lib/spree/core/controller_helpers/auth.rb +1 -1
  65. data/lib/spree/core/controller_helpers/common.rb +1 -1
  66. data/lib/spree/core/controller_helpers/order.rb +2 -2
  67. data/lib/spree/core/current_store.rb +5 -1
  68. data/lib/spree/core/delegate_belongs_to.rb +1 -1
  69. data/lib/spree/core/routes.rb +6 -32
  70. data/lib/spree/core/search/base.rb +2 -2
  71. data/lib/spree/core/stock_configuration.rb +6 -0
  72. data/lib/spree/core/version.rb +2 -2
  73. data/lib/spree/core.rb +2 -1
  74. data/lib/spree/i18n.rb +7 -0
  75. data/lib/spree/mailer_previews/carton_preview.rb +2 -1
  76. data/lib/spree/mailer_previews/order_preview.rb +8 -3
  77. data/lib/spree/mailer_previews/reimbursement_preview.rb +11 -0
  78. data/lib/spree/migrations.rb +13 -7
  79. data/lib/spree/permitted_attributes.rb +1 -1
  80. data/lib/spree/testing_support/capybara_ext.rb +6 -1
  81. data/lib/spree/testing_support/common_rake.rb +3 -7
  82. data/lib/spree/testing_support/controller_requests.rb +8 -0
  83. data/lib/spree/testing_support/factories/order_factory.rb +30 -8
  84. data/lib/spree/testing_support/factories/payment_factory.rb +1 -1
  85. data/lib/spree/testing_support/factories/product_factory.rb +6 -0
  86. data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -0
  87. data/lib/tasks/migrations/copy_shipped_shipments_to_cartons.rake +3 -1
  88. data/solidus_core.gemspec +3 -3
  89. data/spec/helpers/base_helper_spec.rb +18 -2
  90. data/spec/lib/i18n_spec.rb +4 -0
  91. data/spec/lib/spree/core/controller_helpers/order_spec.rb +16 -4
  92. data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +75 -59
  93. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +1 -1
  94. data/spec/lib/spree/core/importer/order_spec.rb +4 -2
  95. data/spec/lib/spree/core/stock_configuration_spec.rb +17 -0
  96. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +195 -0
  97. data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +6 -0
  98. data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +6 -0
  99. data/spec/lib/spree/migrations_spec.rb +3 -9
  100. data/spec/lib/tasks/migrations/copy_shipped_shipments_to_cartons_spec.rb +1 -1
  101. data/spec/mailers/carton_mailer_spec.rb +1 -1
  102. data/spec/mailers/order_mailer_spec.rb +2 -2
  103. data/spec/mailers/reimbursement_mailer_spec.rb +1 -1
  104. data/spec/models/spree/address_spec.rb +22 -0
  105. data/spec/models/spree/adjustment_spec.rb +0 -10
  106. data/spec/models/spree/carton_spec.rb +1 -1
  107. data/spec/models/spree/country_spec.rb +9 -1
  108. data/spec/models/spree/gateway/bogus_spec.rb +1 -1
  109. data/spec/models/spree/item_adjustments_spec.rb +33 -0
  110. data/spec/models/spree/line_item_spec.rb +2 -21
  111. data/spec/models/spree/order/checkout_spec.rb +32 -45
  112. data/spec/models/spree/order/payment_spec.rb +1 -16
  113. data/spec/models/spree/order_cancellations_spec.rb +8 -3
  114. data/spec/models/spree/order_contents_spec.rb +48 -0
  115. data/spec/models/spree/order_merger_spec.rb +8 -5
  116. data/spec/models/spree/order_shipping_spec.rb +3 -4
  117. data/spec/models/spree/order_spec.rb +23 -59
  118. data/spec/models/spree/order_update_attributes_spec.rb +1 -5
  119. data/spec/models/spree/order_updater_spec.rb +39 -11
  120. data/spec/models/spree/payment_create_spec.rb +61 -0
  121. data/spec/models/spree/payment_method/store_credit_spec.rb +23 -10
  122. data/spec/models/spree/payment_spec.rb +17 -4
  123. data/spec/models/spree/product_spec.rb +1 -1
  124. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +8 -13
  125. data/spec/models/spree/promotion/rules/product_spec.rb +33 -0
  126. data/spec/models/spree/promotion/rules/taxon_spec.rb +52 -8
  127. data/spec/models/spree/promotion_spec.rb +18 -12
  128. data/spec/models/spree/return_authorization_spec.rb +0 -16
  129. data/spec/models/spree/shipment_spec.rb +57 -36
  130. data/spec/models/spree/stock/coordinator_spec.rb +0 -5
  131. data/spec/models/spree/stock/package_spec.rb +0 -1
  132. data/spec/models/spree/stock_item_spec.rb +35 -145
  133. data/spec/models/spree/store_spec.rb +24 -10
  134. data/spec/models/spree/tax_rate_spec.rb +2 -2
  135. data/spec/models/spree/user_spec.rb +1 -1
  136. data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +20 -12
  137. data/spec/support/concerns/working_factories.rb +4 -0
  138. metadata +30 -10
  139. 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(FakeController) {}
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(subject).to eq(
40
- ActionController::Parameters.new(
41
- order: {
42
- payments_attributes: [
43
- {
44
- payment_method_id: payment_method_1.id.to_s,
45
- source_attributes: credit_card_1_params
46
- }
47
- ],
48
- other_order_param: 1
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
- it('returns the original hash') { expect(subject).to eq(params) }
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
- it('returns the original hash') { expect(subject).to eq(params) }
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
- it('returns the original hash') { expect(subject).to eq(params) }
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
- it('returns the original hash') { expect(subject).to eq(params) }
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
- it('returns the original hash') { expect(subject).to eq(params) }
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(subject).to eq(
99
- ActionController::Parameters.new(
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: '456'
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
- it('returns the original hash') { expect(subject).to eq(params) }
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
- it('returns the original hash') { expect(subject).to eq(params) }
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(subject).to eq(
168
- ActionController::Parameters.new(
169
- order: {
170
- payments_attributes: [{ amount: 101 }],
171
- other_order_param: 1
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
@@ -8,7 +8,7 @@ module Spree
8
8
  class DelegateBelongsToStubModel < Spree::Base
9
9
  self.table_name = "spree_payment_methods"
10
10
  belongs_to :product
11
- ActiveSupport::Deprecation.silence do
11
+ Spree::Deprecation.silence do
12
12
  delegate_belongs_to :product, :name
13
13
  end
14
14
  end
@@ -123,8 +123,10 @@ module Spree
123
123
  params = { line_items_attributes: line_items }
124
124
 
125
125
  expect {
126
- Importer::Order.import(user, params)
127
- }.to raise_error /Validation failed/
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
@@ -9,4 +9,10 @@ RSpec.describe 'reimbursement factory' do
9
9
 
10
10
  it_behaves_like 'a working factory'
11
11
  end
12
+
13
+ describe 'total' do
14
+ subject { FactoryGirl.create(:reimbursement).total }
15
+
16
+ it { is_expected.to be_present }
17
+ end
12
18
  end
@@ -12,24 +12,18 @@ module Spree
12
12
 
13
13
  subject { described_class.new(config, "spree") }
14
14
 
15
- before do
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
- silence_stream(STDOUT) {
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.check).to eq nil
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.address
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
- ActiveSupport::Deprecation.silence do
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
- ActiveSupport::Deprecation.silence do
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
- ActiveSupport::Deprecation.silence do
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.body).to include("Caro Cliente,")
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 order numbers it is associated to" do
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(ActiveSupport::Deprecation).to receive(:warn)
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
- ActiveSupport::Deprecation.silence do
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