Adapt tests to updated tournament controller
This commit is contained in:
parent
ec4e2797c2
commit
2385650be0
|
|
@ -58,18 +58,24 @@ 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
|
||||||
|
|
||||||
|
context 'without authentication headers' do
|
||||||
|
it 'renders an unauthorized error response' do
|
||||||
|
put :create, params: create_data
|
||||||
|
expect(response).to have_http_status(:unauthorized)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with authentication headers' do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
apply_authentication_headers_for @user
|
apply_authentication_headers_for @user
|
||||||
end
|
end
|
||||||
|
|
@ -84,16 +90,14 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
it 'associates the new tournament with the authenticated user' do
|
it 'associates the new tournament with the authenticated user' do
|
||||||
expect do
|
expect do
|
||||||
post :create, params: create_data
|
post :create, params: create_data
|
||||||
end.to change(@user.tournaments, :size).by(1)
|
end.to change(@user.tournaments, :count).by(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'associates the given teams with the created tournament' do
|
it 'associates the given teams with the created tournament' do
|
||||||
new_teams = create_list(:detached_team, 4)
|
post :create, params: create_data
|
||||||
new_teams_create_data = create_data
|
body = deserialize_response response
|
||||||
new_teams_create_data[:data][:relationships][:teams][:data] = \
|
tournament = Tournament.find(body[:id])
|
||||||
new_teams.map { |team| { type: 'teams', id: team.id } }
|
expect(tournament.teams).to match_array(@teams)
|
||||||
post :create, params: new_teams_create_data
|
|
||||||
expect(Tournament.last.teams).to match_array(new_teams)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders a JSON response with the new tournament' do
|
it 'renders a JSON response with the new tournament' do
|
||||||
|
|
@ -104,6 +108,7 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
let(:valid_update) do
|
let(:valid_update) do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue