Adapt tests to updated tournament controller

This commit is contained in:
Thor77 2019-04-07 19:27:28 +02:00
parent ec4e2797c2
commit 2385650be0
No known key found for this signature in database
GPG Key ID: 5051E71B46AA669A
1 changed files with 35 additions and 30 deletions

View File

@ -58,49 +58,54 @@ RSpec.describe TournamentsController, type: :controller do
end end
end end
describe 'POST #create', skip: true do describe 'POST #create' do
let(:create_data) do let(:create_data) do
{ {
name: Faker::Creature::Dog.name, name: Faker::Creature::Dog.name,
description: Faker::Lorem.sentence, description: Faker::Lorem.sentence,
public: false, public: false,
teams: { teams: @teams.map { |team| { id: team.id } }
data: @teams.map { |team| { type: 'teams', id: team.id } }
}
} }
end end
before(:each) do context 'without authentication headers' do
apply_authentication_headers_for @user it 'renders an unauthorized error response' do
put :create, params: create_data
expect(response).to have_http_status(:unauthorized)
end
end end
context 'with valid params' do context 'with authentication headers' do
it 'creates a new Tournament' do before(:each) do
expect do apply_authentication_headers_for @user
end
context 'with valid params' do
it 'creates a new Tournament' do
expect do
post :create, params: create_data
end.to change(Tournament, :count).by(1)
end
it 'associates the new tournament with the authenticated user' do
expect do
post :create, params: create_data
end.to change(@user.tournaments, :count).by(1)
end
it 'associates the given teams with the created tournament' do
post :create, params: create_data post :create, params: create_data
end.to change(Tournament, :count).by(1) body = deserialize_response response
end tournament = Tournament.find(body[:id])
expect(tournament.teams).to match_array(@teams)
end
it 'associates the new tournament with the authenticated user' do it 'renders a JSON response with the new tournament' do
expect do
post :create, params: create_data post :create, params: create_data
end.to change(@user.tournaments, :size).by(1) expect(response).to have_http_status(:created)
end expect(response.content_type).to eq('application/json')
expect(response.location).to eq(tournament_url(Tournament.last))
it 'associates the given teams with the created tournament' do end
new_teams = create_list(:detached_team, 4)
new_teams_create_data = create_data
new_teams_create_data[:data][:relationships][:teams][:data] = \
new_teams.map { |team| { type: 'teams', id: team.id } }
post :create, params: new_teams_create_data
expect(Tournament.last.teams).to match_array(new_teams)
end
it 'renders a JSON response with the new tournament' do
post :create, params: create_data
expect(response).to have_http_status(:created)
expect(response.content_type).to eq('application/json')
expect(response.location).to eq(tournament_url(Tournament.last))
end end
end end
end end