Event schedules controller tests improved
This commit is contained in:
parent
a1c7f67735
commit
8975df6a6b
2 changed files with 53 additions and 72 deletions
|
|
@ -3,6 +3,7 @@ require 'spec_helper'
|
||||||
describe Admin::EventSchedulesController do
|
describe Admin::EventSchedulesController do
|
||||||
let(:venue) { create(:venue) }
|
let(:venue) { create(:venue) }
|
||||||
let(:conference) { create(:conference, venue: venue) }
|
let(:conference) { create(:conference, venue: venue) }
|
||||||
|
let(:room) { create(:room, venue: venue) }
|
||||||
let(:schedule) { create(:schedule, program: conference.program)}
|
let(:schedule) { create(:schedule, program: conference.program)}
|
||||||
let(:event_schedule) { create(:event_schedule, schedule: schedule)}
|
let(:event_schedule) { create(:event_schedule, schedule: schedule)}
|
||||||
let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
|
let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) }
|
||||||
|
|
@ -16,51 +17,42 @@ describe Admin::EventSchedulesController do
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
context 'with valid attributes' do
|
context 'with valid attributes' do
|
||||||
it 'saves the event schedule to the database' do
|
let(:create_action) do
|
||||||
expected = expect 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)
|
|
||||||
end
|
|
||||||
expected.to change { EventSchedule.count }.by 1
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'renders JSON without errors' do
|
|
||||||
post :create, conference_id: conference.short_title, event_schedule:
|
post :create, conference_id: conference.short_title, event_schedule:
|
||||||
attributes_for(:event_schedule,
|
attributes_for(:event_schedule,
|
||||||
schedule_id: schedule.id,
|
schedule_id: schedule.id,
|
||||||
event_id: create(:event, program: conference.program).id,
|
event_id: create(:event, program: conference.program).id,
|
||||||
room_id: create(:room, venue: venue).id,
|
room_id: create(:room, venue: venue).id,
|
||||||
start_time: conference.start_date)
|
start_time: conference.start_date)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'saves the event schedule to the database' do
|
||||||
|
expect{ create_action }.to change { EventSchedule.count }.by 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders JSON without errors' do
|
||||||
|
create_action
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with invalid attributes' do
|
context 'with invalid attributes' do
|
||||||
it 'does not save the event schedule to the database' do
|
|
||||||
expected = expect 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)
|
|
||||||
end
|
|
||||||
expected.to_not change { EventSchedule.count }
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'renders JSON with error' do
|
let(:create_action) do
|
||||||
post :create, conference_id: conference.short_title, event_schedule:
|
post :create, conference_id: conference.short_title, event_schedule:
|
||||||
attributes_for(:event_schedule,
|
attributes_for(:event_schedule,
|
||||||
schedule_id: schedule.id,
|
schedule_id: schedule.id,
|
||||||
event_id: nil,
|
event_id: nil,
|
||||||
room_id: nil,
|
room_id: nil,
|
||||||
start_time: nil)
|
start_time: nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not save the event schedule to the database' do
|
||||||
|
expect{ create_action }.to_not change { EventSchedule.count }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders JSON with error' do
|
||||||
|
create_action
|
||||||
expect(response.status).to eq(422)
|
expect(response.status).to eq(422)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -68,71 +60,60 @@ describe Admin::EventSchedulesController do
|
||||||
|
|
||||||
describe 'POST #update' do
|
describe 'POST #update' do
|
||||||
context 'with valid attributes' do
|
context 'with valid attributes' do
|
||||||
it 'changes event schedule attributes' do
|
before :each do
|
||||||
event = create(:event, program: conference.program)
|
|
||||||
room = create(:room, venue: venue)
|
|
||||||
patch :update, id: event_schedule.id, conference_id: conference.short_title, event_schedule:
|
patch :update, id: event_schedule.id, conference_id: conference.short_title, event_schedule:
|
||||||
attributes_for(:event_schedule,
|
attributes_for(:event_schedule,
|
||||||
schedule_id: schedule.id,
|
schedule_id: schedule.id,
|
||||||
event_id: event.id,
|
event_id: create(:event, program: conference.program).id,
|
||||||
room_id: room.id,
|
room_id: room.id,
|
||||||
start_time: conference.start_date)
|
start_time: conference.start_date)
|
||||||
event_schedule.reload
|
event_schedule.reload
|
||||||
expect(event_schedule.schedule_id).to eq(schedule.id)
|
end
|
||||||
expect(event_schedule.event_id).to eq(event.id)
|
|
||||||
|
it 'updates the room' do
|
||||||
expect(event_schedule.room_id).to eq(room.id)
|
expect(event_schedule.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_schedule.start_time).to eq(conference.start_date)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders JSON without errors' do
|
it 'renders JSON without errors' 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: create(:room, venue: venue).id,
|
|
||||||
start_time: conference.start_date)
|
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with invalid attributes' do
|
context 'with invalid attributes' do
|
||||||
it 'does not save the event schedule to the database' do
|
let(:update_action) do
|
||||||
expected = expect 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)
|
|
||||||
end
|
|
||||||
expected.to_not change { event_schedule }
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'renders JSON with error' do
|
|
||||||
patch :update, id: event_schedule.id, conference_id: conference.short_title, event_schedule:
|
patch :update, id: event_schedule.id, conference_id: conference.short_title, event_schedule:
|
||||||
attributes_for(:event_schedule,
|
attributes_for(:event_schedule,
|
||||||
schedule_id: schedule.id,
|
schedule_id: schedule.id,
|
||||||
event_id: nil,
|
event_id: nil,
|
||||||
room_id: nil,
|
room_id: nil,
|
||||||
start_time: nil)
|
start_time: nil)
|
||||||
|
end
|
||||||
|
it 'does not save the event schedule to the database' do
|
||||||
|
expect{ update_action }.to_not change { event_schedule }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders JSON with error' do
|
||||||
|
update_action
|
||||||
expect(response.status).to eq(422)
|
expect(response.status).to eq(422)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE #destroy' do
|
describe 'DELETE #destroy' do
|
||||||
it 'deletes the event schedule' do
|
let(:destroy_action) do
|
||||||
expected = expect do
|
|
||||||
delete :destroy, id: event_schedule.id, conference_id: conference.short_title
|
|
||||||
end
|
|
||||||
|
|
||||||
expected.to change { EventSchedule.count }.by(-1)
|
|
||||||
end
|
|
||||||
it 'renders JSON without errors' do
|
|
||||||
delete :destroy, id: event_schedule.id, conference_id: conference.short_title
|
delete :destroy, id: event_schedule.id, conference_id: conference.short_title
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'deletes the event schedule' do
|
||||||
|
expect{ destroy_action }.to change { EventSchedule.count }.by(-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders JSON without errors' do
|
||||||
|
destroy_action
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -20,42 +20,42 @@ describe Admin::SchedulesController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
|
let(:create_action){ post :create, conference_id: conference.short_title }
|
||||||
|
|
||||||
it 'saves the schedule to the database' do
|
it 'saves the schedule to the database' do
|
||||||
expected = expect do
|
expect{ create_action }.to change { Schedule.count }.by 1
|
||||||
post :create, conference_id: conference.short_title
|
|
||||||
end
|
|
||||||
expected.to change { Schedule.count }.by 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to schedules#show' do
|
it 'redirects to schedules#show' do
|
||||||
post :create, conference_id: conference.short_title
|
create_action
|
||||||
|
|
||||||
expect(response).to redirect_to admin_conference_schedule_path(
|
expect(response).to redirect_to admin_conference_schedule_path(
|
||||||
conference.short_title, assigns[:schedule])
|
conference.short_title, assigns[:schedule])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
|
let(:show_action){ get :show, id: schedule.id, conference_id: conference.short_title }
|
||||||
|
|
||||||
it 'assigns the requested schedule to schedule' do
|
it 'assigns the requested schedule to schedule' do
|
||||||
get :show, id: schedule.id, conference_id: conference.short_title
|
show_action
|
||||||
expect(assigns(:schedule)).to eq schedule
|
expect(assigns(:schedule)).to eq schedule
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders the show template' do
|
it 'renders the show template' do
|
||||||
get :show, id: schedule.id, conference_id: conference.short_title
|
show_action
|
||||||
expect(response).to render_template :show
|
expect(response).to render_template :show
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'DELETE #destroy' do
|
describe 'DELETE #destroy' do
|
||||||
|
let(:destroy_action){ delete :destroy, id: schedule.id, conference_id: conference.short_title }
|
||||||
|
|
||||||
it 'deletes the schedule' do
|
it 'deletes the schedule' do
|
||||||
expected = expect do
|
expect{ destroy_action }.to change { Schedule.count }.by(-1)
|
||||||
delete :destroy, id: schedule.id, conference_id: conference.short_title
|
|
||||||
end
|
|
||||||
expected.to change { Schedule.count }.by(-1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to schedules#index' do
|
it 'redirects to schedules#index' do
|
||||||
delete :destroy, id: schedule.id, conference_id: conference.short_title
|
destroy_action
|
||||||
expect(response).to redirect_to admin_conference_schedules_path(conference.short_title)
|
expect(response).to redirect_to admin_conference_schedules_path(conference.short_title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue