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.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/concerns/spree/ransackable_attributes.rb +6 -1
  3. data/app/models/concerns/spree/user_methods.rb +10 -0
  4. data/app/models/spree/legacy_user.rb +0 -8
  5. data/app/models/spree/order.rb +1 -1
  6. data/app/models/spree/product.rb +8 -0
  7. data/app/models/spree/product/scopes.rb +7 -3
  8. data/app/models/spree/stock_transfer.rb +1 -1
  9. data/config/locales/en.yml +2 -0
  10. data/lib/spree/core/version.rb +1 -1
  11. data/spree_core.gemspec +2 -2
  12. metadata +11 -208
  13. data/spec/fixtures/microdata.html +0 -22
  14. data/spec/fixtures/microdata_itemref.html +0 -15
  15. data/spec/fixtures/microdata_no_itemscope.html +0 -20
  16. data/spec/fixtures/thinking-cat.jpg +0 -0
  17. data/spec/helpers/base_helper_spec.rb +0 -200
  18. data/spec/helpers/products_helper_spec.rb +0 -296
  19. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  20. data/spec/lib/i18n_spec.rb +0 -123
  21. data/spec/lib/search/base_spec.rb +0 -86
  22. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  23. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  24. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  25. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  26. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  27. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  28. data/spec/lib/spree/core/importer/order_spec.rb +0 -605
  29. data/spec/lib/spree/core/number_generator_spec.rb +0 -175
  30. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  31. data/spec/lib/spree/core/validators/email_spec.rb +0 -53
  32. data/spec/lib/spree/core_spec.rb +0 -23
  33. data/spec/lib/spree/localized_number_spec.rb +0 -48
  34. data/spec/lib/spree/migrations_spec.rb +0 -36
  35. data/spec/lib/spree/money_spec.rb +0 -122
  36. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  37. data/spec/mailers/order_mailer_spec.rb +0 -122
  38. data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
  39. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  40. data/spec/mailers/test_mailer_spec.rb +0 -38
  41. data/spec/models/option_type_prototype_spec.rb +0 -9
  42. data/spec/models/spree/ability_spec.rb +0 -251
  43. data/spec/models/spree/address_spec.rb +0 -291
  44. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  45. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  46. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  47. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  48. data/spec/models/spree/adjustment_spec.rb +0 -189
  49. data/spec/models/spree/app_configuration_spec.rb +0 -26
  50. data/spec/models/spree/asset_spec.rb +0 -28
  51. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  52. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  53. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  54. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  55. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  56. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  57. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -51
  58. data/spec/models/spree/calculator/shipping.rb +0 -8
  59. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  60. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  61. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  62. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  63. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  64. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  65. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  66. data/spec/models/spree/calculator_spec.rb +0 -69
  67. data/spec/models/spree/classification_spec.rb +0 -93
  68. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  69. data/spec/models/spree/concerns/user_methods_spec.rb +0 -55
  70. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  71. data/spec/models/spree/country_spec.rb +0 -55
  72. data/spec/models/spree/credit_card_spec.rb +0 -328
  73. data/spec/models/spree/customer_return_spec.rb +0 -240
  74. data/spec/models/spree/exchange_spec.rb +0 -75
  75. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  76. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  77. data/spec/models/spree/gateway_spec.rb +0 -61
  78. data/spec/models/spree/image_spec.rb +0 -8
  79. data/spec/models/spree/inventory_unit_spec.rb +0 -225
  80. data/spec/models/spree/line_item_spec.rb +0 -327
  81. data/spec/models/spree/option_type_spec.rb +0 -14
  82. data/spec/models/spree/option_value_spec.rb +0 -18
  83. data/spec/models/spree/order/address_spec.rb +0 -50
  84. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  85. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  86. data/spec/models/spree/order/checkout_spec.rb +0 -782
  87. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  88. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  89. data/spec/models/spree/order/helpers_spec.rb +0 -5
  90. data/spec/models/spree/order/payment_spec.rb +0 -214
  91. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  92. data/spec/models/spree/order/shipments_spec.rb +0 -43
  93. data/spec/models/spree/order/state_machine_spec.rb +0 -211
  94. data/spec/models/spree/order/store_credit_spec.rb +0 -426
  95. data/spec/models/spree/order/tax_spec.rb +0 -84
  96. data/spec/models/spree/order/totals_spec.rb +0 -24
  97. data/spec/models/spree/order/updating_spec.rb +0 -18
  98. data/spec/models/spree/order/validations_spec.rb +0 -15
  99. data/spec/models/spree/order_contents_spec.rb +0 -297
  100. data/spec/models/spree/order_inventory_spec.rb +0 -238
  101. data/spec/models/spree/order_merger_spec.rb +0 -135
  102. data/spec/models/spree/order_spec.rb +0 -967
  103. data/spec/models/spree/order_updater_spec.rb +0 -305
  104. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  105. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  106. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  107. data/spec/models/spree/payment_method_spec.rb +0 -103
  108. data/spec/models/spree/payment_spec.rb +0 -919
  109. data/spec/models/spree/preference_spec.rb +0 -80
  110. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  111. data/spec/models/spree/preferences/preferable_spec.rb +0 -348
  112. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  113. data/spec/models/spree/preferences/store_spec.rb +0 -46
  114. data/spec/models/spree/price_spec.rb +0 -128
  115. data/spec/models/spree/product/scopes_spec.rb +0 -183
  116. data/spec/models/spree/product_duplicator_spec.rb +0 -103
  117. data/spec/models/spree/product_filter_spec.rb +0 -26
  118. data/spec/models/spree/product_option_type_spec.rb +0 -9
  119. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  120. data/spec/models/spree/product_property_spec.rb +0 -22
  121. data/spec/models/spree/product_spec.rb +0 -540
  122. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -50
  123. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  124. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  125. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  126. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  127. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  128. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  129. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  130. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  131. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  132. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  133. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  134. data/spec/models/spree/promotion_action_spec.rb +0 -10
  135. data/spec/models/spree/promotion_category_spec.rb +0 -17
  136. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  137. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  138. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  139. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  140. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  141. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  142. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  143. data/spec/models/spree/promotion_spec.rb +0 -644
  144. data/spec/models/spree/property_prototype_spec.rb +0 -9
  145. data/spec/models/spree/property_spec.rb +0 -5
  146. data/spec/models/spree/prototype_spec.rb +0 -5
  147. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  148. data/spec/models/spree/refund_reason_spec.rb +0 -7
  149. data/spec/models/spree/refund_spec.rb +0 -195
  150. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  151. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  152. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  153. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  154. data/spec/models/spree/reimbursement_spec.rb +0 -188
  155. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  156. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  157. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  158. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  159. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  160. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  161. data/spec/models/spree/return_authorization_spec.rb +0 -230
  162. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  163. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  164. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  165. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  166. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  167. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  168. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  169. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  170. data/spec/models/spree/return_item_spec.rb +0 -731
  171. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  172. data/spec/models/spree/role_spec.rb +0 -7
  173. data/spec/models/spree/shipment_spec.rb +0 -740
  174. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  175. data/spec/models/spree/shipping_category_spec.rb +0 -19
  176. data/spec/models/spree/shipping_method_spec.rb +0 -95
  177. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  178. data/spec/models/spree/state_spec.rb +0 -29
  179. data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
  180. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  181. data/spec/models/spree/stock/coordinator_spec.rb +0 -51
  182. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  183. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  184. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
  185. data/spec/models/spree/stock/package_spec.rb +0 -194
  186. data/spec/models/spree/stock/packer_spec.rb +0 -70
  187. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  188. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  189. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  190. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  191. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  192. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  193. data/spec/models/spree/stock_item_spec.rb +0 -428
  194. data/spec/models/spree/stock_location_spec.rb +0 -243
  195. data/spec/models/spree/stock_movement_spec.rb +0 -56
  196. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  197. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  198. data/spec/models/spree/store_credit_spec.rb +0 -786
  199. data/spec/models/spree/store_spec.rb +0 -78
  200. data/spec/models/spree/tax_category_spec.rb +0 -32
  201. data/spec/models/spree/tax_rate_spec.rb +0 -542
  202. data/spec/models/spree/taxon_spec.rb +0 -74
  203. data/spec/models/spree/taxonomy_spec.rb +0 -18
  204. data/spec/models/spree/tracker_spec.rb +0 -21
  205. data/spec/models/spree/user_spec.rb +0 -203
  206. data/spec/models/spree/variant_spec.rb +0 -795
  207. data/spec/models/spree/zone_member_spec.rb +0 -38
  208. data/spec/models/spree/zone_spec.rb +0 -470
  209. data/spec/spec_helper.rb +0 -77
  210. data/spec/support/big_decimal.rb +0 -5
  211. data/spec/support/concerns/adjustment_source.rb +0 -23
  212. data/spec/support/concerns/default_price.rb +0 -37
  213. data/spec/support/rake.rb +0 -13
  214. data/spec/support/test_gateway.rb +0 -2
  215. data/spec/validators/db_maximum_length_validator_spec.rb +0 -22
@@ -1,305 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe OrderUpdater, type: :model do
5
- let(:order) { Spree::Order.create }
6
- let(:updater) { Spree::OrderUpdater.new(order) }
7
-
8
- context "order totals" do
9
- before do
10
- 2.times do
11
- create(:line_item, order: order, price: 10)
12
- end
13
- end
14
-
15
- it "updates payment totals" do
16
- create(:payment_with_refund, order: order)
17
- Spree::OrderUpdater.new(order).update_payment_total
18
- expect(order.payment_total).to eq(40.75)
19
- end
20
-
21
- it "update item total" do
22
- updater.update_item_total
23
- expect(order.item_total).to eq(20)
24
- end
25
-
26
- it "update shipment total" do
27
- create(:shipment, order: order, cost: 10)
28
- updater.update_shipment_total
29
- expect(order.shipment_total).to eq(10)
30
- end
31
-
32
- context 'with order promotion followed by line item addition' do
33
- let(:promotion) { Spree::Promotion.create!(name: "10% off") }
34
- let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
35
-
36
- let(:promotion_action) do
37
- Promotion::Actions::CreateAdjustment.create!({
38
- calculator: calculator,
39
- promotion: promotion,
40
- })
41
- end
42
-
43
- before do
44
- updater.update
45
- create(:adjustment, source: promotion_action, adjustable: order, order: order)
46
- create(:line_item, order: order, price: 10) # in addition to the two already created
47
- updater.update
48
- end
49
-
50
- it "updates promotion total" do
51
- expect(order.promo_total).to eq(-3)
52
- end
53
- end
54
-
55
- it "update order adjustments" do
56
- # A line item will not have both additional and included tax,
57
- # so please just humour me for now.
58
- order.line_items.first.update_columns({
59
- adjustment_total: 10.05,
60
- additional_tax_total: 0.05,
61
- included_tax_total: 0.05,
62
- })
63
- updater.update_adjustment_total
64
- expect(order.adjustment_total).to eq(10.05)
65
- expect(order.additional_tax_total).to eq(0.05)
66
- expect(order.included_tax_total).to eq(0.05)
67
- end
68
- end
69
-
70
- describe "#update_with_updater!" do
71
- it "updates item count" do
72
- create(:line_item, order: order)
73
- create(:line_item, order: order)
74
-
75
- order.update_with_updater!
76
-
77
- expect(order.item_count).to eq(2)
78
- end
79
- end
80
-
81
- context "updating shipment state" do
82
- before do
83
- allow(order).to receive_messages backordered?: false
84
- allow(order).to receive_message_chain(:shipments, :shipped, :count).and_return(0)
85
- allow(order).to receive_message_chain(:shipments, :ready, :count).and_return(0)
86
- allow(order).to receive_message_chain(:shipments, :pending, :count).and_return(0)
87
- end
88
-
89
- it "is backordered" do
90
- allow(order).to receive_messages backordered?: true
91
- updater.update_shipment_state
92
-
93
- expect(order.shipment_state).to eq('backorder')
94
- end
95
-
96
- it "is nil" do
97
- allow(order).to receive_message_chain(:shipments, :states).and_return([])
98
- allow(order).to receive_message_chain(:shipments, :count).and_return(0)
99
-
100
- updater.update_shipment_state
101
- expect(order.shipment_state).to be_nil
102
- end
103
-
104
-
105
- ["shipped", "ready", "pending"].each do |state|
106
- it "is #{state}" do
107
- allow(order).to receive_message_chain(:shipments, :states).and_return([state])
108
- updater.update_shipment_state
109
- expect(order.shipment_state).to eq(state.to_s)
110
- end
111
- end
112
-
113
- it "is partial" do
114
- allow(order).to receive_message_chain(:shipments, :states).and_return(["pending", "ready"])
115
- updater.update_shipment_state
116
- expect(order.shipment_state).to eq('partial')
117
- end
118
- end
119
-
120
- context "updating payment state" do
121
- let(:order) { Order.new }
122
- let(:updater) { order.updater }
123
-
124
- it "is failed if no valid payments" do
125
- allow(order).to receive_message_chain(:payments, :valid, :size).and_return(0)
126
-
127
- updater.update_payment_state
128
- expect(order.payment_state).to eq('failed')
129
- end
130
-
131
- context "payment total is greater than order total" do
132
- it "is credit_owed" do
133
- order.payment_total = 2
134
- order.total = 1
135
-
136
- expect {
137
- updater.update_payment_state
138
- }.to change { order.payment_state }.to 'credit_owed'
139
- end
140
- end
141
-
142
- context "order total is greater than payment total" do
143
- it "is balance_due" do
144
- order.payment_total = 1
145
- order.total = 2
146
-
147
- expect {
148
- updater.update_payment_state
149
- }.to change { order.payment_state }.to 'balance_due'
150
- end
151
- end
152
-
153
- context "order total equals payment total" do
154
- it "is paid" do
155
- order.payment_total = 30
156
- order.total = 30
157
-
158
- expect {
159
- updater.update_payment_state
160
- }.to change { order.payment_state }.to 'paid'
161
- end
162
- end
163
-
164
- context "order is canceled" do
165
-
166
- before do
167
- order.state = 'canceled'
168
- end
169
-
170
- context "and is still unpaid" do
171
- it "is void" do
172
- order.payment_total = 0
173
- order.total = 30
174
- expect {
175
- updater.update_payment_state
176
- }.to change { order.payment_state }.to 'void'
177
- end
178
- end
179
-
180
- context "and is paid" do
181
-
182
- it "is credit_owed" do
183
- order.payment_total = 30
184
- order.total = 30
185
- allow(order).to receive_message_chain(:payments, :valid, :size).and_return(1)
186
- allow(order).to receive_message_chain(:payments, :completed, :size).and_return(1)
187
- expect {
188
- updater.update_payment_state
189
- }.to change { order.payment_state }.to 'credit_owed'
190
- end
191
-
192
- end
193
-
194
- context "and payment is refunded" do
195
- it "is void" do
196
- order.payment_total = 0
197
- order.total = 30
198
- expect {
199
- updater.update_payment_state
200
- }.to change { order.payment_state }.to 'void'
201
- end
202
- end
203
- end
204
-
205
- end
206
-
207
- it "state change" do
208
- order.shipment_state = 'shipped'
209
- state_changes = double
210
- allow(order).to receive_messages state_changes: state_changes
211
- expect(state_changes).to receive(:create).with(
212
- previous_state: nil,
213
- next_state: 'shipped',
214
- name: 'shipment',
215
- user_id: nil
216
- )
217
-
218
- order.state_changed('shipment')
219
- end
220
-
221
- context "completed order" do
222
- before { allow(order).to receive_messages completed?: true }
223
-
224
- describe "#update" do
225
- it "updates payment state" do
226
- expect(updater).to receive(:update_payment_state)
227
- updater.update
228
- end
229
-
230
- it "updates shipment state" do
231
- expect(updater).to receive(:update_shipment_state)
232
- updater.update
233
- end
234
-
235
- it "updates shipments total again after updating shipments" do
236
- expect(updater).to receive(:update_shipment_total).ordered
237
- expect(updater).to receive(:update_shipments).ordered
238
- expect(updater).to receive(:update_shipment_total).ordered
239
- updater.update
240
- end
241
- end
242
-
243
- describe "#update_shipments" do
244
- it "updates each shipment" do
245
- shipment = stub_model(Spree::Shipment, order: order)
246
- shipments = [shipment]
247
- allow(order).to receive_messages shipments: shipments
248
- allow(shipments).to receive_messages states: []
249
- allow(shipments).to receive_messages ready: []
250
- allow(shipments).to receive_messages pending: []
251
- allow(shipments).to receive_messages shipped: []
252
-
253
- expect(shipment).to receive(:update!).with(order)
254
- updater.update_shipments
255
- end
256
-
257
- it "refreshes shipment rates" do
258
- shipment = stub_model(Spree::Shipment, order: order)
259
- shipments = [shipment]
260
- allow(order).to receive_messages shipments: shipments
261
-
262
- expect(shipment).to receive(:refresh_rates)
263
- updater.update_shipments
264
- end
265
-
266
- it "updates the shipment amount" do
267
- shipment = stub_model(Spree::Shipment, order: order)
268
- shipments = [shipment]
269
- allow(order).to receive_messages shipments: shipments
270
-
271
- expect(shipment).to receive(:update_amounts)
272
- updater.update_shipments
273
- end
274
- end
275
- end
276
-
277
- context "incompleted order" do
278
- before { allow(order).to receive_messages completed?: false }
279
-
280
- it "doesnt update payment state" do
281
- expect(updater).not_to receive(:update_payment_state)
282
- updater.update
283
- end
284
-
285
- it "doesnt update shipment state" do
286
- expect(updater).not_to receive(:update_shipment_state)
287
- updater.update
288
- end
289
-
290
- it "doesnt update each shipment" do
291
- shipment = stub_model(Spree::Shipment)
292
- shipments = [shipment]
293
- allow(order).to receive_messages shipments: shipments
294
- allow(shipments).to receive_messages states: []
295
- allow(shipments).to receive_messages ready: []
296
- allow(shipments).to receive_messages pending: []
297
- allow(shipments).to receive_messages shipped: []
298
-
299
- allow(updater).to receive(:update_totals) # Otherwise this gets called and causes a scene
300
- expect(updater).not_to receive(:update_shipments).with(order)
301
- updater.update
302
- end
303
- end
304
- end
305
- end
@@ -1,127 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe Spree::Payment::GatewayOptions, type: :model do
4
- let(:options) { Spree::Payment::GatewayOptions.new(payment) }
5
-
6
- let(:payment) do
7
- double(
8
- Spree::Payment,
9
- order: order,
10
- number: "P1566",
11
- currency: "EUR",
12
- payment_method: payment_method
13
- )
14
- end
15
-
16
- let(:payment_method) do
17
- double(
18
- Spree::Gateway::Bogus,
19
- exchange_multiplier: Spree::Gateway::FROM_DOLLAR_TO_CENT_RATE
20
- )
21
- end
22
-
23
- let(:order) do
24
- double(
25
- Spree::Order,
26
- email: "test@email.com",
27
- user_id: 144,
28
- last_ip_address: "0.0.0.0",
29
- number: "R1444",
30
- ship_total: "12.44".to_d,
31
- additional_tax_total: "1.53".to_d,
32
- item_total: "15.11".to_d,
33
- promo_total: "2.57".to_d,
34
- bill_address: bill_address,
35
- ship_address: ship_address
36
- )
37
- end
38
-
39
- let(:bill_address) do
40
- double Spree::Address, active_merchant_hash: { bill: :address }
41
- end
42
-
43
- let(:ship_address) do
44
- double Spree::Address, active_merchant_hash: { ship: :address }
45
- end
46
-
47
- describe "#email" do
48
- subject { options.email }
49
- it { should == "test@email.com" }
50
- end
51
-
52
- describe "#customer" do
53
- subject { options.customer }
54
- it { should == "test@email.com" }
55
- end
56
-
57
- describe "#customer_id" do
58
- subject { options.customer_id }
59
- it { should == 144 }
60
- end
61
-
62
- describe "#ip" do
63
- subject { options.ip }
64
- it { should == "0.0.0.0" }
65
- end
66
-
67
- describe "#order_id" do
68
- subject { options.order_id }
69
- it { should == "R1444-P1566" }
70
- end
71
-
72
- describe "#shipping" do
73
- subject { options.shipping }
74
- it { should == 1244 }
75
- end
76
-
77
- describe "#tax" do
78
- subject { options.tax }
79
- it { should == 153 }
80
- end
81
-
82
- describe "#subtotal" do
83
- subject { options.subtotal }
84
- it { should == 1511 }
85
- end
86
-
87
- describe "#discount" do
88
- subject { options.discount }
89
- it { should == 257 }
90
- end
91
-
92
- describe "#currency" do
93
- subject { options.currency }
94
- it { should == "EUR" }
95
- end
96
-
97
- describe "#billing_address" do
98
- subject { options.billing_address }
99
- it { should == { bill: :address } }
100
- end
101
-
102
- describe "#shipping_address" do
103
- subject { options.shipping_address }
104
- it { should == { ship: :address } }
105
- end
106
-
107
- describe "#to_hash" do
108
- subject { options.to_hash }
109
- let(:expected) do
110
- {
111
- email: "test@email.com",
112
- customer: "test@email.com",
113
- customer_id: 144,
114
- ip: "0.0.0.0",
115
- order_id: "R1444-P1566",
116
- shipping: "1244".to_d,
117
- tax: "153".to_d,
118
- subtotal: "1511".to_d,
119
- discount: "257".to_d,
120
- currency: "EUR",
121
- billing_address: { bill: :address },
122
- shipping_address: { ship: :address }
123
- }
124
- end
125
- it { should == expected }
126
- end
127
- end
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'Payment' do
4
- context '#cancel!' do
5
- subject { payment.cancel! }
6
-
7
- context 'a store credit' do
8
- let(:store_credit) { create(:store_credit, amount_used: captured_amount) }
9
- let(:auth_code) { '1-SC-20141111111111' }
10
- let(:captured_amount) { 10.0 }
11
- let(:payment) { create(:store_credit_payment, response_code: auth_code) }
12
-
13
- let!(:capture_event) do
14
- create(:store_credit_auth_event,
15
- action: Spree::StoreCredit::CAPTURE_ACTION,
16
- authorization_code: auth_code,
17
- amount: captured_amount,
18
- store_credit: store_credit)
19
- end
20
-
21
- let(:successful_response) do
22
- ActiveMerchant::Billing::Response.new(
23
- true,
24
- Spree.t('store_credit_payment_method.successful_action', action: :cancel),
25
- {},
26
- authorization: payment.response_code
27
- )
28
- end
29
-
30
- let(:failed_response) do
31
- ActiveMerchant::Billing::Response.new(
32
- false,
33
- Spree.t('store_credit_payment_method.unable_to_find_for_action', action: :cancel,
34
- auth_code: payment.response_code),
35
- {},
36
- {}
37
- )
38
- end
39
-
40
- it 'attemps to cancels the payment' do
41
- expect(payment.payment_method).to receive(:cancel).with(payment.response_code) { successful_response }
42
- subject
43
- end
44
-
45
- context 'cancels successfully' do
46
- it 'voids the payment' do
47
- expect { subject }.to change { payment.state }.to('void')
48
- end
49
- end
50
-
51
- context 'does not cancel successfully' do
52
- it 'does not change the payment state' do
53
- expect(payment.payment_method).to receive(:cancel).with(payment.response_code) { failed_response }
54
- expect { subject }.to raise_error(Spree::Core::GatewayError)
55
- expect(payment.reload.state).not_to eq 'void'
56
- end
57
- end
58
- end
59
- end
60
- end