From 7638b33926caa3b4062db85de80927e20d19c1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Geuken?= Date: Thu, 21 May 2015 18:48:07 +0200 Subject: [PATCH 1/4] Fix registration_dates_given? When the registration period is nil registration_dates_given? should return false. --- app/models/conference.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index e7a0790c..9c1cde4a 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -155,7 +155,7 @@ class Conference < ActiveRecord::Base # * +false+ -> If the conference registration dates are not set # * +true+ -> If conference registration dates are set def registration_dates_given? - if registration_period && (registration_period.start_date.blank? || registration_period.end_date.blank?) + if registration_period.nil? || (registration_period.start_date.blank? || registration_period.end_date.blank?) false else true From bc966259fb15737de57ef6d2298b6c615726d031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Geuken?= Date: Thu, 21 May 2015 18:53:27 +0200 Subject: [PATCH 2/4] Refactor registration_dates_given? --- app/models/conference.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index 9c1cde4a..13c99f8c 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -155,11 +155,9 @@ class Conference < ActiveRecord::Base # * +false+ -> If the conference registration dates are not set # * +true+ -> If conference registration dates are set def registration_dates_given? - if registration_period.nil? || (registration_period.start_date.blank? || registration_period.end_date.blank?) - false - else - true - end + registration_period.present? && + registration_period.start_date.present? && + registration_period.end_date.present? end ## From 0d8a77c9eff9b18736a72b14b5457e555a3b3f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Geuken?= Date: Tue, 19 May 2015 20:02:02 +0200 Subject: [PATCH 3/4] Refactor registration_open? method The registration_period is already checked in registration_dates_given? method. No need to check it twice --- app/models/conference.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index 13c99f8c..221af5ba 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -141,7 +141,7 @@ class Conference < ActiveRecord::Base # * +true+ -> If today is in the registration period. def registration_open? today = Date.current - if registration_period && registration_dates_given? + if registration_dates_given? (registration_period.start_date..registration_period.end_date).cover?(today) else false From f180ce0d274f272ace2aa857111fd2e16f89e5f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Geuken?= Date: Tue, 19 May 2015 20:04:19 +0200 Subject: [PATCH 4/4] Refactor registration_open? method, part II --- app/models/conference.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/models/conference.rb b/app/models/conference.rb index 221af5ba..78fa1999 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -140,12 +140,8 @@ class Conference < ActiveRecord::Base # registration period. # * +true+ -> If today is in the registration period. def registration_open? - today = Date.current - if registration_dates_given? - (registration_period.start_date..registration_period.end_date).cover?(today) - else - false - end + registration_dates_given? && + (registration_period.start_date..registration_period.end_date).cover?(Date.current) end ##