Implements lazy let for conference controller spec
This commit is contained in:
parent
3dfb73d619
commit
e87e7e8fe6
1 changed files with 59 additions and 51 deletions
|
|
@ -2,54 +2,58 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Admin::ConferenceController do
|
describe Admin::ConferenceController do
|
||||||
|
|
||||||
shared_examples 'access as administration or organizer' do
|
let(:conference) { create(:conference) }
|
||||||
|
let(:admin) { create(:admin) }
|
||||||
|
let(:organizer) { create(:organizer) }
|
||||||
|
let(:participant) { create(:participant) }
|
||||||
|
|
||||||
|
shared_examples 'access as administration or organizer' do
|
||||||
describe 'PATCH #update' do
|
describe 'PATCH #update' do
|
||||||
context 'valid attributes' do
|
context 'valid attributes' do
|
||||||
it 'locates the requested @conference' do
|
it 'locates the requested conference' do
|
||||||
patch :update, id: @conference.short_title, conference:
|
patch :update, id: conference.short_title, conference:
|
||||||
attributes_for(:conference, title: 'Example Con')
|
attributes_for(:conference, title: 'Example Con')
|
||||||
|
|
||||||
expect(assigns(:conference)).to eq(@conference)
|
expect(assigns(:conference)).to eq(conference)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'changes @conference attributes' do
|
it 'changes conference attributes' do
|
||||||
patch :update, id: @conference.short_title, conference:
|
patch :update, id: conference.short_title, conference:
|
||||||
attributes_for(:conference, title: 'Example Con',
|
attributes_for(:conference, title: 'Example Con',
|
||||||
short_title: 'ExCon')
|
short_title: 'ExCon')
|
||||||
|
|
||||||
@conference.reload
|
conference.reload
|
||||||
expect(@conference.title).to eq('Example Con')
|
expect(conference.title).to eq('Example Con')
|
||||||
expect(@conference.short_title).to eq('ExCon')
|
expect(conference.short_title).to eq('ExCon')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'redirects to the updated @conference' do
|
it 'redirects to the updated conference' do
|
||||||
patch :update, id: @conference.short_title, conference:
|
patch :update, id: conference.short_title, conference:
|
||||||
attributes_for(:conference, title: 'Example Con')
|
attributes_for(:conference, title: 'Example Con')
|
||||||
|
|
||||||
expect(response).to redirect_to admin_conference_path(
|
expect(response).to redirect_to admin_conference_path(
|
||||||
@conference.short_title)
|
conference.short_title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'invalid attributes' do
|
context 'invalid attributes' do
|
||||||
it 'does not change conference attributes' do
|
it 'does not change conference attributes' do
|
||||||
patch :update, id: @conference.short_title, conference:
|
patch :update, id: conference.short_title, conference:
|
||||||
attributes_for(:conference, title: 'Example Con',
|
attributes_for(:conference, title: 'Example Con',
|
||||||
short_title: nil)
|
short_title: nil)
|
||||||
|
|
||||||
@conference.reload
|
conference.reload
|
||||||
expect(@conference.title).to eq('The dog and pony show')
|
expect(conference.title).to eq('The dog and pony show')
|
||||||
expect(@conference.short_title).to eq('dps14')
|
expect(conference.short_title).to eq('dps14')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 're-renders the #show template' do
|
it 're-renders the #show template' do
|
||||||
patch :update, id: @conference.short_title, conference:
|
patch :update, id: conference.short_title, conference:
|
||||||
attributes_for(:conference, title: 'Example Con',
|
attributes_for(:conference, title: 'Example Con',
|
||||||
short_title: nil)
|
short_title: nil)
|
||||||
|
|
||||||
expect(response).to redirect_to admin_conference_path(
|
expect(response).to redirect_to admin_conference_path(
|
||||||
@conference.short_title)
|
conference.short_title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -91,6 +95,7 @@ describe Admin::ConferenceController do
|
||||||
|
|
||||||
context 'with duplicate conference short title' do
|
context 'with duplicate conference short title' do
|
||||||
it 'does not save the conference to the database' do
|
it 'does not save the conference to the database' do
|
||||||
|
conference
|
||||||
expected = expect do
|
expected = expect do
|
||||||
post :create, conference:
|
post :create, conference:
|
||||||
attributes_for(:conference)
|
attributes_for(:conference)
|
||||||
|
|
@ -99,6 +104,7 @@ describe Admin::ConferenceController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 're-renders the new template' do
|
it 're-renders the new template' do
|
||||||
|
conference
|
||||||
post :create, conference: attributes_for(:conference)
|
post :create, conference: attributes_for(:conference)
|
||||||
expect(response).to redirect_to new_admin_conference_path
|
expect(response).to redirect_to new_admin_conference_path
|
||||||
end
|
end
|
||||||
|
|
@ -106,33 +112,43 @@ describe Admin::ConferenceController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
it 'assigns the requested conference to @conference' do
|
it 'assigns the requested conference to conference' do
|
||||||
get :show, id: @conference.short_title
|
get :show, id: conference.short_title
|
||||||
expect(assigns(:conference)).to eq @conference
|
expect(assigns(:conference)).to eq conference
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders the show template' do
|
it 'renders the show template' do
|
||||||
get :show, id: @conference.short_title
|
get :show, id: conference.short_title
|
||||||
expect(response).to render_template :show
|
expect(response).to render_template :show
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
it 'populates an array with conferences' do
|
context 'with more than 0 conferences' do
|
||||||
con2 = create(:conference, short_title: 'dps15',
|
it 'populates an array with conferences' do
|
||||||
title: 'The dog and pony show 2015')
|
con2 = create(:conference, short_title: 'dps15',
|
||||||
get :index
|
title: 'The dog and pony show 2015')
|
||||||
expect(assigns(:conferences)).to match_array([@conference, con2])
|
get :index
|
||||||
|
expect(assigns(:conferences)).to match_array([conference, con2])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the index template' do
|
||||||
|
conference
|
||||||
|
get :index
|
||||||
|
expect(response).to render_template :index
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders the index template' do
|
context 'no conferences' do
|
||||||
get :index
|
it 'redirect to new conference' do
|
||||||
expect(response).to render_template :index
|
get :index
|
||||||
|
expect(response).to redirect_to(redirect_to new_admin_conference_path)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #new' do
|
describe 'GET #new' do
|
||||||
it 'assigns a new conference to @conference' do
|
it 'assigns a new conference to conference' do
|
||||||
get :new
|
get :new
|
||||||
expect(assigns(:conference)).to be_a_new(Conference)
|
expect(assigns(:conference)).to be_a_new(Conference)
|
||||||
end
|
end
|
||||||
|
|
@ -145,10 +161,9 @@ describe Admin::ConferenceController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'administrator access' do
|
describe 'administrator access' do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@conference = create(:conference)
|
sign_in(admin)
|
||||||
@admin = create(:admin)
|
|
||||||
sign_in(@admin)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'access as administration or organizer'
|
it_behaves_like 'access as administration or organizer'
|
||||||
|
|
@ -156,10 +171,9 @@ describe Admin::ConferenceController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'organizer access' do
|
describe 'organizer access' do
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@conference = create(:conference)
|
sign_in(organizer)
|
||||||
@organizer = create(:organizer)
|
|
||||||
sign_in(@organizer)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'access as administration or organizer'
|
it_behaves_like 'access as administration or organizer'
|
||||||
|
|
@ -169,7 +183,7 @@ describe Admin::ConferenceController do
|
||||||
shared_examples 'access as participant or guest' do |success_path|
|
shared_examples 'access as participant or guest' do |success_path|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
it 'requires admin privileges' do
|
it 'requires admin privileges' do
|
||||||
get :show, id: @conference.short_title
|
get :show, id: conference.short_title
|
||||||
expect(response).to redirect_to(send(success_path))
|
expect(response).to redirect_to(send(success_path))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -198,9 +212,9 @@ describe Admin::ConferenceController do
|
||||||
|
|
||||||
describe 'PATCH #update' do
|
describe 'PATCH #update' do
|
||||||
it 'requires admin privileges' do
|
it 'requires admin privileges' do
|
||||||
patch :update, id: @conference.short_title,
|
patch :update, id: conference.short_title,
|
||||||
conference: attributes_for(:conference,
|
conference: attributes_for(:conference,
|
||||||
short_title: 'ExCon')
|
short_title: 'ExCon')
|
||||||
expect(response).to redirect_to(send(success_path))
|
expect(response).to redirect_to(send(success_path))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -208,9 +222,7 @@ describe Admin::ConferenceController do
|
||||||
|
|
||||||
describe 'participant access' do
|
describe 'participant access' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@conference = create(:conference)
|
sign_in(participant)
|
||||||
@participant = create(:participant)
|
|
||||||
sign_in(@participant)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'access as participant or guest', :root_path
|
it_behaves_like 'access as participant or guest', :root_path
|
||||||
|
|
@ -219,10 +231,6 @@ describe Admin::ConferenceController do
|
||||||
|
|
||||||
describe 'guest access' do
|
describe 'guest access' do
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
@conference = create(:conference)
|
|
||||||
end
|
|
||||||
|
|
||||||
it_behaves_like 'access as participant or guest', :new_user_session_path
|
it_behaves_like 'access as participant or guest', :new_user_session_path
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue