Modify tournament index spec for "type" parameter
This commit is contained in:
parent
c4d03b52c3
commit
6d40d091a4
|
|
@ -24,29 +24,69 @@ RSpec.describe TournamentsController, type: :controller do
|
|||
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] })
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns no private tournaments for unauthenticated users' do
|
||||
get :index
|
||||
tournaments = deserialize_response response
|
||||
private_tournaments = tournaments.reject { |t| t[:public] }
|
||||
expect(private_tournaments.size).to eq(0)
|
||||
context 'with type=private parameter' do
|
||||
let(:params) do
|
||||
{ type: 'private' }
|
||||
end
|
||||
|
||||
it 'returns private tournaments owned by the authenticated user' do
|
||||
it 'returns all private tournaments' do
|
||||
apply_authentication_headers_for @another_user
|
||||
get :index
|
||||
get :index, params: params
|
||||
tournaments = deserialize_response response
|
||||
private_tournaments = Tournament.where(owner: @another_user, public: false).map { |t| t[:id] }
|
||||
returned_private_tournaments = tournaments.filter { |t| !t[:public] }.map { |t| t[:id] }
|
||||
expect(returned_private_tournaments).to match_array(private_tournaments)
|
||||
end
|
||||
|
||||
it 'returns no private tournaments for unauthenticated users' do
|
||||
get :index, params: params
|
||||
tournaments = deserialize_response response
|
||||
private_tournaments = tournaments.reject { |t| t[:public] }
|
||||
expect(private_tournaments.size).to eq(0)
|
||||
end
|
||||
|
||||
it 'returns no private tournaments owned by another user' do
|
||||
apply_authentication_headers_for @user
|
||||
get :index
|
||||
get :index, params: params
|
||||
tournaments = deserialize_response response
|
||||
expect(tournaments.map { |t| t[:id] }).not_to include(@private_tournament.id)
|
||||
end
|
||||
|
||||
it 'returns no public tournaments' do
|
||||
apply_authentication_headers_for @another_user
|
||||
get :index, params: params
|
||||
tournaments = deserialize_response response
|
||||
expect(tournaments.filter { |t| t[:public] }.size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with type=public parameter' do
|
||||
let(:params) do
|
||||
{ type: 'public' }
|
||||
end
|
||||
|
||||
it 'returns all public tournaments' do
|
||||
get :index, params: params
|
||||
tournaments = deserialize_response response
|
||||
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] })
|
||||
end
|
||||
|
||||
it 'returns no private tournaments' do
|
||||
apply_authentication_headers_for @another_user
|
||||
get :index, params: params
|
||||
tournaments = deserialize_response response
|
||||
expect(tournaments.filter { |t| !t[:public] }.size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with invalid type parameter' do
|
||||
it 'renders a bad request error response' do
|
||||
put :index, params: { type: 'invalid' }
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue