Browse Source

Safe navigation

Maarten van den Berg 6 years ago
parent
commit
3925353e1a
4 changed files with 4 additions and 23 deletions
  1. 0 17
      .rubocop.yml
  2. 2 2
      app/controllers/authentication_controller.rb
  3. 1 1
      app/models/activity.rb
  4. 1 3
      app/models/person.rb

+ 0 - 17
.rubocop.yml

@@ -268,15 +268,6 @@ Style/RedundantSelf:
268 268
     - 'app/models/token.rb'
269 269
     - 'app/models/user.rb'
270 270
 
271
-# Offense count: 3
272
-# Cop supports --auto-correct.
273
-# Configuration parameters: ConvertCodeThatCanStartToReturnNil, Whitelist.
274
-# Whitelist: present?, blank?, presence, try, try!
275
-Style/SafeNavigation:
276
-  Exclude:
277
-    - 'app/controllers/authentication_controller.rb'
278
-    - 'app/models/person.rb'
279
-
280 271
 # Offense count: 215
281 272
 # Cop supports --auto-correct.
282 273
 # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
@@ -302,14 +293,6 @@ Style/SymbolProc:
302 293
     - 'app/models/member.rb'
303 294
     - 'db/migrate/20180904163645_generate_calendar_tokens.rb'
304 295
 
305
-# Offense count: 1
306
-# Cop supports --auto-correct.
307
-# Configuration parameters: EnforcedStyleForMultiline.
308
-# SupportedStylesForMultiline: comma, consistent_comma, no_comma
309
-Style/TrailingCommaInArguments:
310
-  Exclude:
311
-    - 'app/models/activity.rb'
312
-
313 296
 # Offense count: 3
314 297
 # Cop supports --auto-correct.
315 298
 # Configuration parameters: WordRegex.

+ 2 - 2
app/controllers/authentication_controller.rb

@@ -11,7 +11,7 @@ class AuthenticationController < ApplicationController
11 11
     else
12 12
       u = User.find_by(email: params[:session][:email])
13 13
 
14
-      if u && u.confirmed && u.authenticate(params[:session][:password])
14
+      if u&.confirmed && u&.authenticate(params[:session][:password])
15 15
         log_in(u, params[:session][:remember_me].to_i)
16 16
 
17 17
         flash_message(:success, I18n.t(:greeting, name: u.person.first_name))
@@ -53,7 +53,7 @@ class AuthenticationController < ApplicationController
53 53
     end
54 54
 
55 55
     user = User.find_by(person: person)
56
-    if user && user.confirmed
56
+    if user&.confirmed
57 57
       flash_message(:warning, I18n.t('authentication.already_activated'))
58 58
       redirect_to action: 'login'
59 59
       return

+ 1 - 1
app/models/activity.rb

@@ -144,7 +144,7 @@ class Activity < ApplicationRecord
144 144
     people.each do |p|
145 145
       Participant.create(
146 146
         activity: self,
147
-        person: p,
147
+        person: p
148 148
       )
149 149
     end
150 150
   end

+ 1 - 3
app/models/person.rb

@@ -207,8 +207,6 @@ class Person < ApplicationRecord
207 207
   # Ensure the person's user email is updated at the same time as the person's
208 208
   # email.
209 209
   def update_user_email
210
-    unless self.user.nil?
211
-      self.user.update!(email: self.email)
212
-    end
210
+    self.user&.update!(email: self.email)
213 211
   end
214 212
 end