-
Notifications
You must be signed in to change notification settings - Fork 2
/
advisor_spec.rb
228 lines (145 loc) · 4.34 KB
/
advisor_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
require 'rails_helper'
feature 'Advisor log in' do
let(:advisor){ create(:advisor) }
before do
visit root_path
end
context 'Before logging in' do
scenario 'defaults to log in path' do
expect(current_path).to eq(new_advisor_session_path)
end
context 'Trying to visit another page' do
before do
visit angular_app_index_path
end
scenario 'redirects to sign in page when accessing url and not signed in' do
expect(current_path).to eq(new_advisor_session_path)
end
scenario 'renders a flash when accessing url and not signed in' do
expect(page).to have_css('#flash')
end
end
end
context 'When logging in correctly' do
before do
sign_in(advisor)
end
scenario 'redirects to root path' do
expect(current_path).to eq(root_path)
end
scenario 'renders a flash' do
expect(page).to have_css('#flash')
end
end
context 'When logging in with incorrect credentials' do
before do
fill_in('Email', with: advisor.email)
fill_in('Password', with: "not password")
find('input[type="submit"]').click
end
scenario 'remains on the sign in page' do
expect(current_path).to eq(new_advisor_session_path)
end
scenario 'renders a flash' do
expect(page).to have_css('#flash')
end
end
end
feature 'Advisor creation' do
let(:advisor) { create(:advisor) }
before do
sign_in(advisor)
find('#add-advisor').click
end
context 'When signing up a new advisor with correct credentials' do
let(:new_advisor) { build(:advisor) }
before do
fill_out_sign_up(new_advisor)
end
scenario 'it creates a new advisor', js: true do
expect { click_on('Sign up') }.to change(Advisor, :count).by(1)
end
end
context 'When signing up a new advisor with correct credentials' do
let(:new_advisor) { build(:advisor, is_admin: false) }
before do
sign_up(new_advisor)
end
scenario 'it redirects to the root path', js: true do
expect(current_path).to eq(root_path)
end
scenario 'it renders a flash message', js: true do
expect(page).to have_css('#flash')
end
scenario 'it does not log in as the newly signed up advisor', js: true do
click_on('Edit my account settings')
email = find_field('Email').value
expect(email).to_not eq(new_advisor.email)
expect(email).to eq(advisor.email)
end
end
context 'When signing up a new admin with correct credentials' do
let(:new_admin) { build(:advisor) }
before do
sign_up(new_admin)
end
scenario 'it redirects to the root path', js: true do
expect(current_path).to eq(root_path)
end
scenario 'it renders a flash message', js: true do
expect(page).to have_css('#flash')
end
end
end
feature 'Advisor logout' do
let(:advisor){ create(:advisor) }
before do
sign_in(advisor)
end
context 'when logging out' do
before do
click_on('Sign Out')
end
scenario 'it redirects to the log in page', js: true do
expect(current_path).to eq(new_advisor_session_path)
end
scenario 'it renders a flash message', js: true do
expect(page).to have_css('#flash')
end
end
end
feature 'Advisor deletion' do
context 'when deleting another advisor' do
let(:advisor){ create(:advisor) }
let(:other_advisor) { create(:advisor) }
before do
sign_in(advisor)
other_advisor
click_on('View advisors')
execute_script('$("a[data-confirm]").removeAttr("data-confirm")');
end
scenario 'it deletes the advisor', js: true do
expect{ click_on('Delete') }.to change(Advisor, :count).by(-1)
end
scenario 'it renders a flash message', js: true do
click_on('Delete')
expect(page).to have_css('#flash')
end
scenario 'it remains on the advisors index page', js: true do
click_on('Delete')
expect(current_path).to eq(advisors_path)
end
end
context 'when attempting to delete own account' do
let(:advisor){ create(:advisor) }
before do
sign_in(advisor)
click_on('View advisors')
end
scenario 'it does not display a delete link', js: true, test_me: true do
within(:css, "td:last-child") do
expect(page).to_not have_content('Delete')
end
end
end
end