Merge pull request #756 from chinmaydd/date_fix

Fixes Start date being greater than End date
This commit is contained in:
Christian Bruckmayer 2016-01-21 09:08:35 +01:00
commit 1feba36d61
2 changed files with 18 additions and 0 deletions

View file

@ -95,6 +95,9 @@ class Conference < ActiveRecord::Base
validates_uniqueness_of :short_title
validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/
# This validation is needed since a conference with a start date greater than the end date is not possible
validate :valid_date_range?
before_create :generate_guid
before_create :create_event_types
before_create :create_difficulty_levels
@ -583,6 +586,14 @@ class Conference < ActiveRecord::Base
self.create_contact
end
##
# Checks if start date of the conference is greater than the end date
#
# Reports an error when such a condition is found
def valid_date_range?
errors.add(:start_date, "Start date is greater than End date") if start_date > end_date
end
##
# Calculates the weeks from a start and a end week.
#

View file

@ -1516,6 +1516,13 @@ describe Conference do
should_not allow_value('&%§!?äÄüÜ/()').for(:short_title)
end
describe 'valid_date_range?' do
it 'is not valid if start date is greater than end date' do
expect(subject.start_date).to be <= subject.end_date
end
end
describe 'before create callbacks' do
it 'has an email setting after creation' do