From 5da682b578099b3c793817fca98883c38d6a07d5 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Tue, 16 Apr 2019 20:38:02 +0200 Subject: [PATCH] Test UpdateMatch interactor --- .../update_match_score_interactor_spec.rb | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 spec/interactors/update_match_score_interactor_spec.rb diff --git a/spec/interactors/update_match_score_interactor_spec.rb b/spec/interactors/update_match_score_interactor_spec.rb new file mode 100644 index 0000000..5885bc6 --- /dev/null +++ b/spec/interactors/update_match_score_interactor_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +RSpec.describe UpdateMatchScore do + before do + @match_score = create(:running_playoff_match).match_scores.first + @match_score_params = { points: 42 } + end + + context 'save succeeds' do + let(:context) do + UpdateMatchScore.call(match_score: @match_score, match_score_params: @match_score_params) + end + + before do + expect_any_instance_of(MatchScore) + .to receive(:save).and_return(true) + expect_any_instance_of(MatchScore) + .to receive(:update).with(@match_score_params).and_return(true) + end + + it 'succeeds' do + expect(context).to be_a_success + end + + it 'provides the match score' do + expect(context.match_score).to eq(@match_score) + end + end + + context 'save fails' do + let(:context) do + UpdateMatchScore.call(match_score: @match_score, match_score_params: @match_score_params) + end + + before do + expect_any_instance_of(MatchScore) + .to receive(:save).and_return(false) + end + + it 'fails' do + test = context.failure? + expect(test).to eq(true) + end + end + + context 'update fails' do + let(:context) do + UpdateMatchScore.call(match_score: @match_score, match_score_params: @match_score_params) + end + + before do + expect_any_instance_of(MatchScore) + .to receive(:update).and_return(false) + end + + it 'fails' do + test = context.failure? + expect(test).to eq(true) + end + end +end