-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from mberlanda/reservation-cc-1
test: increase reservation controller code coverage
- Loading branch information
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'ReservationsController#status', type: :request do | ||
let(:competition1) { FactoryBot.create(:competition) } | ||
let(:team_a) { FactoryBot.create(:team) } | ||
let(:team_b) { FactoryBot.create(:team) } | ||
let(:fan) { FactoryBot.create(:user, role: :fan, status: :active) } | ||
let(:another_fan) { FactoryBot.create(:user, role: :fan, status: :active) } | ||
let(:admin) { FactoryBot.create(:user, role: :admin, status: :active) } | ||
let(:eventa) do | ||
FactoryBot.create( | ||
:event, requested_seats: 0, confirmed_seats: 0, | ||
competition: competition1, home_team: team_a, away_team: team_b | ||
) | ||
end | ||
let!(:reservation1) do | ||
FactoryBot.create(:reservation, user: fan, event: eventa, fan_names: %w[Foo|Bar]) | ||
end | ||
|
||
before(:each) do | ||
Rails.cache.clear | ||
end | ||
|
||
context 'when a fan is logged in' do | ||
it 'shows the fan reservation status' do | ||
sign_in fan | ||
|
||
get "/reservations/#{reservation1.id}/status" | ||
|
||
expect(status).to eq(200) | ||
expect(response).to render_template(:status) | ||
end | ||
end | ||
|
||
context 'when an admin is logged in' do | ||
it 'shows the fan reservation status' do | ||
sign_in admin | ||
|
||
get "/reservations/#{reservation1.id}/status" | ||
|
||
expect(status).to eq(200) | ||
expect(response).to render_template(:status) | ||
end | ||
end | ||
|
||
context 'when another fan is logged in' do | ||
it 'shows the fan reservation status' do | ||
sign_in another_fan | ||
|
||
get "/reservations/#{reservation1.id}/status" | ||
|
||
expect(status).to eq(200) | ||
expect(response).to render_template(:status) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'ReservationsController#status', type: :request do | ||
let(:fan) { FactoryBot.create(:user, role: :fan, status: :active) } | ||
let(:another_fan) { FactoryBot.create(:user, role: :fan, status: :active) } | ||
let(:admin) { FactoryBot.create(:user, role: :admin, status: :active) } | ||
let(:event) do | ||
FactoryBot.create(:event, requested_seats: 0, confirmed_seats: 0) | ||
end | ||
before(:each) do | ||
Rails.cache.clear | ||
end | ||
|
||
context 'when a user is rejected' do | ||
it 'renders rejected static page' do | ||
fan.rejected! | ||
sign_in fan | ||
|
||
get '/reservations/user_form', params: { event_id: event.id } | ||
|
||
expect(status).to eq(200) | ||
expect(response).to render_template('reservations/rejected_user') | ||
end | ||
end | ||
|
||
context 'when a user is pending' do | ||
it 'renders pending static page' do | ||
fan.pending! | ||
sign_in fan | ||
|
||
get '/reservations/user_form', params: { event_id: event.id } | ||
|
||
expect(status).to eq(200) | ||
expect(response).to render_template('reservations/pending_user') | ||
end | ||
end | ||
|
||
context 'when the event is not bookable' do | ||
it 'renders not bookable static page' do | ||
allow(event).to receive(:book_range?).and_return(false) | ||
sign_in fan | ||
|
||
get '/reservations/user_form', params: { event_id: event.id } | ||
|
||
expect(status).to eq(200) | ||
expect(response).to render_template('reservations/no_user_form') | ||
end | ||
end | ||
|
||
context 'when a user has already booked' do | ||
it 'redirects to reservation status' do | ||
allow(event).to receive(:book_range?).and_return(true) | ||
reservation = FactoryBot.create(:reservation, user_id: fan.id, event_id: event.id, | ||
fan_names: %w[Foo|Bar]) | ||
sign_in fan | ||
|
||
get '/reservations/user_form', params: { event_id: event.id } | ||
|
||
expect(status).to eq(302) | ||
expect(response).to redirect_to("/reservations/#{reservation.id}/status") | ||
end | ||
end | ||
|
||
context 'when a user cannot book an available event' do | ||
it 'renders not bookable static page' do | ||
allow(event).to receive(:book_range?).and_return(true) | ||
allow(fan).to receive(:can_book?).with(event).and_return(false) | ||
|
||
sign_in fan | ||
|
||
get '/reservations/user_form', params: { event_id: event.id } | ||
|
||
expect(status).to eq(200) | ||
expect(response).to render_template('reservations/no_user_form') | ||
end | ||
end | ||
|
||
context 'when a user can book an available event' do | ||
it 'renders not bookable static page' do | ||
allow(event).to receive(:book_range?).and_return(true) | ||
allow(fan).to receive(:can_book?).with(event).and_return(true) | ||
|
||
sign_in fan | ||
|
||
get '/reservations/user_form', params: { event_id: event.id } | ||
|
||
expect(status).to eq(200) | ||
expect(response).to render_template('reservations/user_form') | ||
end | ||
end | ||
end |