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

Add FactoryGirl integration #17

Closed
wants to merge 5 commits into from
Closed

Conversation

calebhearth
Copy link
Owner

Introduce optional FactoryGirl syntax that makes it easier to use Formulaic
to fill in attributes from a factory with a single argument:
fill_with_factory(:user); limit the attributes from a factory:
fill_with_factory(:user, :name, :address); and even pass arguments to the
factory, such as traits and overrides:
fill_with_factory(:user, :name, :address, factory_arguments: [:with_verified_address].

@calebhearth
Copy link
Owner Author

@joshuaclayton @derekprior @gabebw @pbrisbin Mind taking a look at this?

fill_with_factory(:user, factory_arguments: [:registered, name: 'Frank'])
```

Which is roughly equivalent to calling:
Copy link

Choose a reason for hiding this comment

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

roughly, or exactly?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm hesitant to say exactly. The result is the same.

Copy link

Choose a reason for hiding this comment

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

Then I'd remove "roughly". That word makes me think "What exactly is different, and how is the developer's cleverness going to bite me in a month?" In this case, you're not being Too Clever®, so I'd just remove "roughly".

Introduce optional FactoryGirl syntax that makes it easier to use
Formulaic to fill in attributes from a factory with a single argument:
`fill_with_factory(:user)`; limit the attributes from a factory:
`fill_with_factory(:user, :name, :address)`; and even pass arguments to
the factory, such as traits and overrides:
`fill_with_factory(:user, :name, :address, factory_arguments: [:with_verified_address]`.

Resolves #11.
Which has the same result as calling:

```ruby
fill_form(:user, attributes_for(:user, :registered, name: 'Frank'))

Choose a reason for hiding this comment

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

All these examples are well and good, but they make me wonder what the hell the message signature of fill_with_factory is. Could you get away with showing the signature and then these examples (perhaps with less text explaining each one)?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah let me take a run at something like that instead.

@derekprior
Copy link

Overall looks fine to me. As I mentioned, I'm mostly interested to see how my actual usage patterns with formulaic and factory girl play out to determine what the right choice between factory args and whitelist args is.

Is it worth pulling this out into formulaic-factory_girl? I suspect this might be somewhat volatile. Having said that, formulaic itself is only at 0.0.5, so maybe that's premature.

@calebhearth calebhearth closed this Aug 6, 2014
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.

4 participants