2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2016-08-08 18:01:35 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
describe Admin::EventSchedulesController do
|
|
|
|
|
let(:venue) { create(:venue) }
|
|
|
|
|
let(:conference) { create(:conference, venue: venue) }
|
2016-08-09 16:23:38 +02:00
|
|
|
let(:room) { create(:room, venue: venue) }
|
2016-08-08 18:01:35 +02:00
|
|
|
let(:schedule) { create(:schedule, program: conference.program)}
|
|
|
|
|
let(:event_schedule) { create(:event_schedule, schedule: schedule)}
|
2019-03-13 10:31:42 +01:00
|
|
|
let!(:organizer) { create(:organizer, resource: conference) }
|
2016-08-08 18:01:35 +02:00
|
|
|
|
|
|
|
|
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
|
2016-08-09 16:23:38 +02:00
|
|
|
let(:create_action) do
|
2019-05-13 17:42:09 +02:00
|
|
|
post :create, params: { conference_id: conference.short_title, event_schedule:
|
2016-08-08 18:01:35 +02:00
|
|
|
attributes_for(:event_schedule,
|
|
|
|
|
schedule_id: schedule.id,
|
2018-11-13 18:01:49 -08:00
|
|
|
event_id: create(:event, program: conference.program).id,
|
|
|
|
|
room_id: create(:room, venue: venue).id,
|
2019-05-13 17:42:09 +02:00
|
|
|
start_time: conference.start_date + conference.start_hour.hours) }
|
2016-08-09 16:23:38 +02:00
|
|
|
end
|
2016-08-08 18:01:35 +02:00
|
|
|
|
2016-08-09 16:23:38 +02:00
|
|
|
it 'saves the event schedule to the database' do
|
|
|
|
|
expect{ create_action }.to change { EventSchedule.count }.by 1
|
|
|
|
|
end
|
|
|
|
|
|
2016-08-10 11:17:23 +02:00
|
|
|
it 'has 200 status code' do
|
2016-08-09 16:23:38 +02:00
|
|
|
create_action
|
2022-01-23 14:06:02 -08:00
|
|
|
expect(response).to be_successful
|
2016-08-08 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with invalid attributes' do
|
|
|
|
|
|
2016-08-09 16:23:38 +02:00
|
|
|
let(:create_action) do
|
2019-05-13 17:42:09 +02:00
|
|
|
post :create, params: { conference_id: conference.short_title, event_schedule:
|
2016-08-08 18:01:35 +02:00
|
|
|
attributes_for(:event_schedule,
|
|
|
|
|
schedule_id: schedule.id,
|
2018-11-13 18:01:49 -08:00
|
|
|
event_id: nil,
|
|
|
|
|
room_id: nil,
|
2019-05-13 17:42:09 +02:00
|
|
|
start_time: nil) }
|
2016-08-09 16:23:38 +02:00
|
|
|
end
|
2016-08-08 18:01:35 +02:00
|
|
|
|
2016-08-09 16:23:38 +02:00
|
|
|
it 'does not save the event schedule to the database' do
|
|
|
|
|
expect{ create_action }.to_not change { EventSchedule.count }
|
|
|
|
|
end
|
|
|
|
|
|
2016-08-10 11:17:23 +02:00
|
|
|
it 'has 422 status code' do
|
2016-08-09 16:23:38 +02:00
|
|
|
create_action
|
2016-08-09 14:55:39 +02:00
|
|
|
expect(response.status).to eq(422)
|
2016-08-08 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'POST #update' do
|
|
|
|
|
context 'with valid attributes' do
|
2016-08-09 16:23:38 +02:00
|
|
|
before :each do
|
2019-05-13 17:42:09 +02:00
|
|
|
patch :update, params: { id: event_schedule.id, conference_id: conference.short_title, event_schedule:
|
2016-08-08 18:01:35 +02:00
|
|
|
attributes_for(:event_schedule,
|
|
|
|
|
schedule_id: schedule.id,
|
2018-11-13 18:01:49 -08:00
|
|
|
event_id: create(:event, program: conference.program).id,
|
|
|
|
|
room_id: room.id,
|
2019-05-13 17:42:09 +02:00
|
|
|
start_time: conference.start_date + conference.start_hour.hours) }
|
2016-08-08 18:01:35 +02:00
|
|
|
event_schedule.reload
|
2016-08-09 16:23:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'updates the room' do
|
2016-08-08 18:01:35 +02:00
|
|
|
expect(event_schedule.room_id).to eq(room.id)
|
2016-08-09 16:23:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'updates the start_time' do
|
2017-04-22 01:20:05 +05:30
|
|
|
expect(event_schedule.start_time).to eq(conference.start_date + conference.start_hour.hours)
|
2016-08-08 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
|
2016-08-10 11:17:23 +02:00
|
|
|
it 'has 200 status code' do
|
2022-01-23 14:06:02 -08:00
|
|
|
expect(response).to be_successful
|
2016-08-08 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'with invalid attributes' do
|
2016-08-09 16:23:38 +02:00
|
|
|
let(:update_action) do
|
2019-05-13 17:42:09 +02:00
|
|
|
patch :update, params: { id: event_schedule.id, conference_id: conference.short_title, event_schedule:
|
2016-08-08 18:01:35 +02:00
|
|
|
attributes_for(:event_schedule,
|
|
|
|
|
schedule_id: schedule.id,
|
2018-11-13 18:01:49 -08:00
|
|
|
event_id: nil,
|
|
|
|
|
room_id: nil,
|
2019-05-13 17:42:09 +02:00
|
|
|
start_time: nil) }
|
2016-08-09 16:23:38 +02:00
|
|
|
end
|
|
|
|
|
it 'does not save the event schedule to the database' do
|
|
|
|
|
expect{ update_action }.to_not change { event_schedule }
|
|
|
|
|
end
|
2016-08-08 18:01:35 +02:00
|
|
|
|
2016-08-10 11:17:23 +02:00
|
|
|
it 'has 422 status code' do
|
2016-08-09 16:23:38 +02:00
|
|
|
update_action
|
2016-08-09 14:55:39 +02:00
|
|
|
expect(response.status).to eq(422)
|
2016-08-08 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'DELETE #destroy' do
|
2016-08-09 16:23:38 +02:00
|
|
|
let(:destroy_action) do
|
2019-05-13 17:42:09 +02:00
|
|
|
delete :destroy, params: { id: event_schedule.id, conference_id: conference.short_title }
|
2016-08-09 16:23:38 +02:00
|
|
|
end
|
2016-08-08 18:01:35 +02:00
|
|
|
|
2016-08-09 16:23:38 +02:00
|
|
|
it 'deletes the event schedule' do
|
|
|
|
|
expect{ destroy_action }.to change { EventSchedule.count }.by(-1)
|
2016-08-08 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
|
2016-08-10 11:17:23 +02:00
|
|
|
it 'has 200 status code' do
|
2016-08-09 16:23:38 +02:00
|
|
|
destroy_action
|
2022-01-23 14:06:02 -08:00
|
|
|
expect(response).to be_successful
|
2016-08-08 18:01:35 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|