Update tickets controller spec for Rails 5

This commit is contained in:
Michael Ball 2020-02-06 01:46:21 -08:00
parent d06c3ce035
commit 231b2a6d72

View file

@ -12,7 +12,7 @@ describe Admin::TicketsController do
before { sign_in admin } before { sign_in admin }
describe 'GET #index' do describe 'GET #index' do
before { get :index, conference_id: conference } before { get :index, params: { conference_id: conference } }
it 'assigns conference and tickets variables via cancancan' do it 'assigns conference and tickets variables via cancancan' do
expect(assigns(:conference)).to eq conference expect(assigns(:conference)).to eq conference
@ -25,7 +25,7 @@ describe Admin::TicketsController do
end end
describe 'GET #edit' do describe 'GET #edit' do
before { get :edit, conference_id: conference, id: ticket } before { get :edit, params: { conference_id: conference, id: ticket } }
it 'assigns ticket variable via cancancan' do it 'assigns ticket variable via cancancan' do
expect(assigns(:ticket)).to eq ticket expect(assigns(:ticket)).to eq ticket
@ -37,7 +37,7 @@ describe Admin::TicketsController do
end end
describe 'GET #new' do describe 'GET #new' do
before { get :new, conference_id: conference } before { get :new, params: { conference_id: conference } }
it 'assigns ticket variable' do it 'assigns ticket variable' do
expect(assigns(:ticket)).to be_instance_of(Ticket) expect(assigns(:ticket)).to be_instance_of(Ticket)
@ -51,7 +51,7 @@ describe Admin::TicketsController do
describe 'POST #create' do describe 'POST #create' do
context 'saves successfuly' do context 'saves successfuly' do
before(:each, run: true) do before(:each, run: true) do
post :create, conference_id: conference, ticket: attributes_for(:ticket) post :create, params: { conference_id: conference, ticket: attributes_for(:ticket) }
end end
let!(:ticket_count) { conference.tickets.count } let!(:ticket_count) { conference.tickets.count }
@ -68,8 +68,10 @@ describe Admin::TicketsController do
it 'creates new ticket' do it 'creates new ticket' do
expect do expect do
post :create, ticket: attributes_for(:ticket), post :create, params: {
ticket: attributes_for(:ticket),
conference_id: conference conference_id: conference
}
end.to change{ conference.tickets.count }.from(ticket_count).to(ticket_count + 1) end.to change{ conference.tickets.count }.from(ticket_count).to(ticket_count + 1)
end end
end end
@ -77,7 +79,7 @@ describe Admin::TicketsController do
context 'save fails' do context 'save fails' do
before do before do
allow_any_instance_of(Ticket).to receive(:save).and_return(false) allow_any_instance_of(Ticket).to receive(:save).and_return(false)
post :create, conference_id: conference, ticket: attributes_for(:ticket) post :create, params: { conference_id: conference, ticket: attributes_for(:ticket) }
end end
let!(:ticket_count) { conference.tickets.count } let!(:ticket_count) { conference.tickets.count }
@ -99,8 +101,10 @@ describe Admin::TicketsController do
describe 'PATCH #update' do describe 'PATCH #update' do
context 'updates successfully' do context 'updates successfully' do
before do before do
patch :update, conference_id: conference, id: ticket, patch :update, params: {
conference_id: conference, id: ticket,
ticket: attributes_for(:ticket, title: new_title) ticket: attributes_for(:ticket, title: new_title)
}
end end
it 'redirects to index path' do it 'redirects to index path' do
@ -122,8 +126,10 @@ describe Admin::TicketsController do
context 'update fails' do context 'update fails' do
before do before do
allow_any_instance_of(Ticket).to receive(:save).and_return(false) allow_any_instance_of(Ticket).to receive(:save).and_return(false)
patch :update, conference_id: conference, id: ticket, patch :update, params: {
conference_id: conference, id: ticket,
ticket: attributes_for(:ticket, title: new_title) ticket: attributes_for(:ticket, title: new_title)
}
end end
it 'renders edit template' do it 'renders edit template' do
@ -144,7 +150,7 @@ describe Admin::TicketsController do
describe 'DELETE #destroy' do describe 'DELETE #destroy' do
context 'deletes successfully' do context 'deletes successfully' do
before(:each, run: true) do before(:each, run: true) do
delete :destroy, conference_id: conference, id: ticket delete :destroy, params: { conference_id: conference, id: ticket }
end end
let!(:ticket_count) { conference.tickets.count } let!(:ticket_count) { conference.tickets.count }
@ -161,7 +167,7 @@ describe Admin::TicketsController do
it 'deletes the ticket' do it 'deletes the ticket' do
expect do expect do
delete :destroy, conference_id: conference, id: ticket delete :destroy, params: { conference_id: conference, id: ticket }
end.to change{ conference.tickets.count }.from(ticket_count).to(ticket_count - 1) end.to change{ conference.tickets.count }.from(ticket_count).to(ticket_count - 1)
end end
end end
@ -171,7 +177,7 @@ describe Admin::TicketsController do
before do before do
allow_any_instance_of(Ticket).to receive(:destroy).and_return(false) allow_any_instance_of(Ticket).to receive(:destroy).and_return(false)
delete :destroy, conference_id: conference, id: ticket delete :destroy, params: { conference_id: conference, id: ticket }
end end
it 'redirects to index path' do it 'redirects to index path' do
@ -195,8 +201,10 @@ describe Admin::TicketsController do
let!(:purchase_count) { admin.ticket_purchases.count } let!(:purchase_count) { admin.ticket_purchases.count }
before do before do
post :give, conference_id: conference, id: ticket, post :give, params: {
conference_id: conference, id: ticket,
ticket_purchase: { user_id: admin.id } ticket_purchase: { user_id: admin.id }
}
end end
it 'redirects to ticket' do it 'redirects to ticket' do
@ -220,8 +228,10 @@ describe Admin::TicketsController do
context 'giving fails' do context 'giving fails' do
before do before do
allow_any_instance_of(TicketPurchase).to receive(:save).and_return(false) allow_any_instance_of(TicketPurchase).to receive(:save).and_return(false)
post :give, conference_id: conference, id: ticket, post :give, params: {
conference_id: conference, id: ticket,
ticket_purchase: { user_id: admin.id } ticket_purchase: { user_id: admin.id }
}
end end
let(:purchase_count) { admin.ticket_purchases.count } let(:purchase_count) { admin.ticket_purchases.count }