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:
parent
c9e1e153df
commit
e0da9ff7b5
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue