From 31ea432cf6c0cd6a98337c03999f88369dd1cccf Mon Sep 17 00:00:00 2001 From: Jack <113976590+bibblobcode@users.noreply.github.com> Date: Thu, 18 May 2023 11:46:47 +0100 Subject: [PATCH] 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 --- spec/factories/form.rb | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/spec/factories/form.rb b/spec/factories/form.rb index 9694cfaac..a1e8a8af4 100644 --- a/spec/factories/form.rb +++ b/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