validate cfp start_date before end_date and end_date before conference.end_date

This commit is contained in:
Stella 2014-11-29 20:00:26 +02:00
parent 1edb4bff9e
commit 6e026746a9
7 changed files with 62 additions and 7 deletions

View file

@ -3,7 +3,7 @@ require 'spec_helper'
describe Admin::ConferenceController do
# 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!(:organizer_role) { create(:role, name: 'organizer', resource: conference) }

View file

@ -3,6 +3,6 @@
FactoryGirl.define do
factory :call_for_paper do
start_date { 1.day.ago }
end_date { 7.days.from_now }
end_date { 6.days.from_now }
end
end

View file

@ -24,7 +24,7 @@ feature Conference do
page.execute_script(
"$('#conference-start-datepicker').val('#{today.strftime('%d/%m/%Y')}')")
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'
@ -34,7 +34,7 @@ feature Conference do
expect(flash).
to eq('Call for papers successfully created.')
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(CallForPaper.count).to eq(expected_count)
@ -57,7 +57,7 @@ feature Conference do
"Start date can't be blank.")
# Fill in date
today = Date.today - 7
today = Date.today - 9
page.execute_script(
"$('#conference-start-datepicker').val('#{today.strftime('%d/%m/%Y')}')")
page.execute_script(

38
spec/models/cfp_spec.rb Normal file
View 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

View file

@ -4,7 +4,7 @@ require 'spec_helper'
describe Conference do
let(:subject) { create(:conference) }
let(:subject) { create(:conference, end_date: '2014-06-30') }
describe '#write_event_distribution_to_db' do

View file

@ -7,7 +7,7 @@ describe 'admin/call_for_papers/show' do
assign :call_for_paper, create(:call_for_paper)
render
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