Adapt controller specs to new api schema
This commit is contained in:
parent
5126e5ae76
commit
dcb8e6b216
|
|
@ -18,22 +18,15 @@ RSpec.describe MatchScoresController, type: :controller do
|
||||||
get :show, params: { id: @match_score.to_param }
|
get :show, params: { id: @match_score.to_param }
|
||||||
body = deserialize_response response
|
body = deserialize_response response
|
||||||
expect(body[:points]).to eq(@match_score.points)
|
expect(body[:points]).to eq(@match_score.points)
|
||||||
expect(body[:team_id]).to eq(@match_score.team.id.to_s)
|
expect(body[:team][:id]).to eq(@match_score.team.id)
|
||||||
expect(body[:match_id]).to eq(@match_score.match.id.to_s)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
let(:valid_update) do
|
let(:valid_update) do
|
||||||
{
|
{
|
||||||
data: {
|
|
||||||
id: @match_score.id,
|
|
||||||
type: 'match_scores',
|
|
||||||
attributes: {
|
|
||||||
points: 42
|
points: 42
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with valid params' do
|
context 'with valid params' do
|
||||||
|
|
@ -43,16 +36,16 @@ RSpec.describe MatchScoresController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates the requested score' do
|
it 'updates the requested score' do
|
||||||
put :update, params: { id: @match_score.to_param }.merge(valid_update)
|
put :update, params: { id: @match_score.to_param, match_score: valid_update }
|
||||||
@match_score.reload
|
@match_score.reload
|
||||||
expect(@match_score.points).to eq(valid_update[:data][:attributes][:points])
|
expect(@match_score.points).to eq(valid_update[:points])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders a response with the updated team' do
|
it 'renders a response with the updated team' do
|
||||||
put :update, params: { id: @match_score.to_param }.merge(valid_update)
|
put :update, params: { id: @match_score.to_param, match_score: valid_update }
|
||||||
expect(response).to be_successful
|
expect(response).to be_successful
|
||||||
body = deserialize_response response
|
body = deserialize_response response
|
||||||
expect(body[:points]).to eq(valid_update[:data][:attributes][:points])
|
expect(body[:points]).to eq(valid_update[:points])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -62,7 +55,7 @@ RSpec.describe MatchScoresController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders a forbidden error response' do
|
it 'renders a forbidden error response' do
|
||||||
put :update, params: { id: @match_score.to_param }.merge(valid_update)
|
put :update, params: { id: @match_score.to_param, match_score: valid_update }
|
||||||
expect(response).to have_http_status(:forbidden)
|
expect(response).to have_http_status(:forbidden)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ RSpec.describe MatchesController, type: :controller do
|
||||||
|
|
||||||
it 'should return the correct state' do
|
it 'should return the correct state' do
|
||||||
get :show, params: { id: @match.to_param }
|
get :show, params: { id: @match.to_param }
|
||||||
body = ActiveModelSerializers::Deserialization.jsonapi_parse(JSON.parse(response.body))
|
body = deserialize_response response
|
||||||
expect(body[:state]).to eq(@match.state)
|
expect(body[:state]).to eq(@match.state)
|
||||||
expect(body[:match_score_ids]).to eq(@match.match_scores.map { |match_score| match_score.id.to_s })
|
expect(body[:match_scores].map { |ms| ms[:id] }).to eq(@match.match_scores.map(&:id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -24,14 +24,8 @@ RSpec.describe TeamsController, type: :controller do
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
let(:valid_update) do
|
let(:valid_update) do
|
||||||
{
|
{
|
||||||
data: {
|
|
||||||
id: @team.id,
|
|
||||||
type: 'teams',
|
|
||||||
attributes: {
|
|
||||||
name: Faker::Dog.name
|
name: Faker::Dog.name
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with valid params as owner' do
|
context 'with valid params as owner' do
|
||||||
|
|
@ -40,17 +34,17 @@ RSpec.describe TeamsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates the requested team' do
|
it 'updates the requested team' do
|
||||||
put :update, params: { id: @team.to_param }.merge(valid_update)
|
put :update, params: { id: @team.to_param, team: valid_update }
|
||||||
@team.reload
|
@team.reload
|
||||||
expect(response).to be_successful
|
expect(response).to be_successful
|
||||||
expect(@team.name).to eq(valid_update[:data][:attributes][:name])
|
expect(@team.name).to eq(valid_update[:name])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders a response with the updated team' do
|
it 'renders a response with the updated team' do
|
||||||
put :update, params: { id: @team.to_param }.merge(valid_update)
|
put :update, params: { id: @team.to_param, team: valid_update }
|
||||||
expect(response).to be_successful
|
expect(response).to be_successful
|
||||||
body = deserialize_response response
|
body = deserialize_response response
|
||||||
expect(body[:name]).to eq(valid_update[:data][:attributes][:name])
|
expect(body[:name]).to eq(valid_update[:name])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -60,7 +54,7 @@ RSpec.describe TeamsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders a forbidden error response' do
|
it 'renders a forbidden error response' do
|
||||||
put :update, params: { id: @team.to_param }.merge(valid_update)
|
put :update, params: { id: @team.to_param, team: valid_update }
|
||||||
expect(response).to have_http_status(:forbidden)
|
expect(response).to have_http_status(:forbidden)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe TournamentsController, type: :controller do
|
RSpec.describe TournamentsController, type: :controller do
|
||||||
def tournament_ids(response)
|
def tournament_ids(response)
|
||||||
deserialize_list(response).map { |t| t[:id].to_i }
|
deserialize_response(response).map { |t| t[:id].to_i }
|
||||||
end
|
end
|
||||||
before do
|
before do
|
||||||
@tournament = create(:tournament)
|
@tournament = create(:tournament)
|
||||||
|
|
@ -22,14 +22,14 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
|
|
||||||
it 'returns all public tournaments' do
|
it 'returns all public tournaments' do
|
||||||
get :index
|
get :index
|
||||||
tournaments = deserialize_list response
|
tournaments = deserialize_response response
|
||||||
public_tournaments = tournaments.select { |t| t[:public] }
|
public_tournaments = tournaments.select { |t| t[:public] }
|
||||||
expect(public_tournaments.size).to eq((Tournament.where public: true).size)
|
expect(public_tournaments.size).to eq((Tournament.where public: true).size)
|
||||||
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_list 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
|
||||||
|
|
@ -62,20 +62,13 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
let(:create_data) do
|
let(:create_data) do
|
||||||
{
|
{
|
||||||
data: {
|
|
||||||
type: 'tournaments',
|
|
||||||
attributes: {
|
|
||||||
name: Faker::Dog.name,
|
name: Faker::Dog.name,
|
||||||
description: Faker::Lorem.sentence,
|
description: Faker::Lorem.sentence,
|
||||||
public: false
|
public: false,
|
||||||
},
|
|
||||||
relationships: {
|
|
||||||
teams: {
|
teams: {
|
||||||
data: @teams.map { |team| { type: 'teams', id: team.id } }
|
data: @teams.map { |team| { type: 'teams', id: team.id } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
@ -116,20 +109,14 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
describe 'PUT #update' do
|
describe 'PUT #update' do
|
||||||
let(:valid_update) do
|
let(:valid_update) do
|
||||||
{
|
{
|
||||||
data: {
|
|
||||||
type: 'tournaments',
|
|
||||||
id: @tournament.id,
|
|
||||||
attributes: {
|
|
||||||
name: Faker::Dog.name
|
name: Faker::Dog.name
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with valid params' do
|
context 'with valid params' do
|
||||||
context 'without authentication headers' do
|
context 'without authentication headers' do
|
||||||
it 'renders a unauthorized error response' do
|
it 'renders a unauthorized error response' do
|
||||||
put :update, params: { id: @tournament.to_param }.merge(valid_update)
|
put :update, params: { id: @tournament.to_param, tournament: valid_update }
|
||||||
expect(response).to have_http_status(:unauthorized)
|
expect(response).to have_http_status(:unauthorized)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -140,13 +127,13 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates the requested tournament' do
|
it 'updates the requested tournament' do
|
||||||
put :update, params: { id: @tournament.to_param }.merge(valid_update)
|
put :update, params: { id: @tournament.to_param, tournament: valid_update }
|
||||||
@tournament.reload
|
@tournament.reload
|
||||||
expect(@tournament.name).to eq(valid_update[:data][:attributes][:name])
|
expect(@tournament.name).to eq(valid_update[:name])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders a JSON response with the tournament' do
|
it 'renders a JSON response with the tournament' do
|
||||||
put :update, params: { id: @tournament.to_param }.merge(valid_update)
|
put :update, params: { id: @tournament.to_param, tournament: valid_update }
|
||||||
expect(response).to have_http_status(:ok)
|
expect(response).to have_http_status(:ok)
|
||||||
expect(response.content_type).to eq('application/json')
|
expect(response.content_type).to eq('application/json')
|
||||||
end
|
end
|
||||||
|
|
@ -158,7 +145,7 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'renders a forbidden error response' do
|
it 'renders a forbidden error response' do
|
||||||
put :update, params: { id: @tournament.to_param }.merge(valid_update)
|
put :update, params: { id: @tournament.to_param, tournament: valid_update }
|
||||||
expect(response).to have_http_status(:forbidden)
|
expect(response).to have_http_status(:forbidden)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue