Improvements in registration specs
Check for true and not truthy in registration model spec. Cover general cases in conf registration controller. Add test for flash in new action when ichain is set and user is not signed in.
This commit is contained in:
parent
5bff60ec7d
commit
7e4d91adaf
3 changed files with 88 additions and 37 deletions
|
|
@ -9,6 +9,22 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
|
|
||||||
context 'user is not signed in' do
|
context 'user is not signed in' do
|
||||||
describe 'GET #new' do
|
describe 'GET #new' do
|
||||||
|
context 'ichain is disabled' do
|
||||||
|
before do
|
||||||
|
get :new, conference_id: conference_with_open_registration.short_title
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'assigns conference, registration and user variable' do
|
||||||
|
expect(assigns(:conference)).to eq conference_with_open_registration
|
||||||
|
expect(assigns(:registration)).to be_instance_of Registration
|
||||||
|
expect(assigns(:user)).to be_instance_of User
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the new template' do
|
||||||
|
expect(response).to render_template('new')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'ichain is enabled' do
|
context 'ichain is enabled' do
|
||||||
before do
|
before do
|
||||||
CONFIG['authentication']['ichain']['enabled'] = true
|
CONFIG['authentication']['ichain']['enabled'] = true
|
||||||
|
|
@ -20,6 +36,10 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
it 'redirects to root path' do
|
it 'redirects to root path' do
|
||||||
expect(response).to redirect_to root_path
|
expect(response).to redirect_to root_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'shows error in flash message' do
|
||||||
|
expect(flash[:alert]).to match 'You are not authorized to access this page. Maybe you need to sign in?'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -56,6 +76,21 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
before { sign_in(user) }
|
before { sign_in(user) }
|
||||||
|
|
||||||
describe 'GET #new' do
|
describe 'GET #new' do
|
||||||
|
context 'successful request' do
|
||||||
|
before do
|
||||||
|
get :new, conference_id: conference_with_open_registration.short_title
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'assigns registration and user variables' do
|
||||||
|
expect(assigns(:registration)).to be_instance_of(Registration)
|
||||||
|
expect(assigns(:user)).to be_instance_of(User)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the new template' do
|
||||||
|
expect(response).to render_template('new')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'user is registered to conference' do
|
context 'user is registered to conference' do
|
||||||
before do
|
before do
|
||||||
create(:registration, user: user, conference: conference_with_open_registration)
|
create(:registration, user: user, conference: conference_with_open_registration)
|
||||||
|
|
@ -82,21 +117,6 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
expect(flash[:alert]).to match "Sorry, registration limit exceeded for #{conference_with_open_registration.title}"
|
expect(flash[:alert]).to match "Sorry, registration limit exceeded for #{conference_with_open_registration.title}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'successful request' do
|
|
||||||
before do
|
|
||||||
get :new, conference_id: conference_with_open_registration.short_title
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'assigns registration and user variables' do
|
|
||||||
expect(assigns(:registration)).to be_instance_of(Registration)
|
|
||||||
expect(assigns(:user)).to be_instance_of(User)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'renders the new template' do
|
|
||||||
expect(response).to render_template('new')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
|
|
@ -104,6 +124,22 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
@registration = create(:registration, conference: conference_with_open_registration, user: user)
|
@registration = create(:registration, conference: conference_with_open_registration, user: user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'successful request' do
|
||||||
|
before do
|
||||||
|
get :show, conference_id: conference_with_open_registration.short_title
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'assigns conference, registration and workshops variables' do
|
||||||
|
expect(assigns(:conference)).to eq conference_with_open_registration
|
||||||
|
expect(assigns(:registration)).to eq @registration
|
||||||
|
expect(assigns(:workshops)).to eq @registration.workshops
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'renders the show template' do
|
||||||
|
expect(response).to render_template('show')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'user has purchased a ticket' do
|
context 'user has purchased a ticket' do
|
||||||
before do
|
before do
|
||||||
@ticket = create(:ticket, conference: conference_with_open_registration)
|
@ticket = create(:ticket, conference: conference_with_open_registration)
|
||||||
|
|
@ -113,14 +149,6 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
get :show, conference_id: conference_with_open_registration.short_title
|
get :show, conference_id: conference_with_open_registration.short_title
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders the show template' do
|
|
||||||
expect(response).to render_template('show')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'assigns workshops variable' do
|
|
||||||
expect(assigns(:workshops)).to eq @registration.workshops
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'assigns price of purchased tickets to total_price and purchased tickets to tickets' do
|
it 'assigns price of purchased tickets to total_price and purchased tickets to tickets' do
|
||||||
expect(assigns(:total_price)).to eq Money.new(10000, 'USD')
|
expect(assigns(:total_price)).to eq Money.new(10000, 'USD')
|
||||||
expect(assigns(:tickets)).to match_array [@purchased_ticket]
|
expect(assigns(:tickets)).to match_array [@purchased_ticket]
|
||||||
|
|
@ -141,33 +169,56 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
|
|
||||||
describe 'GET #edit' do
|
describe 'GET #edit' do
|
||||||
before do
|
before do
|
||||||
create(:registration, conference: conference_with_open_registration, user: user)
|
@registration = create(:registration, conference: conference_with_open_registration, user: user)
|
||||||
get :edit, conference_id: conference_with_open_registration.short_title
|
get :edit, conference_id: conference_with_open_registration.short_title
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'assigns conference and registration variable' do
|
||||||
|
expect(assigns(:conference)).to eq conference_with_open_registration
|
||||||
|
expect(assigns(:registration)).to eq @registration
|
||||||
|
end
|
||||||
|
|
||||||
it 'renders the edit template' do
|
it 'renders the edit template' do
|
||||||
expect(response).to render_template('edit')
|
expect(response).to render_template('edit')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
context "tickets are available and user hasn't bought any" do
|
context 'successfully registers' do
|
||||||
|
it 'assigns user variable' do
|
||||||
|
post :create, registration: attributes_for(:registration),
|
||||||
|
conference_id: conference_with_open_registration.short_title
|
||||||
|
expect(assigns(:user)).to eq user
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a new registration' do
|
||||||
|
expect do
|
||||||
|
post :create, registration: attributes_for(:registration),
|
||||||
|
conference_id: conference_with_open_registration.short_title
|
||||||
|
end.to change{ Registration.count }.by 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'tickets are available' do
|
||||||
before do
|
before do
|
||||||
create(:ticket, conference: conference_with_open_registration)
|
create(:ticket, conference: conference_with_open_registration)
|
||||||
post :create, registration: attributes_for(:registration),
|
post :create, registration: attributes_for(:registration),
|
||||||
conference_id: conference_with_open_registration.short_title
|
conference_id: conference_with_open_registration.short_title
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'assigns user variable' do
|
|
||||||
expect(assigns(:user)).to eq user
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'redirects to conference tickets path' do
|
it 'redirects to conference tickets path' do
|
||||||
expect(response).to redirect_to conference_tickets_path(conference_with_open_registration.short_title)
|
expect(response).to redirect_to conference_tickets_path(conference_with_open_registration.short_title)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'creates a new registration' do
|
context 'tickets are not available' do
|
||||||
expect(Registration.count).to eq 1
|
before do
|
||||||
|
post :create, registration: attributes_for(:registration),
|
||||||
|
conference_id: conference_with_open_registration.short_title
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to registration show path' do
|
||||||
|
expect(response).to redirect_to conference_conference_registrations_path(conference_with_open_registration.short_title)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -228,7 +279,7 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows error in flash message' do
|
it 'shows error in flash message' do
|
||||||
expect(flash[:error]).to include 'Could not update your registration'
|
expect(flash[:error]).to match "Could not update your registration for The dog and pony show: #{@registration.errors.full_messages.join('. ')}."
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not update the registration' do
|
it 'does not update the registration' do
|
||||||
|
|
@ -253,7 +304,7 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows success message in flash notice' do
|
it 'shows success message in flash notice' do
|
||||||
expect(flash[:notice]).to match("You are not registered for #{conference_with_open_registration.title} anymore!")
|
expect(flash[:notice]).to match('You are not registered for The dog and pony show anymore!')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deletes the registration' do
|
it 'deletes the registration' do
|
||||||
|
|
@ -272,11 +323,11 @@ describe ConferenceRegistrationsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows error in flash message' do
|
it 'shows error in flash message' do
|
||||||
expect(flash[:error]).to include 'Could not delete your registration'
|
expect(flash[:error]).to match "Could not delete your registration for The dog and pony show: #{@registration.errors.full_messages.join('. ')}."
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not delete the registration' do
|
it 'does not delete the registration' do
|
||||||
expect(Registration.last).to eq @registration
|
expect(assigns(:registration)).to eq @registration
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ feature Registration do
|
||||||
click_link 'Unregister'
|
click_link 'Unregister'
|
||||||
expect(conference.user_registered?(participant)).to be(false)
|
expect(conference.user_registered?(participant)).to be(false)
|
||||||
expect(current_path).to eq root_path
|
expect(current_path).to eq root_path
|
||||||
expect(flash).to eq "You are not registered for #{conference.title} anymore!"
|
expect(flash).to eq 'You are not registered for The dog and pony show anymore!'
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'deletion of registration is unsuccessful' do
|
scenario 'deletion of registration is unsuccessful' do
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ describe Registration do
|
||||||
describe '#subscribe_to_conference' do
|
describe '#subscribe_to_conference' do
|
||||||
it 'subscribes to conference' do
|
it 'subscribes to conference' do
|
||||||
expect(subject).to receive(:subscribe_to_conference)
|
expect(subject).to receive(:subscribe_to_conference)
|
||||||
expect(subject.user.subscribed?(subject.conference)).to be_truthy
|
expect(subject.user.subscribed?(subject.conference)).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue