Browse Source

Date ist verboten

Maarten van den Berg 6 years ago
parent
commit
360cf7c7d2

+ 3 - 0
.rubocop.yml

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

+ 0 - 10
.rubocop_todo.yml

20
   Exclude:
20
   Exclude:
21
     - 'db/migrate/20170210180426_remove_tokens_from_users.rb'
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
 # Offense count: 1
23
 # Offense count: 1
34
 # Configuration parameters: EnforcedStyle.
24
 # Configuration parameters: EnforcedStyle.
35
 # SupportedStyles: slashes, arguments
25
 # SupportedStyles: slashes, arguments

+ 2 - 2
app/controllers/groups_controller.rb

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

+ 1 - 1
app/helpers/authentication_helper.rb

60
   def logged_in?
60
   def logged_in?
61
     # Case 1: User has an active session inside the cookie.
61
     # Case 1: User has an active session inside the cookie.
62
     # We verify that the session hasn't expired yet.
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
       user_session
65
       user_session
66
 
66
 

+ 1 - 1
app/models/person.rb

190
 
190
 
191
   # Assert that the person's birth date, if any, lies in the past.
191
   # Assert that the person's birth date, if any, lies in the past.
192
   def birth_date_cannot_be_in_future
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
   end
194
   end
195
 
195
 
196
   # Explicitly force nil to false in the admin field.
196
   # Explicitly force nil to false in the admin field.

+ 3 - 3
db/seeds.rb

13
   first_name: 'Maarten',
13
   first_name: 'Maarten',
14
   infix: 'van den',
14
   infix: 'van den',
15
   last_name: 'Berg',
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
   email: 'maarten@maartenberg.nl',
17
   email: 'maarten@maartenberg.nl',
18
   is_admin: true
18
   is_admin: true
19
 )
19
 )
29
 Person.create!(
29
 Person.create!(
30
   first_name: 'Henkie',
30
   first_name: 'Henkie',
31
   last_name: 'Gekke',
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
   email: 'gekkehenkie@maartenberg.nl'
33
   email: 'gekkehenkie@maartenberg.nl'
34
 )
34
 )
35
 
35
 
47
   Person.create!(
47
   Person.create!(
48
     first_name: Faker::Name.first_name,
48
     first_name: Faker::Name.first_name,
49
     last_name: Faker::Name.last_name,
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
     email: "testuser#{i}@maartenberg.nl"
51
     email: "testuser#{i}@maartenberg.nl"
52
   )
52
   )
53
 end
53
 end