diff --git a/app/models/conference.rb b/app/models/conference.rb index 8e658759..f3565814 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -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. # diff --git a/spec/models/conference_spec.rb b/spec/models/conference_spec.rb index a0a5576e..d5ffcbca 100755 --- a/spec/models/conference_spec.rb +++ b/spec/models/conference_spec.rb @@ -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