Implements Adding Tournaments to Database
This commit is contained in:
parent
26bcc3dc88
commit
7ba1f98fb4
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in New Issue