mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Reorganize #add_attribute
This commit is contained in:
parent
eb21a449de
commit
a50adda6c3
2 changed files with 6 additions and 8 deletions
|
@ -13,6 +13,7 @@ module FactoryGirl
|
|||
|
||||
def declare_attribute(declaration)
|
||||
@declarations << declaration
|
||||
declaration
|
||||
end
|
||||
|
||||
def define_attribute(attribute)
|
||||
|
|
|
@ -33,18 +33,15 @@ module FactoryGirl
|
|||
# * value: +Object+
|
||||
# If no block is given, this value will be used for this attribute.
|
||||
def add_attribute(name, value = nil, &block)
|
||||
if block_given?
|
||||
if value
|
||||
raise AttributeDefinitionError, "Both value and block given"
|
||||
else
|
||||
declaration = Declaration::Dynamic.new(name, @ignore, block)
|
||||
end
|
||||
raise AttributeDefinitionError, "Both value and block given" if value && block_given?
|
||||
|
||||
declaration = if block_given?
|
||||
Declaration::Dynamic.new(name, @ignore, block)
|
||||
else
|
||||
declaration = FactoryGirl::Declaration::Static.new(name, value, @ignore)
|
||||
Declaration::Static.new(name, value, @ignore)
|
||||
end
|
||||
|
||||
@factory.declare_attribute(declaration)
|
||||
declaration
|
||||
end
|
||||
|
||||
def ignore(&block)
|
||||
|
|
Loading…
Reference in a new issue