Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
daec7e3
commit 9826658
Showing
1 changed file
with
17 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |