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

Ensure factory_bot only loads after initialization #347

Merged
merged 1 commit into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions features/reloading.feature
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,45 @@ Feature:
And I run `spring stop` with a clean environment
Then the output should contain "1 runs, 1 assertions"
And the output should not contain "Failure:"

Scenario: Initializing the reloader with I18n support
Copy link
Contributor

Choose a reason for hiding this comment

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

very self-explanatory and specific test 👏

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the review! I will merge this and close #343 for now.

When I successfully run `bundle exec rails new testapp -m ../../features/support/rails_template`
And I cd to "testapp"
And I add "factory_bot_rails" from this project as a dependency
And I add "test-unit" as a dependency
And I run `bundle install` with a clean environment
And I run `bundle exec rake db:migrate` with a clean environment
And I write to "app/models/user.rb" with:
"""
class User
TRANSLATION = I18n.translate("translation_key")
end
"""
And I write to "config/locales/en.yml" with:
"""
en:
translation_key: "translation_value"
"""
And I write to "test/factories.rb" with:
"""
FactoryBot.define do
factory :user do
User::TRANSLATION
end
end
"""
And I write to "test/unit/user_test.rb" with:
"""
require 'test_helper'

class UserTest < ActiveSupport::TestCase
test "use factory" do
user = FactoryBot.build(:user)

assert_equal "translation_value", User::TRANSLATION
end
end
"""
And I run `bundle exec rake test` with a clean environment
Then the output should contain "1 runs, 1 assertions"
And the output should not contain "Failure:"
6 changes: 5 additions & 1 deletion lib/factory_bot_rails/reloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def reloader_class
end

def register_reloader(reloader)
closed_over_app = app

config.to_prepare do
reloader.execute
if closed_over_app.initialized?
reloader.execute
end
end

app.reloaders << reloader
Expand Down