Skip to content

2.11.4 breaks modified factories in default paths #3906

@tmtrademarked

Description

@tmtrademarked

In 2.11.4, attempting to modify a factory defined in the spec/factories/ directory of an application ends up failing with a Factory not registered error. This same factory worked just fine in 2.11.3, but fails in 2.11.4.

For context, here's an example of one of our factories which extends a built in Solidus factory:

# file: spec/factories/option_types.rb

# frozen_string_literal: true
require 'spree/testing_support/factories'

FactoryBot.modify do
  factory :option_type do
    description { 'Testing testing testing' }
  end
end

Solidus Version:
2.11.4

To Reproduce

  1. Author a factory that modifies a built-in factory as described above.
  2. Run any spec of your application.

Current behavior
Fails to run with Factory not registered error.

Expected behavior
Specs should run and find the modified factories.

Context

It looks like the problem is this line here: https://github.com/solidusio/solidus/blob/master/core/lib/spree/testing_support.rb#L36

Assuming I'm understanding the behavior of the FactoryBot railtie correctly, I believe this puts "spec/factories/_factory.rb" into the FactoryBot.definition_file_paths list first, which means it attempts to load these factories before it loads the default Spree factories.

It seems like this may be fixable either by reordering the traversal of the file definitions for FactoryBot, or perhaps by documenting a better naming convention/location for overrides of Solidus default factories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions