Implements Adding Tournaments to Database

This commit is contained in:
Daniel Schädler 2018-11-29 11:49:22 +01:00
parent 26bcc3dc88
commit 7ba1f98fb4
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
class SaveTournamentToDatabase
include Interactor
def call
if context.tournament.save
nil
else
context.fail!
end
end
end

View File

@ -0,0 +1,40 @@
# frozen_string_literal: true
RSpec.describe SaveTournamentToDatabase do
before do
@tournament = create(:tournament)
end
context 'save succeeds' do
let(:context) do
SaveTournamentToDatabase.call(tournament: @tournament)
end
before do
expect_any_instance_of(Tournament)
.to receive(:save).and_return(true)
end
it 'succeeds' do
expect(context).to be_a_success
end
it 'provides the tournament' do
expect(context.tournament).to eq(@tournament)
end
end
context 'save fails' do
let(:context) do
SaveTournamentToDatabase.call(tournament: @tournament)
end
before do
expect_any_instance_of(Tournament)
.to receive(:save).and_return(false)
end
it 'fails' do
test = context.failure?
expect(test).to eq(true)
end
end
end