RuboCop: Style/EmptyCaseCondition

some auto, some manual if there was a better fitting construct than
an if/elsif/else

Change-Id: Ifee268f80d411b7b4c98a024c209d2014c7d0c9f
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/277998
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2021-11-11 09:51:22 -07:00
parent 6bdee6ed50
commit c2be81fc42
8 changed files with 24 additions and 34 deletions

View File

@ -132,6 +132,8 @@ Style/ConditionalAssignment:
Severity: error
Style/Documentation:
Enabled: false # most things don't need to be documented
Style/EmptyCaseCondition:
Severity: error
Style/Encoding:
Severity: error
Style/FrozenStringLiteralComment:

View File

@ -804,12 +804,12 @@ class CalendarEventsApiController < ApplicationController
respond_to do |format|
format.ics do
name = t('ics_title', "%{course_or_group_name} Calendar (Canvas)", :course_or_group_name => @context.name)
description = case
when @context.is_a?(Course)
description = case @context
when Course
t('ics_description_course', "Calendar events for the course, %{course_name}", :course_name => @context.name)
when @context.is_a?(Group)
when Group
t('ics_description_group', "Calendar events for the group, %{group_name}", :group_name => @context.name)
when @context.is_a?(User)
when User
t('ics_description_user', "Calendar events for the user, %{user_name}", :user_name => @context.name)
else
t('ics_description', "Calendar events for %{context_name}", :context_name => @context.name)

View File

@ -286,12 +286,7 @@ class PseudonymsController < ApplicationController
def get_user
user_id = params[:user_id] || params[:user].try(:[], :id)
@user = case
when user_id
api_find(User, user_id)
else
@current_user
end
@user = user_id ? api_find(User, user_id) : @current_user
true
end
protected :get_user

View File

@ -305,10 +305,9 @@ class SubmissionsController < SubmissionsBaseController
log_asset_access(@assignment, "assignments", @assignment_group, 'submit')
format.html do
flash[:notice] = t('assignment_submit_success', 'Assignment successfully submitted.')
tardiness = case
when @submission.late?
tardiness = if @submission.late?
2 # late
when @submission.cached_due_date.nil?
elsif @submission.cached_due_date.nil?
0 # don't know
else
1 # on time

View File

@ -41,14 +41,14 @@ class Alert < ActiveRecord::Base
include_teachers = false
admin_role_ids = []
self.recipients.try(:each) do |recipient|
case
when recipient == :student
case recipient
when :student
include_student = true
when recipient == :teachers
when :teachers
include_teachers = true
when recipient.is_a?(String)
when String
admin_role_ids << find_role_by_name(recipient).id
when recipient.is_a?(Hash)
when Hash
admin_role_ids << recipient[:role_id]
else
raise "Unsupported recipient type!"

View File

@ -597,12 +597,11 @@ class DiscussionTopic < ActiveRecord::Base
def subscription_hold(user, session)
return nil unless user
case
when initial_post_required?(user, session)
if initial_post_required?(user, session)
:initial_post_required
when root_topic? && !child_topic_for(user)
elsif root_topic? && !child_topic_for(user)
:not_in_group_set
when context.is_a?(Group) && !context.has_member?(user)
elsif context.is_a?(Group) && !context.has_member?(user)
:not_in_group
end
end

View File

@ -159,14 +159,9 @@ module AttachmentFu # :nodoc:
end
def load_related_exception?(e) # :nodoc: implementation specific
case
when e.kind_of?(LoadError), e.kind_of?(MissingSourceFile), $!.class.name == "CompilationError"
# We can't rescue CompilationError directly, as it is part of the RubyInline library.
# We must instead rescue RuntimeError, and check the class' name.
true
else
false
end
# We can't rescue CompilationError directly, as it is part of the RubyInline library.
# We must instead rescue RuntimeError, and check the class' name.
e.is_a?(LoadError) || e.is_a?(MissingSourceFile) || e.instance_of?(CompilationError)
end
private :load_related_exception?
end

View File

@ -228,18 +228,18 @@ module ConversationsCommon
# Allows you to select between
def click_more_options(opts, message = 0)
case
# First case is for clicking on message gear menu
when opts[:message]
if opts[:message]
# The More Options gear menu only shows up on mouse over of message
driver.action.move_to(ff('.message-item-view')[message]).perform
wait_for_ajaximations
f('.actions li .inline-block .al-trigger').click
# This case is for clicking on gear menu at conversation heading level
when opts[:convo]
elsif opts[:convo]
f('.message-header .al-trigger').click
# Otherwise, it clicks the topmost gear menu
else f('#admin-btn.al-trigger').click
else
f('#admin-btn.al-trigger').click
end
wait_for_ajaximations
end