Created
September 5, 2011 21:39
-
-
Save mikz/1195984 to your computer and use it in GitHub Desktop.
factory_girl singleton helper
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
require 'factory_girl/step_definitions' | |
def FactorySingleton(*args) | |
FactorySingleton.find_or_self *args | |
end | |
module FactorySingleton | |
def find_or_self object, attribute = nil | |
# FIXME: instead of this probably could check validation reflection for unique attributes | |
attribute ||= case object | |
when User | |
:login | |
end | |
raise 'Unknown class. Please supply attribute' unless attribute | |
object.class.where(attribute => object.send(attribute)).first || object | |
end | |
extend self | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment