Browse Source

Load FormFixture only in tests (#1643)

It caused superclass mismatch errors. We can stop seeing this bug in local development by defining the class only in test environments
pull/1634/head
Jack 2 years ago committed by GitHub
parent
commit
31ea432cf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      spec/factories/form.rb

42
spec/factories/form.rb

@ -1,25 +1,27 @@
class FormFixture < Form
attr_accessor :sections, :subsections, :pages, :questions
end
class FormFactory
def initialize(year:, type:)
@year = year
@type = type
if Rails.env.test?
class FormFixture < Form
attr_accessor :sections, :subsections, :pages, :questions
end
def with_sections(sections)
@sections = sections
self
end
class FormFactory
def initialize(year:, type:)
@year = year
@type = type
end
def with_sections(sections)
@sections = sections
self
end
def build
form = FormFixture.new(nil, @year, [], @type)
@sections.each { |section| section.form = form }
form.sections = @sections
form.subsections = form.sections.flat_map(&:subsections)
form.pages = form.subsections.flat_map(&:pages)
form.questions = form.pages.flat_map(&:questions)
form
def build
form = FormFixture.new(nil, @year, [], @type)
@sections.each { |section| section.form = form }
form.sections = @sections
form.subsections = form.sections.flat_map(&:subsections)
form.pages = form.subsections.flat_map(&:pages)
form.questions = form.pages.flat_map(&:questions)
form
end
end
end

Loading…
Cancel
Save