2010-06-24 09:45:57 -04:00
|
|
|
module FactoryGirl
|
2009-01-02 16:39:24 -05:00
|
|
|
class Proxy #:nodoc:
|
2009-02-17 16:38:15 -05:00
|
|
|
class Build < Proxy #:nodoc:
|
2011-12-06 17:26:48 -05:00
|
|
|
def self.association(factory_name, overrides = {})
|
2011-05-19 10:56:45 -04:00
|
|
|
factory = FactoryGirl.factory_by_name(factory_name)
|
2011-11-21 22:27:42 -05:00
|
|
|
factory.run(get_method(overrides[:method]), overrides.except(:method))
|
2011-08-10 16:26:29 -04:00
|
|
|
end
|
|
|
|
|
2011-12-06 17:26:48 -05:00
|
|
|
def result
|
2009-10-10 00:46:19 -04:00
|
|
|
run_callbacks(:after_build)
|
2011-11-22 18:01:01 -05:00
|
|
|
result_instance
|
2008-12-23 14:03:29 -05:00
|
|
|
end
|
2011-08-10 16:26:29 -04:00
|
|
|
|
2011-10-20 15:06:01 -04:00
|
|
|
private
|
|
|
|
|
2011-12-06 17:26:48 -05:00
|
|
|
def self.get_method(method)
|
2011-10-20 15:06:01 -04:00
|
|
|
case method
|
|
|
|
when :build then Proxy::Build
|
|
|
|
when :create then Proxy::Create
|
|
|
|
when nil then Proxy::Create
|
|
|
|
else raise "unrecognized method #{method}"
|
|
|
|
end
|
|
|
|
end
|
2008-12-23 14:03:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|