mirror of
https://github.com/thoughtbot/factory_bot.git
synced 2022-11-09 11:43:51 -05:00
Simplify Factory::Runner by always having attribute add_to(proxy)
This commit is contained in:
parent
5a4812941e
commit
3803be3846
5 changed files with 17 additions and 22 deletions
|
@ -52,5 +52,13 @@ module FactoryGirl
|
|||
"rather than 'f.#{attribute_name} = value'"
|
||||
end
|
||||
end
|
||||
|
||||
def set_proxy_value(proxy, value)
|
||||
if @ignored
|
||||
proxy.set_ignored(name, value)
|
||||
else
|
||||
proxy.set(name, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,11 +12,7 @@ module FactoryGirl
|
|||
raise SequenceAbuseError
|
||||
end
|
||||
|
||||
if @ignored
|
||||
proxy.set_ignored(name, value)
|
||||
else
|
||||
proxy.set(name, value)
|
||||
end
|
||||
set_proxy_value(proxy, value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,11 +9,7 @@ module FactoryGirl
|
|||
|
||||
def add_to(proxy)
|
||||
value = FactoryGirl.generate(@sequence)
|
||||
if @ignored
|
||||
proxy.set_ignored(name, value)
|
||||
else
|
||||
proxy.set(name, value)
|
||||
end
|
||||
set_proxy_value(proxy, value)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,11 +11,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def add_to(proxy)
|
||||
if @ignored
|
||||
proxy.set_ignored(name, @value)
|
||||
else
|
||||
proxy.set(name, @value)
|
||||
end
|
||||
set_proxy_value(proxy, @value)
|
||||
end
|
||||
|
||||
def priority
|
||||
|
|
|
@ -165,7 +165,7 @@ module FactoryGirl
|
|||
end
|
||||
|
||||
def apply_remaining_overrides
|
||||
@overrides.each { |attr, val| proxy.set(attr, val) }
|
||||
@overrides.each { |attr, val| add_static_attribute(attr, val) }
|
||||
end
|
||||
|
||||
def overrides_for_attribute(attribute)
|
||||
|
@ -174,16 +174,15 @@ module FactoryGirl
|
|||
|
||||
def handle_attribute_with_overrides(attribute)
|
||||
overrides_for_attribute(attribute).each do |attr, val|
|
||||
if attribute.ignored
|
||||
proxy.set_ignored(attr, val)
|
||||
else
|
||||
proxy.set(attr, val)
|
||||
end
|
||||
|
||||
add_static_attribute(attr, val, attribute.ignored)
|
||||
@overrides.delete(attr)
|
||||
end
|
||||
end
|
||||
|
||||
def add_static_attribute(attr, val, ignored = false)
|
||||
Attribute::Static.new(attr, val, ignored).add_to(proxy)
|
||||
end
|
||||
|
||||
def handle_attribute_without_overrides(attribute)
|
||||
attribute.add_to(proxy)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue