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

Support file_fixture in Factory definitions #427

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seanpdoyle
Copy link
Contributor

Related to factory_bot#1282

rails/rails#45606 has been merged and is likely to be released as part of Rails 7.1.

With that addition, the path toward resolving factory_bot#1282 becomes more clear. If factories can pass along Pathname instances to attachment attributes, Active Support will handle the rest.

Instances of ActiveSupport::TestCase provide a file_fixture helper to construct a Pathname instance based on the path defined by ActiveSupport::TestCase.file_fixture_path (relative to the Rails root directory).


if defined?(RSpec)
RSpec.configure do |config|
if config.respond_to?(:file_fixture_path)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this conditional is always resolving to false, and so the file_fixture_path is never set.

As of [email protected], that setting is available. The current Gemfile.lock that are generated for me locally depends on [email protected], so a hunch tells me that a loading order issue is at the root of the failure.

Copy link

@dorianmariecom dorianmariecom left a comment

Choose a reason for hiding this comment

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

I would test an actual file upload if possible. Otherwise looks good to me

spec/factory_bot_rails/factory_spec.rb Outdated Show resolved Hide resolved
@mike-burns
Copy link
Contributor

This is our first time extending FactoryBot::SyntaxRunner. Do you think this should be something people opt in to? Will this break anything?

I can't think of how this could break existing tests but maybe I'm just not being creative enough.

@seanpdoyle seanpdoyle marked this pull request as ready for review October 25, 2024 19:14
@seanpdoyle seanpdoyle force-pushed the file-fixture-path-support branch 5 times, most recently from a343bd3 to 0cd66df Compare October 26, 2024 13:26
Related to [factory_bot#1282][]

[rails/rails#45606][] has been merged and is likely to be released as
part of Rails 7.1.

With that addition, the path toward resolving [factory_bot#1282][]
becomes more clear. If factories can pass along [Pathname][] instances
to attachment attributes, Active Support will handle the rest.

Instances of `ActiveSupport::TestCase` provide a [file_fixture][] helper
to construct a `Pathname` instance based on the path defined by
`ActiveSupport::TestCase.file_fixture_path` (relative to the Rails root
directory).

[factory_bot#1282]: thoughtbot/factory_bot#1282 (comment)
[rails/rails#45606]: rails/rails#45606
[Pathname]: https://docs.ruby-lang.org/en/master/Pathname.html
[file_fixture]: https://api.rubyonrails.org/classes/ActiveSupport/Testing/FileFixtures.html#method-i-file_fixture
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.

3 participants