Browse Source

The Rubocopening, ruby version bump

Maarten van den Berg 6 years ago
parent
commit
0fdea40e7e

+ 0 - 58
.rubocop_todo.yml

6
 # Note that changes in the inspected code, or installation of new
6
 # Note that changes in the inspected code, or installation of new
7
 # versions of RuboCop, may require this file to be generated again.
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
 # Offense count: 1
9
 # Offense count: 1
17
 # Configuration parameters: Include.
10
 # Configuration parameters: Include.
18
 # Include: db/migrate/*.rb
11
 # Include: db/migrate/*.rb
21
     - 'db/migrate/20170210180426_remove_tokens_from_users.rb'
14
     - 'db/migrate/20170210180426_remove_tokens_from_users.rb'
22
 
15
 
23
 # Offense count: 1
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
 # Configuration parameters: Include.
17
 # Configuration parameters: Include.
56
 # Include: db/migrate/*.rb
18
 # Include: db/migrate/*.rb
57
 Rails/ReversibleMigration:
19
 Rails/ReversibleMigration:
58
   Exclude:
20
   Exclude:
59
     - 'db/migrate/20161214112504_remove_group_type_from_groups.rb'
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
-2.5.1
1
+2.5.3

+ 3 - 0
Gemfile

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

+ 19 - 1
Gemfile.lock

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

+ 4 - 4
app/controllers/activities_controller.rb

26
   def index
26
   def index
27
     @activities = if params[:past]
27
     @activities = if params[:past]
28
                     @group.activities
28
                     @group.activities
29
-                          .where('start < ?', Time.now)
29
+                          .where('start < ?', Time.zone.now)
30
                           .order(start: :desc)
30
                           .order(start: :desc)
31
                           .paginate(page: params[:page], per_page: 25)
31
                           .paginate(page: params[:page], per_page: 25)
32
                   else
32
                   else
33
                     @group.activities
33
                     @group.activities
34
-                          .where('start > ?', Time.now)
34
+                          .where('start > ?', Time.zone.now)
35
                           .order(start: :asc)
35
                           .order(start: :asc)
36
                           .paginate(page: params[:page], per_page: 25)
36
                           .paginate(page: params[:page], per_page: 25)
37
                   end
37
                   end
273
       return
273
       return
274
     end
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
       head :locked
277
       head :locked
278
       return
278
       return
279
     end
279
     end
280
 
280
 
281
     params[:notes] = params[:participant][:notes] if params[:participant]
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
     head :no_content
283
     head :no_content
284
   end
284
   end
285
 
285
 

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

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

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

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

+ 1 - 1
app/controllers/application_controller.rb

8
   private
8
   private
9
 
9
 
10
   def invalid_auth_token
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
   end
12
   end
13
 end
13
 end

+ 2 - 2
app/controllers/dashboard_controller.rb

5
     @upcoming = current_person
5
     @upcoming = current_person
6
                 .participants
6
                 .participants
7
                 .joins(:activity)
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
                 .order('activities.start ASC')
9
                 .order('activities.start ASC')
10
     @user_organized = @upcoming
10
     @user_organized = @upcoming
11
                       .where(is_organizer: true)
11
                       .where(is_organizer: true)
20
   def set_settings_params!
20
   def set_settings_params!
21
     @person = current_person
21
     @person = current_person
22
     @send_attendance_reminder = @person.send_attendance_reminder
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
   end
24
   end
25
 
25
 
26
   def settings
26
   def settings

+ 2 - 2
app/controllers/members_controller.rb

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

+ 1 - 1
app/helpers/authentication_helper.rb

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

+ 1 - 1
app/models/activity.rb

152
     defaults = group.default_subgroups
152
     defaults = group.default_subgroups
153
 
153
 
154
     # If there are no subgroups, there cannot be subgroup division.
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
     defaults.each do |dsg|
157
     defaults.each do |dsg|
158
       sg = Subgroup.new(activity: self)
158
       sg = Subgroup.new(activity: self)

+ 1 - 1
app/models/group.rb

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

+ 2 - 2
app/models/person.rb

34
   #   @return [Boolean]
34
   #   @return [Boolean]
35
   #     whether or not the person has administrative rights.
35
   #     whether or not the person has administrative rights.
36
 
36
 
37
-  has_one :user
37
+  has_one :user, dependent: :destroy
38
   has_many :members,
38
   has_many :members,
39
            dependent: :destroy
39
            dependent: :destroy
40
   has_many :participants,
40
   has_many :participants,
109
     cal = Icalendar::Calendar.new
109
     cal = Icalendar::Calendar.new
110
     cal.x_wr_calname = 'Aardbei'
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
     selection =
114
     selection =
115
       participants
115
       participants

+ 1 - 1
app/models/token.rb

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

+ 2 - 2
app/models/user.rb

21
   # Set all sessions associated with this User to inactive, for instance after
21
   # Set all sessions associated with this User to inactive, for instance after
22
   # a password change, or when the user selects this options in the Settings.
22
   # a password change, or when the user selects this options in the Settings.
23
   def logout_all_sessions!
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
   end
26
   end
27
 
27
 
28
   private
28
   private

+ 1 - 1
config/environments/development.rb

13
   config.consider_all_requests_local = true
13
   config.consider_all_requests_local = true
14
 
14
 
15
   # Enable/disable caching. By default caching is disabled.
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
     config.action_controller.perform_caching = true
17
     config.action_controller.perform_caching = true
18
 
18
 
19
     config.cache_store = :memory_store
19
     config.cache_store = :memory_store

+ 2 - 2
db/seeds.rb

64
 
64
 
65
 Group.all.each do |g|
65
 Group.all.each do |g|
66
   10.times do
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
     deadline  = 5.days.ago(starttime)
69
     deadline  = 5.days.ago(starttime)
70
 
70
 
71
     Activity.create!(
71
     Activity.create!(