Use factories to create objects in production
This commit is contained in:
parent
658e769a7f
commit
3b1d6d292c
|
|
@ -1,4 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
require 'factory_bot'
|
||||||
|
FactoryBot.definition_file_paths = %w(../../spec/factories)
|
||||||
|
|
||||||
class GroupStageService
|
class GroupStageService
|
||||||
def self.generate_group_stage(groups)
|
def self.generate_group_stage(groups)
|
||||||
|
|
@ -8,11 +10,11 @@ class GroupStageService
|
||||||
raise 'Groups need to be equal size' unless (groups.flatten.length.to_f / groups.length.to_f % 1).zero?
|
raise 'Groups need to be equal size' unless (groups.flatten.length.to_f / groups.length.to_f % 1).zero?
|
||||||
|
|
||||||
groups = groups.map(&method(:get_group_object_from))
|
groups = groups.map(&method(:get_group_object_from))
|
||||||
Stage.new level: -1, groups: groups
|
FactoryBot.create(:group_stage, groups: groups)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_group_object_from(team_array)
|
def self.get_group_object_from(team_array)
|
||||||
Group.new matches: generate_all_matches_between(team_array)
|
FactoryBot.create(:group, matches: generate_all_matches_between(team_array))
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.generate_all_matches_between(teams)
|
def self.generate_all_matches_between(teams)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue