Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to use AR class names as arguments to create, build etc #386

Closed
wants to merge 1 commit into from
Closed

Allow to use AR class names as arguments to create, build etc #386

wants to merge 1 commit into from

Conversation

ineu
Copy link

@ineu ineu commented May 22, 2012

According to discussion in c006dd1#commitcomment-1320334
As Object.make syntax is deprecated now, we need a way to pass classes to build/create methods. Currently you have to do

my_class = BookAuthor
create my_class.to_s.underscore

This commit allows to do

my_class = BookAuthor
create my_class

I never looked into FG internals, so please let me know if this patch should be modified or rewritten.

@@ -65,6 +65,7 @@ def self.register_factory(factory)
end

def self.factory_by_name(name)
name = name.to_s.underscore unless name.class.in? String, Symbol # looks like AR object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking aloud here; @jferris and @joshuaclayton might have more ideas on this. How about if FactoryGirl::Registry's @items was a subclass of Hash that knew what to do with Class objects for keys.

class ClassyHash < Hash
  def [](key)
    super || super(key.to_s.underscore)
  end
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually a few decorators now - I think it'd make more sense there, actually, but I like that idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants