-
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 #217 from mberlanda/events-controllers
Improve test coverage on sitemap and events controllers
- Loading branch information
Showing
9 changed files
with
304 additions
and
131 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
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
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,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Crud::EventsController, type: :controller do | ||
context 'when user not logged' do | ||
it 'redirects to login page' do | ||
get :index | ||
aggregate_failures do | ||
expect(response).to have_http_status(:found) | ||
expect(response).to redirect_to(new_user_session_url) | ||
end | ||
end | ||
end | ||
|
||
context 'when active fan is logged in' do | ||
it 'redirects to home page' do | ||
sign_in FactoryBot.create(:user, role: :fan, status: :active) | ||
get :index | ||
aggregate_failures do | ||
expect(response).to have_http_status(:found) | ||
expect(response).to redirect_to(root_url) | ||
end | ||
end | ||
end | ||
|
||
context 'when admin is logged in' do | ||
let(:admin) { FactoryBot.create(:user, role: :admin, status: :active) } | ||
let(:event) { FactoryBot.create(:event) } | ||
|
||
before do | ||
FactoryBot.create(:reservation, event: event, fan_names: %w[Foo|Bar]) | ||
sign_in admin | ||
end | ||
|
||
it 'renders events list' do | ||
get :index | ||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'shows a given event' do | ||
get :show, params: { id: event.id } | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'renders event reservations list' do | ||
get :datatable_reservations, params: { id: event.id }, format: :json | ||
|
||
expect(response).to have_http_status(:ok) | ||
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,95 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe EventsController, type: :controller do | ||
let!(:event) { FactoryBot.create(:event) } | ||
|
||
context 'when user is not logged in' do | ||
it 'can see upcoming events' do | ||
get :upcoming | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'can see all events' do | ||
get :all | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'can see event details' do | ||
get :details, params: { id: event.id } | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'cannot see reservations for an event' do | ||
get :reservations, params: { id: event.id } | ||
|
||
expect(response).to have_http_status(:found) | ||
expect(response).to redirect_to(new_user_session_url) | ||
end | ||
|
||
it 'cannot export reservations csv for an event' do | ||
get :csv_reservations, params: { id: event.id }, format: :csv | ||
|
||
expect(response).to have_http_status(:unauthorized) | ||
end | ||
end | ||
|
||
context 'when active fan is logged in' do | ||
let(:active_fan) { FactoryBot.create(:user, role: :fan, status: :active) } | ||
|
||
before do | ||
sign_in active_fan | ||
end | ||
|
||
it 'can see event details without a reservation' do | ||
get :details, params: { id: event.id } | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'can see event details with a reservation' do | ||
FactoryBot.create(:reservation, event: event, user: active_fan, | ||
fan_names: %w[Foo|Bar]) | ||
|
||
get :details, params: { id: event.id } | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'cannot see reservations for an event' do | ||
get :reservations, params: { id: event.id } | ||
|
||
expect(response).to redirect_to(root_url) | ||
end | ||
|
||
it 'cannot export reservations csv for an event' do | ||
get :csv_reservations, params: { id: event.id }, format: :csv | ||
|
||
expect(response).to redirect_to(root_url) | ||
end | ||
end | ||
|
||
context 'when admin is logged in' do | ||
let(:admin) { FactoryBot.create(:user, role: :admin, status: :active) } | ||
|
||
before do | ||
sign_in admin | ||
end | ||
|
||
it 'can see reservations for an event' do | ||
get :reservations, params: { id: event.id } | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
|
||
it 'can export reservations csv for an event' do | ||
get :csv_reservations, params: { id: event.id }, format: :csv | ||
|
||
expect(response).to have_http_status(:ok) | ||
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe SitemapController, type: :controller do | ||
it 'return the expected sitemap without authentication' do | ||
FactoryBot.create(:event) | ||
|
||
get :index, format: :xml | ||
|
||
expect(response).to have_http_status(:ok) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.