Assign empty array if object_to_save is nil before pushing values to it

https://stackoverflow.com/questions/12163625/create-or-append-to-array-in-ruby
This commit is contained in:
Daniel Schädler 2019-06-13 00:19:49 +02:00
parent c9e1e153df
commit e0da9ff7b5
7 changed files with 7 additions and 7 deletions

View File

@ -13,7 +13,7 @@ class AddGroupStageToTournament
tournament.instant_finalists_amount, tournament.intermediate_round_participants_amount =
TournamentService.calculate_default_amount_of_teams_advancing(tournament.playoff_teams_amount,
group_stage.groups.size)
context.object_to_save = tournament
(context.object_to_save ||= []) << tournament
rescue StandardError
context.fail!
end

View File

@ -13,7 +13,7 @@ class AddPlayoffsToTournament
tournament.stages.concat playoff_stages
end
context.intermediate_stage = tournament.stages.find(&:intermediate_stage?)
context.object_to_save = [tournament]
(context.object_to_save ||= []) << tournament
else
context.fail!
end

View File

@ -9,6 +9,6 @@ class AdvanceTeamsInIntermediateStage
intermediate_stage.matches.select { |m| m.state == 'single_team' }
.each { |match| PopulateMatchBelowAndSave.call(match: match) }
context.object_to_save << intermediate_stage
(context.object_to_save ||= []) << intermediate_stage
end
end

View File

@ -7,7 +7,7 @@ class PopulateMatchBelow
match = context.match
begin
objects_to_save = PlayoffStageService.populate_match_below(match)
context.object_to_save = objects_to_save
(context.object_to_save ||= []) << objects_to_save
rescue StandardError
context.fail!
end

View File

@ -4,7 +4,7 @@ class UpdateGroupsGroupScores
include Interactor
def call
context.object_to_save = GroupStageService.update_group_scores(context.group)
(context.object_to_save ||= []) << GroupStageService.update_group_scores(context.group)
rescue StandardError
context.fail!
end

View File

@ -21,7 +21,7 @@ RSpec.describe PopulateMatchBelow, type: :interactor do
end
it 'provides the objects to save' do
expect(context.object_to_save).to match_array(@objects_to_save)
expect(context.object_to_save.flatten).to match_array(@objects_to_save.flatten)
end
end

View File

@ -22,7 +22,7 @@ RSpec.describe UpdateGroupsGroupScores, type: :interactor do
end
it 'provides the objects to save' do
expect(context.object_to_save).to eq(@group_scores)
expect(context.object_to_save.flatten).to eq(@group_scores)
end
end