/
events_spec.rb
232 lines (201 loc) · 9.69 KB
/
events_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
229
230
231
232
require "rails_helper"
RSpec.feature "Event application letters overview on event page", :type => :feature do
before :each do
@event = FactoryGirl.create(:event)
end
scenario "logged in as Pupil I can click the apply button on the index page" do
login(:pupil)
visit events_path
click_link 'Bewerben'
expect(page).to have_current_path(new_application_letter_path(:event_id => @event.id))
end
scenario "logged in as Pupil I can click the apply button on the show page" do
login(:pupil)
visit event_path(@event)
click_link 'Bewerben'
expect(page).to have_current_path(new_application_letter_path(:event_id => @event.id))
end
scenario "logged in as Pupil I can not see overview" do
login(:pupil)
visit event_path(@event)
expect(page).to_not have_table("applicants")
expect(page).to_not have_css("div#free_places")
expect(page).to_not have_css("div#occupied_places")
end
scenario "logged in as Coach I can see overview" do
login(:coach)
visit event_path(@event)
expect(page).to have_table("applicants")
expect(page).to have_css("div#free_places")
expect(page).to have_css("div#occupied_places")
end
scenario "logged in as Organizer I can see overview" do
login(:organizer)
visit event_path(@event)
expect(page).to have_table("applicants")
expect(page).to have_css("div#free_places")
expect(page).to have_css("div#occupied_places")
end
scenario "logged in as Organizer I want to be unable to send emails if there is any unclassified application left" do
login(:organizer)
@event.update!(max_participants: 1)
@pupil = FactoryGirl.create(:profile)
@pupil.user.role = :pupil
@pending_application = FactoryGirl.create(:application_letter, :event => @event, :user => @pupil.user)
visit event_path(@event)
expect(page).to have_button(I18n.t('events.applicants_overview.sending_acceptances'), disabled: true)
expect(page).to have_button(I18n.t('events.applicants_overview.sending_rejections'), disabled: true)
end
scenario "logged in as Organizer I want to be unable to send emails if there is a negative number of free places left" do
login(:organizer)
@event.update!(max_participants: 1)
2.times do |n|
@pupil = FactoryGirl.create(:profile)
@pupil.user.role = :pupil
FactoryGirl.create(:application_letter_accepted, :event => @event, :user => @pupil.user)
end
visit event_path(@event)
expect(page).to have_button(I18n.t('events.applicants_overview.sending_acceptances'), disabled: true)
expect(page).to have_button(I18n.t('events.applicants_overview.sending_rejections'), disabled: true)
end
scenario "logged in as Organizer I want to be able to send an email to all accepted applicants" do
login(:organizer)
@event.update!(max_participants: 2)
2.times do |n|
@pupil = FactoryGirl.create(:profile)
@pupil.user.role = :pupil
FactoryGirl.create(:application_letter_accepted, :event => @event, :user => @pupil.user)
end
visit event_path(@event)
click_link I18n.t('events.applicants_overview.sending_acceptances')
choose(I18n.t('emails.email_form.show_recipients'))
fill_in('email_subject', with: 'Subject')
fill_in('email_content', with: 'Content')
expect{click_button I18n.t('emails.email_form.send')}.to change{ActionMailer::Base.deliveries.count}.by(1)
end
scenario "logged in as Organizer I want to be able to send an email to all rejected applicants" do
login(:organizer)
@event.update!(max_participants: 2)
2.times do |n|
@pupil = FactoryGirl.create(:profile)
@pupil.user.role = :pupil
FactoryGirl.create(:application_letter_rejected, :event => @event, :user => @pupil.user)
end
visit event_path(@event)
click_link I18n.t('events.applicants_overview.sending_rejections')
choose(I18n.t('emails.email_form.show_recipients'))
fill_in('email_subject', with: 'Subject')
fill_in('email_content', with: 'Content')
expect{click_button I18n.t('emails.email_form.send')}.to change{ActionMailer::Base.deliveries.count}.by(1)
end
scenario "logged in as Organizer I can see the correct count of free/occupied places" do
login(:organizer)
@event.update!(max_participants: 1)
visit event_path(@event)
expect(page).to have_text(I18n.t "free_places", count: (@event.max_participants).to_i, scope: [:events, :applicants_overview])
expect(page).to have_text(I18n.t "occupied_places", count: 0, scope: [:events, :applicants_overview])
2.times do |i| #2 to also test negative free places, those are fine
@pupil = FactoryGirl.create(:profile)
@pupil.user.role = :pupil
@application_letter = FactoryGirl.create(:application_letter_accepted, event: @event, user: @pupil.user)
visit event_path(@event)
expect(page).to have_text(I18n.t "free_places", count: (@event.max_participants).to_i - (i+1), scope: [:events, :applicants_overview])
expect(page).to have_text(I18n.t "occupied_places", count: (i+1), scope: [:events, :applicants_overview])
end
end
scenario "logged in as Organizer I can change application status with radio buttons" do
login(:organizer)
@event.application_status_locked = false
@event.save
@pupil = FactoryGirl.create(:profile)
@application_letter = FactoryGirl.create(:application_letter, event: @event, user: @pupil.user)
visit event_path(@event)
ApplicationLetter.statuses.keys.each do |new_status|
choose(I18n.t "application_status.#{new_status}")
expect(ApplicationLetter.where(id: @application_letter.id)).to exist
end
end
scenario "logged in as Organizer I can not change application status with radio buttons if the applications are locked" do
login(:organizer)
@event.lock_application_status
@pupil = FactoryGirl.create(:profile)
@application_letter = FactoryGirl.create(:application_letter, event: @event, user: @pupil.user)
visit event_path(@event)
ApplicationLetter.statuses.keys.each do |new_status|
if new_status != @application_letter.status
expect(page).not_to have_text(I18n.t "application_status.#{new_status}")
end
end
end
scenario "logged in as Organizer I can lock the event application statuses by pressing one of the email buttons" do
login(:organizer)
@pupil = FactoryGirl.create(:profile)
@application_letter = FactoryGirl.create(:application_letter_accepted, event: @event, user: @pupil.user)
['.events.applicants_overview.sending_acceptances', '.events.applicants_overview.sending_rejections'].each do | email_button |
@event.application_status_locked = false
@event.save
visit event_path(@event)
click_link I18n.t email_button
expect(Event.find(@event.id).application_status_locked).to be(true)
end
end
scenario "logged in as Coach I can see application status" do
login(:coach)
@pupil = FactoryGirl.create(:profile)
@application_letter = FactoryGirl.create(:application_letter, event: @event, user: @pupil.user)
visit event_path(@event)
expect(page).to have_text(I18n.t "application_status.#{@application_letter.status}")
end
scenario "Logged in as organizer I can see a table with the applicants and sort them by attributes" do
login(:organizer)
@event = FactoryGirl.create(:event)
visit event_path(@event)
table = page.find(:xpath, '//table[@id="applicants"]')
@event.application_letters.each do |application_letter|
expect(table).to have_text(application_letter.user.profile.name)
end
['name', 'gender'].each do |attribute|
link_name = I18n.t("activerecord.attributes.profile.#{attribute}")
click_link link_name
sorted_by_attribute = @event.application_letters.to_a.sort_by { |letter| letter.user.profile.send(attribute) }
names = sorted_by_attribute.map {|l| l.user.profile.name }
expect(page).to contain_ordered(names)
click_link link_name # again
expect(page).to contain_ordered(names.reverse)
end
link_name = I18n.t('events.applicants_overview.age_when_event_starts')
click_link link_name
sorted_by_attribute = @event.application_letters.to_a.sort_by { |letter| letter.send(attribute) }
names = sorted_by_attribute.map {|l| l.user.profile.name }
expect(page).to contain_ordered(names)
click_link link_name # again
expect(page).to contain_ordered(names.reverse)
end
scenario "logged in as Organizer I can filter displayed application letters by their status", js: true do
login(:organizer)
@event = FactoryGirl.create(:event_with_accepted_applications)
@event.application_letters.each do |letter|
letter.user.profile = FactoryGirl.build(:profile, user: letter.user)
end
visit event_path(@event)
click_button I18n.t 'events.applicants_overview.filter_by'
check I18n.t 'application_status.accepted'
click_button I18n.t 'events.applicants_overview.filter'
accepted_names = @event.application_letters.to_a.select { |l| l.status.to_sym == :accepted }.map {|l| l.user.profile.name}
not_accepted_names = @event.application_letters.to_a.select { |l| l.status.to_sym != :accepted }.map {|l| l.user.profile.name}
expect(page).to have_every_text(accepted_names)
expect(page).to have_no_text(not_accepted_names)
click_button I18n.t 'events.applicants_overview.filter_by'
uncheck I18n.t 'application_status.accepted'
check I18n.t 'application_status.rejected'
check I18n.t 'application_status.pending'
click_button I18n.t 'events.applicants_overview.filter'
expect(page).to have_every_text(not_accepted_names)
expect(page).to have_no_text(accepted_names)
end
def login(role)
@profile = FactoryGirl.create(:profile)
@profile.user.role = role
login_as(@profile.user, :scope => :user)
end
end