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).

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 force-pushed the file-fixture-path-support branch from 8a739aa to 5a1a15e Compare October 25, 2024 19:14
@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 6 times, most recently from 0cd66df to 33c1348 Compare November 1, 2024 03:40
@seanpdoyle seanpdoyle force-pushed the file-fixture-path-support branch from 33c1348 to 61baf5f Compare January 10, 2025 20:44
@seanpdoyle seanpdoyle force-pushed the file-fixture-path-support branch 7 times, most recently from 611f31f to f878964 Compare January 10, 2025 23:06
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
@seanpdoyle seanpdoyle force-pushed the file-fixture-path-support branch from f878964 to 43e18b9 Compare January 10, 2025 23:12
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