spree_core 3.2.1 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spree/core/version.rb +1 -1
  3. data/spree_core.gemspec +1 -1
  4. metadata +3 -206
  5. data/spec/fixtures/microdata.html +0 -22
  6. data/spec/fixtures/microdata_itemref.html +0 -15
  7. data/spec/fixtures/microdata_no_itemscope.html +0 -20
  8. data/spec/fixtures/thinking-cat.jpg +0 -0
  9. data/spec/helpers/base_helper_spec.rb +0 -200
  10. data/spec/helpers/products_helper_spec.rb +0 -289
  11. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  12. data/spec/lib/i18n_spec.rb +0 -123
  13. data/spec/lib/search/base_spec.rb +0 -86
  14. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  15. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  16. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  17. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  18. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  19. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  20. data/spec/lib/spree/core/importer/order_spec.rb +0 -605
  21. data/spec/lib/spree/core/number_generator_spec.rb +0 -175
  22. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  23. data/spec/lib/spree/core/validators/email_spec.rb +0 -53
  24. data/spec/lib/spree/core_spec.rb +0 -23
  25. data/spec/lib/spree/localized_number_spec.rb +0 -48
  26. data/spec/lib/spree/migrations_spec.rb +0 -36
  27. data/spec/lib/spree/money_spec.rb +0 -122
  28. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  29. data/spec/mailers/order_mailer_spec.rb +0 -122
  30. data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
  31. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  32. data/spec/mailers/test_mailer_spec.rb +0 -38
  33. data/spec/models/option_type_prototype_spec.rb +0 -9
  34. data/spec/models/spree/ability_spec.rb +0 -251
  35. data/spec/models/spree/address_spec.rb +0 -402
  36. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  37. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  38. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  39. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  40. data/spec/models/spree/adjustment_spec.rb +0 -189
  41. data/spec/models/spree/app_configuration_spec.rb +0 -26
  42. data/spec/models/spree/asset_spec.rb +0 -28
  43. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  44. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  45. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  46. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  47. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  48. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  49. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
  50. data/spec/models/spree/calculator/shipping.rb +0 -8
  51. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  52. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  53. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  54. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  55. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  56. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  57. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  58. data/spec/models/spree/calculator_spec.rb +0 -69
  59. data/spec/models/spree/classification_spec.rb +0 -93
  60. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  61. data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
  62. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  63. data/spec/models/spree/country_spec.rb +0 -55
  64. data/spec/models/spree/credit_card_spec.rb +0 -328
  65. data/spec/models/spree/customer_return_spec.rb +0 -240
  66. data/spec/models/spree/exchange_spec.rb +0 -75
  67. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  68. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  69. data/spec/models/spree/gateway_spec.rb +0 -61
  70. data/spec/models/spree/image_spec.rb +0 -8
  71. data/spec/models/spree/inventory_unit_spec.rb +0 -256
  72. data/spec/models/spree/line_item_spec.rb +0 -346
  73. data/spec/models/spree/option_type_spec.rb +0 -14
  74. data/spec/models/spree/option_value_spec.rb +0 -18
  75. data/spec/models/spree/order/address_spec.rb +0 -50
  76. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  77. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  78. data/spec/models/spree/order/checkout_spec.rb +0 -770
  79. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  80. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  81. data/spec/models/spree/order/helpers_spec.rb +0 -5
  82. data/spec/models/spree/order/payment_spec.rb +0 -214
  83. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  84. data/spec/models/spree/order/shipments_spec.rb +0 -43
  85. data/spec/models/spree/order/state_machine_spec.rb +0 -212
  86. data/spec/models/spree/order/store_credit_spec.rb +0 -426
  87. data/spec/models/spree/order/tax_spec.rb +0 -84
  88. data/spec/models/spree/order/totals_spec.rb +0 -24
  89. data/spec/models/spree/order/updating_spec.rb +0 -18
  90. data/spec/models/spree/order/validations_spec.rb +0 -15
  91. data/spec/models/spree/order_contents_spec.rb +0 -297
  92. data/spec/models/spree/order_inventory_spec.rb +0 -239
  93. data/spec/models/spree/order_merger_spec.rb +0 -135
  94. data/spec/models/spree/order_spec.rb +0 -1046
  95. data/spec/models/spree/order_updater_spec.rb +0 -305
  96. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  97. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  98. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  99. data/spec/models/spree/payment_method_spec.rb +0 -103
  100. data/spec/models/spree/payment_spec.rb +0 -919
  101. data/spec/models/spree/preference_spec.rb +0 -80
  102. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  103. data/spec/models/spree/preferences/preferable_spec.rb +0 -344
  104. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  105. data/spec/models/spree/preferences/store_spec.rb +0 -46
  106. data/spec/models/spree/price_spec.rb +0 -128
  107. data/spec/models/spree/product/scopes_spec.rb +0 -183
  108. data/spec/models/spree/product_duplicator_spec.rb +0 -103
  109. data/spec/models/spree/product_filter_spec.rb +0 -26
  110. data/spec/models/spree/product_option_type_spec.rb +0 -9
  111. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  112. data/spec/models/spree/product_property_spec.rb +0 -26
  113. data/spec/models/spree/product_spec.rb +0 -629
  114. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
  115. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  116. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  117. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  118. data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
  119. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  120. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  121. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  122. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  123. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  124. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  125. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  126. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  127. data/spec/models/spree/promotion_action_spec.rb +0 -10
  128. data/spec/models/spree/promotion_category_spec.rb +0 -17
  129. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  130. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  131. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  132. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  133. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  134. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  135. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  136. data/spec/models/spree/promotion_spec.rb +0 -679
  137. data/spec/models/spree/property_prototype_spec.rb +0 -9
  138. data/spec/models/spree/property_spec.rb +0 -5
  139. data/spec/models/spree/prototype_spec.rb +0 -5
  140. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  141. data/spec/models/spree/refund_reason_spec.rb +0 -20
  142. data/spec/models/spree/refund_spec.rb +0 -195
  143. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  144. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  145. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  146. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  147. data/spec/models/spree/reimbursement_spec.rb +0 -188
  148. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  149. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  150. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  151. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  152. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  153. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  154. data/spec/models/spree/return_authorization_spec.rb +0 -230
  155. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  156. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  157. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  158. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  159. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  160. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  161. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  162. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  163. data/spec/models/spree/return_item_spec.rb +0 -731
  164. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  165. data/spec/models/spree/role_spec.rb +0 -7
  166. data/spec/models/spree/shipment_spec.rb +0 -742
  167. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  168. data/spec/models/spree/shipping_category_spec.rb +0 -19
  169. data/spec/models/spree/shipping_method_spec.rb +0 -95
  170. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  171. data/spec/models/spree/state_spec.rb +0 -29
  172. data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
  173. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  174. data/spec/models/spree/stock/coordinator_spec.rb +0 -61
  175. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  176. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  177. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
  178. data/spec/models/spree/stock/package_spec.rb +0 -182
  179. data/spec/models/spree/stock/packer_spec.rb +0 -70
  180. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  181. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  182. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  183. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  184. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  185. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  186. data/spec/models/spree/stock_item_spec.rb +0 -432
  187. data/spec/models/spree/stock_location_spec.rb +0 -243
  188. data/spec/models/spree/stock_movement_spec.rb +0 -120
  189. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  190. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  191. data/spec/models/spree/store_credit_spec.rb +0 -786
  192. data/spec/models/spree/store_spec.rb +0 -78
  193. data/spec/models/spree/tax_category_spec.rb +0 -32
  194. data/spec/models/spree/tax_rate_spec.rb +0 -561
  195. data/spec/models/spree/taxon_spec.rb +0 -85
  196. data/spec/models/spree/taxonomy_spec.rb +0 -18
  197. data/spec/models/spree/tracker_spec.rb +0 -21
  198. data/spec/models/spree/user_spec.rb +0 -203
  199. data/spec/models/spree/variant_spec.rb +0 -818
  200. data/spec/models/spree/zone_member_spec.rb +0 -38
  201. data/spec/models/spree/zone_spec.rb +0 -472
  202. data/spec/spec_helper.rb +0 -79
  203. data/spec/support/big_decimal.rb +0 -5
  204. data/spec/support/concerns/adjustment_source.rb +0 -23
  205. data/spec/support/concerns/default_price.rb +0 -37
  206. data/spec/support/rake.rb +0 -13
  207. data/spec/support/test_gateway.rb +0 -2
