Move index specs into without parameters context
This commit is contained in:
parent
ffc1b7c19e
commit
09ca262ab1
|
|
@ -12,37 +12,39 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #index' do
|
describe 'GET #index' do
|
||||||
it 'returns a success response' do
|
context 'without parameters' do
|
||||||
get :index
|
it 'returns a success response' do
|
||||||
expect(response).to be_successful
|
get :index
|
||||||
end
|
expect(response).to be_successful
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns all public tournaments' do
|
it 'returns all public tournaments' do
|
||||||
get :index
|
get :index
|
||||||
tournaments = deserialize_response response
|
tournaments = deserialize_response response
|
||||||
public_tournaments = tournaments.select { |t| t[:public] }
|
public_tournaments = tournaments.select { |t| t[:public] }
|
||||||
expect(public_tournaments.map { |t| t[:id] }).to match_array(Tournament.where(public: true).map { |t| t[:id] })
|
expect(public_tournaments.map { |t| t[:id] }).to match_array(Tournament.where(public: true).map { |t| t[:id] })
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns no private tournaments for unauthenticated users' do
|
it 'returns no private tournaments for unauthenticated users' do
|
||||||
get :index
|
get :index
|
||||||
tournaments = deserialize_response response
|
tournaments = deserialize_response response
|
||||||
private_tournaments = tournaments.reject { |t| t[:public] }
|
private_tournaments = tournaments.reject { |t| t[:public] }
|
||||||
expect(private_tournaments.size).to eq(0)
|
expect(private_tournaments.size).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns private tournaments owned by the authenticated user' do
|
it 'returns private tournaments owned by the authenticated user' do
|
||||||
apply_authentication_headers_for @user
|
apply_authentication_headers_for @user
|
||||||
get :index
|
get :index
|
||||||
tournaments = deserialize_response response
|
tournaments = deserialize_response response
|
||||||
expect(tournaments.filter { |t| !t[:public] }).to match_array(Tournament.where(owner: @owner, public: false))
|
expect(tournaments.filter { |t| !t[:public] }).to match_array(Tournament.where(owner: @owner, public: false))
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns no private tournaments owned by another user' do
|
it 'returns no private tournaments owned by another user' do
|
||||||
apply_authentication_headers_for @user
|
apply_authentication_headers_for @user
|
||||||
get :index
|
get :index
|
||||||
tournaments = deserialize_response response
|
tournaments = deserialize_response response
|
||||||
expect(tournaments.map { |t| t[:id] }).not_to include(@private_tournament.id)
|
expect(tournaments.map { |t| t[:id] }).not_to include(@private_tournament.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue