Skip to content

Commit 7b61411

Browse files
committed
Use the latest Rails rubocop config
1 parent 3bfe787 commit 7b61411

File tree

125 files changed

+3220
-3218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+3220
-3218
lines changed

.rubocop.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1+
inherit_gem:
2+
rubocop-rails_config:
3+
- config/rails.yml
4+
15
AllCops:
2-
Include:
3-
- '**/config.ru'
4-
- '**/Rakefile'
5-
Exclude:
6-
- 'db/**/*'
7-
- 'ext/**/*'
8-
- 'tmp/**/*'
96
TargetRubyVersion: 2.5
107

11-
Rails:
12-
Enabled: true
13-
148
# Style
9+
Style/StringLiterals:
10+
Enabled: true
11+
EnforcedStyle: single_quotes
1512

1613
Style/Documentation:
1714
Enabled: false

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ group :development, :test do
6767
gem 'launchy' # for capybara's save_and_open_page
6868
gem 'mimic', '~> 0.4.3'
6969
gem 'railroady' # for doc/diagrams
70-
gem 'rubocop', '~> 0.35.0', require: false
70+
gem 'rubocop', '~> 0.59.2', require: false
71+
gem 'rubocop-rails_config', '~> 0.2.4'
7172
gem 'ruby-prof', '~> 0.12.2' # for performance tests
7273
gem 'simplecov'
7374
end

Gemfile.lock

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ GEM
4646
andand (1.3.3)
4747
arel (6.0.4)
4848
ast (2.4.0)
49-
astrolabe (1.3.1)
50-
parser (~> 2.2)
5149
autoprefixer-rails (8.2.0)
5250
execjs
5351
bootstrap (4.0.0)
@@ -130,6 +128,7 @@ GEM
130128
hurley (0.2)
131129
i18n (0.9.5)
132130
concurrent-ruby (~> 1.0)
131+
jaro_winkler (1.5.1)
133132
jquery-rails (3.1.4)
134133
railties (>= 3.0, < 5.0)
135134
thor (>= 0.14, < 2.0)
@@ -183,7 +182,8 @@ GEM
183182
mime-types
184183
mimemagic (~> 0.3.0)
185184
terrapin (~> 0.6.0)
186-
parser (2.5.0.5)
185+
parallel (1.12.1)
186+
parser (2.5.1.2)
187187
ast (~> 2.4.0)
188188
pdfkit (0.8.2)
189189
pg (0.19.0)
@@ -196,7 +196,7 @@ GEM
196196
multi_json (~> 1.0)
197197
websocket-driver (>= 0.2.0)
198198
popper_js (1.12.9)
199-
powerpack (0.1.1)
199+
powerpack (0.1.2)
200200
pry (0.11.3)
201201
coderay (~> 1.1.0)
202202
method_source (~> 0.9.0)
@@ -237,8 +237,7 @@ GEM
237237
activesupport (= 4.2.10)
238238
rake (>= 0.8.7)
239239
thor (>= 0.18.1, < 2.0)
240-
rainbow (2.2.2)
241-
rake
240+
rainbow (3.0.0)
242241
rake (12.3.1)
243242
rb-fsevent (0.10.3)
244243
rb-inotify (0.9.10)
@@ -286,15 +285,19 @@ GEM
286285
rspec-mocks (~> 3.5.0)
287286
rspec-support (~> 3.5.0)
288287
rspec-support (3.5.0)
289-
rubocop (0.35.1)
290-
astrolabe (~> 1.3)
291-
parser (>= 2.2.3.0, < 3.0)
288+
rubocop (0.59.2)
289+
jaro_winkler (~> 1.5.1)
290+
parallel (~> 1.10)
291+
parser (>= 2.5, != 2.5.1.1)
292292
powerpack (~> 0.1)
293-
rainbow (>= 1.99.1, < 3.0)
293+
rainbow (>= 2.2.2, < 4.0)
294294
ruby-progressbar (~> 1.7)
295-
tins (<= 1.6.0)
295+
unicode-display_width (~> 1.0, >= 1.0.1)
296+
rubocop-rails_config (0.2.4)
297+
railties (>= 3.0)
298+
rubocop (~> 0.56)
296299
ruby-prof (0.12.2)
297-
ruby-progressbar (1.9.0)
300+
ruby-progressbar (1.10.0)
298301
sass (3.5.6)
299302
sass-listen (~> 4.0.0)
300303
sass-listen (4.0.0)
@@ -337,7 +340,6 @@ GEM
337340
thor (0.20.0)
338341
thread_safe (0.3.6)
339342
tilt (2.0.8)
340-
tins (1.6.0)
341343
transaction_isolation (1.0.3)
342344
activerecord (>= 3.0.11)
343345
tzinfo (1.2.5)
@@ -349,6 +351,7 @@ GEM
349351
unf (0.1.4)
350352
unf_ext
351353
unf_ext (0.0.7.5)
354+
unicode-display_width (1.4.0)
352355
websocket-driver (0.7.0)
353356
websocket-extensions (>= 0.1.0)
354357
websocket-extensions (0.1.3)
@@ -404,7 +407,8 @@ DEPENDENCIES
404407
rspec-activemodel-mocks (~> 1.0.0)
405408
rspec-core (~> 3.5.2)
406409
rspec-rails (~> 3.5.1)
407-
rubocop (~> 0.35.0)
410+
rubocop (~> 0.59.2)
411+
rubocop-rails_config (~> 0.2.4)
408412
ruby-prof (~> 0.12.2)
409413
sass-rails (~> 5.0)
410414
simplecov
@@ -415,4 +419,4 @@ DEPENDENCIES
415419
xml-simple (~> 1.1.1)
416420

417421
BUNDLED WITH
418-
1.16.2
422+
1.16.5

app/controllers/api/beta/base_controller.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ def present(hash)
2929

3030
private
3131

32-
def authenticate_user!
33-
if doorkeeper_token
34-
@current_user = User.find(doorkeeper_token.resource_owner_id)
35-
end
32+
def authenticate_user!
33+
if doorkeeper_token
34+
@current_user = User.find(doorkeeper_token.resource_owner_id)
35+
end
3636

37-
return if @current_user
37+
return if @current_user
3838

39-
render json: { errors: ['User is not authenticated!'] }, status: :unauthorized
40-
end
39+
render json: { errors: ['User is not authenticated!'] }, status: :unauthorized
40+
end
4141

42-
attr_reader :current_user
42+
attr_reader :current_user
4343

44-
def errors_json(messages)
45-
{ errors: [*messages] }
46-
end
44+
def errors_json(messages)
45+
{ errors: [*messages] }
46+
end
4747
end

app/controllers/api/v8/base_controller.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ def present(hash)
3030

3131
private
3232

33-
def authenticate_user!
34-
return @current_user if @current_user
35-
if doorkeeper_token
36-
@current_user ||= User.find_by(id: doorkeeper_token.resource_owner_id)
37-
raise 'Invalid token' unless @current_user
33+
def authenticate_user!
34+
return @current_user if @current_user
35+
if doorkeeper_token
36+
@current_user ||= User.find_by(id: doorkeeper_token.resource_owner_id)
37+
raise 'Invalid token' unless @current_user
38+
end
39+
@current_user ||= user_from_session || Guest.new
3840
end
39-
@current_user ||= user_from_session || Guest.new
40-
end
4141

42-
attr_reader :current_user
42+
attr_reader :current_user
4343

44-
def errors_json(messages)
45-
{ errors: [*messages] }
46-
end
44+
def errors_json(messages)
45+
{ errors: [*messages] }
46+
end
4747
end
4848
end
4949
end

app/controllers/api/v8/core/submissions/reviews_controller.rb

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -63,60 +63,60 @@ def create
6363

6464
private
6565

66-
def award_points
67-
submission = @review.submission
68-
exercise = submission.exercise
69-
course = exercise.course
70-
raise 'Exercise of submission has been moved or deleted' unless exercise
71-
72-
available_points = exercise.available_points.where(requires_review: true).map(&:name)
73-
previous_points = course.awarded_points.where(user_id: submission.user_id, name: available_points).map(&:name)
74-
75-
new_points = []
76-
if params[:review][:points].respond_to?(:keys)
77-
params[:review][:points].keys.each do |point_name|
78-
unless exercise.available_points.where(name: point_name).any?
79-
raise "Point does not exist: #{point_name}"
66+
def award_points
67+
submission = @review.submission
68+
exercise = submission.exercise
69+
course = exercise.course
70+
raise 'Exercise of submission has been moved or deleted' unless exercise
71+
72+
available_points = exercise.available_points.where(requires_review: true).map(&:name)
73+
previous_points = course.awarded_points.where(user_id: submission.user_id, name: available_points).map(&:name)
74+
75+
new_points = []
76+
if params[:review][:points].respond_to?(:keys)
77+
params[:review][:points].keys.each do |point_name|
78+
unless exercise.available_points.where(name: point_name).any?
79+
raise "Point does not exist: #{point_name}"
80+
end
81+
82+
new_points << point_name
83+
pt = submission.awarded_points.build(
84+
course_id: submission.course_id,
85+
user_id: submission.user_id,
86+
name: point_name
87+
)
88+
authorize! :create, pt
89+
pt.save!
8090
end
81-
82-
new_points << point_name
83-
pt = submission.awarded_points.build(
84-
course_id: submission.course_id,
85-
user_id: submission.user_id,
86-
name: point_name
87-
)
88-
authorize! :create, pt
89-
pt.save!
9091
end
91-
end
9292

93-
@review.points = (@review.points_list + new_points + previous_points).uniq.natsort.join(' ')
94-
submission.points = (submission.points_list + new_points + previous_points).uniq.natsort.join(' ')
95-
end
93+
@review.points = (@review.points_list + new_points + previous_points).uniq.natsort.join(' ')
94+
submission.points = (submission.points_list + new_points + previous_points).uniq.natsort.join(' ')
95+
end
9696

97-
def mark_as_reviewed
98-
sub = @review.submission
99-
sub.reviewed = true
100-
sub.review_dismissed = false
101-
sub.of_same_kind
102-
.where('(requires_review OR requests_review) AND NOT reviewed')
103-
.where(['created_at < ?', sub.created_at])
104-
.update_all(newer_submission_reviewed: true)
105-
end
97+
def mark_as_reviewed
98+
sub = @review.submission
99+
sub.reviewed = true
100+
sub.review_dismissed = false
101+
sub.of_same_kind
102+
.where('(requires_review OR requests_review) AND NOT reviewed')
103+
.where(['created_at < ?', sub.created_at])
104+
.update_all(newer_submission_reviewed: true)
105+
end
106106

107-
def notify_user_about_new_review
108-
channel = '/broadcast/user/' + @review.submission.user.username + '/review-available'
109-
data = {
110-
exercise_name: @review.submission.exercise_name,
111-
url: submission_reviews_url(@review.submission),
112-
points: @review.points_list
113-
}
114-
CometServer.get.try_publish(channel, data)
115-
end
107+
def notify_user_about_new_review
108+
channel = '/broadcast/user/' + @review.submission.user.username + '/review-available'
109+
data = {
110+
exercise_name: @review.submission.exercise_name,
111+
url: submission_reviews_url(@review.submission),
112+
points: @review.points_list
113+
}
114+
CometServer.get.try_publish(channel, data)
115+
end
116116

117-
def send_email_about_new_review
118-
ReviewMailer.review_email(@review).deliver
119-
end
117+
def send_email_about_new_review
118+
ReviewMailer.review_email(@review).deliver
119+
end
120120
end
121121
end
122122
end

