Skip to content

Commit 8be727a

Browse files
committed
Follow rubocop recommendations for using params
I've reviewed all these changes and they look like the params are always required https://redirect.github.com/rubocop/rubocop-rails/pull/1583
1 parent c7c0dd8 commit 8be727a

10 files changed

Lines changed: 17 additions & 17 deletions

app/controllers/admin/projects_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def scoped_resource
99
end
1010

1111
def destroy_image
12-
image = requested_resource.images.find(params[:image_id])
12+
image = requested_resource.images.find(params.expect(:image_id))
1313
image.purge
1414
redirect_back_or_to(requested_resource)
1515
end

app/controllers/api/feedback_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def create
3131
end
3232

3333
def set_read
34-
feedback = Feedback.find(params[:id])
34+
feedback = Feedback.find(params.expect(:id))
3535
result = Feedback::SetRead.call(feedback: feedback)
3636

3737
if result.success?

app/controllers/api/join_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def create
3030
private
3131

3232
def find_school_and_class
33-
@school_class = SchoolClass.find_by!(join_code: JoinCodeGenerator.normalize(params[:join_code]))
33+
@school_class = SchoolClass.find_by!(join_code: JoinCodeGenerator.normalize(params.expect(:join_code)))
3434
@school = @school_class.school
3535
end
3636

app/controllers/api/projects/images_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ class ImagesController < ApiController
66
before_action :authorize_user, only: %i[create]
77

88
def show
9-
@project = Project.find_by!(identifier: params[:project_id])
9+
@project = Project.find_by!(identifier: params.expect(:project_id))
1010
authorize! :show, @project
1111
render '/api/projects/images', formats: [:json]
1212
end
1313

1414
def create
15-
@project = Project.find_by!(identifier: params[:project_id])
15+
@project = Project.find_by!(identifier: params.expect(:project_id))
1616
authorize! :update, @project
1717
@project.images.attach(params[:images])
1818
render '/api/projects/images', formats: [:json]

app/controllers/api/projects/remixes_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def create
4343
private
4444

4545
def project
46-
@project ||= Project.find_by!(identifier: params[:project_id])
46+
@project ||= Project.find_by!(identifier: params.expect(:project_id))
4747
end
4848

4949
def load_and_authorize_remix

app/controllers/api/school_classes_controller.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def import
6060
end
6161

6262
def update
63-
school_class = @school.classes.find(params[:id])
63+
school_class = @school.classes.find(params.expect(:id))
6464
result = SchoolClass::Update.call(school_class:, school_class_params:)
6565

6666
if result.success?
@@ -176,25 +176,25 @@ def assign_students_to_class(school_class, school_students)
176176
end
177177

178178
def load_and_authorize_school
179-
@school = if params[:school_id].match?(/\d\d-\d\d-\d\d/)
179+
@school = if params.expect(:school_id).match?(/\d\d-\d\d-\d\d/)
180180
School.find_by(code: params[:school_id])
181181
else
182-
School.find(params[:school_id])
182+
School.find(params.expect(:school_id))
183183
end
184184
authorize! :read, @school
185185
end
186186

187187
def load_and_authorize_school_class
188188
if %w[index create import].include?(params[:action])
189-
authorize! params[:action].to_sym, SchoolClass
189+
authorize! params.expect(:action).to_sym, SchoolClass
190190
else
191-
@school_class = if params[:id].match?(/\d\d-\d\d-\d\d/)
191+
@school_class = if params.expect(:id).match?(/\d\d-\d\d-\d\d/)
192192
@school.classes.find_by(code: params[:id])
193193
else
194-
@school.classes.find(params[:id])
194+
@school.classes.find(params.expect(:id))
195195
end
196196

197-
authorize! params[:action].to_sym, @school_class
197+
authorize! params.expect(:action).to_sym, @school_class
198198
end
199199
end
200200

app/controllers/api/school_projects_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def set_finished
7474
private
7575

7676
def project
77-
@project ||= Project.find_by!(identifier: params[:id])
77+
@project ||= Project.find_by!(identifier: params.expect(:id))
7878
end
7979

8080
def school_project

app/controllers/api/schools_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def create
3030
end
3131

3232
def update
33-
school = School.find(params[:id])
33+
school = School.find(params.expect(:id))
3434
result = School::Update.call(school:, school_params: update_params)
3535

3636
if result.success?

app/controllers/api/scratch/projects_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def move_pending_scratch_upload_to_remix(pending_upload, remix_project)
101101
end
102102

103103
def load_project
104-
@project = Project.find_by!(identifier: params[:id], project_type: Project::Types::CODE_EDITOR_SCRATCH)
104+
@project = Project.find_by!(identifier: params.expect(:id), project_type: Project::Types::CODE_EDITOR_SCRATCH)
105105
end
106106
end
107107
end

app/models/project.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def create_school_project_if_needed
114114
end
115115

116116
def identifier_cannot_be_taken_by_another_user
117-
return if Project.where(identifier: self.identifier).where.not(user_id:).empty?
117+
return if Project.where(identifier:).where.not(user_id:).empty?
118118

119119
errors.add(:identifier, "can't be taken by another user")
120120
end

0 commit comments

Comments
 (0)