mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Add test for conference registration controller edit and update action
This commit is contained in:
parent
2f15309f0c
commit
b41d2bd5c1
1 changed files with 76 additions and 0 deletions
76
spec/controllers/conference_registration_controller_spec.rb
Normal file
76
spec/controllers/conference_registration_controller_spec.rb
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe ConferenceRegistrationsController, type: :controller do
|
||||
let(:conference) { create(:conference) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
context 'user is signed in' do
|
||||
before { sign_in(user) }
|
||||
|
||||
describe 'GET #edit' do
|
||||
before do
|
||||
@registration = create(:registration, conference: conference, user: user)
|
||||
get :edit, conference_id: conference.short_title
|
||||
end
|
||||
|
||||
it 'assigns conference and registration variable' do
|
||||
expect(assigns(:conference)).to eq conference
|
||||
expect(assigns(:registration)).to eq @registration
|
||||
end
|
||||
|
||||
it 'renders the edit template' do
|
||||
expect(response).to render_template('edit')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH #update' do
|
||||
before do
|
||||
@registration = create(:registration,
|
||||
conference: conference,
|
||||
user: user,
|
||||
arrival: Date.new(2014, 04, 25))
|
||||
end
|
||||
|
||||
context 'updates successfully' do
|
||||
before do
|
||||
patch :update, registration: attributes_for(:registration, arrival: Date.new(2014, 04, 29)),
|
||||
conference_id: conference.short_title
|
||||
end
|
||||
|
||||
it 'redirects to registration show path' do
|
||||
expect(response).to redirect_to conference_conference_registrations_path(conference.short_title)
|
||||
end
|
||||
|
||||
it 'shows success message in flash notice' do
|
||||
expect(flash[:notice]).to match('Registration was successfully updated.')
|
||||
end
|
||||
|
||||
it 'updates the registration' do
|
||||
@registration.reload
|
||||
expect(@registration.arrival).to eq Date.new(2014, 04, 29)
|
||||
end
|
||||
end
|
||||
|
||||
context 'update fails' do
|
||||
before do
|
||||
allow_any_instance_of(Registration).to receive(:update_attributes).and_return(false)
|
||||
patch :update, registration: attributes_for(:registration, arrival: Date.new(2014, 04, 27)),
|
||||
conference_id: conference.short_title
|
||||
end
|
||||
|
||||
it 'renders edit template' do
|
||||
expect(response).to render_template('edit')
|
||||
end
|
||||
|
||||
it 'shows error in flash message' do
|
||||
expect(flash[:error]).to match "Could not update your registration for The dog and pony show: #{@registration.errors.full_messages.join('. ')}."
|
||||
end
|
||||
|
||||
it 'does not update the registration' do
|
||||
@registration.reload
|
||||
expect(@registration.arrival).to eq Date.new(2014, 04, 25)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue