Move scope of tournament creation in match_score controller test
This fixes the problem we had with the update of the match score returning :forbidden because the @owner variable was not set properly. Also names of the tests should now be easier to read.
This commit is contained in:
parent
60f12430af
commit
ceea95c3d3
|
|
@ -62,17 +62,12 @@ RSpec.describe MatchScoresController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'triggers group point calculation' do
|
describe 'on a real tournament' do
|
||||||
before(:each) do
|
|
||||||
apply_authentication_headers_for @owner
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@owner = create(:user)
|
@owner = create(:user)
|
||||||
@tournament = create(:group_stage_tournament, stage_count: 0, match_factory: :filled_group_match, owner: @owner)
|
@tournament = create(:group_stage_tournament, stage_count: 0, match_factory: :filled_group_match, owner: @owner)
|
||||||
@group = @tournament.stages.first.groups.first
|
@group = @tournament.stages.first.groups.first
|
||||||
@match_score = @group.matches.first.match_scores.first
|
@match_score = @group.matches.first.match_scores.first
|
||||||
# expect(UpdateGroupsGroupScoresAndSave).to receive(:call).once.with(group: @group).and_return(context)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:valid_update) do
|
let(:valid_update) do
|
||||||
|
|
@ -81,23 +76,30 @@ RSpec.describe MatchScoresController, type: :controller do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for 'update_of_match_score' do
|
describe 'updating a match_score' do
|
||||||
it 'returns a 200 status code' do
|
before(:each) do
|
||||||
put :update, params: { id: @match_score.to_param }.merge(valid_update)
|
apply_authentication_headers_for @owner
|
||||||
expect(response).to be_successful
|
expect(UpdateGroupsGroupScoresAndSave).to receive(:call).once.with(group: @group).and_return(context)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context 'when successful' do
|
shared_examples_for 'successful_update_of_match_score' do
|
||||||
let(:context) { double(:context, success?: true) }
|
it 'returns a 200 status code' do
|
||||||
|
put :update, params: { id: @match_score.to_param }.merge(valid_update)
|
||||||
|
expect(response).to be_successful
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it_should_behave_like 'update_of_match_score'
|
context 'when group_score calculation succeeds' do
|
||||||
end
|
let(:context) { double(:context, success?: true) }
|
||||||
|
|
||||||
context 'when unsuccessful' do
|
it_should_behave_like 'successful_update_of_match_score'
|
||||||
let(:context) { double(:context, success?: false) }
|
end
|
||||||
|
|
||||||
it_should_behave_like 'update_of_match_score'
|
context 'when group_score calculation fails' do
|
||||||
|
let(:context) { double(:context, success?: false) }
|
||||||
|
|
||||||
|
it_should_behave_like 'successful_update_of_match_score'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue