Skip to content

Commit 6231f6b

Browse files
committed
[refactor] Standardize on flash[:alert] instead of flash[:error]
Notice & alert are the two standard ones: https://api.rubyonrails.org/classes/ActionDispatch/Flash.html
1 parent 978d6d3 commit 6231f6b

11 files changed

+38
-45
lines changed

app/controllers/manage/bus_lists_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def toggle_bus_captain
5151

5252
def send_update_email
5353
if Message.for_trigger("bus_list.notes_update").empty?
54-
flash[:error] = 'Error: No automated message is configured for bus note updates!'
54+
flash[:alert] = 'Error: No automated message is configured for bus note updates!'
5555
redirect_to [:manage, @bus_list]
5656
return
5757
end

app/controllers/manage/messages_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def destroy
4444

4545
def deliver
4646
if @message.automated?
47-
flash[:error] = "Automated messages cannot be manually delivered. Only bulk messages can."
47+
flash[:alert] = "Automated messages cannot be manually delivered. Only bulk messages can."
4848
return redirect_to manage_message_path(@message)
4949
end
5050
if @message.status != "drafted"
51-
flash[:error] = "Message cannot be re-delivered"
51+
flash[:alert] = "Message cannot be re-delivered"
5252
return redirect_to manage_messages_path
5353
end
5454
@message.update_attribute(:queued_at, Time.now)
@@ -96,7 +96,7 @@ def set_message
9696
def check_message_access
9797
return if @message.can_edit?
9898

99-
flash[:error] = "Message can no longer be modified"
99+
flash[:alert] = "Message can no longer be modified"
100100
redirect_to manage_message_path(@message)
101101
end
102102
end

app/controllers/manage/questionnaires_controller.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create
3838
if user.save
3939
@questionnaire.save
4040
else
41-
flash[:error] = user.errors.full_messages.join(", ")
41+
flash[:alert] = user.errors.full_messages.join(", ")
4242
if user.errors.include?(:email)
4343
@questionnaire.errors.add(:email, user.errors[:email].join(", "))
4444
end
@@ -70,7 +70,7 @@ def check_in
7070
@questionnaire.user.update_attributes(email: email)
7171
end
7272
unless @questionnaire.valid?
73-
flash[:error] = @questionnaire.errors.full_messages.join(", ")
73+
flash[:alert] = @questionnaire.errors.full_messages.join(", ")
7474
redirect_to show_redirect_path
7575
return
7676
end
@@ -82,7 +82,7 @@ def check_in
8282
@questionnaire.update_attribute(:checked_in_by_id, current_user.id)
8383
flash[:notice] = "#{@questionnaire.full_name} no longer checked in."
8484
else
85-
flash[:error] = "No check-in action provided!"
85+
flash[:alert] = "No check-in action provided!"
8686
redirect_to show_redirect_path
8787
return
8888
end
@@ -106,7 +106,7 @@ def destroy
106106
def update_acc_status
107107
new_status = params[:questionnaire][:acc_status]
108108
if new_status.blank?
109-
flash[:error] = "No status provided"
109+
flash[:alert] = "No status provided"
110110
redirect_to(manage_questionnaire_path(@questionnaire))
111111
return
112112
end
@@ -118,7 +118,7 @@ def update_acc_status
118118
if @questionnaire.save(validate: false)
119119
flash[:notice] = "Updated acceptance status to \"#{Questionnaire::POSSIBLE_ACC_STATUS[new_status]}\""
120120
else
121-
flash[:error] = "Failed to update acceptance status"
121+
flash[:alert] = "Failed to update acceptance status"
122122
end
123123

124124
redirect_to manage_questionnaire_path(@questionnaire)

app/controllers/manage/schools_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ def merge
4545
def perform_merge
4646
new_school_name = params[:school][:id]
4747
if new_school_name.blank?
48-
flash[:error] = "Error: Must include the new school to merge into!"
48+
flash[:alert] = "Error: Must include the new school to merge into!"
4949
render :merge
5050
return
5151
end
5252

5353
new_school = School.where(name: new_school_name).first
5454
if new_school.blank?
55-
flash[:error] = "Error: School doesn't exist: #{new_school_name}"
55+
flash[:alert] = "Error: School doesn't exist: #{new_school_name}"
5656
render :merge
5757
return
5858
end
@@ -68,7 +68,7 @@ def perform_merge
6868
if @school.questionnaire_count < 1
6969
@school.destroy
7070
else
71-
flash[:error] = "*** Old school NOT deleted: #{@school.questionnaire_count} questionnaires still associated!\n"
71+
flash[:alert] = "*** Old school NOT deleted: #{@school.questionnaire_count} questionnaires still associated!\n"
7272
end
7373

7474
redirect_to manage_school_path(new_school)

app/controllers/rsvps_controller.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def accept
2121
flash[:notice] = "Thank you for confirming your attendance! You're all set to attend."
2222
flash[:notice] += " See below for additional bus information." if BusList.any?
2323
else
24-
flash[:error] = rsvp_error_notice
24+
flash[:alert] = rsvp_error_notice
2525
end
2626
redirect_to rsvp_path
2727
end
@@ -34,7 +34,7 @@ def deny
3434
if @questionnaire.save
3535
flash[:notice] = "Your RSVP has been updated."
3636
else
37-
flash[:error] = rsvp_error_notice
37+
flash[:alert] = rsvp_error_notice
3838
end
3939
redirect_to rsvp_path
4040
end
@@ -44,13 +44,13 @@ def deny
4444
# rubocop:disable PerceivedComplexity
4545
def update
4646
unless @questionnaire.update_attributes(params.require(:questionnaire).permit(:agreement_accepted, :phone))
47-
flash[:error] = @questionnaire.errors.full_messages.join(", ")
47+
flash[:alert] = @questionnaire.errors.full_messages.join(", ")
4848
redirect_to rsvp_path
4949
return
5050
end
5151

5252
unless ["rsvp_confirmed", "rsvp_denied"].include? params[:questionnaire][:acc_status]
53-
flash[:error] = "Please select a RSVP status."
53+
flash[:alert] = "Please select a RSVP status."
5454
redirect_to rsvp_path
5555
return
5656
end
@@ -64,22 +64,22 @@ def update
6464
is_joining_bus = new_bus_list.present? && @questionnaire.bus_list != new_bus_list
6565
if is_joining_bus && new_bus_list.full?
6666
if @questionnaire.bus_list_id?
67-
flash[:error] = "Sorry, that bus is full. You are still signed up for the '#{@questionnaire.bus_list.name}' bus."
67+
flash[:alert] = "Sorry, that bus is full. You are still signed up for the '#{@questionnaire.bus_list.name}' bus."
6868
else
69-
flash[:error] = "Sorry, that bus is full. You may need to arrange other plans for transportation."
69+
flash[:alert] = "Sorry, that bus is full. You may need to arrange other plans for transportation."
7070
end
7171
else
7272
@questionnaire.bus_list = new_bus_list
7373
@questionnaire.bus_captain_interest = params[:questionnaire][:bus_captain_interest]
7474
end
7575

7676
unless @questionnaire.save
77-
flash[:error] = @questionnaire.errors.full_message.join(", ")
77+
flash[:alert] = @questionnaire.errors.full_message.join(", ")
7878
redirect_to rsvp_path
7979
return
8080
end
8181

82-
if flash[:notice].blank? && flash[:error].blank?
82+
if flash[:notice].blank? && flash[:alert].blank?
8383
flash[:notice] = "Your RSVP has been updated."
8484
flash[:notice] += " See below for additional bus information!" if @questionnaire.bus_list_id?
8585
end

app/controllers/users/omniauth_callbacks_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def mlh
1111
end
1212

1313
def failure
14-
flash[:error] = "External authentication failed - try again?"
14+
flash[:alert] = "External authentication failed - try again?"
1515
redirect_to new_user_session_url
1616
end
1717
end

app/views/layouts/_flashes.html.haml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
- if flash[:error].present?
2-
.flashes.flashes--error
3-
.container
4-
.form-container
5-
%span.fa.fa-info-circle.flashes__icon
6-
= flash[:error].html_safe
7-
81
- if flash[:alert].present?
92
.flashes.flashes--error
103
.container

app/views/layouts/manage/_flashes.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
- if flash[:error].present?
1+
- if flash[:alert].present?
22
.alert.alert-danger.mt-3
33
%span.fa.fa-exclamation-triangle.icon-space-r-half
4-
= flash[:error].html_safe
4+
= flash[:alert].html_safe
55

66
- if flash[:notice].present?
77
.alert.alert-info.mt-3

test/controllers/manage/messages_controller_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,22 @@ class Manage::MessagesControllerTest < ActionController::TestCase
305305
assert_difference("enqueued_jobs.size", 0) do
306306
patch :deliver, params: { id: @message }
307307
end
308-
assert_match /cannot be manually delivered/, flash[:error]
308+
assert_match /cannot be manually delivered/, flash[:alert]
309309
assert_redirected_to manage_message_path(assigns(:message))
310310
end
311311

312312
should "not allow multiple deliveries" do
313313
patch :deliver, params: { id: @message }
314314
assert_match /queued/, flash[:notice]
315315
patch :deliver, params: { id: @message }
316-
assert_match /cannot/, flash[:error]
316+
assert_match /cannot/, flash[:alert]
317317
end
318318

319319
should "not be able to modify message after delivery" do
320320
@message.update_attribute(:delivered_at, 1.minute.ago)
321321
old_message_name = @message.name
322322
patch :update, params: { id: @message, message: { name: "New Message Name" } }
323-
assert_match /can no longer/, flash[:error]
323+
assert_match /can no longer/, flash[:alert]
324324
assert_equal old_message_name, @message.reload.name
325325
end
326326

test/controllers/manage/questionnaires_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
377377
assert_equal false, @questionnaire.can_share_info
378378
assert_equal "", @questionnaire.phone
379379
assert_equal "old_email@example.com", @questionnaire.email
380-
assert_match /No check-in action provided/, flash[:error]
380+
assert_match /No check-in action provided/, flash[:alert]
381381
assert_response :redirect
382382
assert_redirected_to manage_questionnaire_path(@questionnaire)
383383
end

test/controllers/rsvps_controller_test.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class RsvpsControllerTest < ActionController::TestCase
110110
context "attempting #{status}" do
111111
should "include error message" do
112112
get status
113-
assert_match /was an error/, flash[:error]
113+
assert_match /was an error/, flash[:alert]
114114
end
115115

116116
should "not change acceptance status" do
@@ -121,7 +121,7 @@ class RsvpsControllerTest < ActionController::TestCase
121121
should "include hackathon name in notice" do
122122
HackathonConfig["name"] = "Foo Bar"
123123
get status
124-
assert_match /Foo Bar Agreement/, flash[:error]
124+
assert_match /Foo Bar Agreement/, flash[:alert]
125125
end
126126
end
127127
end
@@ -154,8 +154,8 @@ class RsvpsControllerTest < ActionController::TestCase
154154
assert_equal "rsvp_confirmed", @questionnaire.reload.acc_status
155155
assert_equal false, @questionnaire.reload.bus_list_id?
156156
assert_equal 0, bus_list.passengers.count
157-
assert_match /full/, flash[:error]
158-
assert_no_match /still signed up/, flash[:error]
157+
assert_match /full/, flash[:alert]
158+
assert_no_match /still signed up/, flash[:alert]
159159
assert_redirected_to rsvp_path
160160
end
161161

@@ -181,19 +181,19 @@ class RsvpsControllerTest < ActionController::TestCase
181181
assert_equal "rsvp_confirmed", @questionnaire.reload.acc_status
182182
assert_equal 0, bus_list2.passengers.count, "passenger should not be assigned to bus that is full"
183183
assert_equal 1, bus_list1.passengers.count, "passenger should stay on original bus"
184-
assert_match /full/, flash[:error]
185-
assert_match /still signed up/, flash[:error]
184+
assert_match /full/, flash[:alert]
185+
assert_match /still signed up/, flash[:alert]
186186
assert_redirected_to rsvp_path
187187
end
188188

189189
should "not error if submitting while already on a full bus" do
190190
bus_list = create(:bus_list, capacity: 1)
191191
# Initial sign up
192192
patch :update, params: { questionnaire: { acc_status: "rsvp_confirmed", bus_list_id: bus_list.id } }
193-
assert_no_match /full/, flash[:error], "should not complain about bus being full"
193+
assert_no_match /full/, flash[:alert], "should not complain about bus being full"
194194
# Submit again
195195
patch :update, params: { questionnaire: { acc_status: "rsvp_confirmed", bus_list_id: bus_list.id } }
196-
assert_no_match /full/, flash[:error], "should not complain about bus being full"
196+
assert_no_match /full/, flash[:alert], "should not complain about bus being full"
197197
end
198198

199199
should "not send email if updating info after confirming" do
@@ -223,7 +223,7 @@ class RsvpsControllerTest < ActionController::TestCase
223223
@questionnaire.update_attribute(:phone, "1111111111")
224224
@questionnaire.update_attribute(:agreement_accepted, false)
225225
patch :update, params: { questionnaire: { phone: "1234567890" } }
226-
assert_not_nil flash[:error]
226+
assert_not_nil flash[:alert]
227227
assert_equal "1111111111", @questionnaire.reload.phone
228228
assert_redirected_to rsvp_path
229229
end
@@ -232,15 +232,15 @@ class RsvpsControllerTest < ActionController::TestCase
232232
@questionnaire.update_attribute(:phone, "1111111111")
233233
@questionnaire.update_attribute(:first_name, "")
234234
patch :update, params: { questionnaire: { phone: "1234567890" } }
235-
assert_not_nil flash[:error]
235+
assert_not_nil flash[:alert]
236236
assert_equal "1111111111", @questionnaire.reload.phone
237237
assert_redirected_to rsvp_path
238238
end
239239

240240
should "not allow forbidden status update to questionnaire" do
241241
patch :update, params: { questionnaire: { acc_status: "pending" } }
242242
assert_equal "accepted", @questionnaire.reload.acc_status
243-
assert_match /select a RSVP status/, flash[:error]
243+
assert_match /select a RSVP status/, flash[:alert]
244244
assert_redirected_to rsvp_path
245245
end
246246
end

0 commit comments

Comments
 (0)