app/controllers/api/v8/courses/exercises_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def index
4646
unless can_see_everything
4747
exercises = exercises.where(hidden: false, disabled_status: 0)
4848
exercises = if unlocked_exercises.empty?
49-
exercises.where(unlock_spec: nil)
50-
else
51-
exercises.where(["unlock_spec IS NULL OR exercises.name IN (#{unlocked_exercises.map { |_| '?' }.join(', ')})", *unlocked_exercises])
52-
end
49+
exercises.where(unlock_spec: nil)
50+
else
51+
exercises.where(["unlock_spec IS NULL OR exercises.name IN (#{unlocked_exercises.map { |_| '?' }.join(', ')})", *unlocked_exercises])
52+
end
5353
end
5454

5555
exercises = exercises.pluck(:id)

app/controllers/api/v8/courses/users/submissions_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SubmissionsController < Api::V8::BaseController
2222
response 403, '$ref': '#/responses/error'
2323
response 404, '$ref': '#/responses/error'
2424
response 200 do
25-
key :description, 'User\'s submissions in json'
25+
key :description, "User's submissions in json"
2626
schema do
2727
key :title, :submissions
2828
key :required, [:submissions]
@@ -39,7 +39,7 @@ class SubmissionsController < Api::V8::BaseController
3939

4040
swagger_path '/api/v8/courses/{course_id}/users/current/submissions' do
4141
operation :get do
42-
key :description, 'Returns the user\'s own submissions in a json format'
42+
key :description, "Returns the user's own submissions in a json format"
4343
key :operationId, 'findUsersOwnSubmissionsById'
4444
key :produces, [
4545
'application/json'
@@ -51,7 +51,7 @@ class SubmissionsController < Api::V8::BaseController
5151
response 403, '$ref': '#/responses/error'
5252
response 404, '$ref': '#/responses/error'
5353
response 200 do
54-
key :description, 'User\'s own submissions in json'
54+
key :description, "User's own submissions in json"
5555
schema do
5656
key :title, :submissions
5757
key :required, [:submissions]

app/controllers/api/v8/organizations/courses/users/submissions_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class SubmissionsController < Api::V8::BaseController
2424
response 403, '$ref': '#/responses/error'
2525
response 404, '$ref': '#/responses/error'
2626
response 200 do
27-
key :description, 'User\'s submissions in json'
27+
key :description, "User's submissions in json"
2828
schema do
2929
key :title, :submissions
3030
key :required, [:submissions]
@@ -41,7 +41,7 @@ class SubmissionsController < Api::V8::BaseController
4141

4242
swagger_path '/api/v8/org/{organization_slug}/courses/{course_name}/users/current/submissions' do
4343
operation :get do
44-
key :description, 'Returns the user\'s own submissions in a json format'
44+
key :description, "Returns the user's own submissions in a json format"
4545
key :operationId, 'findUsersOwnSubmissionsByCourseName'
4646
key :produces, [
4747
'application/json'
@@ -54,7 +54,7 @@ class SubmissionsController < Api::V8::BaseController
5454
response 403, '$ref': '#/responses/error'
5555
response 404, '$ref': '#/responses/error'
5656
response 200 do
57-
key :description, 'User\'s own submissions in json'
57+
key :description, "User's own submissions in json"
5858
schema do
5959
key :title, :submissions
6060
key :required, [:submissions]

app/controllers/api/v8/users/basic_info_by_usernames_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class BasicInfoByUsernamesController < Api::V8::BaseController
88

99
swagger_path '/api/v8/users/basic_info_by_usernames' do
1010
operation :post do
11-
key :description, 'Find all users\' basic infos with the posted json array of usernames'
11+
key :description, "Find all users' basic infos with the posted json array of usernames"
1212
key :operationId, 'findUsersBasicInfoByUsernames'
1313
parameter do
1414
key :name, :usernames
@@ -26,7 +26,7 @@ class BasicInfoByUsernamesController < Api::V8::BaseController
2626
'user'
2727
]
2828
response 200 do
29-
key :description, 'Users\' username, email, and administrator status by usernames as json'
29+
key :description, "Users' username, email, and administrator status by usernames as json"
3030
schema do
3131
key :title, :user
3232
key :required, [:user]

0 commit comments

Comments
 (0)