Decided to not use FactoryBot in prod afterall
This commit is contained in:
parent
3b1d6d292c
commit
56e9c94b6f
3
Gemfile
3
Gemfile
|
|
@ -40,12 +40,11 @@ gem 'interactor-rails'
|
||||||
|
|
||||||
gem 'active_model_serializers'
|
gem 'active_model_serializers'
|
||||||
|
|
||||||
gem 'factory_bot_rails'
|
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
gem 'byebug', platforms: %i[mri mingw x64_mingw]
|
gem 'byebug', platforms: %i[mri mingw x64_mingw]
|
||||||
gem 'coveralls', require: false
|
gem 'coveralls', require: false
|
||||||
|
gem 'factory_bot_rails'
|
||||||
gem 'faker'
|
gem 'faker'
|
||||||
gem 'rspec-rails'
|
gem 'rspec-rails'
|
||||||
gem 'shoulda-matchers'
|
gem 'shoulda-matchers'
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
# 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)
|
||||||
|
|
@ -10,11 +8,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))
|
||||||
FactoryBot.create(:group_stage, groups: groups)
|
Stage.new level: -1, groups: groups
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_group_object_from(team_array)
|
def self.get_group_object_from(team_array)
|
||||||
FactoryBot.create(:group, matches: generate_all_matches_between(team_array))
|
Group.new matches: generate_all_matches_between(team_array)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.generate_all_matches_between(teams)
|
def self.generate_all_matches_between(teams)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :group do
|
factory :group do
|
||||||
transient do
|
transient do
|
||||||
matches { nil }
|
|
||||||
match_count { 4 }
|
match_count { 4 }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -11,11 +10,7 @@ FactoryBot.define do
|
||||||
stage
|
stage
|
||||||
|
|
||||||
after(:create) do |group, evaluator|
|
after(:create) do |group, evaluator|
|
||||||
if evaluator.matches.nil?
|
create_list(:group_match, evaluator.match_count, group: group)
|
||||||
create_list(:group_match, evaluator.match_count, group: group)
|
|
||||||
else
|
|
||||||
evaluator.matches
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,10 @@ FactoryBot.define do
|
||||||
factory :group_stage do
|
factory :group_stage do
|
||||||
level { -1 }
|
level { -1 }
|
||||||
transient do
|
transient do
|
||||||
groups { nil }
|
|
||||||
group_count { 4 }
|
group_count { 4 }
|
||||||
end
|
end
|
||||||
after(:create) do |stage, evaluator|
|
after(:create) do |stage, evaluator|
|
||||||
stage.groups = if evaluator.groups.nil?
|
stage.groups = create_list(:group, evaluator.group_count)
|
||||||
create_list(:group, evaluator.group_count)
|
|
||||||
else
|
|
||||||
evaluator.groups
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue