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

Include DatabaseCleaner usage when demoing FactoryGirl.lint #611

Merged
merged 1 commit into from Feb 26, 2014

Conversation

joshuaclayton
Copy link
Contributor

Because built factories create associated records, the database may not be
empty when the suite is run. This encourages developers to start
DatabaseCleaner and clean after linting is complete to ensure a clean
database.

cc @jferris

@jferris
Copy link
Member

jferris commented Feb 13, 2014

Can we avoid this issue by having FactoryGirl.lint use build_stubbed?

@joshuaclayton
Copy link
Contributor Author

@jferris that's a good question; with validations and other things happening in the model, I'm not confident build_stubbed would fix every issue, whereas clearing out the database would, I think.

Alternatively, we could provide a rake task in factory_girl_rails which runs lint and encourage developers to add the task as a prereq for tests; that way, it's run independently of the test suite and can be run on its own (would we want to ensure a test env?).

@garysweaver
Copy link

I like the fact that factory_girl has introduced something to try to test factories easily. We have a test that runs in CI (needs work, but here is a gist) to test creates for existing models, but lint found those we had missed- factories that no longer worked that we weren't using because tables and models went away.

But:

  1. I don't think that just building factories is sufficient for factory testing. It is a good tool to have available, but it is just as valid to test creates and have DB cleaner clean that. So, if anything lint should take an optional set of strategies to test, and default to build, e.g. FactoryGirl.lint :build, :create
  2. On the opposite end, even lint building all factories can cause unnecessary red flags. Some factories are used as dependencies to other factories and not really called by themselves in tests, even if the assumption is there that they should be buildable by the fact that they exist- so why test build for something unnecessarily? For this reason, I do not think that it should be the default in factory_girl_rails unless there were an obvious and stated config option to be able to tell it to only do a subset or none at all, but that still seems non-obvious. To remedy this, I think that options passed to lint like :include and :exclude that take arrays of factory names may be good, even if that doesn't solve having to test traits, etc. Maybe even additional an additional option on/in the factories definitions would be a good way to indicate what strategies should not be tested by lint- I dk.

Sorry I did a dupe PR for this, and thanks for factory_girl and all of your work. Much appreciated!

Because built factories create associated records, the database may not
be empty when the suite is run. This encourages developers to start
DatabaseCleaner and clean after linting is complete to ensure a clean
database.

Closes #619, #611, #620
@joshuaclayton joshuaclayton merged commit 7f31ba9 into master Feb 26, 2014
@joshuaclayton joshuaclayton deleted the jc-improve-lint-docs branch February 26, 2014 14:08
@garysweaver
Copy link

Cool! Thanks, @joshuaclayton.

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

7 participants