validate cfp start_date before end_date and end_date before conference.end_date
This commit is contained in:
parent
1edb4bff9e
commit
6e026746a9
7 changed files with 62 additions and 7 deletions
|
|
@ -6,6 +6,8 @@ class CallForPaper < ActiveRecord::Base
|
||||||
|
|
||||||
validates_presence_of :start_date, :end_date
|
validates_presence_of :start_date, :end_date
|
||||||
validates :rating, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }
|
validates :rating, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 10 }
|
||||||
|
validate :before_end_of_conference
|
||||||
|
validate :start_after_end_date
|
||||||
|
|
||||||
##
|
##
|
||||||
# Calculates how many weeks the call for paper is.
|
# Calculates how many weeks the call for paper is.
|
||||||
|
|
@ -60,4 +62,19 @@ class CallForPaper < ActiveRecord::Base
|
||||||
&& !self.conference.email_settings.call_for_papers_dates_updates_subject.blank?\
|
&& !self.conference.email_settings.call_for_papers_dates_updates_subject.blank?\
|
||||||
&& !self.conference.email_settings.call_for_papers_dates_updates_template.blank?
|
&& !self.conference.email_settings.call_for_papers_dates_updates_template.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def before_end_of_conference
|
||||||
|
errors.
|
||||||
|
add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && end_date && (end_date > conference.end_date)
|
||||||
|
|
||||||
|
errors.
|
||||||
|
add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && start_date && (start_date > conference.end_date)
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_after_end_date
|
||||||
|
errors.
|
||||||
|
add(:start_date, "can't be after the end date") if start_date && end_date && start_date > end_date
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
||||||
describe Admin::ConferenceController do
|
describe Admin::ConferenceController do
|
||||||
|
|
||||||
# It is necessary to use bang version of let to build roles before user
|
# It is necessary to use bang version of let to build roles before user
|
||||||
let(:conference) { create(:conference) }
|
let(:conference) { create(:conference, end_date: Date.new(2014, 05, 26) + 15) }
|
||||||
let!(:first_user) { create(:user) }
|
let!(:first_user) { create(:user) }
|
||||||
let!(:organizer_role) { create(:role, name: 'organizer', resource: conference) }
|
let!(:organizer_role) { create(:role, name: 'organizer', resource: conference) }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,6 @@
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :call_for_paper do
|
factory :call_for_paper do
|
||||||
start_date { 1.day.ago }
|
start_date { 1.day.ago }
|
||||||
end_date { 7.days.from_now }
|
end_date { 6.days.from_now }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -24,7 +24,7 @@ feature Conference do
|
||||||
page.execute_script(
|
page.execute_script(
|
||||||
"$('#conference-start-datepicker').val('#{today.strftime('%d/%m/%Y')}')")
|
"$('#conference-start-datepicker').val('#{today.strftime('%d/%m/%Y')}')")
|
||||||
page.execute_script(
|
page.execute_script(
|
||||||
"$('#conference-end-datepicker').val('#{(today + 7).strftime('%d/%m/%Y')}')")
|
"$('#conference-end-datepicker').val('#{(today + 6).strftime('%d/%m/%Y')}')")
|
||||||
|
|
||||||
fill_in 'call_for_paper_rating', with: '4'
|
fill_in 'call_for_paper_rating', with: '4'
|
||||||
|
|
||||||
|
|
@ -34,7 +34,7 @@ feature Conference do
|
||||||
expect(flash).
|
expect(flash).
|
||||||
to eq('Call for papers successfully created.')
|
to eq('Call for papers successfully created.')
|
||||||
expect(find('#start_date').text).to eq(today.strftime('%A, %B %-d. %Y'))
|
expect(find('#start_date').text).to eq(today.strftime('%A, %B %-d. %Y'))
|
||||||
expect(find('#end_date').text).to eq((today + 7).strftime('%A, %B %-d. %Y'))
|
expect(find('#end_date').text).to eq((today + 6).strftime('%A, %B %-d. %Y'))
|
||||||
expect(find('#rating').text).to eq('4')
|
expect(find('#rating').text).to eq('4')
|
||||||
|
|
||||||
expect(CallForPaper.count).to eq(expected_count)
|
expect(CallForPaper.count).to eq(expected_count)
|
||||||
|
|
@ -57,7 +57,7 @@ feature Conference do
|
||||||
"Start date can't be blank.")
|
"Start date can't be blank.")
|
||||||
|
|
||||||
# Fill in date
|
# Fill in date
|
||||||
today = Date.today - 7
|
today = Date.today - 9
|
||||||
page.execute_script(
|
page.execute_script(
|
||||||
"$('#conference-start-datepicker').val('#{today.strftime('%d/%m/%Y')}')")
|
"$('#conference-start-datepicker').val('#{today.strftime('%d/%m/%Y')}')")
|
||||||
page.execute_script(
|
page.execute_script(
|
||||||
|
|
|
||||||
38
spec/models/cfp_spec.rb
Normal file
38
spec/models/cfp_spec.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe CallForPaper do
|
||||||
|
let!(:conference) { create(:conference, end_date: Date.today) }
|
||||||
|
|
||||||
|
describe '#before_end_of_conference' do
|
||||||
|
describe 'fails to save cfp' do
|
||||||
|
it 'when cfp end_date is after conference end_date' do
|
||||||
|
cfp = build(:call_for_paper, end_date: Date.today + 1, conference_id: conference.id)
|
||||||
|
expect(cfp.valid?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'when cfp start_date is after conference end_date' do
|
||||||
|
cfp = build(:call_for_paper, end_date: Date.today + 1, conference_id: conference.id)
|
||||||
|
expect(cfp.valid?).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'successfully saves cfp' do
|
||||||
|
it 'when cfp end_date and start_date are not after conference end_date' do
|
||||||
|
cfp = build(:call_for_paper, start_date: Date.today - 2, end_date: Date.today - 1, conference_id: conference.id)
|
||||||
|
expect(cfp.valid?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#start_after_end_date' do
|
||||||
|
it 'fails when cfp start_date is after cfp end_date' do
|
||||||
|
cfp = build(:call_for_paper, start_date: Date.today - 1, end_date: Date.today - 2, conference_id: conference.id)
|
||||||
|
expect(cfp.valid?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'succeeds when cfp start_date is after cfp end_date' do
|
||||||
|
cfp = build(:call_for_paper, start_date: Date.today - 2, end_date: Date.today - 1, conference_id: conference.id)
|
||||||
|
expect(cfp.valid?).to be true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -4,7 +4,7 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Conference do
|
describe Conference do
|
||||||
|
|
||||||
let(:subject) { create(:conference) }
|
let(:subject) { create(:conference, end_date: '2014-06-30') }
|
||||||
|
|
||||||
describe '#write_event_distribution_to_db' do
|
describe '#write_event_distribution_to_db' do
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ describe 'admin/call_for_papers/show' do
|
||||||
assign :call_for_paper, create(:call_for_paper)
|
assign :call_for_paper, create(:call_for_paper)
|
||||||
render
|
render
|
||||||
expect(rendered).to include(1.day.ago.strftime('%A, %B %-d. %Y'))
|
expect(rendered).to include(1.day.ago.strftime('%A, %B %-d. %Y'))
|
||||||
expect(rendered).to include(7.days.from_now.strftime('%A, %B %-d. %Y'))
|
expect(rendered).to include(6.days.from_now.strftime('%A, %B %-d. %Y'))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue