This commit is contained in:
Ana María Martínez Gómez 2017-01-26 15:36:04 +00:00 committed by GitHub
commit 24582706be
9 changed files with 311 additions and 125 deletions

View file

@ -4,30 +4,39 @@ describe Admin::EventSchedulesController do
let(:venue) { create(:venue) }
let(:conference) { create(:conference, venue: venue) }
let(:room) { create(:room, venue: venue) }
let(:schedule) { create(:schedule, program: conference.program)}
let(:event_schedule) { create(:event_schedule, schedule: schedule)}
let(:schedule) { create(:schedule, program: conference.program) }
let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
let(:organizer) { create(:user, role_ids: organizer_role.id) }
context 'logged in as an organizer' do
before :each do
sign_in(organizer)
event_schedule
end
describe 'POST #create' do
context 'with valid attributes' do
let(:event1) { create(:event, program: conference.program) }
let(:event2) { create(:event, program: conference.program) }
let(:create_action) do
post :create, conference_id: conference.short_title, event_schedule:
attributes_for(:event_schedule,
schedule_id: schedule.id,
event_id: create(:event, program: conference.program).id,
room_id: create(:room, venue: venue).id,
start_time: conference.start_date)
post :bulk_create, conference_id: conference.short_title,
event_schedules: {
event1.id => {
schedule_id: schedule.id,
event_id: event1.id,
room_id: create(:room, venue: venue).id,
start_time: conference.start_date
},
event2.id => {
schedule_id: schedule.id,
event_id: event2.id,
room_id: create(:room, venue: venue).id,
start_time: conference.start_date
}
}
end
it 'saves the event schedule to the database' do
expect{ create_action }.to change { EventSchedule.count }.by 1
expect{ create_action }.to change { EventSchedule.count }.by 2
end
it 'has 200 status code' do
@ -37,14 +46,17 @@ describe Admin::EventSchedulesController do
end
context 'with invalid attributes' do
let(:event1) { create(:event, program: conference.program) }
let(:create_action) do
post :create, conference_id: conference.short_title, event_schedule:
attributes_for(:event_schedule,
schedule_id: schedule.id,
event_id: nil,
room_id: nil,
start_time: nil)
post :bulk_create, conference_id: conference.short_title,
event_schedules: {
event1.id => {
schedule_id: schedule.id,
event_id: event1.id,
room_id: nil,
start_time: nil
}
}
end
it 'does not save the event schedule to the database' do
@ -60,22 +72,38 @@ describe Admin::EventSchedulesController do
describe 'POST #update' do
context 'with valid attributes' do
let(:event1) { create(:event, program: conference.program) }
let(:event2) { create(:event, program: conference.program) }
let(:event_schedule1) { create(:event_schedule, schedule: schedule, event: event1) }
let(:event_schedule2) { create(:event_schedule, schedule: schedule, event: event2) }
before :each do
patch :update, id: event_schedule.id, conference_id: conference.short_title, event_schedule:
attributes_for(:event_schedule,
schedule_id: schedule.id,
event_id: create(:event, program: conference.program).id,
room_id: room.id,
start_time: conference.start_date)
event_schedule.reload
post :bulk_update, conference_id: conference.short_title,
event_schedules: {
event1.id => {
event_schedule1.id => {
room_id: room.id,
start_time: conference.start_date
}
},
event2.id => {
event_schedule2.id => {
room_id: room.id,
start_time: conference.start_date + 1.day
}
}
}
event_schedule1.reload
event_schedule2.reload
end
it 'updates the room' do
expect(event_schedule.room_id).to eq(room.id)
expect(event_schedule1.room_id).to eq(room.id)
expect(event_schedule2.room_id).to eq(room.id)
end
it 'updates the start_time' do
expect(event_schedule.start_time).to eq(conference.start_date)
expect(event_schedule1.start_time).to eq(conference.start_date)
expect(event_schedule2.start_time).to eq(conference.start_date + 1.day)
end
it 'has 200 status code' do
@ -84,13 +112,18 @@ describe Admin::EventSchedulesController do
end
context 'with invalid attributes' do
let(:event) { create(:event, program: conference.program) }
let(:event_schedule) { create(:event_schedule, schedule: schedule, event: event) }
let(:update_action) do
patch :update, id: event_schedule.id, conference_id: conference.short_title, event_schedule:
attributes_for(:event_schedule,
schedule_id: schedule.id,
event_id: nil,
room_id: nil,
start_time: nil)
post :bulk_update, conference_id: conference.short_title,
event_schedules: {
event.id => {
event_schedule.id => {
room_id: nil,
start_time: nil
}
}
}
end
it 'does not save the event schedule to the database' do
expect{ update_action }.to_not change { event_schedule }
@ -104,12 +137,22 @@ describe Admin::EventSchedulesController do
end
describe 'DELETE #destroy' do
let(:event1) { create(:event, program: conference.program) }
let(:event2) { create(:event, program: conference.program) }
let(:event_schedule1) { create(:event_schedule, schedule: schedule, event: event1) }
let(:event_schedule2) { create(:event_schedule, schedule: schedule, event: event2) }
let(:destroy_action) do
delete :destroy, id: event_schedule.id, conference_id: conference.short_title
post :bulk_destroy, conference_id: conference.short_title,
event_schedules: {
event1.id => event_schedule1,
event2.id => event_schedule2
}
end
it 'deletes the event schedule' do
expect{ destroy_action }.to change { EventSchedule.count }.by(-1)
event_schedule1.reload
event_schedule2.reload
expect{ destroy_action }.to change { EventSchedule.count }.by(-2)
end
it 'has 200 status code' do

View file

@ -17,5 +17,32 @@ describe EventSchedule do
it { is_expected.to validate_presence_of(:event) }
it { is_expected.to validate_presence_of(:room) }
it { is_expected.to validate_presence_of(:start_time) }
describe '#not_overlapping' do
let!(:event) { create(:event, event_type: create(:event_type, length: 60)) }
let!(:event2) { create(:event, event_type: create(:event_type, length: 30), program: event.program) }
let!(:schedule) { create(:schedule, program: event.program) }
let!(:room) { create(:room, venue: create(:venue, conference: event.program.conference)) }
let!(:event_schedule) { create(:event_schedule, schedule: schedule, event: event, room: room, start_time: event.program.conference.start_date.tomorrow.to_time + 60.minutes) }
describe "can't be scheduled at the same time than other event in the same room" do
it 'case 1' do
expect(build(:event_schedule, schedule: schedule, event: event2, room: room, start_time: event_schedule.start_time - 15.minutes)).to_not be_valid
end
it 'case 2' do
expect(build(:event_schedule, schedule: schedule, event: event2, room: room, start_time: event_schedule.start_time + 45.minutes)).to_not be_valid
end
it 'case 3' do
expect(build(:event_schedule, schedule: schedule, event: event2, room: room, start_time: event_schedule.start_time + 15.minutes)).to_not be_valid
end
it 'case 4' do
event2.event_type = create(:event_type, length: 120)
expect(build(:event_schedule, schedule: schedule, event: event2, room: room, start_time: event_schedule.start_time - 30.minutes)).to_not be_valid
end
end
end
end
end