Permalink
Browse files

Don't inherit from Proxy::Build

  • Loading branch information...
1 parent daec7e3 commit 9826658fb8c92f23e6005a35349be702c3f7df0e @joshuaclayton joshuaclayton committed Feb 8, 2012
Showing with 17 additions and 1 deletion.
  1. +17 −1 lib/factory_girl/proxy/create.rb
@@ -1,13 +1,29 @@
module FactoryGirl
class Proxy #:nodoc:
- class Create < Build #:nodoc:
+ class Create < Proxy #:nodoc:
+ def association(factory_name, overrides = {})
+ factory = FactoryGirl.factory_by_name(factory_name)
+ factory.run(get_method(overrides[:method]), overrides.except(:method))
+ end
+
def result(attribute_assigner, to_create)
attribute_assigner.object.tap do |result_instance|
run_callbacks(:after_build, result_instance)
to_create[result_instance]
run_callbacks(:after_create, result_instance)
end
end
+
+ private
+
+ def get_method(method)
+ case method
+ when :build then Proxy::Build
+ when :create then Proxy::Create
+ when nil then Proxy::Create
+ else raise "unrecognized method #{method}"
+ end
+ end
end
end
end

0 comments on commit 9826658

Please sign in to comment.