Revisions
-
renius revised this gist
May 29, 2015 . 1 changed file with 12 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,17 @@ module FactoryGirl module Syntax module Methods def find_or_create(name, attributes = {}, &block) attributes = FactoryGirl.attributes_for(name).merge(attributes) result = FactoryGirl. factory_by_name(name). build_class. find_by(attributes, &block) result || FactoryGirl.create(name, attributes, &block) end end end end -
thewatts revised this gist
Dec 23, 2014 . 1 changed file with 9 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,17 @@ module FactoryGirl::Syntax::Methods def find_or_create(name, attributes = {}, &block) factory = FactoryGirl.factory_by_name(name) klass = factory.build_class factory_attributes = FactoryGirl.attributes_for(name) attributes = factory_attributes.merge(attributes) result = klass.find_by(attributes, &block) if result result else FactoryGirl.create(name, attributes, &block) end end end -
abinoam revised this gist
Dec 5, 2014 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,11 @@ module FactoryGirl::Syntax::Methods def find_or_create(name, attributes = {}, &block) factory = FactoryGirl.factory_by_name(name) clazz = factory.build_class factory_attributes = FactoryGirl.attributes_for(name) attributes = factory_attributes.merge(attributes) clazz.find_or_create_by(attributes, &block) end end -
abinoam revised this gist
Dec 5, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ module FactoryGirl::Syntax::Methods def find_or_create(resource_name, attributes = {}, &block) clazz = resource_name.to_s.classify.constantize model = clazz.find_by(attributes) || FactoryGirl.build(resource_name, attributes) -
Aerlinger renamed this gist
Oct 21, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Aerlinger revised this gist
Oct 21, 2014 . 1 changed file with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,11 @@ module FactoryGirl def self.find_or_create(resource_name, attributes = {}, &block) clazz = resource_name.to_s.classify.constantize model = clazz.find_by(attributes) || FactoryGirl.build(resource_name, attributes) yield(model) if block_given? && model.new_record? model.tap(&:save) end end -
Aerlinger created this gist
Oct 21, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ def find_or_create(resource_name, attributes = {}, &block) clazz = resource_name.to_s.classify.constantize model = clazz.find_by(attributes) || FactoryGirl.build(resource_name, attributes) yield(model) if block_given? && model.new_record? model.tap(&:save) end