@@ -1,42 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Order, type: :model do
4
- let(:order) { stub_model(Spree::Order) }
5
- before do
6
- Spree::Order.define_state_machine!
7
- end
8
-
9
- context "validations" do
10
- context "email validation" do
11
- # Regression test for #1238
12
- it "o'brien@gmail.com is a valid email address" do
13
- order.state = 'address'
14
- order.email = "o'brien@gmail.com"
15
- expect(order.error_on(:email).size).to eq(0)
16
- end
17
- end
18
- end
19
-
20
- context "#save" do
21
- context "when associated with a registered user" do
22
- let(:user) { double(:user, email: "test@example.com") }
23
-
24
- before do
25
- allow(order).to receive_messages user: user
26
- end
27
-
28
- it "should assign the email address of the user" do
29
- order.run_callbacks(:create)
30
- expect(order.email).to eq(user.email)
31
- end
32
- end
33
- end
34
-
35
- context "in the cart state" do
36
- it "should not validate email address" do
37
- order.state = "cart"
38
- order.email = nil
39
- expect(order.error_on(:email).size).to eq(0)
40
- end
41
- end
42
- end
@@ -1,770 +0,0 @@
1
- require 'spec_helper'
2
- require 'spree/testing_support/order_walkthrough'
3
-
4
- describe Spree::Order, type: :model do
5
- let(:order) { Spree::Order.new }
6
-
7
- before { create(:store) }
8
-
9
- def assert_state_changed(order, from, to)
10
- state_change_exists = order.state_changes.where(previous_state: from, next_state: to).exists?
11
- assert state_change_exists, "Expected order to transition from #{from} to #{to}, but didn't."
12
- end
13
-
14
- context "with default state machine" do
15
- let(:transitions) do
16
- [
17
- { address: :delivery },
18
- { delivery: :payment },
19
- { payment: :confirm },
20
- { confirm: :complete },
21
- { payment: :complete },
22
- { delivery: :complete }
23
- ]
24
- end
25
-
26
- it "has the following transitions" do
27
- transitions.each do |transition|
28
- transition = Spree::Order.find_transition(from: transition.keys.first, to: transition.values.first)
29
- expect(transition).not_to be_nil
30
- end
31
- end
32
-
33
- it "does not have a transition from delivery to confirm" do
34
- transition = Spree::Order.find_transition(from: :delivery, to: :confirm)
35
- expect(transition).to be_nil
36
- end
37
-
38
- it '.find_transition when contract was broken' do
39
- expect(Spree::Order.find_transition({foo: :bar, baz: :dog})).to be_falsey
40
- end
41
-
42
- it '.remove_transition' do
43
- options = {from: transitions.first.keys.first, to: transitions.first.values.first}
44
- expect(Spree::Order).to receive_messages(
45
- removed_transitions: [],
46
- next_event_transitions: transitions.dup
47
- )
48
- expect(Spree::Order.remove_transition(options)).to be_truthy
49
- expect(Spree::Order.removed_transitions).to eql([options])
50
- expect(Spree::Order.next_event_transitions).to_not include(transitions.first)
51
- end
52
-
53
- it '.remove_transition when contract was broken' do
54
- expect(Spree::Order.remove_transition(nil)).to be_falsey
55
- end
56
-
57
- it "always return integer on checkout_step_index" do
58
- expect(order.checkout_step_index("imnotthere")).to be_a Integer
59
- expect(order.checkout_step_index("delivery")).to be > 0
60
- end
61
-
62
- it "passes delivery state when transitioning from address over delivery to payment" do
63
- allow(order).to receive_messages payment_required?: true
64
- order.state = "address"
65
- expect(order.passed_checkout_step?("delivery")).to be false
66
- order.state = "delivery"
67
- expect(order.passed_checkout_step?("delivery")).to be false
68
- order.state = "payment"
69
- expect(order.passed_checkout_step?("delivery")).to be true
70
- end
71
-
72
- context "#checkout_steps" do
73
- context "when confirmation not required" do
74
- before do
75
- allow(order).to receive_messages confirmation_required?: false
76
- allow(order).to receive_messages payment_required?: true
77
- end
78
-
79
- specify do
80
- expect(order.checkout_steps).to eq(%w(address delivery payment complete))
81
- end
82
- end
83
-
84
- context "when confirmation required" do
85
- before do
86
- allow(order).to receive_messages confirmation_required?: true
87
- allow(order).to receive_messages payment_required?: true
88
- end
89
-
90
- specify do
91
- expect(order.checkout_steps).to eq(%w(address delivery payment confirm complete))
92
- end
93
- end
94
-
95
- context "when payment not required" do
96
- before { allow(order).to receive_messages payment_required?: false }
97
- specify do
98
- expect(order.checkout_steps).to eq(%w(address delivery complete))
99
- end
100
- end
101
-
102
- context "when payment required" do
103
- before { allow(order).to receive_messages payment_required?: true }
104
- specify do
105
- expect(order.checkout_steps).to eq(%w(address delivery payment complete))
106
- end
107
- end
108
- end
109
-
110
- it "starts out at cart" do
111
- expect(order.state).to eq("cart")
112
- end
113
-
114
- context "to address" do
115
- before do
116
- order.email = "user@example.com"
117
- order.save!
118
- end
119
-
120
- context "with a line item" do
121
- before do
122
- order.line_items << FactoryGirl.create(:line_item)
123
- end
124
-
125
- it "transitions to address" do
126
- order.next!
127
- assert_state_changed(order, 'cart', 'address')
128
- expect(order.state).to eq("address")
129
- end
130
-
131
- it "doesn't raise an error if the default address is invalid" do
132
- order.user = mock_model(Spree::LegacyUser, ship_address: Spree::Address.new, bill_address: Spree::Address.new)
133
- expect { order.next! }.to_not raise_error
134
- end
135
-
136
- context "with default addresses" do
137
- let(:default_address) { FactoryGirl.create(:address) }
138
-
139
- before do
140
- order.user = FactoryGirl.create(:user, "#{address_kind}_address" => default_address)
141
- order.next!
142
- order.reload
143
- end
144
-
145
- shared_examples "it cloned the default address" do
146
- it do
147
- default_attributes = default_address.attributes
148
- order_attributes = order.send("#{address_kind}_address".to_sym).try(:attributes) || {}
149
-
150
- expect(order_attributes.except('id', 'created_at', 'updated_at')).to eql(default_attributes.except('id', 'created_at', 'updated_at'))
151
- end
152
- end
153
-
154
- it_behaves_like "it cloned the default address" do
155
- let(:address_kind) { 'ship' }
156
- end
157
-
158
- it_behaves_like "it cloned the default address" do
159
- let(:address_kind) { 'bill' }
160
- end
161
- end
162
- end
163
-
164
- it "cannot transition to address without any line items" do
165
- expect(order.line_items).to be_blank
166
- expect { order.next! }.to raise_error(StateMachines::InvalidTransition, /#{Spree.t(:there_are_no_items_for_this_order)}/)
167
- end
168
- end
169
-
170
- context "from address" do
171
- before do
172
- order.state = 'address'
173
- allow(order).to receive(:has_available_payment)
174
- shipment = FactoryGirl.create(:shipment, order: order)
175
- order.email = "user@example.com"
176
- order.save!
177
- end
178
-
179
- it "updates totals" do
180
- allow(order).to receive_messages(ensure_available_shipping_rates: true)
181
- line_item = FactoryGirl.create(:line_item, price: 10, adjustment_total: 10)
182
- line_item.variant.update_attributes!(price: 10)
183
- order.line_items << line_item
184
- tax_rate = create(:tax_rate, tax_category: line_item.tax_category, amount: 0.05)
185
- allow(Spree::TaxRate).to receive_messages match: [tax_rate]
186
- FactoryGirl.create(:tax_adjustment, adjustable: line_item, source: tax_rate, order: order)
187
- order.email = "user@example.com"
188
- order.next!
189
- expect(order.adjustment_total).to eq(0.5)
190
- expect(order.additional_tax_total).to eq(0.5)
191
- expect(order.included_tax_total).to eq(0)
192
- expect(order.total).to eq(10.5)
193
- end
194
-
195
- it 'updates prices' do
196
- allow(order).to receive_messages(ensure_available_shipping_rates: true)
197
- line_item = FactoryGirl.create(:line_item, price: 10, adjustment_total: 10)
198
- line_item.variant.update_attributes!(price: 20)
199
- order.line_items << line_item
200
- tax_rate = create :tax_rate,
201
- included_in_price: true,
202
- tax_category: line_item.tax_category,
203
- amount: 0.05
204
- allow(Spree::TaxRate).to receive_messages(match: [tax_rate])
205
- FactoryGirl.create :tax_adjustment,
206
- adjustable: line_item,
207
- source: tax_rate,
208
- order: order
209
- order.email = "user@example.com"
210
- order.next!
211
- expect(order.adjustment_total).to eq(0)
212
- expect(order.additional_tax_total).to eq(0)
213
- expect(order.included_tax_total).to eq(0.95)
214
- expect(order.total).to eq(20)
215
- end
216
-
217
- it "transitions to delivery" do
218
- allow(order).to receive_messages(ensure_available_shipping_rates: true)
219
- order.next!
220
- assert_state_changed(order, 'address', 'delivery')
221
- expect(order.state).to eq("delivery")
222
- end
223
-
224
- it "does not call persist_order_address if there is no address on the order" do
225
- # otherwise, it will crash
226
- allow(order).to receive_messages(ensure_available_shipping_rates: true)
227
-
228
- order.user = FactoryGirl.create(:user)
229
- order.save!
230
-
231
- expect(order.user).to_not receive(:persist_order_address).with(order)
232
- order.next!
233
- end
234
-
235
- it "calls persist_order_address on the order's user" do
236
- allow(order).to receive_messages(ensure_available_shipping_rates: true)
237
-
238
- order.user = FactoryGirl.create(:user)
239
- order.ship_address = FactoryGirl.create(:address)
240
- order.bill_address = FactoryGirl.create(:address)
241
- order.save!
242
-
243
- expect(order.user).to receive(:persist_order_address).with(order)
244
- order.next!
245
- end
246
-
247
- it "does not call persist_order_address on the order's user for a temporary address" do
248
- allow(order).to receive_messages(ensure_available_shipping_rates: true)
249
-
250
- order.user = FactoryGirl.create(:user)
251
- order.temporary_address = true
252
- order.save!
253
-
254
- expect(order.user).to_not receive(:persist_order_address)
255
- order.next!
256
- end
257
-
258
- context "cannot transition to delivery" do
259
- context "with an existing shipment" do
260
- before do
261
- line_item = FactoryGirl.create(:line_item, price: 10)
262
- order.line_items << line_item
263
- end
264
-
265
- context "if there are no shipping rates for any shipment" do
266
- it "raises an InvalidTransitionError" do
267
- transition = lambda { order.next! }
268
- expect(transition).to raise_error(StateMachines::InvalidTransition, /#{Spree.t(:items_cannot_be_shipped)}/)
269
- end
270
-
271
- it "deletes all the shipments" do
272
- order.next
273
- expect(order.shipments).to be_empty
274
- end
275
- end
276
- end
277
- end
278
- end
279
-
280
- context "to delivery" do
281
- context 'when order has default selected_shipping_rate_id' do
282
- let(:shipment) { create(:shipment, order: order) }
283
- let(:shipping_method) { create(:shipping_method) }
284
- let(:shipping_rate) { [
285
- Spree::ShippingRate.create!(shipping_method: shipping_method, cost: 10.00, shipment: shipment)
286
- ] }
287
-
288
- before do
289
- order.state = 'address'
290
- shipment.selected_shipping_rate_id = shipping_rate.first.id
291
- order.email = "user@example.com"
292
- order.save!
293
-
294
- allow(order).to receive(:has_available_payment)
295
- allow(order).to receive(:create_proposed_shipments)
296
- allow(order).to receive(:ensure_available_shipping_rates) { true }
297
- end
298
-
299
- it 'should invoke set_shipment_cost' do
300
- expect(order).to receive(:set_shipments_cost)
301
- order.next!
302
- end
303
-
304
- it 'should update shipment_total' do
305
- expect { order.next! }.to change{ order.shipment_total }.by(10.00)
306
- end
307
- end
308
- end
309
-
310
- context "from delivery" do
311
- before do
312
- order.state = 'delivery'
313
- allow(order).to receive(:apply_free_shipping_promotions)
314
- end
315
-
316
- it "attempts to apply free shipping promotions" do
317
- expect(order).to receive(:apply_free_shipping_promotions)
318
- order.next!
319
- end
320
-
321
- context "with payment required" do
322
- before do
323
- allow(order).to receive_messages payment_required?: true
324
- end
325
-
326
- it "transitions to payment" do
327
- expect(order).to receive(:set_shipments_cost)
328
- order.next!
329
- assert_state_changed(order, 'delivery', 'payment')
330
- expect(order.state).to eq('payment')
331
- end
332
- end
333
-
334
- context "without payment required" do
335
- before do
336
- allow(order).to receive_messages payment_required?: false
337
- end
338
-
339
- it "transitions to complete" do
340
- order.next!
341
- expect(order.state).to eq("complete")
342
- end
343
- end
344
-
345
- context "correctly determining payment required based on shipping information" do
346
- let(:shipment) do
347
- FactoryGirl.create(:shipment)
348
- end
349
-
350
- before do
351
- # Needs to be set here because we're working with a persisted order object
352
- order.email = "test@example.com"
353
- order.save!
354
- order.shipments << shipment
355
- end
356
-
357
- context "with a shipment that has a price" do
358
- before do
359
- shipment.shipping_rates.first.update_column(:cost, 10)
360
- order.set_shipments_cost
361
- end
362
-
363
- it "transitions to payment" do
364
- order.next!
365
- expect(order.state).to eq("payment")
366
- end
367
- end
368
-
369
- context "with a shipment that is free" do
370
- before do
371
- shipment.shipping_rates.first.update_column(:cost, 0)
372
- order.set_shipments_cost
373
- end
374
-
375
- it "skips payment, transitions to complete" do
376
- order.next!
377
- expect(order.state).to eq("complete")
378
- end
379
- end
380
- end
381
- end
382
-
383
- context "from payment" do
384
- before do
385
- order.state = 'payment'
386
- end
387
-
388
- context "with confirmation required" do
389
- before do
390
- allow(order).to receive_messages confirmation_required?: true
391
- end
392
-
393
- it "transitions to confirm" do
394
- order.next!
395
- assert_state_changed(order, 'payment', 'confirm')
396
- expect(order.state).to eq("confirm")
397
- end
398
- end
399
-
400
- context "without confirmation required" do
401
- before do
402
- order.email = "spree@example.com"
403
- allow(order).to receive_messages confirmation_required?: false
404
- allow(order).to receive_messages payment_required?: true
405
- order.payments << FactoryGirl.create(:payment, state: payment_state, order: order)
406
- end
407
-
408
- context 'when there is at least one valid payment' do
409
- let(:payment_state) { 'checkout' }
410
-
411
- context 'line_items are in stock' do
412
- before do
413
- expect(order).to receive(:process_payments!).once { true }
414
- end
415
-
416
- it "transitions to complete" do
417
- order.next!
418
- assert_state_changed(order, 'payment', 'complete')
419
- expect(order.state).to eq('complete')
420
- end
421
- end
422
-
423
- context 'line_items are not in stock' do
424
- before do
425
- expect(order).to receive(:ensure_line_items_are_in_stock).once { false }
426
- end
427
-
428
- it 'should not receive process_payments!' do
429
- expect(order).not_to receive(:process_payments!)
430
- order.next
431
- end
432
-
433
- it 'does not transition to complete' do
434
- order.next
435
- expect(order.state).to eq('payment')
436
- end
437
- end
438
- end
439
-
440
- context 'when there is only an invalid payment' do
441
- let(:payment_state) { 'failed' }
442
-
443
- it "raises a StateMachine::InvalidTransition" do
444
- expect {
445
- order.next!
446
- }.to raise_error(StateMachines::InvalidTransition, /#{Spree.t(:no_payment_found)}/)
447
-
448
- expect(order.errors[:base]).to include(Spree.t(:no_payment_found))
449
- end
450
- end
451
- end
452
-
453
- # Regression test for #2028
454
- context "when payment is not required" do
455
- before do
456
- allow(order).to receive_messages payment_required?: false
457
- end
458
-
459
- it "does not call process payments" do
460
- expect(order).not_to receive(:process_payments!)
461
- order.next!
462
- assert_state_changed(order, 'payment', 'complete')
463
- expect(order.state).to eq("complete")
464
- end
465
- end
466
- end
467
- end
468
-
469
- context "to complete" do
470
- before do
471
- order.state = 'confirm'
472
- order.save!
473
- end
474
-
475
- context "default credit card" do
476
- before do
477
- order.user = FactoryGirl.create(:user)
478
- order.email = 'spree@example.org'
479
- order.payments << FactoryGirl.create(:payment)
480
-
481
- # make sure we will actually capture a payment
482
- allow(order).to receive_messages(payment_required?: true)
483
- order.line_items << FactoryGirl.create(:line_item)
484
- Spree::OrderUpdater.new(order).update
485
-
486
- order.save!
487
- end
488
-
489
- it "makes the current credit card a user's default credit card" do
490
- order.next!
491
- expect(order.state).to eq 'complete'
492
- expect(order.user.reload.default_credit_card.try(:id)).to eq(order.credit_cards.first.id)
493
- end
494
-
495
- it "does not assign a default credit card if temporary_credit_card is set" do
496
- order.temporary_credit_card = true
497
- order.next!
498
- expect(order.user.reload.default_credit_card).to be_nil
499
- end
500
- end
501
- end
502
-
503
- context "subclassed order" do
504
- # This causes another test above to fail, but fixing this test should make
505
- # the other test pass
506
- class SubclassedOrder < Spree::Order
507
- checkout_flow do
508
- go_to_state :payment
509
- go_to_state :complete
510
- end
511
- end
512
-
513
- skip "should only call default transitions once when checkout_flow is redefined" do
514
- order = SubclassedOrder.new
515
- allow(order).to receive_messages payment_required?: true
516
- expect(order).to receive(:process_payments!).once
517
- order.state = "payment"
518
- order.next!
519
- assert_state_changed(order, 'payment', 'complete')
520
- expect(order.state).to eq("complete")
521
- end
522
- end
523
-
524
- context "re-define checkout flow" do
525
- before do
526
- @old_checkout_flow = Spree::Order.checkout_flow
527
- Spree::Order.class_eval do
528
- checkout_flow do
529
- go_to_state :payment
530
- go_to_state :complete
531
- end
532
- end
533
- end
534
-
535
- after do
536
- Spree::Order.checkout_flow(&@old_checkout_flow)
537
- end
538
-
539
- it "should not keep old event transitions when checkout_flow is redefined" do
540
- expect(Spree::Order.next_event_transitions).to eq([{cart: :payment}, {payment: :complete}])
541
- end
542
-
543
- it "should not keep old events when checkout_flow is redefined" do
544
- state_machine = Spree::Order.state_machine
545
- expect(state_machine.states.any? { |s| s.name == :address }).to be false
546
- known_states = state_machine.events[:next].branches.map(&:known_states).flatten
547
- expect(known_states).not_to include(:address)
548
- expect(known_states).not_to include(:delivery)
549
- expect(known_states).not_to include(:confirm)
550
- end
551
- end
552
-
553
- # Regression test for #3665
554
- context "with only a complete step" do
555
- before do
556
- @old_checkout_flow = Spree::Order.checkout_flow
557
- Spree::Order.class_eval do
558
- checkout_flow do
559
- go_to_state :complete
560
- end
561
- end
562
- end
563
-
564
- after do
565
- Spree::Order.checkout_flow(&@old_checkout_flow)
566
- end
567
-
568
- it "does not attempt to process payments" do
569
- allow(order).to receive_message_chain(:line_items, :present?) { true }
570
- allow(order).to receive(:ensure_line_items_are_in_stock) { true }
571
- allow(order).to receive(:ensure_line_item_variants_are_not_discontinued) { true }
572
- expect(order).not_to receive(:payment_required?)
573
- expect(order).not_to receive(:process_payments!)
574
- order.next!
575
- assert_state_changed(order, 'cart', 'complete')
576
- end
577
-
578
- end
579
-
580
- context "insert checkout step" do
581
- before do
582
- @old_checkout_flow = Spree::Order.checkout_flow
583
- Spree::Order.class_eval do
584
- insert_checkout_step :new_step, before: :address
585
- end
586
- end
587
-
588
- after do
589
- Spree::Order.checkout_flow(&@old_checkout_flow)
590
- end
591
-
592
- it "should maintain removed transitions" do
593
- transition = Spree::Order.find_transition(from: :delivery, to: :confirm)
594
- expect(transition).to be_nil
595
- end
596
-
597
- context "before" do
598
- before do
599
- Spree::Order.class_eval do
600
- insert_checkout_step :before_address, before: :address
601
- end
602
- end
603
-
604
- specify do
605
- order = Spree::Order.new
606
- expect(order.checkout_steps).to eq(%w(new_step before_address address delivery complete))
607
- end
608
-
609
- it 'goes through checkout without raising error' do
610
- expect{ OrderWalkthrough.up_to(:complete) }.to_not raise_error
611
- end
612
- end
613
-
614
- context "after" do
615
- before do
616
- Spree::Order.class_eval do
617
- insert_checkout_step :after_address, after: :address
618
- end
619
- end
620
-
621
- specify do
622
- order = Spree::Order.new
623
- expect(order.checkout_steps).to eq(%w(new_step address after_address delivery complete))
624
- end
625
-
626
- it 'goes through checkout without raising error' do
627
- expect{ OrderWalkthrough.up_to(:complete) }.to_not raise_error
628
- end
629
- end
630
- end
631
-
632
- context "remove checkout step" do
633
- before do
634
- @old_checkout_flow = Spree::Order.checkout_flow
635
- Spree::Order.class_eval do
636
- remove_checkout_step :address
637
- end
638
- end
639
-
640
- after do
641
- Spree::Order.checkout_flow(&@old_checkout_flow)
642
- end
643
-
644
- it "should maintain removed transitions" do
645
- transition = Spree::Order.find_transition(from: :delivery, to: :confirm)
646
- expect(transition).to be_nil
647
- end
648
-
649
- specify do
650
- order = Spree::Order.new
651
- expect(order.checkout_steps).to eq(%w(delivery complete))
652
- end
653
- end
654
-
655
- describe 'update_from_params' do
656
- let(:permitted_params) { {} }
657
- let(:params) { {} }
658
-
659
- it 'calls update_atributes without order params' do
660
- expect(order).to receive(:update_attributes).with({})
661
- order.update_from_params( params, permitted_params)
662
- end
663
-
664
- it 'runs the callbacks' do
665
- expect(order).to receive(:run_callbacks).with(:updating_from_params)
666
- order.update_from_params( params, permitted_params)
667
- end
668
-
669
- context "passing a credit card" do
670
- let(:permitted_params) do
671
- Spree::PermittedAttributes.checkout_attributes +
672
- [payments_attributes: Spree::PermittedAttributes.payment_attributes]
673
- end
674
-
675
- let(:credit_card) { create(:credit_card, user_id: order.user_id) }
676
-
677
- let(:params) do
678
- ActionController::Parameters.new(
679
- order: { payments_attributes: [{payment_method_id: 1}], existing_card: credit_card.id },
680
- cvc_confirm: "737",
681
- payment_source: {
682
- "1" => { name: "Luis Braga",
683
- number: "4111 1111 1111 1111",
684
- expiry: "06 / 2016",
685
- verification_value: "737",
686
- cc_type: "" }
687
- }
688
- )
689
- end
690
-
691
- before { order.user_id = 3 }
692
-
693
- it "sets confirmation value when its available via :cvc_confirm" do
694
- allow(Spree::CreditCard).to receive_messages find: credit_card
695
- expect(credit_card).to receive(:verification_value=)
696
- order.update_from_params(params, permitted_params)
697
- end
698
-
699
- it "sets existing card as source for new payment" do
700
- expect {
701
- order.update_from_params(params, permitted_params)
702
- }.to change { Spree::Payment.count }.by(1)
703
-
704
- expect(Spree::Payment.last.source).to eq credit_card
705
- end
706
-
707
- it "sets request_env on payment" do
708
- request_env = { "USER_AGENT" => "Firefox" }
709
-
710
- order.update_from_params(params, permitted_params, request_env)
711
- expect(order.payments[0].request_env).to eq request_env
712
- end
713
-
714
- it "dont let users mess with others users cards" do
715
- credit_card.update_column :user_id, 5
716
-
717
- expect {
718
- order.update_from_params(params, permitted_params)
719
- }.to raise_error(Spree.t(:invalid_credit_card))
720
- end
721
- end
722
-
723
- context 'has params' do
724
- let(:permitted_params) { [ :good_param ] }
725
- let(:params) { ActionController::Parameters.new(order: { bad_param: 'okay' } ) }
726
-
727
- it 'does not let through unpermitted attributes' do
728
- expect(order).to receive(:update_attributes).with(ActionController::Parameters.new.permit!)
729
- order.update_from_params(params, permitted_params)
730
- end
731
-
732
- context 'has existing_card param' do
733
- let(:permitted_params) do
734
- Spree::PermittedAttributes.checkout_attributes +
735
- [payments_attributes: Spree::PermittedAttributes.payment_attributes]
736
- end
737
- let(:credit_card) { create(:credit_card, user_id: order.user_id) }
738
- let(:params) do
739
- ActionController::Parameters.new(
740
- order: { payments_attributes: [{payment_method_id: 1}], existing_card: credit_card.id }
741
- )
742
- end
743
-
744
- before do
745
- Dummy::Application.config.action_controller.action_on_unpermitted_parameters = :raise
746
- order.user_id = 3
747
- end
748
-
749
- after do
750
- Dummy::Application.config.action_controller.action_on_unpermitted_parameters = :log
751
- end
752
-
753
- it 'does not attempt to permit existing_card' do
754
- expect {
755
- order.update_from_params(params, permitted_params)
756
- }.not_to raise_error
757
- end
758
- end
759
-
760
- context 'has allowed params' do
761
- let(:params) { ActionController::Parameters.new(order: { good_param: 'okay' } ) }
762
-
763
- it 'accepts permitted attributes' do
764
- expect(order).to receive(:assign_attributes).with(ActionController::Parameters.new("good_param" => 'okay').permit!)
765
- order.update_from_params(params, permitted_params)
766
- end
767
- end
768
- end
769
- end
770
- end