voting period is open when voting dates are not set

This commit is contained in:
differentreality 2016-08-17 15:55:10 +03:00 committed by Stella Rouzi
parent d07de3ca88
commit ea868d4cc7
3 changed files with 6 additions and 6 deletions

View file

@ -4,7 +4,7 @@ module ApplicationHelper
# #
def voting_open_or_close(program) def voting_open_or_close(program)
return if program.voting_period? return if program.voting_period?
if program.voting_start_date > Date.today if program.voting_start_date > Time.current
return 'Voting period has not started yet!' return 'Voting period has not started yet!'
else # voting_end_date > Date.today because voting_start_date < voting_end_date else # voting_end_date > Date.today because voting_start_date < voting_end_date
return 'Voting period is over!' return 'Voting period is over!'

View file

@ -72,16 +72,16 @@ class Program < ActiveRecord::Base
def show_voting? def show_voting?
return true unless blind_voting return true unless blind_voting
Date.today > voting_end_date Time.current > voting_end_date
end end
## ##
# Checks if we are still in voting period # Checks if we are still in voting period
# ====Returns # ====Returns
# * +true+ -> If the voting period is not over yet # * +true+ -> If the voting period is not over yet (or if the voting dates are not set)
# * +false+ -> If the voting period is over # * +false+ -> If the voting period is over
def voting_period? def voting_period?
return false unless voting_start_date && voting_end_date return true unless voting_start_date && voting_end_date
(voting_start_date.to_datetime..voting_end_date.to_datetime).cover? Time.current (voting_start_date.to_datetime..voting_end_date.to_datetime).cover? Time.current
end end

View file

@ -90,8 +90,8 @@ describe Program do
end end
describe 'voting_period?' do describe 'voting_period?' do
it 'retuns false when voting dates are not set' do it 'retuns true when voting dates are not set' do
expect(program.voting_period?).to eq false expect(program.voting_period?).to eq true
end end
shared_examples 'voting period' do |voting_start_date, voting_end_date, returns| shared_examples 'voting period' do |voting_start_date, voting_end_date, returns|