1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Allow checking if definition uses a custom to_create

This commit is contained in:
Joshua Clayton 2012-05-06 16:09:53 -04:00
parent 8ff5fc274a
commit 7e41f4f327

View file

@ -7,7 +7,7 @@ module FactoryGirl
@declarations = DeclarationList.new(name)
@callbacks = []
@defined_traits = []
@to_create = ->(instance) { instance.save! }
@to_create = default_to_create
@base_traits = base_traits
@additional_traits = []
@constructor = default_constructor
@ -60,12 +60,20 @@ module FactoryGirl
@constructor != default_constructor
end
def custom_to_create?
@to_create != default_to_create
end
private
def default_constructor
@default_constructor ||= -> { new }
end
def default_to_create
@default_to_create ||= ->(instance) { instance.save! }
end
def base_traits
@base_traits.map { |name| trait_by_name(name) }
end