Skip to content

Commit

Permalink
Merge pull request #17165 from bdunne/handle_string_factories
Browse files Browse the repository at this point in the history
Allow usage of string factories
  • Loading branch information
kbrock authored Mar 16, 2018
2 parents 039b787 + 941f4d7 commit 450526b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions spec/support/missing_factory_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module Spec
module Support
module MissingFactoryHelper
def build(factory, *args, &block)
registered_factory_symbols.include?(factory) ? super : class_from_symbol(factory).new(*args)
factory_exists?(factory) ? super : class_from_symbol(factory).new(*args)
end

def create(factory, *args, &block)
registered_factory_symbols.include?(factory) ? super : class_from_symbol(factory).create!(*args)
factory_exists?(factory) ? super : class_from_symbol(factory).create!(*args)
end

private
Expand All @@ -16,6 +16,10 @@ def class_from_symbol(symbol)
symbol.to_s.classify.constantize
end

def factory_exists?(factory)
registered_factory_symbols.include?(factory.to_sym)
end

def registered_factory_symbols
@registered_factory_symbols ||= begin
require 'set'
Expand Down

0 comments on commit 450526b

Please sign in to comment.