1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot_rails.git synced 2022-11-09 11:49:18 -05:00
Commit graph

21 commits

Author SHA1 Message Date
Alex Golubenko
7780065bd2
Fix for factory class naming (#366)
Changing the process of name selection for factory defining

Example:

rails g model UserMedia filename:string --force-plural
...
invoke      factory_bot
create        spec/factories/user_media.rb

it generates the correct factory naming:

FactoryBot.define do
  factory :user_media do
    filename { "MyString" }
  end
end

Fixes: #356
2020-04-03 21:50:47 -04:00
Daniel Colson
5c52981fcc
Update rails versions on Travis (#367)
This commit gets the Travis build passing by:

- Removing Rails 4.2 so we don't have to deal with bundler < 2 anymore
- Bumping to latest Rails versions
- Explicitly listing all gems that appear in the default Rails Gemfile
- Avoiding bootsnap and javascript, since they aren't relevant to these tests

Co-authored-by: alex <alexandr1golubenko@gmail.com>
2020-03-29 11:51:41 -04:00
yuuji.yaginuma
e6509920a6 Use compatible sqlite3 version in test application
Currently, the `sqlite3` in `Gemfile` generated by `rails new` is not
compatible with Rails.

To solve this issue, modified it to use compatible `sqlite3` using
template.
Ref: https://github.com/rails/rails/issues/35161
2019-02-06 09:18:41 -05:00
Daniel Colson
baffdb9005 Generate namespaced factories in a directory
Closes #231

When generating factories for namespaced models
(like `Admin::User`), we can follow the pattern used by the model and
model test generators of generating the file inside a directory matching
the namespace. With this commit we generate
`test/factories/admin/user.rb` instead of
`test/factories/admin_user.rb`.
2018-12-03 23:09:17 -05:00
Daniel Colson
b48cff7d99 Allow using custom template for the generator
PR #135 introduced the ability to generate factories in one file, but it
also removed the ability to use custom templates for generating
factories. This PR adds back the ability to use custom templates when
generating factories in separate files. I doubt this was a heavily used
feature, but it has come up a few times and it I think supporting it
simplifies the generator.

Closes #147
Closes #148
Closes #193

PR #193 basically reverted #135, which is undesirable. thoughtbot
projects generally prefer putting all the factories in one file.

Co-authored-by: Nick Sanford <me@nicksanford.io>
2018-12-03 21:12:47 -05:00
Daniel Colson
79ab64d8ad
Add newline between factories in same file
Fixes #305

When generating factories in the same file (for example
spec/factories.rb), before this PR we didn't put newlines between the
factories. So if you generated a user factory, then a robot factory, you
would end up with something like this:

```rb
FactoryBot.define do
  factory :robot do
    name { "MyString" }
  end
  factory :user do
    name { "MyString" }
  end
end
```

With this PR, generating those factories will now look like:

```rb
FactoryBot.define do
  factory :robot do
    name { "MyString" }
  end

  factory :user do
    name { "MyString" }
  end

end
```

Note that the final newline is not ideal, but it will only be added when
generating the first factory, whereas the missing newline after
factories was happening every time we generated a new factory. So
with this PR we will only need to fix a whitespace style error once,
rather than N-1 times. We can could open another issue to fix the extra
newline at the end, but I think it may be more complicated than it
sounds.

Co-authored-by: Nick Sanford <me@nicksanford.io>
2018-11-30 22:07:38 -05:00
Atul Bhosale
01a23ffbe1 Update ModelGenerator to generate dynamic attributes 2018-09-03 15:37:26 +00:00
Avielle Wolfe
c5d11518d7 Rename all girl -> bot
* Rename files and code
* Change factory_girl dependency to factory_bot

This change will bring _rails name in line with factory_bot
c716ce01b4
2017-10-20 18:21:52 -04:00
Joshua Clayton
3ac64d789f Factories are added after the define block
Fixes #150
2015-03-14 21:59:59 -04:00
Peter Marsh
3a050736f3 Change FactoryGirl::Generators::Base#explicit_class_option to output 1.9 Hashes 2015-03-14 20:30:51 -04:00
Takeo Fujita
3488c767c7 fix indent of generated factory file 2015-03-13 21:32:48 -04:00
Jessie A. Young
8c8c564578 Remove unnecessary --fixture-replacement in spec
* FG automatically configures FG as fixture replacement
2014-08-07 16:15:39 -07:00
Jessie A. Young
da421ce31d Do not generate new file if factories.rb exists
* Instead, insert factory into `factories.rb`
* Reference: https://github.com/thoughtbot/suspenders/pull/339
* Add info on change to README
2014-08-07 13:15:52 -07:00
Dan Croak
00cb2eabb1 Test against Rails 3.2, 4.0, 4.1
* Remove gemfiles from version control to match same testing style as
  Clearance and Suspenders.
* MiniTest does not need to be manually included as it is automatically
  included by Rails by default.
* Add spring for Rails 4.1.
* Disable Spring to get specs to pass on Rails 4.1.
* Add therubyrhino for JRuby.
* Remove old references to Rails 3.
* Fix JRuby test where output is "1 runs", not "1 tests".
* Remove Rails 3.0 reference to "turn".
2014-05-27 00:41:24 -07:00
Matt Jankowski
a179d7f366 Newer versions of activerecord-jdbcsqlite3-adapter work without a specially named db driver in database.yml 2013-01-07 15:49:11 -05:00
Matt Jankowski
51cc9ed402 Instead of modifying the environment, run bundle install in a new process
JRuby does not support setting/unsetting environment variables.

Thus, we will launch an entirely new process without the parents env when
we run `bundle install` inside the generated rails apps, forcing them to
use their own Gemfile, instead of the BUNDLE_GEMFILE setting from the main
gem codebase.
2012-12-21 11:08:37 -05:00
Matt Jankowski
95eaa4af9a Improve the way we switch between project Gemfile and appraisal gemfiles
Previously, the railties required by the project gemspec was in conflict with
the rails versions being pulled in by Appraisal.

There were situations where a newer rails app was generated by `rails new...`
even though the Appraisal gemfiles/ value should have been setting it correctly.

We need to be able to use the versions of things specified in the appraisal gemfiles/
specify the version of rails for the initial generation of the applications,
but subsequently allow those applications to point to the `Gemfile` within
the newly generated rails apps, rather than wherever BUNDLE_GEMFILE was previously
set by Appraisal.
2012-12-19 14:46:21 -05:00
Matt Jankowski
742f38dc9e jruby needs a separate sqlite3 adapter 2012-12-13 16:41:16 -05:00
Eric Hu
e85aa34ace Add suffix option for Rails config
Closes #78
2012-12-07 10:40:51 -05:00
Joshua Flanagan
7df9c9b13a Respect model namespaces when generating factories.
The factory name for the model Namespaced::User wil be :namespaced_user.
The :class option is specified as a string to prevent class reloading issues.

Addresses GH-44
2012-02-26 12:58:48 -06:00
Mike Gehard
9f26cabfdf Move generators from rails3-generators gem over to factory_girl_rails. 2011-07-11 21:11:06 -06:00