Browse Source

The Rubocopening, ruby version bump

Maarten van den Berg 6 years ago
parent
commit
0fdea40e7e

+ 0 - 58
.rubocop_todo.yml

@@ -6,13 +6,6 @@
6 6
 # Note that changes in the inspected code, or installation of new
7 7
 # versions of RuboCop, may require this file to be generated again.
8 8
 
9
-# Offense count: 2
10
-# Cop supports --auto-correct.
11
-Rails/ActiveRecordAliases:
12
-  Exclude:
13
-    - 'app/controllers/activities_controller.rb'
14
-    - 'app/controllers/api/activities_controller.rb'
15
-
16 9
 # Offense count: 1
17 10
 # Configuration parameters: Include.
18 11
 # Include: db/migrate/*.rb
@@ -21,59 +14,8 @@ Rails/CreateTableWithTimestamps:
21 14
     - 'db/migrate/20170210180426_remove_tokens_from_users.rb'
22 15
 
23 16
 # Offense count: 1
24
-# Configuration parameters: EnforcedStyle.
25
-# SupportedStyles: slashes, arguments
26
-Rails/FilePath:
27
-  Exclude:
28
-    - 'config/environments/development.rb'
29
-
30
-# Offense count: 1
31
-# Configuration parameters: Include.
32
-# Include: app/models/**/*.rb
33
-Rails/HasManyOrHasOneDependent:
34
-  Exclude:
35
-    - 'app/models/person.rb'
36
-
37
-# Offense count: 1
38
-# Cop supports --auto-correct.
39
-# Configuration parameters: EnforcedStyle.
40
-# SupportedStyles: numeric, symbolic
41
-Rails/HttpStatus:
42
-  Exclude:
43
-    - 'app/controllers/application_controller.rb'
44
-
45
-# Offense count: 6
46
-# Cop supports --auto-correct.
47
-Rails/PluralizationGrammar:
48
-  Exclude:
49
-    - 'app/helpers/authentication_helper.rb'
50
-    - 'app/models/person.rb'
51
-    - 'app/models/token.rb'
52
-    - 'db/seeds.rb'
53
-
54
-# Offense count: 1
55 17
 # Configuration parameters: Include.
56 18
 # Include: db/migrate/*.rb
57 19
 Rails/ReversibleMigration:
58 20
   Exclude:
59 21
     - 'db/migrate/20161214112504_remove_group_type_from_groups.rb'
60
-
61
-# Offense count: 4
62
-# Configuration parameters: Blacklist, Whitelist.
63
-# Blacklist: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters
64
-Rails/SkipsModelValidations:
65
-  Exclude:
66
-    - 'app/controllers/members_controller.rb'
67
-    - 'app/models/activity.rb'
68
-    - 'app/models/user.rb'
69
-
70
-# Offense count: 9
71
-# Configuration parameters: EnforcedStyle.
72
-# SupportedStyles: strict, flexible
73
-Rails/TimeZone:
74
-  Exclude:
75
-    - 'app/controllers/activities_controller.rb'
76
-    - 'app/controllers/api/groups_controller.rb'
77
-    - 'app/controllers/dashboard_controller.rb'
78
-    - 'app/models/group.rb'
79
-    - 'db/seeds.rb'

+ 1 - 1
.ruby-version

@@ -1 +1 @@
1
-2.5.1
1
+2.5.3

+ 3 - 0
Gemfile

@@ -90,6 +90,9 @@ group :development do
90 90
 
91 91
   # Translation helpers
92 92
   gem 'i18n_generators'
93
+
94
+  # Codestyle enforcement
95
+  gem 'rubocop'
93 96
 end
94 97
 
95 98
 group :production do

+ 19 - 1
Gemfile.lock

@@ -39,6 +39,7 @@ GEM
39 39
       minitest (~> 5.1)
40 40
       tzinfo (~> 1.1)
41 41
     arel (7.1.4)
42
+    ast (2.4.0)
42 43
     autoprefixer-rails (9.4.3)
43 44
       execjs
44 45
     babel-source (5.8.35)
@@ -96,6 +97,7 @@ GEM
96 97
     icalendar (2.5.2)
97 98
       ice_cube (~> 0.16)
98 99
     ice_cube (0.16.3)
100
+    jaro_winkler (1.5.2)
99 101
     jquery-rails (4.3.3)
100 102
       rails-dom-testing (>= 1, < 3)
101 103
       railties (>= 4.2.0)
@@ -126,7 +128,11 @@ GEM
126 128
     nokogiri (1.9.1)
127 129
       mini_portile2 (~> 2.4.0)
128 130
     oj (3.7.4)
131
+    parallel (1.13.0)
132
+    parser (2.6.0.0)
133
+      ast (~> 2.4.0)
129 134
     pg (1.1.3)
135
+    powerpack (0.1.2)
130 136
     puma (3.12.0)
131 137
     rabl (0.14.0)
132 138
       activesupport (>= 2.3.14)
@@ -156,6 +162,7 @@ GEM
156 162
       method_source
157 163
       rake (>= 0.8.7)
158 164
       thor (>= 0.18.1, < 2.0)
165
+    rainbow (3.0.0)
159 166
     rake (12.3.2)
160 167
     rb-fsevent (0.10.3)
161 168
     rb-inotify (0.10.0)
@@ -164,6 +171,15 @@ GEM
164 171
       http-cookie (>= 1.0.2, < 2.0)
165 172
       mime-types (>= 1.16, < 4.0)
166 173
       netrc (~> 0.8)
174
+    rubocop (0.63.0)
175
+      jaro_winkler (~> 1.5.1)
176
+      parallel (~> 1.10)
177
+      parser (>= 2.5, != 2.5.1.1)
178
+      powerpack (~> 0.1)
179
+      rainbow (>= 2.2.2, < 4.0)
180
+      ruby-progressbar (~> 1.7)
181
+      unicode-display_width (~> 1.4.0)
182
+    ruby-progressbar (1.10.0)
167 183
     sass (3.7.2)
168 184
       sass-listen (~> 4.0.0)
169 185
     sass-listen (4.0.0)
@@ -207,6 +223,7 @@ GEM
207 223
     unf (0.1.4)
208 224
       unf_ext
209 225
     unf_ext (0.0.7.5)
226
+    unicode-display_width (1.4.1)
210 227
     web-console (3.7.0)
211 228
       actionview (>= 5.0)
212 229
       activemodel (>= 5.0)
@@ -248,6 +265,7 @@ DEPENDENCIES
248 265
   puma (~> 3.0)
249 266
   rabl
250 267
   rails (~> 5.0.0, >= 5.0.0.1)
268
+  rubocop
251 269
   sass-rails (~> 5.0)
252 270
   sentry-raven
253 271
   spring
@@ -262,4 +280,4 @@ DEPENDENCIES
262 280
   yard
263 281
 
264 282
 BUNDLED WITH
265
-   1.17.1
283
+   1.17.3

+ 4 - 4
app/controllers/activities_controller.rb

@@ -26,12 +26,12 @@ class ActivitiesController < ApplicationController
26 26
   def index
27 27
     @activities = if params[:past]
28 28
                     @group.activities
29
-                          .where('start < ?', Time.now)
29
+                          .where('start < ?', Time.zone.now)
30 30
                           .order(start: :desc)
31 31
                           .paginate(page: params[:page], per_page: 25)
32 32
                   else
33 33
                     @group.activities
34
-                          .where('start > ?', Time.now)
34
+                          .where('start > ?', Time.zone.now)
35 35
                           .order(start: :asc)
36 36
                           .paginate(page: params[:page], per_page: 25)
37 37
                   end
@@ -273,13 +273,13 @@ class ActivitiesController < ApplicationController
273 273
       return
274 274
     end
275 275
 
276
-    if @activity.deadline && @activity.deadline < Time.now && !@activity.may_change?(current_person)
276
+    if @activity.deadline&.past? && !@activity.may_change?(current_person)
277 277
       head :locked
278 278
       return
279 279
     end
280 280
 
281 281
     params[:notes] = params[:participant][:notes] if params[:participant]
282
-    participant.update_attributes(params.permit(:notes, :attending))
282
+    participant.update!(params.permit(:notes, :attending))
283 283
     head :no_content
284 284
   end
285 285
 

+ 1 - 1
app/controllers/api/activities_controller.rb

@@ -83,7 +83,7 @@ module Api
83 83
         activity: @activity
84 84
       )
85 85
 
86
-      participant.update_attributes(params.permit(:attending))
86
+      participant.update!(params.permit(:attending))
87 87
       head :no_content
88 88
     end
89 89
 

+ 1 - 1
app/controllers/api/groups_controller.rb

@@ -61,7 +61,7 @@ module Api
61 61
       return unless input
62 62
 
63 63
       begin
64
-        DateTime.parse input # rubocop:disable Style/DateTime
64
+        DateTime.zone.parse input
65 65
       rescue ArgumentError
66 66
         nil
67 67
       end

+ 1 - 1
app/controllers/application_controller.rb

@@ -8,6 +8,6 @@ class ApplicationController < ActionController::Base
8 8
   private
9 9
 
10 10
   def invalid_auth_token
11
-    render text: I18n.t(:invalid_csrf), status: 400
11
+    render text: I18n.t(:invalid_csrf), status: :bad_request
12 12
   end
13 13
 end

+ 2 - 2
app/controllers/dashboard_controller.rb

@@ -5,7 +5,7 @@ class DashboardController < ApplicationController
5 5
     @upcoming = current_person
6 6
                 .participants
7 7
                 .joins(:activity)
8
-                .where('activities.end >= ? OR (activities.end IS NULL AND activities.start >= ?)', Time.now, Time.now)
8
+                .where('activities.end >= ? OR (activities.end IS NULL AND activities.start >= ?)', Time.zone.now, Time.zone.now)
9 9
                 .order('activities.start ASC')
10 10
     @user_organized = @upcoming
11 11
                       .where(is_organizer: true)
@@ -20,7 +20,7 @@ class DashboardController < ApplicationController
20 20
   def set_settings_params!
21 21
     @person = current_person
22 22
     @send_attendance_reminder = @person.send_attendance_reminder
23
-    @active_sessions = Session.where(user: current_user).where(active: true).where('expires > ?', Time.now).count
23
+    @active_sessions = Session.where(user: current_user).where(active: true).where('expires > ?', Time.zone.now).count
24 24
   end
25 25
 
26 26
   def settings

+ 2 - 2
app/controllers/members_controller.rb

@@ -28,13 +28,13 @@ class MembersController < ApplicationController
28 28
   end
29 29
 
30 30
   def promote
31
-    @member.update_attribute(:is_leader, true)
31
+    @member.update!(is_leader: true)
32 32
     flash_message(:success, I18n.t('groups.leader_added', name: @member.person.full_name))
33 33
     redirect_to group_members_path(@group)
34 34
   end
35 35
 
36 36
   def demote
37
-    @member.update_attribute(:is_leader, false)
37
+    @member.update!(is_leader: false)
38 38
     flash_message(:success, I18n.t('groups.leader_removed', name: @member.person.full_name))
39 39
     redirect_to group_members_path(@group)
40 40
   end

+ 1 - 1
app/helpers/authentication_helper.rb

@@ -11,7 +11,7 @@ module AuthenticationHelper
11 11
 
12 12
     if remember == 1
13 13
       token = Session.new_token
14
-      expiry = 1.years.since
14
+      expiry = 1.year.since
15 15
       cookies.signed.permanent[:remember_token] = {
16 16
         value: token,
17 17
         httponly: true

+ 1 - 1
app/models/activity.rb

@@ -152,7 +152,7 @@ class Activity < ApplicationRecord
152 152
     defaults = group.default_subgroups
153 153
 
154 154
     # If there are no subgroups, there cannot be subgroup division.
155
-    update_attribute(:subgroup_division_enabled, false) if defaults.none?
155
+    update!(:subgroup_division_enabled, false) if defaults.none?
156 156
 
157 157
     defaults.each do |dsg|
158 158
       sg = Subgroup.new(activity: self)

+ 1 - 1
app/models/group.rb

@@ -30,7 +30,7 @@ class Group < ApplicationRecord
30 30
 
31 31
   # @return [Array<Activity>] the activities that haven't started yet.
32 32
   def future_activities
33
-    activities.where('start > ?', Time.now)
33
+    activities.where('start > ?', Time.zone.now)
34 34
   end
35 35
 
36 36
   # @return [Array<Activity>]

+ 2 - 2
app/models/person.rb

@@ -34,7 +34,7 @@ class Person < ApplicationRecord
34 34
   #   @return [Boolean]
35 35
   #     whether or not the person has administrative rights.
36 36
 
37
-  has_one :user
37
+  has_one :user, dependent: :destroy
38 38
   has_many :members,
39 39
            dependent: :destroy
40 40
   has_many :participants,
@@ -109,7 +109,7 @@ class Person < ApplicationRecord
109 109
     cal = Icalendar::Calendar.new
110 110
     cal.x_wr_calname = 'Aardbei'
111 111
 
112
-    tzid = 1.seconds.since.time_zone.tzinfo.name
112
+    tzid = 1.second.since.time_zone.tzinfo.name
113 113
 
114 114
     selection =
115 115
       participants

+ 1 - 1
app/models/token.rb

@@ -55,7 +55,7 @@ class Token < ApplicationRecord
55 55
   def generate_expiry
56 56
     case tokentype
57 57
     when TYPES[:password_reset]
58
-      self.expires = 1.days.since
58
+      self.expires = 1.day.since
59 59
     when TYPES[:account_confirmation]
60 60
       self.expires = 7.days.since
61 61
     end

+ 2 - 2
app/models/user.rb

@@ -21,8 +21,8 @@ class User < ApplicationRecord
21 21
   # Set all sessions associated with this User to inactive, for instance after
22 22
   # a password change, or when the user selects this options in the Settings.
23 23
   def logout_all_sessions!
24
-    sessions = Session.where(user: self)
25
-    sessions.update_all(active: false)
24
+    Session.where(user: self)
25
+           .update_all(active: false) # rubocop:disable Rails/SkipsModelValidations
26 26
   end
27 27
 
28 28
   private

+ 1 - 1
config/environments/development.rb

@@ -13,7 +13,7 @@ Rails.application.configure do
13 13
   config.consider_all_requests_local = true
14 14
 
15 15
   # Enable/disable caching. By default caching is disabled.
16
-  if Rails.root.join('tmp/caching-dev.txt').exist?
16
+  if Rails.root.join('tmp', 'caching-dev.txt').exist?
17 17
     config.action_controller.perform_caching = true
18 18
 
19 19
     config.cache_store = :memory_store

+ 2 - 2
db/seeds.rb

@@ -64,8 +64,8 @@ Activity.create!(
64 64
 
65 65
 Group.all.each do |g|
66 66
   10.times do
67
-    starttime = Faker::Time.between(Time.now, 1.years.since, :morning)
68
-    endtime   = Faker::Time.between(1.hours.since(starttime), 1.days.since(starttime), :afternoon)
67
+    starttime = Faker::Time.between(Time.zone.now, 1.year.since, :morning)
68
+    endtime   = Faker::Time.between(1.hour.since(starttime), 1.day.since(starttime), :afternoon)
69 69
     deadline  = 5.days.ago(starttime)
70 70
 
71 71
     Activity.create!(