effective_orders 1.8.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +150 -60
  4. data/Rakefile +0 -3
  5. data/active_admin/effective_orders.rb +14 -9
  6. data/app/assets/javascripts/effective_orders.js +2 -0
  7. data/app/assets/javascripts/effective_orders/{stripe_charges.js.coffee → providers/stripe_charges.js.coffee} +1 -1
  8. data/app/assets/javascripts/effective_orders/{stripe_subscriptions.js.coffee → providers/stripe_subscriptions.js.coffee} +1 -1
  9. data/app/assets/stylesheets/effective_orders/_order.scss +9 -3
  10. data/app/controllers/admin/orders_controller.rb +87 -3
  11. data/app/controllers/concerns/acts_as_active_admin_controller.rb +2 -1
  12. data/app/controllers/effective/carts_controller.rb +4 -2
  13. data/app/controllers/effective/orders_controller.rb +101 -60
  14. data/app/controllers/effective/providers/app_checkout.rb +10 -2
  15. data/app/controllers/effective/providers/ccbill.rb +34 -0
  16. data/app/controllers/effective/providers/cheque.rb +30 -0
  17. data/app/controllers/effective/providers/moneris.rb +7 -7
  18. data/app/controllers/effective/providers/paypal.rb +7 -5
  19. data/app/controllers/effective/providers/pretend.rb +22 -0
  20. data/app/controllers/effective/providers/stripe.rb +26 -24
  21. data/app/controllers/effective/webhooks_controller.rb +1 -1
  22. data/app/helpers/effective_carts_helper.rb +59 -29
  23. data/app/helpers/effective_ccbill_helper.rb +25 -0
  24. data/app/helpers/effective_orders_helper.rb +50 -41
  25. data/app/helpers/effective_paypal_helper.rb +11 -11
  26. data/app/mailers/effective/orders_mailer.rb +95 -20
  27. data/app/models/concerns/acts_as_purchasable.rb +14 -22
  28. data/app/models/effective/cart.rb +9 -15
  29. data/app/models/effective/cart_item.rb +15 -13
  30. data/app/models/effective/customer.rb +9 -9
  31. data/app/models/effective/datatables/order_items.rb +14 -8
  32. data/app/models/effective/datatables/orders.rb +56 -69
  33. data/app/models/effective/order.rb +250 -139
  34. data/app/models/effective/order_item.rb +23 -16
  35. data/app/models/effective/product.rb +23 -0
  36. data/app/models/effective/providers/ccbill_postback.rb +85 -0
  37. data/app/models/effective/{stripe_charge.rb → providers/stripe_charge.rb} +1 -1
  38. data/app/models/effective/subscription.rb +16 -12
  39. data/app/models/effective/tax_rate_calculator.rb +45 -0
  40. data/app/views/admin/customers/index.html.haml +2 -5
  41. data/app/views/admin/order_items/index.html.haml +2 -5
  42. data/app/views/admin/orders/_actions.html.haml +2 -0
  43. data/app/views/admin/orders/_form.html.haml +28 -0
  44. data/app/views/admin/orders/_order_item_fields.html.haml +9 -0
  45. data/app/views/admin/orders/index.html.haml +9 -5
  46. data/app/views/admin/orders/new.html.haml +3 -0
  47. data/app/views/effective/carts/_cart.html.haml +3 -12
  48. data/app/views/effective/carts/_cart_actions.html.haml +4 -0
  49. data/app/views/effective/carts/show.html.haml +10 -12
  50. data/app/views/effective/orders/_checkout_step1.html.haml +46 -0
  51. data/app/views/effective/orders/_checkout_step2.html.haml +33 -0
  52. data/app/views/effective/orders/_order.html.haml +2 -0
  53. data/app/views/effective/orders/_order_actions.html.haml +10 -5
  54. data/app/views/effective/orders/_order_footer.html.haml +1 -0
  55. data/app/views/effective/orders/_order_items.html.haml +11 -9
  56. data/app/views/effective/orders/_order_note.html.haml +8 -0
  57. data/app/views/effective/orders/_order_note_fields.html.haml +5 -0
  58. data/app/views/effective/orders/_order_shipping.html.haml +4 -4
  59. data/app/views/effective/orders/_order_user_fields.html.haml +1 -0
  60. data/app/views/effective/orders/_orders_table.html.haml +27 -0
  61. data/app/views/effective/orders/ccbill/_form.html.haml +24 -0
  62. data/app/views/effective/orders/checkout_step1.html.haml +3 -0
  63. data/app/views/effective/orders/checkout_step2.html.haml +3 -0
  64. data/app/views/effective/orders/cheque/_form.html.haml +2 -0
  65. data/app/views/effective/orders/cheque/pay_by_cheque.html.haml +9 -0
  66. data/app/views/effective/orders/declined.html.haml +4 -2
  67. data/app/views/effective/orders/my_purchases.html.haml +1 -1
  68. data/app/views/effective/orders/my_sales.html.haml +1 -1
  69. data/app/views/effective/orders/purchased.html.haml +3 -2
  70. data/app/views/effective/orders/show.html.haml +1 -1
  71. data/app/views/effective/orders/stripe/_form.html.haml +5 -5
  72. data/app/views/effective/orders_mailer/order_error.html.haml +11 -0
  73. data/app/views/effective/orders_mailer/payment_request_to_buyer.html.haml +13 -0
  74. data/app/views/effective/orders_mailer/pending_order_invoice_to_buyer.html.haml +13 -0
  75. data/app/views/layouts/effective_orders_mailer_layout.html.haml +7 -7
  76. data/config/routes.rb +39 -24
  77. data/db/migrate/01_create_effective_orders.rb.erb +20 -1
  78. data/db/upgrade/03_upgrade_effective_orders_from1x.rb.erb +95 -0
  79. data/lib/effective_orders.rb +67 -9
  80. data/lib/effective_orders/app_checkout_service.rb +1 -2
  81. data/lib/effective_orders/engine.rb +46 -14
  82. data/lib/effective_orders/version.rb +1 -1
  83. data/lib/generators/effective_orders/install_generator.rb +1 -0
  84. data/lib/generators/effective_orders/upgrade_from03x_generator.rb +1 -0
  85. data/lib/generators/effective_orders/upgrade_from1x_generator.rb +31 -0
  86. data/lib/generators/templates/effective_orders.rb +131 -66
  87. data/lib/generators/templates/effective_orders_mailer_preview.rb +28 -13
  88. data/spec/controllers/admin/orders_controller_spec.rb +242 -0
  89. data/spec/controllers/ccbill_orders_controller_spec.rb +103 -0
  90. data/spec/controllers/moneris_orders_controller_spec.rb +23 -23
  91. data/spec/controllers/orders_controller_spec.rb +167 -79
  92. data/spec/controllers/stripe_orders_controller_spec.rb +7 -7
  93. data/spec/dummy/app/models/product.rb +0 -8
  94. data/spec/dummy/app/models/product_with_float_price.rb +0 -8
  95. data/spec/dummy/app/models/user.rb +2 -19
  96. data/spec/dummy/config/application.rb +2 -1
  97. data/spec/dummy/config/environments/test.rb +1 -0
  98. data/spec/dummy/config/initializers/effective_orders.rb +109 -64
  99. data/spec/dummy/db/schema.rb +15 -2
  100. data/spec/dummy/db/test.sqlite3 +0 -0
  101. data/spec/dummy/log/test.log +0 -258
  102. data/spec/models/acts_as_purchasable_spec.rb +8 -6
  103. data/spec/models/factories_spec.rb +7 -1
  104. data/spec/models/order_item_spec.rb +1 -1
  105. data/spec/models/order_spec.rb +165 -46
  106. data/spec/models/stripe_charge_spec.rb +5 -5
  107. data/spec/spec_helper.rb +2 -0
  108. data/spec/support/factories.rb +49 -33
  109. metadata +47 -64
  110. data/app/views/effective/orders/_checkout_step_1.html.haml +0 -43
  111. data/app/views/effective/orders/_checkout_step_2.html.haml +0 -25
  112. data/app/views/effective/orders/_my_purchases.html.haml +0 -17
  113. data/app/views/effective/orders/checkout.html.haml +0 -3
  114. data/app/views/effective/orders/new.html.haml +0 -4
  115. data/spec/dummy/log/development.log +0 -82
