effective_orders 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/effective_orders/version.rb +1 -1
- metadata +10 -258
- data/spec/controllers/admin/orders_controller_spec.rb +0 -243
- data/spec/controllers/carts_controller_spec.rb +0 -143
- data/spec/controllers/ccbill_orders_controller_spec.rb +0 -103
- data/spec/controllers/moneris_orders_controller_spec.rb +0 -133
- data/spec/controllers/orders_controller_spec.rb +0 -500
- data/spec/controllers/stripe_orders_controller_spec.rb +0 -128
- data/spec/controllers/webhooks_controller_spec.rb +0 -170
- data/spec/dummy/README.rdoc +0 -8
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/product.rb +0 -9
- data/spec/dummy/app/models/product_with_float_price.rb +0 -9
- data/spec/dummy/app/models/user.rb +0 -11
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -32
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -80
- data/spec/dummy/config/environments/test.rb +0 -36
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/devise.rb +0 -254
- data/spec/dummy/config/initializers/effective_addresses.rb +0 -15
- data/spec/dummy/config/initializers/effective_orders.rb +0 -269
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/simple_form.rb +0 -189
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -3
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/db/schema.rb +0 -158
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -164
- data/spec/dummy/log/test.log +0 -60
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/fixtures/stripe_webhooks/invoice.payment_succeeded.without_renewals.json +0 -76
- data/spec/helpers/effective_orders_helper_spec.rb +0 -21
- data/spec/models/acts_as_purchasable_spec.rb +0 -75
- data/spec/models/customer_spec.rb +0 -72
- data/spec/models/factories_spec.rb +0 -35
- data/spec/models/order_item_spec.rb +0 -35
- data/spec/models/order_spec.rb +0 -445
- data/spec/models/stripe_charge_spec.rb +0 -39
- data/spec/models/subscription_spec.rb +0 -103
- data/spec/spec_helper.rb +0 -46
- data/spec/support/factories.rb +0 -139
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# Attributes
|
4
|
-
describe 'Factories' do
|
5
|
-
let(:factories) { [:user, :customer, :subscription, :address, :product, :cart, :order_item, :order, :purchased_order, :declined_order, :cart_with_subscription, :order_with_subscription] }
|
6
|
-
|
7
|
-
before { StripeMock.start }
|
8
|
-
after { StripeMock.stop }
|
9
|
-
|
10
|
-
it 'should have all valid factories' do
|
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
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should have created an Order with a billing_address and shipping_address' do
|
21
|
-
order = FactoryGirl.create(:order)
|
22
|
-
|
23
|
-
order.billing_address.present?.should eq true
|
24
|
-
order.shipping_address.present?.should eq true
|
25
|
-
|
26
|
-
order.billing_address.valid?.should eq true
|
27
|
-
order.shipping_address.valid?.should eq true
|
28
|
-
|
29
|
-
order.billing_address.full_name.present?.should eq true
|
30
|
-
order.shipping_address.full_name.present?.should eq true
|
31
|
-
|
32
|
-
order.save.should eq true
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# # Attributes
|
4
|
-
describe Effective::OrderItem do
|
5
|
-
let(:order) { FactoryGirl.create(:order) }
|
6
|
-
let(:order_item) { FactoryGirl.create(:order_item) }
|
7
|
-
|
8
|
-
describe 'validations' do
|
9
|
-
it 'is invalid without required fields' do
|
10
|
-
order_item = Effective::OrderItem.new()
|
11
|
-
order_item.valid?.should eq false
|
12
|
-
|
13
|
-
order_item.errors[:title].present?.should eq true
|
14
|
-
order_item.errors[:quantity].present?.should eq true
|
15
|
-
order_item.errors[:tax_exempt].present?.should eq true
|
16
|
-
order_item.errors[:purchasable].present?.should eq true
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe 'scopes' do
|
21
|
-
it 'is included in the Sold scope when order is purchased' do
|
22
|
-
order.purchase!
|
23
|
-
(order.order_items.size > 0).should eq true
|
24
|
-
|
25
|
-
sold_items = Effective::OrderItem.sold.to_a
|
26
|
-
sold_items.size.should eq order.order_items.size
|
27
|
-
|
28
|
-
order.order_items.each { |oi| sold_items.include?(oi).should eq true }
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
data/spec/models/order_spec.rb
DELETED
@@ -1,445 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Effective::Order, type: :model do
|
4
|
-
let(:cart) { FactoryGirl.create(:cart) }
|
5
|
-
let(:order) { FactoryGirl.create(:order) }
|
6
|
-
let(:user) { FactoryGirl.create(:user) }
|
7
|
-
let(:product) { FactoryGirl.create(:product) }
|
8
|
-
let(:product2) { FactoryGirl.create(:product) }
|
9
|
-
|
10
|
-
it 'calculates dollars based on its order items' do
|
11
|
-
order.subtotal.should eq order.order_items.collect(&:subtotal).sum
|
12
|
-
order.total.should eq (order.order_items.collect(&:subtotal).sum + order.tax.to_i)
|
13
|
-
order.num_items.should eq order.order_items.collect(&:quantity).sum
|
14
|
-
end
|
15
|
-
|
16
|
-
describe '#initialize' do
|
17
|
-
it 'creates appropriate OrderItems when initialized with a Cart' do
|
18
|
-
order = Effective::Order.new(cart)
|
19
|
-
|
20
|
-
order.order_items.each_with_index do |order_item, x|
|
21
|
-
order_item.title.should eq cart.cart_items[x].title
|
22
|
-
order_item.price.should eq cart.cart_items[x].price
|
23
|
-
order_item.quantity.should eq cart.cart_items[x].quantity
|
24
|
-
order_item.purchasable.should eq cart.cart_items[x].purchasable
|
25
|
-
end
|
26
|
-
|
27
|
-
order.order_items.length.should eq cart.cart_items.length
|
28
|
-
order.subtotal.should eq cart.subtotal
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'creates appropriate OrderItems when initialized with an array of purchasables' do
|
32
|
-
order = Effective::Order.new([product, product2])
|
33
|
-
order.order_items.size.should eq 2
|
34
|
-
|
35
|
-
order.subtotal.should eq (product.price + product2.price)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'creates appropriate OrderItems when initialized with a single purchasable' do
|
39
|
-
order = Effective::Order.new(product)
|
40
|
-
order.order_items.size.should eq 1
|
41
|
-
|
42
|
-
order_item = order.order_items.first
|
43
|
-
|
44
|
-
order_item.title.should eq product.title
|
45
|
-
order_item.price.should eq product.price
|
46
|
-
order_item.purchasable.should eq product
|
47
|
-
order_item.quantity.should eq 1
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'throws an Exception when passed something unexpected' do
|
51
|
-
expect { Effective::Order.new(Object.new()) }.to raise_error(Exception)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe 'minimum zero math' do
|
56
|
-
it 'has a minimum order total of 0' do
|
57
|
-
order.subtotal = nil
|
58
|
-
order.total = nil
|
59
|
-
|
60
|
-
order.order_items.each { |oi| oi.price = -1000; oi.tax_exempt = true; }
|
61
|
-
order.order_items.collect(&:total).sum.should eq -3000
|
62
|
-
|
63
|
-
order.total.should eq 0
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'has no minimum subtotal' do
|
67
|
-
order.subtotal = nil
|
68
|
-
|
69
|
-
order.order_items.each { |oi| oi.price = -1000; oi.tax_exempt = true; }
|
70
|
-
order.order_items.collect(&:subtotal).sum.should eq -3000
|
71
|
-
|
72
|
-
order.subtotal.should eq -3000
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'user=' do
|
77
|
-
it 'assigns the user' do
|
78
|
-
order = Effective::Order.new()
|
79
|
-
order.user = user
|
80
|
-
order.user.should eq user
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'assigns addresses from the user' do
|
84
|
-
order = Effective::Order.new()
|
85
|
-
|
86
|
-
user.billing_address = FactoryGirl.create(:address, category: :billing)
|
87
|
-
user.shipping_address = FactoryGirl.create(:address, category: :shipping)
|
88
|
-
|
89
|
-
order.user = user
|
90
|
-
|
91
|
-
order.billing_address.should eq user.billing_address
|
92
|
-
order.save_billing_address.should eq true
|
93
|
-
|
94
|
-
order.shipping_address.should eq user.shipping_address
|
95
|
-
order.save_shipping_address.should eq true
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
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
|
-
|
104
|
-
it 'should be invalid without a user or order_items' do
|
105
|
-
order = Effective::Order.new()
|
106
|
-
order.valid?.should eq false
|
107
|
-
|
108
|
-
order.errors[:user_id].present?.should eq true
|
109
|
-
order.errors[:order_items].present?.should eq true
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'should be invalid when user is invalid' do
|
113
|
-
allow(order.user).to receive(:valid?).and_return(false)
|
114
|
-
order.valid?.should eq false
|
115
|
-
|
116
|
-
order.errors[:user].present?.should eq true
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'should be invalid when an order_item is invalid' do
|
120
|
-
allow(order.order_items.first).to receive(:valid?).and_return(false)
|
121
|
-
order.valid?.should eq false
|
122
|
-
|
123
|
-
order.errors[:order_items].present?.should eq true
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'should be invalid when less than the minimum charge' do
|
127
|
-
order.order_items.each { |oi| oi.price = 1 }
|
128
|
-
order.valid?.should eq false
|
129
|
-
|
130
|
-
order.errors[:total].present?.should eq true
|
131
|
-
order.errors[:total].first.downcase.include?('minimum order of 50 is required').should eq true
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should be valid when >= minimum charge' do
|
135
|
-
allow(order).to receive(:total).and_return(50)
|
136
|
-
order.valid?.should eq true
|
137
|
-
|
138
|
-
allow(order).to receive(:total).and_return(51)
|
139
|
-
order.valid?.should eq true
|
140
|
-
end
|
141
|
-
|
142
|
-
it 'should be valid for a free order' do
|
143
|
-
order.order_items.each { |order_item| allow(order_item).to receive(:total).and_return(0) }
|
144
|
-
|
145
|
-
order.valid?.should eq true
|
146
|
-
order.errors[:total].present?.should eq false
|
147
|
-
end
|
148
|
-
end
|
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
|
-
|
266
|
-
describe 'purchase!' do
|
267
|
-
it 'assigns the purchase_state, purchase_at and payment' do
|
268
|
-
order.purchase!(details: 'by a test').should eq true
|
269
|
-
|
270
|
-
order.purchase_state.should eq EffectiveOrders::PURCHASED
|
271
|
-
order.purchased_at.kind_of?(Time).should eq true
|
272
|
-
order.payment[:details].should eq 'by a test'
|
273
|
-
end
|
274
|
-
|
275
|
-
it 'sends purchased callback to all order_items' do
|
276
|
-
order.order_items.each { |oi| oi.purchasable.should_receive(:purchased!).with(order, oi) }
|
277
|
-
order.purchase!(details: 'by a test')
|
278
|
-
end
|
279
|
-
|
280
|
-
it 'returns true when purchased twice' do
|
281
|
-
order.purchase!(details: 'first time by a test')
|
282
|
-
order.purchase!(details: 'second time by a test').should eq false
|
283
|
-
end
|
284
|
-
|
285
|
-
it 'sends emails to the admin, buyer and seller' do
|
286
|
-
Effective::OrdersMailer.deliveries.clear
|
287
|
-
|
288
|
-
order.purchase!(details: 'by a test')
|
289
|
-
|
290
|
-
Effective::OrdersMailer.deliveries.length.should eq 2
|
291
|
-
|
292
|
-
Effective::OrdersMailer.deliveries[0].to.first.should eq 'admin@example.com'
|
293
|
-
Effective::OrdersMailer.deliveries[0].subject.include?("Order Receipt: ##{order.to_param}").should eq true
|
294
|
-
|
295
|
-
Effective::OrdersMailer.deliveries[1].to.first.should eq order.user.email
|
296
|
-
Effective::OrdersMailer.deliveries[1].subject.include?("Order Receipt: ##{order.to_param}").should eq true
|
297
|
-
end
|
298
|
-
|
299
|
-
it 'does not send email if passed email: false' do
|
300
|
-
Effective::OrdersMailer.deliveries.clear
|
301
|
-
|
302
|
-
order.purchase!(details: 'by a test', email: false)
|
303
|
-
|
304
|
-
Effective::OrdersMailer.deliveries.length.should eq 0
|
305
|
-
end
|
306
|
-
|
307
|
-
it 'is included with the purchased scope' do
|
308
|
-
order.purchase!(details: 'by a test')
|
309
|
-
Effective::Order.purchased.to_a.include?(order).should eq true
|
310
|
-
Effective::Order.purchased_by(order.user).to_a.include?(order).should eq true
|
311
|
-
end
|
312
|
-
|
313
|
-
it 'is not included with the declined scope' do
|
314
|
-
order.purchase!(details: 'by a test')
|
315
|
-
Effective::Order.declined.to_a.include?(order).should eq false
|
316
|
-
end
|
317
|
-
|
318
|
-
it 'should return false when the Order is invalid' do
|
319
|
-
allow(order).to receive(:valid?).and_return(false)
|
320
|
-
expect { order.purchase!(details: 'by a test') }.to raise_exception(Exception)
|
321
|
-
end
|
322
|
-
|
323
|
-
it 'should return true when the Order is invalid and validate: false is passed' do
|
324
|
-
allow(order).to receive(:valid?).and_return(false)
|
325
|
-
order.purchase!(details: 'by a test', validate: false).should eq true
|
326
|
-
end
|
327
|
-
|
328
|
-
end
|
329
|
-
|
330
|
-
describe 'purchased?' do
|
331
|
-
it 'returns true when a purchased order' do
|
332
|
-
order.purchase!(details: 'by a test')
|
333
|
-
order.purchased?.should eq true
|
334
|
-
end
|
335
|
-
|
336
|
-
it 'returns false when not purchased' do
|
337
|
-
order.purchased?.should eq false
|
338
|
-
end
|
339
|
-
|
340
|
-
it 'returns false when declined' do
|
341
|
-
order.decline!(details: 'by a test')
|
342
|
-
order.purchased?.should eq false
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
describe 'decline!' do
|
347
|
-
it 'assigns the purchase_state' do
|
348
|
-
order.decline!(details: 'by a test').should eq true
|
349
|
-
|
350
|
-
order.purchase_state.should eq EffectiveOrders::DECLINED
|
351
|
-
order.payment[:details].should eq 'by a test'
|
352
|
-
order.purchased_at.should eq nil
|
353
|
-
end
|
354
|
-
|
355
|
-
it 'sends declined callback to all order_items' do
|
356
|
-
order.order_items.each { |oi| oi.purchasable.should_receive(:declined!).with(order, oi) }
|
357
|
-
order.decline!(details: 'by a test')
|
358
|
-
end
|
359
|
-
|
360
|
-
it 'returns false when declined twice' do
|
361
|
-
order.decline!(details: 'first time')
|
362
|
-
order.decline!(details: 'second time').should eq false
|
363
|
-
end
|
364
|
-
|
365
|
-
it 'returns false when declined twice' do
|
366
|
-
order.decline!(details: 'first time')
|
367
|
-
order.decline!(details: 'second time').should eq false
|
368
|
-
end
|
369
|
-
|
370
|
-
it 'is included with the declined scope' do
|
371
|
-
order.decline!(details: 'by a test')
|
372
|
-
Effective::Order.declined.to_a.include?(order).should eq true
|
373
|
-
end
|
374
|
-
|
375
|
-
it 'is not included with the purchased scope' do
|
376
|
-
order.decline!(details: 'by a test')
|
377
|
-
Effective::Order.purchased.to_a.include?(order).should eq false
|
378
|
-
Effective::Order.purchased_by(order.user).to_a.include?(order).should eq false
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
describe 'declined?' do
|
383
|
-
it 'returns true when a declined order' do
|
384
|
-
order.decline!(details: 'by a test')
|
385
|
-
order.declined?.should eq true
|
386
|
-
end
|
387
|
-
|
388
|
-
it 'returns false when not declined' do
|
389
|
-
order.declined?.should eq false
|
390
|
-
end
|
391
|
-
|
392
|
-
it 'returns false when purchased' do
|
393
|
-
order.purchase!(details: 'by a test')
|
394
|
-
order.declined?.should eq false
|
395
|
-
end
|
396
|
-
end
|
397
|
-
|
398
|
-
describe '#save_billing_address?' do
|
399
|
-
it 'is true when save_billing_address is 1' do
|
400
|
-
order.save_billing_address = '1'
|
401
|
-
order.save_billing_address?.should eq true
|
402
|
-
end
|
403
|
-
|
404
|
-
it 'is false when save_billing_address is 0' do
|
405
|
-
order.save_billing_address = '0'
|
406
|
-
order.save_billing_address?.should eq false
|
407
|
-
end
|
408
|
-
|
409
|
-
it 'is false when save_billing_address is nil' do
|
410
|
-
order.save_billing_address = nil
|
411
|
-
order.save_billing_address?.should eq false
|
412
|
-
end
|
413
|
-
end
|
414
|
-
|
415
|
-
describe '#save_shipping_address?' do
|
416
|
-
it 'is true when save_shipping_address is 1' do
|
417
|
-
order.save_shipping_address = '1'
|
418
|
-
order.save_shipping_address?.should eq true
|
419
|
-
end
|
420
|
-
|
421
|
-
it 'is false when save_shipping_address is 0' do
|
422
|
-
order.save_shipping_address = '0'
|
423
|
-
order.save_shipping_address?.should eq false
|
424
|
-
end
|
425
|
-
|
426
|
-
it 'is false when save_shipping_address is nil' do
|
427
|
-
order.save_shipping_address = nil
|
428
|
-
order.save_shipping_address?.should eq false
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
|
-
describe '#to_param' do
|
433
|
-
it 'returns an obfuscated ID' do
|
434
|
-
(order.to_param.length >= 10).should eq true
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
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
|
445
|
-
end
|