-
-
Notifications
You must be signed in to change notification settings - Fork 128
/
user_registrations_controller_spec.rb
97 lines (78 loc) 路 2.56 KB
/
user_registrations_controller_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# frozen_string_literal: true
RSpec.describe Spree::UserRegistrationsController, type: :controller do
before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
context '#create' do
before do
allow(controller).to receive(:after_sign_up_path_for) do
spree.root_path(thing: 7)
end
end
let(:password_confirmation) { 'foobar123' }
subject do
post(:create, {
params: {
spree_user: {
email: 'foobar@example.com',
password: 'foobar123',
password_confirmation: password_confirmation
}
}
})
end
context 'when user created successfuly' do
it 'saves the user' do
expect { subject }.to change { Spree::User.count }.from(0).to(1)
end
it 'sets flash message' do
subject
expect(flash[:notice]).to eq('Welcome! You have signed up successfully.')
end
it 'signs in user' do
expect(controller.warden).to receive(:set_user)
subject
end
it 'sets spree_user_signup session' do
subject
expect(session[:spree_user_signup]).to be true
end
it 'redirects to after_sign_up path' do
subject
expect(response).to redirect_to spree.root_path(thing: 7)
end
context 'with a guest token present' do
before do
request.cookie_jar.signed[:guest_token] = 'ABC'
end
it 'assigns orders with the correct token and no user present' do
order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil)
subject
user = Spree::User.find_by(email: 'foobar@example.com')
order.reload
expect(order.user_id).to eq user.id
expect(order.created_by_id).to eq user.id
end
it 'does not assign orders with an existing user' do
order = create(:order, guest_token: 'ABC', user_id: 200)
subject
expect(order.reload.user_id).to eq 200
end
it 'does not assign orders with a different token' do
order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil)
subject
expect(order.reload.user_id).to be_nil
end
end
end
context 'when user not valid' do
let(:password_confirmation) { 'foobard123' }
it 'resets password fields' do
expect(controller).to receive(:clean_up_passwords)
subject
end
it 'renders new view' do
subject
expect(:response).to render_template(:new)
end
end
end
end