forked from minnestar/sessionizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticipants_controller_spec.rb
More file actions
187 lines (163 loc) · 6.65 KB
/
Copy pathparticipants_controller_spec.rb
File metadata and controls
187 lines (163 loc) · 6.65 KB
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
require 'spec_helper'
describe ParticipantsController do
let(:participant) { create(:participant) }
describe "#index" do
let!(:participant) { create(:participant, name: 'one two three', email: 'test@example.org') }
it "should be successful" do
get :index, format: :json
expect(response).to be_successful
json = JSON.parse(response.body)
expect(json).to eq [ { "value"=>'one two three', "tokens"=>["one", "two", "three"], "id"=>participant.id } ]
end
end
describe "#new" do
it "should be successful" do
get :new
expect(response).to be_successful
expect(assigns(:participant)).to be_kind_of Participant
end
end
describe "#create" do
it "should be successful" do
post :create, params: { participant: { name: 'Alan Turing',
email: 'tapewriter@example.org',
password: 'infinite-memory'
}
}
expect(response).to redirect_to root_path
expect(flash[:notice]).to eq "Thanks for registering an account. Please check your email to confirm your account."
end
it "should not be successful if a bot provides contact_details field" do
expect{
post :create, params: { participant: { name: 'spam bot',
email: 'spambot@example.org',
password: 'spam-bot',
contact_details: 'this is a honeypot field that i fell for because im a spam bot'
}
}
}.not_to change(Participant, :count)
expect(response).to render_template(:new)
expect(flash[:error]).to eq "There was a problem creating your account."
end
it "does not set coc_agreed_at on the participant when the user has not signed the code of conduct" do
post :create, params: { participant: { name: 'Alan Turing',
email: 'tapewriter@example.org',
password: 'infinite-memory',
code_of_conduct_agreement: '0'
}
}
expect(Participant.find_by(email: 'tapewriter@example.org').coc_agreed_at).to be_nil
end
it "sets coc_agreed_at on the participant when the user has signed the code of conduct" do
post :create, params: { participant: { name: 'Alan Turing',
email: 'tapewriter@example.org',
password: 'infinite-memory',
code_of_conduct_agreement: '1'
}
}
expect(Participant.find_by(email: 'tapewriter@example.org').coc_agreed_at).not_to be_nil
end
end
describe "#show" do
it "should be successful" do
get :show, params: {id: participant}
expect(response).to be_successful
expect(assigns(:participant)).to be_kind_of Participant
end
context "when logged in" do
context "when logged in user has not confirmed email" do
let(:unconfirmed_email_participant) { create(:participant, email_confirmed_at: nil )}
before do
activate_authlogic
ParticipantSession.create(unconfirmed_email_participant)
end
it "should display confirm email flash message" do
get :show, params: {id: participant}
expect(flash[:alert]).to be_present
end
end
end
context "when logged in user has confirmed email" do
let(:unconfirmed_email_participant) { create(:participant, email_confirmed_at: Time.now )}
before do
activate_authlogic
ParticipantSession.create(unconfirmed_email_participant)
end
it "should not display confirm email flash message" do
get :show, params: {id: participant}
expect(flash[:alert]).not_to be_present
end
end
context "when not logged in" do
it "should not show confirm email flash message" do
get :show, params: {id: participant}
expect(flash[:alert]).not_to be_present
end
end
end
context "when the logged in user operates on someone elses record" do
let(:luke) { create(:luke) }
before do
activate_authlogic
ParticipantSession.create(luke)
end
describe "#edit" do
it "should be not be allowed" do
get :edit, params: {id: participant}
expect(response).to be_redirect
end
end
describe "#update" do
it "will not be allowed" do
put :update, params: {id: participant, participant: { name: 'Alan Kay' }}
expect(response).to be_redirect
expect(participant.reload.name).to_not eq 'Alan Kay'
end
end
end
context "when the logged in user operates on their own record" do
before do
activate_authlogic
ParticipantSession.create(joe)
end
let(:joe) { create(:joe) }
describe "#edit" do
it "should be successful" do
get :edit, params: {id: joe}
expect(response).to be_successful
expect(assigns(:participant)).to be_kind_of Participant
end
end
describe "#update" do
it "should be successful" do
put :update, params: {id: joe, participant: { name: 'schmoe, joe' }}
expect(response).to redirect_to participant_path(joe)
expect(joe.reload.name).to eq 'schmoe, joe'
end
it "does not set coc_agreed_at on the participant when the user has not signed the code of conduct" do
put :update, params: { id: joe, participant: { name: 'Alan Turing', code_of_conduct_agreement: '0' } }
expect(joe.reload.coc_agreed_at).to be_nil
end
it "sets coc_agreed_at on the participant when the user has signed the code of conduct" do
put :update, params: { id: joe, participant: { code_of_conduct_agreement: '1' } }
expect(joe.reload.coc_agreed_at).not_to be_nil
end
describe "more attributes are not required" do
it "should be successful" do
put :update, params: {
id: joe, participant: { bio: 'schmoe' }
}
expect(response).to be_redirect
expect(joe.reload.bio).to eq 'schmoe'
end
end
describe "when email address is changed" do
it "should unconfirm the user's email" do
put :update, params: {id: joe, participant: { email: 'new@example.org',}}
expect(response).to be_redirect
expect(joe.reload.email_confirmed_at).to be_nil
end
end
end
end
end