Skip to content

Fix support for namespaced fixtures with rspec-rails 6.1.0 and rails 7.1 #2716

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

Merged
merged 1 commit into from
Dec 10, 2023

Conversation

benedikt
Copy link
Contributor

@benedikt benedikt commented Nov 23, 2023

This pull request fixes an issue with namespaced fixtures in Rails 7.1 and RSpec Rails 6.1 as described in #2715

The problem is related to this change in fixture_support.rb.

The fixtures method is only looking at the keys of fixture sets, but I think it also needs to look at the values. The keys seem to represent the method name, and the values represent the fixture names.

It works fine for not namespaced fixtures, but the values are different for namespaced ones:

{
  "accounts"=>"accounts",
  "users"=>"users",
  "oauth2_access_tokens"=>"oauth2/access_tokens",
  "oauth2_refresh_tokens"=>"oauth2/refresh_tokens",   
  "oauth2_applications"=>"oauth2/applications",
}

Calling access_fixture with the method name raises the error described above, because the fixture cache is based on the fixture name (with / in the values).

This pull request changes the implementation to use both method_name and fixture_name.

@benedikt benedikt changed the title Fix support for namespaced fixtures with Rails 7.1 Fix support for namespaced fixtures with rspec-rails 6.1.0 and rails 7.1 Nov 23, 2023
@benedikt benedikt force-pushed the main branch 2 times, most recently from 7fa6d14 to 54a1e50 Compare November 23, 2023 17:41
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Thank you!
I kindly appreciate if you find a way to prevent regression with some spec that won’t add a new doc example.

@@ -104,3 +104,23 @@ Feature: Transactional examples
"""
When I run `rspec spec/models/thing_spec.rb`
Then the examples should all pass

Scenario: Run in transactions with namespaced fixture
Copy link
Member

Choose a reason for hiding this comment

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

Even though this may be a good measure against regressions, this also serves as public-facing documentation. And this scenario doesn’t bring value as such. Do you think it would be possible to cover this differently?

Copy link
Member

Choose a reason for hiding this comment

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

Specs aren’t probably an option. Might be the example_app_generator or snippets (eg https://github.com/rspec/rspec-rails/blob/main/snippets/use_active_record_false.rb)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pirj I removed the changes to the feature file for now. I'll see if I can come up with a way to test this otherwise, but I'm not familiar with the project setup so any help would be appreciated 🙂

Copy link
Member

@JonRowe JonRowe left a comment

Choose a reason for hiding this comment

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

I'm happy to merge this but it needs a regression check of some sorts, it probably needs a generated spec in the example app...

@JonRowe JonRowe changed the base branch from main to add-namespaced-fixture-spec December 10, 2023 22:52
@JonRowe JonRowe merged commit ef07a92 into rspec:add-namespaced-fixture-spec Dec 10, 2023
@JonRowe
Copy link
Member

JonRowe commented Dec 11, 2023

I added the required regression check and have merged this in, thank you for your work.

@benedikt
Copy link
Contributor Author

@JonRowe Thanks for figuring out the regression tests! I'm pretty sure I wouldn't have been able to figure out the solution you landed on 👍

JonRowe added a commit that referenced this pull request Dec 11, 2023
JonRowe added a commit that referenced this pull request Dec 11, 2023
@JonRowe
Copy link
Member

JonRowe commented Jan 25, 2024

Released in 6.1.1

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