Browse Source

Date ist verboten

Maarten van den Berg 6 years ago
parent
commit
360cf7c7d2

+ 3 - 0
.rubocop.yml

@@ -1,5 +1,8 @@
1 1
 inherit_from: .rubocop_todo.yml
2 2
 
3
+Rails:
4
+  Enabled: true
5
+
3 6
 # This configuration was generated by
4 7
 # `rubocop --auto-gen-config`
5 8
 # on 2018-12-24 11:44:14 +0100 using RuboCop version 0.60.0.

+ 0 - 10
.rubocop_todo.yml

@@ -20,16 +20,6 @@ Rails/CreateTableWithTimestamps:
20 20
   Exclude:
21 21
     - 'db/migrate/20170210180426_remove_tokens_from_users.rb'
22 22
 
23
-# Offense count: 7
24
-# Configuration parameters: EnforcedStyle.
25
-# SupportedStyles: strict, flexible
26
-Rails/Date:
27
-  Exclude:
28
-    - 'app/controllers/groups_controller.rb'
29
-    - 'app/helpers/authentication_helper.rb'
30
-    - 'app/models/person.rb'
31
-    - 'db/seeds.rb'
32
-
33 23
 # Offense count: 1
34 24
 # Configuration parameters: EnforcedStyle.
35 25
 # SupportedStyles: slashes, arguments

+ 2 - 2
app/controllers/groups_controller.rb

@@ -25,7 +25,7 @@ class GroupsController < ApplicationController
25 25
                             .organized_activities
26 26
                             .joins(:activity)
27 27
                             .where('activities.group_id': @group.id)
28
-                            .where('start > ?', Date.today)
28
+                            .where('start > ?', Time.zone.today)
29 29
 
30 30
     @groupmenu = if @organized_activities.any?
31 31
                    'col-md-6'
@@ -34,7 +34,7 @@ class GroupsController < ApplicationController
34 34
                  end
35 35
 
36 36
     @upcoming = @group.activities
37
-                      .where('start > ?', Date.today)
37
+                      .where('start > ?', Time.zone.today)
38 38
                       .order('start ASC')
39 39
     @upcoming_ps = Participant
40 40
                    .where(person: current_person)

+ 1 - 1
app/helpers/authentication_helper.rb

@@ -60,7 +60,7 @@ module AuthenticationHelper
60 60
   def logged_in?
61 61
     # Case 1: User has an active session inside the cookie.
62 62
     # We verify that the session hasn't expired yet.
63
-    if session[:user_id] && session[:expires].to_time.future?
63
+    if session[:user_id] && session[:expires]&.future?
64 64
 
65 65
       user_session
66 66
 

+ 1 - 1
app/models/person.rb

@@ -190,7 +190,7 @@ class Person < ApplicationRecord
190 190
 
191 191
   # Assert that the person's birth date, if any, lies in the past.
192 192
   def birth_date_cannot_be_in_future
193
-    errors.add(:birth_date, I18n.t('person.errors.cannot_future')) if birth_date && birth_date > Date.today
193
+    errors.add(:birth_date, I18n.t('person.errors.cannot_future')) if birth_date&.future?
194 194
   end
195 195
 
196 196
   # Explicitly force nil to false in the admin field.

+ 3 - 3
db/seeds.rb

@@ -13,7 +13,7 @@ its_me = Person.create!(
13 13
   first_name: 'Maarten',
14 14
   infix: 'van den',
15 15
   last_name: 'Berg',
16
-  birth_date: Faker::Date.between(21.years.ago, Date.today),
16
+  birth_date: Faker::Date.between(21.years.ago, Time.zone.today),
17 17
   email: 'maarten@maartenberg.nl',
18 18
   is_admin: true
19 19
 )
@@ -29,7 +29,7 @@ User.create!(
29 29
 Person.create!(
30 30
   first_name: 'Henkie',
31 31
   last_name: 'Gekke',
32
-  birth_date: Faker::Date.between(21.years.ago, Date.today),
32
+  birth_date: Faker::Date.between(21.years.ago, Time.zone.today),
33 33
   email: 'gekkehenkie@maartenberg.nl'
34 34
 )
35 35
 
@@ -47,7 +47,7 @@ end
47 47
   Person.create!(
48 48
     first_name: Faker::Name.first_name,
49 49
     last_name: Faker::Name.last_name,
50
-    birth_date: Faker::Date.between(21.years.ago, Date.today),
50
+    birth_date: Faker::Date.between(21.years.ago, Time.zone.today),
51 51
     email: "testuser#{i}@maartenberg.nl"
52 52
   )
53 53
 end