disable factory model generator #62

Closed
wants to merge 1 commit into
from

Projects

None yet

10 participants

@brewster1134

can disable factories from being generated

config.generators do |g|
  g.factories false
end
@brewster1134 brewster1134 factories generator
can disable factories from being generated

config.generators do |g|
  g.factories false
end
e7257fe
@mike-burns
Member

What's the use of this option? Why would someone run the generators if they didn't want it to generate code?

Also you're missing a test-driven implementation, as well as a test-driven implementation for the Test::Unit case.

@brewster1134

using rspec I typically keep my factories defined in spec/factories.rb rather than in individual files in spec/factories/foo.rb. when generating a rails model, the factory girl generator is invoked and the individual file is created. I would have to remember to delete it otherwise there are errors about the factory already being defined. its nice having the the option to disable it so only the model and rspec files are generated.

and sorry about the lack of tests. im surprised i did that actually. sometimes im spaced out when im working. i will add those unless its decided this feature unwanted.

@mike-burns
Member

@joshuaclayton @jferris @brewster1134 how about this idea: if spec/factories.rb exists, don't generate anything; otherwise, generate the spec/factories/foo.rb stub.

Or should we generate anything at all?

@jferris
Member
jferris commented Jun 20, 2012

It makes the most sense to me to not generate anything at all when that option is set.

@joshmattvander

@mike-burns I personally would prefer an explicit declaration for generating factories along with models / resources.

The conditional check for factories.rb could lead to some confusing behavior for someone unfamiliar with this change.

@volkanunsal

This is a good idea. I also use factories.rb and the generator has been causing a lot of errors in production because I don't realize there is a duplicate factory until deployment. I've tried disabling the generator from application.rb file, but didn't seem to work.

@brewster1134

@tenaciousflea setting the factories generator to false will only work if you are using my fork (https://github.com/brewster1134/factory_girl_rails) or once the pull request is approved.

@mateusg
mateusg commented Sep 19, 2012

Any news on this issue?
I agree with @joshmattvander. The automatic check for factories.rb could be confusing for those who are not familiar with this behaviour.
Could you please add the tests to the pull request, @brewster1134?

@fzf
fzf commented Dec 5, 2012

Can we pull this in, it seems like a pretty straightforward request and should not affect anyones current configuration.

@oogabooga

+1.

Is there something that I can help to get this issue into being merged into master?

@brewster1134

@oogabooga if you wanted to write a test for this I think it may get merged. This has been on my to-do list for a long time now but I have been hard-pressed for time. I apologize.

@Iazel
Iazel commented Feb 19, 2013

Also the method used in generators set up is still too forced. For example, if I want to use a different fixture_replacement with a test_framework != rspec, it's not possibile, because it's automatically set in the initializer.

Disabling through g.factories false is the best option.

EDIT: I've just seen the commit, it's not perfect. IMHO, it should be:

next if rails_option[:factory_girl] == false

At line 10.

@deivid-rodriguez

I think this feature is already implemented. If you don't want any factories to be generated just do this in your config:

config.generators do |g|
  g.test_framework :rspec, fixture_replacement: false
end

or even easier, you can just move factory_girl_rails out of the development group in your Gemfile.

What it would actually be nice in my opinion is to have the default factory generated where you expect, either appended to spec/factories.rb or in its own file in spec/factories

@joshuaclayton joshuaclayton added a commit that closed this pull request Apr 5, 2013
@joshuaclayton joshuaclayton Break generator up for separate frameworks
Closes #91, Closes #62
90e02a3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment