Skip to content

Commit

Permalink
Factories are added after the define block
Browse files Browse the repository at this point in the history
Fixes #150
  • Loading branch information
joshuaclayton committed Mar 15, 2015
1 parent c761d47 commit 3ac64d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions features/generators.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ Feature:
"""
And the file "test/factories/namespaced_users.rb" should contain "factory :namespaced_user, class: 'Namespaced::User' do"

Scenario: The factory_girl_rails generators add a factory in the correct spot
When I run `bundle install` with a clean environment
And I write to "test/factories.rb" with:
"""
FactoryGirl.define do
end
"""
And I run `bundle exec rails generate model User name:string` with a clean environment
Then the file "test/factories.rb" should contain exactly:
"""
FactoryGirl.define do
factory :user do
name "MyString"
end
end
"""

Scenario: The factory_girl_rails generators does not create a factory file for each model if there is a factories.rb file in the test directory
When I run `bundle install` with a clean environment
And I write to "test/factories.rb" with:
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/factory_girl/model/model_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def insert_factory_into_existing_file
insert_into_file(
factories_file,
factory_definition,
after: "FactoryGirl.define do"
after: "FactoryGirl.define do\n"
)
end

Expand Down

0 comments on commit 3ac64d7

Please sign in to comment.