Add test for non-existing team and names
This commit is contained in:
parent
2385650be0
commit
cdd6b6737f
|
|
@ -80,7 +80,7 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
apply_authentication_headers_for @user
|
apply_authentication_headers_for @user
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with valid params' do
|
context 'with existing teams' do
|
||||||
it 'creates a new Tournament' do
|
it 'creates a new Tournament' do
|
||||||
expect do
|
expect do
|
||||||
post :create, params: create_data
|
post :create, params: create_data
|
||||||
|
|
@ -107,6 +107,26 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
expect(response.location).to eq(tournament_url(Tournament.last))
|
expect(response.location).to eq(tournament_url(Tournament.last))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with missing teams' do
|
||||||
|
it 'returns an error response' do
|
||||||
|
data = create_data
|
||||||
|
data[:teams] << { id: Team.last.id + 1 }
|
||||||
|
post :create, params: data
|
||||||
|
expect(response).to have_http_status(:not_found)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with team names' do
|
||||||
|
it 'creates teams for given names' do
|
||||||
|
data = create_data
|
||||||
|
data.delete :teams
|
||||||
|
data[:teams] = (1..12).collect { { name: Faker::Creature::Dog.name } }
|
||||||
|
expect do
|
||||||
|
post :create, params: data
|
||||||
|
end.to change(Team, :count).by(data[:teams].count)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue