-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathuser_spec.rb
63 lines (52 loc) · 1.85 KB
/
user_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'spec_helper'
describe User do
it 'I can create a new user' do
user = User.create(email: '[email protected]', fname: 'John', lname: 'Doe')
expect(user.id).to_not be_nil
end
it 'validates the required fields' do
user = User.new(email: nil, fname: nil, lname: nil)
user.errors[:email].should include('is required')
user.errors[:fname].should include('is required')
user.errors[:lname].should include('is required')
end
it 'assigns a unique referral code' do
user = User.create!(email: '[email protected]', fname: 'John', lname: 'Doe')
expect(user.referral_code).to_not be_nil
end
# it 'sends a welcome email' do
# user = User.create(email: '[email protected]', fname: 'John', lname: 'Doe')
# expect(Delayed::Job.count).to eq(1)
# end
context 'orders' do
before(:all) do
@user = User.create(email: '[email protected]', fname: 'John', lname: 'Doe')
@product = Product.create(name: 'Rails for Dummies')
end
before(:each) do
@orders = []
@packages = []
10.times do
order = Order.create(user: @user, @product: @product)
package = Package.create(order: order, shipping_address: '123 Street Ave, New York, NY')
@orders << order
@packages << package
end
end
it 'returns orders and packages for a user' do
expect(@user.orders.size).to eq(10)
expect(@user.packages.size).to eq(10)
end
context '#most_recent_package' do
it 'returns the most recent package' do
expect(@user.most_recent_package).to eq(@packages.last)
end
it 'the most recent package belongs to the last order' do
expect(@user.most_recent_package.order).to eq(@orders.last)
end
end
it 'the has_orders method indicates whether a user has any orders' do
expect(@user.has_orders).to eq(true)
end
end
end