@@ -9,13 +9,13 @@ describe Product do
9
9
 
10
10
  describe 'assumptions' do
11
11
  it 'should be effectively purchasable' do
12
- product.is_effectively_purchasable?.should eq true
12
+ product.kind_of?(ActsAsPurchasable).should eq true
13
13
  end
14
14
  end
15
15
 
16
16
  describe 'purchased' do
17
17
  it 'is purchased? when in a purchased Order' do
18
- order.purchase!('by a test')
18
+ order.purchase!
19
19
 
20
20
  product.purchased?.should eq true
21
21
  product.purchased_orders.include?(order).should eq true
@@ -36,7 +36,7 @@ describe Product do
36
36
  end
37
37
  end
38
38
 
39
- order.purchase!('by a test')
39
+ order.purchase!
40
40
 
41
41
  instance_order.purchased?.should eq true
42
42
  instance_product.purchased?.should eq true
@@ -44,7 +44,7 @@ describe Product do
44
44
  end
45
45
 
46
46
  it 'is returned by the purchased scopes' do
47
- order.purchase!('by a test')
47
+ order.purchase!
48
48
 
49
49
  Product.purchased.to_a.include?(product).should eq true
50
50
  Product.purchased_by(order.user).to_a.include?(product).should eq true
@@ -60,7 +60,8 @@ describe Product do
60
60
  product_with_float_price.price = 20.00
61
61
  product_with_float_price.tax_exempt = true
62
62
 
63
- order = Effective::Order.new(product_with_float_price, user)
63
+ order = Effective::Order.new(product_with_float_price, user: user)
64
+ order.billing_address = FactoryGirl.create(:address, state_code: 'AB')
64
65
 
65
66
  order.subtotal.should eq 2000
66
67
  order.tax.should eq 0
@@ -71,7 +72,8 @@ describe Product do
71
72
  product_with_float_price.price = 20.00
72
73
  product_with_float_price.tax_exempt = false
73
74
 
74
- order = Effective::Order.new(product_with_float_price, user)
75
+ order = Effective::Order.new(product_with_float_price, user: user)
76
+ order.billing_address = FactoryGirl.create(:address, state_code: 'AB')
75
77
 
76
78
  order.subtotal.should eq 2000
77
79
  order.tax.should eq 100
@@ -8,7 +8,13 @@ describe 'Factories' do
8
8
  after { StripeMock.stop }
9
9
 
10
10
  it 'should have all valid factories' do
11
- factories.each { |factory| FactoryGirl.create(factory).valid?.should eq true }
11
+ factories.each do |factory|
12
+ obj = FactoryGirl.create(factory)
13
+
14
+ puts "Invalid factory #{factory}: #{obj.errors.inspect}" unless obj.valid?
15
+
16
+ obj.valid?.should eq true
17
+ end
12
18
  end
13
19
 
14
20
  it 'should have created an Order with a billing_address and shipping_address' do
@@ -19,7 +19,7 @@ describe Effective::OrderItem do
19
19
 
20
20
  describe 'scopes' do
21
21
  it 'is included in the Sold scope when order is purchased' do
22
- order.purchase!('from a test')
22
+ order.purchase!
23
23
  (order.order_items.size > 0).should eq true
24
24
 
25
25
  sold_items = Effective::OrderItem.sold.to_a
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Effective::Order do
3
+ describe Effective::Order, type: :model do
4
4
  let(:cart) { FactoryGirl.create(:cart) }
5
5
  let(:order) { FactoryGirl.create(:order) }
6
6
  let(:user) { FactoryGirl.create(:user) }
@@ -8,9 +8,8 @@ describe Effective::Order do
8
8
  let(:product2) { FactoryGirl.create(:product) }
9
9
 
10
10
  it 'calculates dollars based on its order items' do
11
- order.total.should eq order.order_items.collect(&:total).sum
12
11
  order.subtotal.should eq order.order_items.collect(&:subtotal).sum
13
- order.tax.should eq order.order_items.collect(&:tax).sum
12
+ order.total.should eq (order.order_items.collect(&:subtotal).sum + order.tax.to_i)
14
13
  order.num_items.should eq order.order_items.collect(&:quantity).sum
15
14
  end
16
15
 
@@ -26,9 +25,7 @@ describe Effective::Order do
26
25
  end
27
26
 
28
27
  order.order_items.length.should eq cart.cart_items.length
29
- order.total.should eq cart.total
30
28
  order.subtotal.should eq cart.subtotal
31
- order.tax.should eq cart.tax
32
29
  end
33
30
 
34
31
  it 'creates appropriate OrderItems when initialized with an array of purchasables' do
@@ -36,7 +33,6 @@ describe Effective::Order do
36
33
  order.order_items.size.should eq 2
37
34
 
38
35
  order.subtotal.should eq (product.price + product2.price)
39
- order.total.should eq ((product.price + product2.price) * 1.05)
40
36
  end
41
37
 
42
38
  it 'creates appropriate OrderItems when initialized with a single purchasable' do
@@ -58,24 +54,22 @@ describe Effective::Order do
58
54
 
59
55
  describe 'minimum zero math' do
60
56
  it 'has a minimum order total of 0' do
61
- order.order_items.each { |order_item| allow(order_item).to receive(:total).and_return(-1000) }
57
+ order.subtotal = nil
58
+ order.total = nil
62
59
 
60
+ order.order_items.each { |oi| oi.price = -1000; oi.tax_exempt = true; }
63
61
  order.order_items.collect(&:total).sum.should eq -3000
62
+
64
63
  order.total.should eq 0
65
64
  end
66
65
 
67
66
  it 'has no minimum subtotal' do
68
- order.order_items.each { |order_item| allow(order_item).to receive(:subtotal).and_return(-1000) }
67
+ order.subtotal = nil
69
68
 
69
+ order.order_items.each { |oi| oi.price = -1000; oi.tax_exempt = true; }
70
70
  order.order_items.collect(&:subtotal).sum.should eq -3000
71
- order.subtotal.should eq -3000
72
- end
73
71
 
74
- it 'has a minimum order tax of 0.00' do
75
- order.order_items.each { |order_item| allow(order_item).to receive(:tax).and_return(-1000) }
76
-
77
- order.order_items.collect(&:tax).sum.should eq -3000
78
- order.tax.should eq 0
72
+ order.subtotal.should eq -3000
79
73
  end
80
74
  end
81
75
 
@@ -89,8 +83,8 @@ describe Effective::Order do
89
83
  it 'assigns addresses from the user' do
90
84
  order = Effective::Order.new()
91
85
 
92
- user.billing_address = FactoryGirl.create(:address, :category => :billing)
93
- user.shipping_address = FactoryGirl.create(:address, :category => :shipping)
86
+ user.billing_address = FactoryGirl.create(:address, category: :billing)
87
+ user.shipping_address = FactoryGirl.create(:address, category: :shipping)
94
88
 
95
89
  order.user = user
96
90
 
@@ -103,6 +97,10 @@ describe Effective::Order do
103
97
  end
104
98
 
105
99
  describe 'validations' do
100
+ it 'should validate inclusion of purchase state' do
101
+ expect(subject).to validate_inclusion_of(:purchase_state).in_array([nil, EffectiveOrders::PURCHASED, EffectiveOrders::DECLINED, EffectiveOrders::PENDING])
102
+ end
103
+
106
104
  it 'should be invalid without a user or order_items' do
107
105
  order = Effective::Order.new()
108
106
  order.valid?.should eq false
@@ -126,8 +124,7 @@ describe Effective::Order do
126
124
  end
127
125
 
128
126
  it 'should be invalid when less than the minimum charge' do
129
- allow(order).to receive(:total).and_return(49)
130
-
127
+ order.order_items.each { |oi| oi.price = 1 }
131
128
  order.valid?.should eq false
132
129
 
133
130
  order.errors[:total].present?.should eq true
@@ -150,9 +147,125 @@ describe Effective::Order do
150
147
  end
151
148
  end
152
149
 
150
+ describe 'tax and tax rate' do
151
+ it 'is invalid with no tax rate' do
152
+ order = Effective::Order.new()
153
+ order.tax_rate.should eq nil
154
+ order.valid?.should eq false
155
+ order.errors[:tax_rate].present?.should eq true
156
+ end
157
+
158
+ it 'is valid with no tax rate when skip_buyer_validations = true' do
159
+ order = Effective::Order.new()
160
+ order.skip_buyer_validations = true
161
+ order.tax_rate.should eq nil
162
+ order.errors[:tax_rate].present?.should eq false
163
+ end
164
+
165
+ it 'sets a tax rate when billing_address is present' do
166
+ order = FactoryGirl.create(:order)
167
+ order.billing_address.present?.should eq true
168
+ order.valid?.should eq true
169
+ order.errors[:tax_rate].blank?.should eq true
170
+ end
171
+
172
+ it 'updates the tax rate on valid? when billing_address changes' do
173
+ order = FactoryGirl.create(:order)
174
+
175
+ order.billing_address = FactoryGirl.create(:address, state_code: 'AB') # 5.0% tax
176
+ order.valid?.should eq true
177
+ order.tax_rate.should eq 5.0
178
+ order.tax.should eq (order.subtotal * 0.05)
179
+ order.total.should eq (order.subtotal + order.tax)
180
+ total_one = order.total
181
+
182
+ order.billing_address = FactoryGirl.create(:address, state_code: 'ON') # 13.0% tax
183
+ order.valid?.should eq true
184
+ order.tax_rate.should eq 13.0
185
+ order.tax.should eq (order.subtotal * 0.13)
186
+ order.total.should eq (order.subtotal + order.tax)
187
+ total_two = order.total
188
+
189
+ total_one.should_not eq total_two
190
+ end
191
+
192
+ end
193
+
194
+ describe 'create_as_pending' do
195
+ it 'sets the pending state' do
196
+ order = FactoryGirl.build(:order)
197
+ order.order_items << FactoryGirl.build(:order_item, order: order)
198
+
199
+ order.create_as_pending.should eq true
200
+ order.pending?.should eq true
201
+ end
202
+
203
+ it 'disregards invalid addresses' do
204
+ order = FactoryGirl.build(:order)
205
+ order.order_items << FactoryGirl.build(:order_item, order: order)
206
+
207
+ order.billing_address = Effective::Address.new(address1: 'invalid')
208
+ order.shipping_address = Effective::Address.new(address1: 'invalid')
209
+
210
+ success = order.create_as_pending
211
+
212
+ success.should eq true
213
+ end
214
+
215
+ it 'sends a request for payment when send_payment_request_to_buyer is true' do
216
+ Effective::OrdersMailer.deliveries.clear
217
+
218
+ order = FactoryGirl.build(:order)
219
+ order.order_items << FactoryGirl.build(:order_item, order: order)
220
+
221
+ order.send_payment_request_to_buyer = true
222
+
223
+ order.create_as_pending.should eq true
224
+ order.send_payment_request_to_buyer?.should eq true
225
+
226
+ Effective::OrdersMailer.deliveries.length.should eq 1
227
+ end
228
+
229
+ it 'does not send a request for payment when send_payment_request_to_buyer is false' do
230
+ Effective::OrdersMailer.deliveries.clear
231
+
232
+ order = FactoryGirl.build(:order)
233
+ order.order_items << FactoryGirl.build(:order_item, order: order)
234
+
235
+ order.create_as_pending.should eq true
236
+
237
+ Effective::OrdersMailer.deliveries.length.should eq 0
238
+ end
239
+
240
+ end
241
+
242
+ describe 'save as pending' do
243
+ let(:order) { FactoryGirl.build(:order, billing_address: FactoryGirl.build(:address), shipping_address: FactoryGirl.build(:address)) }
244
+
245
+ it 'sets the pending state' do
246
+ order.order_items << FactoryGirl.build(:order_item, order: order)
247
+
248
+ order.purchase_state = EffectiveOrders::PENDING
249
+
250
+ order.save.should eq true
251
+ order.pending?.should eq true
252
+ end
253
+
254
+ it 'does not accept invalid addresses' do
255
+ order.order_items << FactoryGirl.build(:order_item, order: order)
256
+
257
+ order.billing_address = Effective::Address.new(address1: 'invalid')
258
+ order.shipping_address = Effective::Address.new(address1: 'invalid')
259
+
260
+ order.purchase_state = EffectiveOrders::PENDING
261
+
262
+ order.save.should eq false
263
+ end
264
+ end
265
+
153
266
  describe 'purchase!' do
154
267
  it 'assigns the purchase_state, purchase_at and payment' do
155
- order.purchase!('by a test').should eq true
268
+ order.purchase!(details: 'by a test').should eq true
156
269
 
157
270
  order.purchase_state.should eq EffectiveOrders::PURCHASED
158
271
  order.purchased_at.kind_of?(Time).should eq true
@@ -161,62 +274,62 @@ describe Effective::Order do
161
274
 
162
275
  it 'sends purchased callback to all order_items' do
163
276
  order.order_items.each { |oi| oi.purchasable.should_receive(:purchased!).with(order, oi) }
164
- order.purchase!('by a test')
277
+ order.purchase!(details: 'by a test')
165
278
  end
166
279
 
167
280
  it 'returns true when purchased twice' do
168
- order.purchase!('first time by a test')
169
- order.purchase!('second time by a test').should eq false
281
+ order.purchase!(details: 'first time by a test')
282
+ order.purchase!(details: 'second time by a test').should eq false
170
283
  end
171
284
 
172
285
  it 'sends emails to the admin, buyer and seller' do
173
286
  Effective::OrdersMailer.deliveries.clear
174
287
 
175
- order.purchase!('by a test')
288
+ order.purchase!(details: 'by a test')
176
289
 
177
290
  Effective::OrdersMailer.deliveries.length.should eq 2
178
291
 
179
292
  Effective::OrdersMailer.deliveries[0].to.first.should eq 'admin@example.com'
180
- Effective::OrdersMailer.deliveries[0].subject.include?("Order ##{order.to_param} Receipt").should eq true
293
+ Effective::OrdersMailer.deliveries[0].subject.include?("Order Receipt: ##{order.to_param}").should eq true
181
294
 
182
295
  Effective::OrdersMailer.deliveries[1].to.first.should eq order.user.email
183
- Effective::OrdersMailer.deliveries[1].subject.include?("Order ##{order.to_param} Receipt").should eq true
296
+ Effective::OrdersMailer.deliveries[1].subject.include?("Order Receipt: ##{order.to_param}").should eq true
184
297
  end
185
298
 
186
- it 'does not send email if passed :email => false' do
299
+ it 'does not send email if passed email: false' do
187
300
  Effective::OrdersMailer.deliveries.clear
188
301
 
189
- order.purchase!('by a test', :email => false)
302
+ order.purchase!(details: 'by a test', email: false)
190
303
 
191
304
  Effective::OrdersMailer.deliveries.length.should eq 0
192
305
  end
193
306
 
194
307
  it 'is included with the purchased scope' do
195
- order.purchase!('by a test')
308
+ order.purchase!(details: 'by a test')
196
309
  Effective::Order.purchased.to_a.include?(order).should eq true
197
310
  Effective::Order.purchased_by(order.user).to_a.include?(order).should eq true
198
311
  end
199
312
 
200
313
  it 'is not included with the declined scope' do
201
- order.purchase!('by a test')
314
+ order.purchase!(details: 'by a test')
202
315
  Effective::Order.declined.to_a.include?(order).should eq false
203
316
  end
204
317
 
205
318
  it 'should return false when the Order is invalid' do
206
319
  allow(order).to receive(:valid?).and_return(false)
207
- expect { order.purchase!('by a test') }.to raise_exception(Exception)
320
+ expect { order.purchase!(details: 'by a test') }.to raise_exception(Exception)
208
321
  end
209
322
 
210
- it 'should return true when the Order is invalid and :validate => false is passed' do
323
+ it 'should return true when the Order is invalid and validate: false is passed' do
211
324
  allow(order).to receive(:valid?).and_return(false)
212
- order.purchase!('by a test', :validate => false).should eq true
325
+ order.purchase!(details: 'by a test', validate: false).should eq true
213
326
  end
214
327
 
215
328
  end
216
329
 
217
330
  describe 'purchased?' do
218
331
  it 'returns true when a purchased order' do
219
- order.purchase!('by a test')
332
+ order.purchase!(details: 'by a test')
220
333
  order.purchased?.should eq true
221
334
  end
222
335
 
@@ -225,14 +338,14 @@ describe Effective::Order do
225
338
  end
226
339
 
227
340
  it 'returns false when declined' do
228
- order.decline!('by a test')
341
+ order.decline!(details: 'by a test')
229
342
  order.purchased?.should eq false
230
343
  end
231
344
  end
232
345
 
233
346
  describe 'decline!' do
234
347
  it 'assigns the purchase_state' do
235
- order.decline!('by a test').should eq true
348
+ order.decline!(details: 'by a test').should eq true
236
349
 
237
350
  order.purchase_state.should eq EffectiveOrders::DECLINED
238
351
  order.payment[:details].should eq 'by a test'
@@ -241,26 +354,26 @@ describe Effective::Order do
241
354
 
242
355
  it 'sends declined callback to all order_items' do
243
356
  order.order_items.each { |oi| oi.purchasable.should_receive(:declined!).with(order, oi) }
244
- order.decline!('by a test')
357
+ order.decline!(details: 'by a test')
245
358
  end
246
359
 
247
360
  it 'returns false when declined twice' do
248
- order.decline!('first time')
249
- order.decline!('second time').should eq false
361
+ order.decline!(details: 'first time')
362
+ order.decline!(details: 'second time').should eq false
250
363
  end
251
364
 
252
365
  it 'returns false when declined twice' do
253
- order.decline!('first time')
254
- order.decline!('second time').should eq false
366
+ order.decline!(details: 'first time')
367
+ order.decline!(details: 'second time').should eq false
255
368
  end
256
369
 
257
370
  it 'is included with the declined scope' do
258
- order.decline!('by a test')
371
+ order.decline!(details: 'by a test')
259
372
  Effective::Order.declined.to_a.include?(order).should eq true
260
373
  end
261
374
 
262
375
  it 'is not included with the purchased scope' do
263
- order.decline!('by a test')
376
+ order.decline!(details: 'by a test')
264
377
  Effective::Order.purchased.to_a.include?(order).should eq false
265
378
  Effective::Order.purchased_by(order.user).to_a.include?(order).should eq false
266
379
  end
@@ -268,7 +381,7 @@ describe Effective::Order do
268
381
 
269
382
  describe 'declined?' do
270
383
  it 'returns true when a declined order' do
271
- order.decline!('by a test')
384
+ order.decline!(details: 'by a test')
272
385
  order.declined?.should eq true
273
386
  end
274
387
 
@@ -277,7 +390,7 @@ describe Effective::Order do
277
390
  end
278
391
 
279
392
  it 'returns false when purchased' do
280
- order.purchase!('by a test')
393
+ order.purchase!(details: 'by a test')
281
394
  order.declined?.should eq false
282
395
  end
283
396
  end
@@ -322,5 +435,11 @@ describe Effective::Order do
322
435
  end
323
436
  end
324
437
 
325
-
438
+ describe '#pending?' do
439
+ it 'should return true for pending orders only' do
440
+ expect(FactoryGirl.create(:purchased_order).pending?).to be_falsey
441
+ expect(FactoryGirl.create(:declined_order).pending?).to be_falsey
442
+ expect(FactoryGirl.create(:pending_order).pending?).to be_truthy
443
+ end
444
+ end
326
445
  end