Use FactoryBot directly

pull/11366/head
Christophe Bliard 2 years ago
parent cd2254e1ec
commit fc8ac9d8f4
No known key found for this signature in database
GPG Key ID: 2BC07603210C3FA4
  1. 2
      spec/support/schedule_helpers/example_methods.rb
  2. 17
      spec/support/schedule_helpers/schedule_builder.rb

@ -50,7 +50,7 @@ module ScheduleHelpers
#
def create_schedule(chart_representation)
chart = Chart.for(chart_representation)
ScheduleBuilder.from_chart(chart, self)
ScheduleBuilder.from_chart(chart)
end
# Change the given work packages according to the given chart representation.

@ -28,8 +28,8 @@
module ScheduleHelpers
class ScheduleBuilder
def self.from_chart(chart, rspec_example)
creator = new(chart, rspec_example)
def self.from_chart(chart)
creator = new(chart)
chart.work_package_names.each do |name|
creator.create_work_package(name)
creator.create_follows_relations(name)
@ -39,9 +39,8 @@ module ScheduleHelpers
attr_reader :chart, :work_packages, :follows_relations
def initialize(chart, rspec_example)
def initialize(chart)
@chart = chart
@rspec_example = rspec_example
@work_packages = {}
@follows_relations = {}
end
@ -52,17 +51,17 @@ module ScheduleHelpers
.work_package_attributes(name)
.excluding(:name)
.merge(parent: parent_of(name))
@rspec_example.create(:work_package, attributes)
FactoryBot.create(:work_package, attributes)
end
end
def create_follows_relations(follower)
chart.predecessors_by_follower(follower).each do |predecessor|
follows_relations[from: follower, to: predecessor] =
@rspec_example.create(:follows_relation,
from: create_work_package(follower),
to: create_work_package(predecessor),
delay: chart.delay_between(predecessor:, follower:))
FactoryBot.create(:follows_relation,
from: create_work_package(follower),
to: create_work_package(predecessor),
delay: chart.delay_between(predecessor:, follower:))
end
end

Loading…
Cancel
Save