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.
Files changed (194) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile +3 -0
  4. data/Rakefile +30 -0
  5. data/app/assets/javascripts/spree.js.coffee.erb +1 -1
  6. data/app/models/spree/ability.rb +1 -1
  7. data/app/models/spree/base.rb +3 -1
  8. data/app/models/spree/order_updater.rb +2 -1
  9. data/app/models/spree/price.rb +7 -12
  10. data/app/models/spree/product.rb +3 -2
  11. data/app/models/spree/reimbursement.rb +1 -1
  12. data/app/models/spree/state.rb +2 -0
  13. data/app/models/spree/zone.rb +1 -1
  14. data/lib/spree/core/version.rb +1 -1
  15. data/lib/spree/testing_support/shoulda_matcher_configuration.rb +6 -0
  16. data/script/rails +9 -0
  17. data/spec/fixtures/thinking-cat.jpg +0 -0
  18. data/spec/helpers/base_helper_spec.rb +137 -0
  19. data/spec/helpers/products_helper_spec.rb +224 -0
  20. data/spec/lib/calculated_adjustments_spec.rb +7 -0
  21. data/spec/lib/i18n_spec.rb +123 -0
  22. data/spec/lib/search/base_spec.rb +86 -0
  23. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +101 -0
  24. data/spec/lib/spree/core/controller_helpers/order_spec.rb +95 -0
  25. data/spec/lib/spree/core/controller_helpers/search_spec.rb +17 -0
  26. data/spec/lib/spree/core/controller_helpers/store_spec.rb +16 -0
  27. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +39 -0
  28. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +22 -0
  29. data/spec/lib/spree/core/importer/order_spec.rb +502 -0
  30. data/spec/lib/spree/core/validators/email_spec.rb +53 -0
  31. data/spec/lib/spree/localized_number_spec.rb +38 -0
  32. data/spec/lib/spree/migrations_spec.rb +34 -0
  33. data/spec/lib/spree/money_spec.rb +122 -0
  34. data/spec/lib/tasks/exchanges_spec.rb +136 -0
  35. data/spec/mailers/order_mailer_spec.rb +124 -0
  36. data/spec/mailers/reimbursement_mailer_spec.rb +47 -0
  37. data/spec/mailers/shipment_mailer_spec.rb +63 -0
  38. data/spec/mailers/test_mailer_spec.rb +24 -0
  39. data/spec/models/spree/ability_spec.rb +246 -0
  40. data/spec/models/spree/address_spec.rb +291 -0
  41. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +286 -0
  42. data/spec/models/spree/adjustment_spec.rb +163 -0
  43. data/spec/models/spree/app_configuration_spec.rb +23 -0
  44. data/spec/models/spree/asset_spec.rb +25 -0
  45. data/spec/models/spree/calculator/default_tax_spec.rb +127 -0
  46. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +25 -0
  47. data/spec/models/spree/calculator/flat_rate_spec.rb +47 -0
  48. data/spec/models/spree/calculator/flexi_rate_spec.rb +41 -0
  49. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +15 -0
  50. data/spec/models/spree/calculator/price_sack_spec.rb +30 -0
  51. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +51 -0
  52. data/spec/models/spree/calculator/shipping.rb +8 -0
  53. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +23 -0
  54. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +13 -0
  55. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +52 -0
  56. data/spec/models/spree/calculator/shipping/per_item_spec.rb +20 -0
  57. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +29 -0
  58. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +40 -0
  59. data/spec/models/spree/calculator/tiered_percent_spec.rb +51 -0
  60. data/spec/models/spree/calculator_spec.rb +69 -0
  61. data/spec/models/spree/classification_spec.rb +93 -0
  62. data/spec/models/spree/concerns/display_money_spec.rb +43 -0
  63. data/spec/models/spree/country_spec.rb +18 -0
  64. data/spec/models/spree/credit_card_spec.rb +324 -0
  65. data/spec/models/spree/customer_return_spec.rb +262 -0
  66. data/spec/models/spree/exchange_spec.rb +75 -0
  67. data/spec/models/spree/gateway/bogus_simple.rb +20 -0
  68. data/spec/models/spree/gateway/bogus_spec.rb +13 -0
  69. data/spec/models/spree/gateway_spec.rb +54 -0
  70. data/spec/models/spree/image_spec.rb +5 -0
  71. data/spec/models/spree/inventory_unit_spec.rb +242 -0
  72. data/spec/models/spree/line_item_spec.rb +267 -0
  73. data/spec/models/spree/option_type_spec.rb +14 -0
  74. data/spec/models/spree/option_value_spec.rb +13 -0
  75. data/spec/models/spree/order/address_spec.rb +50 -0
  76. data/spec/models/spree/order/adjustments_spec.rb +29 -0
  77. data/spec/models/spree/order/callbacks_spec.rb +42 -0
  78. data/spec/models/spree/order/checkout_spec.rb +764 -0
  79. data/spec/models/spree/order/currency_updater_spec.rb +32 -0
  80. data/spec/models/spree/order/finalizing_spec.rb +117 -0
  81. data/spec/models/spree/order/helpers_spec.rb +5 -0
  82. data/spec/models/spree/order/payment_spec.rb +214 -0
  83. data/spec/models/spree/order/risk_assessment_spec.rb +84 -0
  84. data/spec/models/spree/order/shipments_spec.rb +43 -0
  85. data/spec/models/spree/order/state_machine_spec.rb +216 -0
  86. data/spec/models/spree/order/tax_spec.rb +84 -0
  87. data/spec/models/spree/order/totals_spec.rb +24 -0
  88. data/spec/models/spree/order/updating_spec.rb +18 -0
  89. data/spec/models/spree/order/validations_spec.rb +15 -0
  90. data/spec/models/spree/order_contents_spec.rb +256 -0
  91. data/spec/models/spree/order_inventory_spec.rb +228 -0
  92. data/spec/models/spree/order_merger_spec.rb +133 -0
  93. data/spec/models/spree/order_spec.rb +954 -0
  94. data/spec/models/spree/order_updater_spec.rb +283 -0
  95. data/spec/models/spree/payment/gateway_options_spec.rb +119 -0
  96. data/spec/models/spree/payment_method_spec.rb +95 -0
  97. data/spec/models/spree/payment_spec.rb +926 -0
  98. data/spec/models/spree/preference_spec.rb +80 -0
  99. data/spec/models/spree/preferences/configuration_spec.rb +30 -0
  100. data/spec/models/spree/preferences/preferable_spec.rb +348 -0
  101. data/spec/models/spree/preferences/scoped_store_spec.rb +58 -0
  102. data/spec/models/spree/preferences/store_spec.rb +46 -0
  103. data/spec/models/spree/price_spec.rb +42 -0
  104. data/spec/models/spree/product/scopes_spec.rb +148 -0
  105. data/spec/models/spree/product_duplicator_spec.rb +103 -0
  106. data/spec/models/spree/product_filter_spec.rb +26 -0
  107. data/spec/models/spree/product_option_type_spec.rb +5 -0
  108. data/spec/models/spree/product_property_spec.rb +11 -0
  109. data/spec/models/spree/product_spec.rb +474 -0
  110. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +50 -0
  111. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +148 -0
  112. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +86 -0
  113. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +36 -0
  114. data/spec/models/spree/promotion/rules/first_order_spec.rb +75 -0
  115. data/spec/models/spree/promotion/rules/item_total_spec.rb +282 -0
  116. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +42 -0
  117. data/spec/models/spree/promotion/rules/option_value_spec.rb +90 -0
  118. data/spec/models/spree/promotion/rules/product_spec.rb +143 -0
  119. data/spec/models/spree/promotion/rules/taxon_spec.rb +102 -0
  120. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +27 -0
  121. data/spec/models/spree/promotion/rules/user_spec.rb +37 -0
  122. data/spec/models/spree/promotion_action_spec.rb +10 -0
  123. data/spec/models/spree/promotion_category_spec.rb +17 -0
  124. data/spec/models/spree/promotion_handler/cart_spec.rb +102 -0
  125. data/spec/models/spree/promotion_handler/coupon_spec.rb +323 -0
  126. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +48 -0
  127. data/spec/models/spree/promotion_handler/page_spec.rb +44 -0
  128. data/spec/models/spree/promotion_rule_spec.rb +29 -0
  129. data/spec/models/spree/promotion_spec.rb +603 -0
  130. data/spec/models/spree/property_spec.rb +5 -0
  131. data/spec/models/spree/prototype_spec.rb +5 -0
  132. data/spec/models/spree/refund_spec.rb +195 -0
  133. data/spec/models/spree/reimbursement/credit_spec.rb +36 -0
  134. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +140 -0
  135. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +83 -0
  136. data/spec/models/spree/reimbursement_performer_spec.rb +30 -0
  137. data/spec/models/spree/reimbursement_spec.rb +215 -0
  138. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +51 -0
  139. data/spec/models/spree/reimbursement_type/credit_spec.rb +53 -0
  140. data/spec/models/spree/reimbursement_type/exchange_spec.rb +46 -0
  141. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +55 -0
  142. data/spec/models/spree/return_authorization_spec.rb +250 -0
  143. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +77 -0
  144. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +58 -0
  145. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +61 -0
  146. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +32 -0
  147. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +29 -0
  148. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +35 -0
  149. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +65 -0
  150. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +43 -0
  151. data/spec/models/spree/return_item_spec.rb +682 -0
  152. data/spec/models/spree/returns_calculator_spec.rb +14 -0
  153. data/spec/models/spree/shipment_spec.rb +740 -0
  154. data/spec/models/spree/shipping_calculator_spec.rb +45 -0
  155. data/spec/models/spree/shipping_category_spec.rb +5 -0
  156. data/spec/models/spree/shipping_method_spec.rb +88 -0
  157. data/spec/models/spree/shipping_rate_spec.rb +141 -0
  158. data/spec/models/spree/state_spec.rb +18 -0
  159. data/spec/models/spree/stock/availability_validator_spec.rb +36 -0
  160. data/spec/models/spree/stock/content_item_spec.rb +22 -0
  161. data/spec/models/spree/stock/coordinator_spec.rb +51 -0
  162. data/spec/models/spree/stock/differentiator_spec.rb +39 -0
  163. data/spec/models/spree/stock/estimator_spec.rb +154 -0
  164. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +38 -0
  165. data/spec/models/spree/stock/package_spec.rb +194 -0
  166. data/spec/models/spree/stock/packer_spec.rb +70 -0
  167. data/spec/models/spree/stock/prioritizer_spec.rb +125 -0
  168. data/spec/models/spree/stock/quantifier_spec.rb +97 -0
  169. data/spec/models/spree/stock/splitter/backordered_spec.rb +29 -0
  170. data/spec/models/spree/stock/splitter/base_spec.rb +21 -0
  171. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +47 -0
  172. data/spec/models/spree/stock/splitter/weight_spec.rb +32 -0
  173. data/spec/models/spree/stock_item_spec.rb +410 -0
  174. data/spec/models/spree/stock_location_spec.rb +243 -0
  175. data/spec/models/spree/stock_movement_spec.rb +56 -0
  176. data/spec/models/spree/stock_transfer_spec.rb +50 -0
  177. data/spec/models/spree/store_spec.rb +50 -0
  178. data/spec/models/spree/tax_category_spec.rb +27 -0
  179. data/spec/models/spree/tax_rate_spec.rb +382 -0
  180. data/spec/models/spree/taxon_spec.rb +74 -0
  181. data/spec/models/spree/taxonomy_spec.rb +18 -0
  182. data/spec/models/spree/tracker_spec.rb +21 -0
  183. data/spec/models/spree/user_spec.rb +130 -0
  184. data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +24 -0
  185. data/spec/models/spree/variant_spec.rb +523 -0
  186. data/spec/models/spree/zone_spec.rb +444 -0
  187. data/spec/spec_helper.rb +74 -0
  188. data/spec/support/big_decimal.rb +5 -0
  189. data/spec/support/concerns/adjustment_source_spec.rb +23 -0
  190. data/spec/support/concerns/default_price_spec.rb +28 -0
  191. data/spec/support/rake.rb +13 -0
  192. data/spec/support/test_gateway.rb +2 -0
  193. data/spree_core.gemspec +48 -0
  194. metadata +185 -4
@@ -0,0 +1,283 @@
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
+ context "updating shipment state" do
71
+ before do
72
+ allow(order).to receive_messages backordered?: false
73
+ allow(order).to receive_message_chain(:shipments, :shipped, :count).and_return(0)
74
+ allow(order).to receive_message_chain(:shipments, :ready, :count).and_return(0)
75
+ allow(order).to receive_message_chain(:shipments, :pending, :count).and_return(0)
76
+ end
77
+
78
+ it "is backordered" do
79
+ allow(order).to receive_messages backordered?: true
80
+ updater.update_shipment_state
81
+
82
+ expect(order.shipment_state).to eq('backorder')
83
+ end
84
+
85
+ it "is nil" do
86
+ allow(order).to receive_message_chain(:shipments, :states).and_return([])
87
+ allow(order).to receive_message_chain(:shipments, :count).and_return(0)
88
+
89
+ updater.update_shipment_state
90
+ expect(order.shipment_state).to be_nil
91
+ end
92
+
93
+
94
+ ["shipped", "ready", "pending"].each do |state|
95
+ it "is #{state}" do
96
+ allow(order).to receive_message_chain(:shipments, :states).and_return([state])
97
+ updater.update_shipment_state
98
+ expect(order.shipment_state).to eq(state.to_s)
99
+ end
100
+ end
101
+
102
+ it "is partial" do
103
+ allow(order).to receive_message_chain(:shipments, :states).and_return(["pending", "ready"])
104
+ updater.update_shipment_state
105
+ expect(order.shipment_state).to eq('partial')
106
+ end
107
+ end
108
+
109
+ context "updating payment state" do
110
+ let(:order) { Order.new }
111
+ let(:updater) { order.updater }
112
+
113
+ it "is failed if no valid payments" do
114
+ allow(order).to receive_message_chain(:payments, :valid, :size).and_return(0)
115
+
116
+ updater.update_payment_state
117
+ expect(order.payment_state).to eq('failed')
118
+ end
119
+
120
+ context "payment total is greater than order total" do
121
+ it "is credit_owed" do
122
+ order.payment_total = 2
123
+ order.total = 1
124
+
125
+ expect {
126
+ updater.update_payment_state
127
+ }.to change { order.payment_state }.to 'credit_owed'
128
+ end
129
+ end
130
+
131
+ context "order total is greater than payment total" do
132
+ it "is balance_due" do
133
+ order.payment_total = 1
134
+ order.total = 2
135
+
136
+ expect {
137
+ updater.update_payment_state
138
+ }.to change { order.payment_state }.to 'balance_due'
139
+ end
140
+ end
141
+
142
+ context "order total equals payment total" do
143
+ it "is paid" do
144
+ order.payment_total = 30
145
+ order.total = 30
146
+
147
+ expect {
148
+ updater.update_payment_state
149
+ }.to change { order.payment_state }.to 'paid'
150
+ end
151
+ end
152
+
153
+ context "order is canceled" do
154
+
155
+ before do
156
+ order.state = 'canceled'
157
+ end
158
+
159
+ context "and is still unpaid" do
160
+ it "is void" do
161
+ order.payment_total = 0
162
+ order.total = 30
163
+ expect {
164
+ updater.update_payment_state
165
+ }.to change { order.payment_state }.to 'void'
166
+ end
167
+ end
168
+
169
+ context "and is paid" do
170
+
171
+ it "is credit_owed" do
172
+ order.payment_total = 30
173
+ order.total = 30
174
+ allow(order).to receive_message_chain(:payments, :valid, :size).and_return(1)
175
+ allow(order).to receive_message_chain(:payments, :completed, :size).and_return(1)
176
+ expect {
177
+ updater.update_payment_state
178
+ }.to change { order.payment_state }.to 'credit_owed'
179
+ end
180
+
181
+ end
182
+
183
+ context "and payment is refunded" do
184
+ it "is void" do
185
+ order.payment_total = 0
186
+ order.total = 30
187
+ expect {
188
+ updater.update_payment_state
189
+ }.to change { order.payment_state }.to 'void'
190
+ end
191
+ end
192
+ end
193
+
194
+ end
195
+
196
+ it "state change" do
197
+ order.shipment_state = 'shipped'
198
+ state_changes = double
199
+ allow(order).to receive_messages state_changes: state_changes
200
+ expect(state_changes).to receive(:create).with(
201
+ previous_state: nil,
202
+ next_state: 'shipped',
203
+ name: 'shipment',
204
+ user_id: nil
205
+ )
206
+
207
+ order.state_changed('shipment')
208
+ end
209
+
210
+ context "completed order" do
211
+ before { allow(order).to receive_messages completed?: true }
212
+
213
+ it "updates payment state" do
214
+ expect(updater).to receive(:update_payment_state)
215
+ updater.update
216
+ end
217
+
218
+ it "updates shipment state" do
219
+ expect(updater).to receive(:update_shipment_state)
220
+ updater.update
221
+ end
222
+
223
+ it "updates each shipment" do
224
+ shipment = stub_model(Spree::Shipment, order: order)
225
+ shipments = [shipment]
226
+ allow(order).to receive_messages shipments: shipments
227
+ allow(shipments).to receive_messages states: []
228
+ allow(shipments).to receive_messages ready: []
229
+ allow(shipments).to receive_messages pending: []
230
+ allow(shipments).to receive_messages shipped: []
231
+
232
+ expect(shipment).to receive(:update!).with(order)
233
+ updater.update_shipments
234
+ end
235
+
236
+ it "refreshes shipment rates" do
237
+ shipment = stub_model(Spree::Shipment, order: order)
238
+ shipments = [shipment]
239
+ allow(order).to receive_messages shipments: shipments
240
+
241
+ expect(shipment).to receive(:refresh_rates)
242
+ updater.update_shipments
243
+ end
244
+
245
+ it "updates the shipment amount" do
246
+ shipment = stub_model(Spree::Shipment, order: order)
247
+ shipments = [shipment]
248
+ allow(order).to receive_messages shipments: shipments
249
+
250
+ expect(shipment).to receive(:update_amounts)
251
+ updater.update_shipments
252
+ end
253
+ end
254
+
255
+ context "incompleted order" do
256
+ before { allow(order).to receive_messages completed?: false }
257
+
258
+ it "doesnt update payment state" do
259
+ expect(updater).not_to receive(:update_payment_state)
260
+ updater.update
261
+ end
262
+
263
+ it "doesnt update shipment state" do
264
+ expect(updater).not_to receive(:update_shipment_state)
265
+ updater.update
266
+ end
267
+
268
+ it "doesnt update each shipment" do
269
+ shipment = stub_model(Spree::Shipment)
270
+ shipments = [shipment]
271
+ allow(order).to receive_messages shipments: shipments
272
+ allow(shipments).to receive_messages states: []
273
+ allow(shipments).to receive_messages ready: []
274
+ allow(shipments).to receive_messages pending: []
275
+ allow(shipments).to receive_messages shipped: []
276
+
277
+ allow(updater).to receive(:update_totals) # Otherwise this gets called and causes a scene
278
+ expect(updater).not_to receive(:update_shipments).with(order)
279
+ updater.update
280
+ end
281
+ end
282
+ end
283
+ end
@@ -0,0 +1,119 @@
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
+ )
13
+ end
14
+
15
+ let(:order) do
16
+ double(
17
+ Spree::Order,
18
+ email: "test@email.com",
19
+ user_id: 144,
20
+ last_ip_address: "0.0.0.0",
21
+ number: "R1444",
22
+ ship_total: "12.44".to_d,
23
+ additional_tax_total: "1.53".to_d,
24
+ item_total: "15.11".to_d,
25
+ promo_total: "2.57".to_d,
26
+ bill_address: bill_address,
27
+ ship_address: ship_address
28
+ )
29
+ end
30
+
31
+ let(:bill_address) do
32
+ double Spree::Address, active_merchant_hash: { bill: :address }
33
+ end
34
+ let(:ship_address) do
35
+ double Spree::Address, active_merchant_hash: { ship: :address }
36
+ end
37
+
38
+ describe "#email" do
39
+ subject { options.email }
40
+ it { should == "test@email.com" }
41
+ end
42
+
43
+ describe "#customer" do
44
+ subject { options.customer }
45
+ it { should == "test@email.com" }
46
+ end
47
+
48
+ describe "#customer_id" do
49
+ subject { options.customer_id }
50
+ it { should == 144 }
51
+ end
52
+
53
+ describe "#ip" do
54
+ subject { options.ip }
55
+ it { should == "0.0.0.0" }
56
+ end
57
+
58
+ describe "#order_id" do
59
+ subject { options.order_id }
60
+ it { should == "R1444-P1566" }
61
+ end
62
+
63
+ describe "#shipping" do
64
+ subject { options.shipping }
65
+ it { should == 1244 }
66
+ end
67
+
68
+ describe "#tax" do
69
+ subject { options.tax }
70
+ it { should == 153 }
71
+ end
72
+
73
+ describe "#subtotal" do
74
+ subject { options.subtotal }
75
+ it { should == 1511 }
76
+ end
77
+
78
+ describe "#discount" do
79
+ subject { options.discount }
80
+ it { should == 257 }
81
+ end
82
+
83
+ describe "#currency" do
84
+ subject { options.currency }
85
+ it { should == "EUR" }
86
+ end
87
+
88
+ describe "#billing_address" do
89
+ subject { options.billing_address }
90
+ it { should == { bill: :address } }
91
+ end
92
+
93
+ describe "#shipping_address" do
94
+ subject { options.shipping_address }
95
+ it { should == { ship: :address } }
96
+ end
97
+
98
+ describe "#to_hash" do
99
+ subject { options.to_hash }
100
+ let(:expected) do
101
+ {
102
+ email: "test@email.com",
103
+ customer: "test@email.com",
104
+ customer_id: 144,
105
+ ip: "0.0.0.0",
106
+ order_id: "R1444-P1566",
107
+ shipping: "1244".to_d,
108
+ tax: "153".to_d,
109
+ subtotal: "1511".to_d,
110
+ discount: "257".to_d,
111
+ currency: "EUR",
112
+ billing_address: { bill: :address },
113
+ shipping_address: { ship: :address }
114
+ }
115
+ end
116
+ it { should == expected }
117
+ end
118
+
119
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::PaymentMethod, type: :model do
4
+ describe "#available" do
5
+ before do
6
+ [nil, 'both', 'front_end', 'back_end'].each do |display_on|
7
+ Spree::Gateway::Test.create(
8
+ name: 'Display Both',
9
+ display_on: display_on,
10
+ active: true,
11
+ description: 'foofah'
12
+ )
13
+ end
14
+ end
15
+
16
+ it "should have 4 total methods" do
17
+ expect(Spree::PaymentMethod.all.size).to eq(4)
18
+ end
19
+
20
+ it "should return all methods available to front-end/back-end when no parameter is passed" do
21
+ expect(Spree::PaymentMethod.available.size).to eq(2)
22
+ end
23
+
24
+ it "should return all methods available to front-end/back-end when display_on = :both" do
25
+ expect(Spree::PaymentMethod.available(:both).size).to eq(2)
26
+ end
27
+
28
+ it "should return all methods available to front-end when display_on = :front_end" do
29
+ expect(Spree::PaymentMethod.available(:front_end).size).to eq(2)
30
+ end
31
+
32
+ it "should return all methods available to back-end when display_on = :back_end" do
33
+ expect(Spree::PaymentMethod.available(:back_end).size).to eq(2)
34
+ end
35
+ end
36
+
37
+ describe '#auto_capture?' do
38
+ class TestGateway < Spree::Gateway
39
+ def provider_class
40
+ Provider
41
+ end
42
+ end
43
+
44
+ let(:gateway) { TestGateway.new }
45
+
46
+ subject { gateway.auto_capture? }
47
+
48
+ context 'when auto_capture is nil' do
49
+ before(:each) do
50
+ expect(Spree::Config).to receive('[]').with(:auto_capture).and_return(auto_capture)
51
+ end
52
+
53
+ context 'and when Spree::Config[:auto_capture] is false' do
54
+ let(:auto_capture) { false }
55
+
56
+ it 'should be false' do
57
+ expect(gateway.auto_capture).to be_nil
58
+ expect(subject).to be false
59
+ end
60
+ end
61
+
62
+ context 'and when Spree::Config[:auto_capture] is true' do
63
+ let(:auto_capture) { true }
64
+
65
+ it 'should be true' do
66
+ expect(gateway.auto_capture).to be_nil
67
+ expect(subject).to be true
68
+ end
69
+ end
70
+ end
71
+
72
+ context 'when auto_capture is not nil' do
73
+ before(:each) do
74
+ gateway.auto_capture = auto_capture
75
+ end
76
+
77
+ context 'and is true' do
78
+ let(:auto_capture) { true }
79
+
80
+ it 'should be true' do
81
+ expect(subject).to be true
82
+ end
83
+ end
84
+
85
+ context 'and is false' do
86
+ let(:auto_capture) { false }
87
+
88
+ it 'should be true' do
89
+ expect(subject).to be false
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ end