Skip to content

Commit 7fa6d14

Browse files
committed
Fix support for namespaced fixtures with Rails 7.1
1 parent b109337 commit 7fa6d14

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

features/model_specs/transactional_examples.feature

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,23 @@ Feature: Transactional examples
104104
"""
105105
When I run `rspec spec/models/thing_spec.rb`
106106
Then the examples should all pass
107+
108+
Scenario: Run in transactions with namespaced fixture
109+
Given a file named "spec/models/thing_spec.rb" with:
110+
"""ruby
111+
require "rails_helper"
112+
113+
RSpec.describe Thing, type: :model do
114+
fixtures 'namespaced/things'
115+
it "fixture method defined" do
116+
namespaced_things(:one)
117+
end
118+
end
119+
"""
120+
Given a file named "spec/fixtures/namespaced/things.yml" with:
121+
"""
122+
one:
123+
name: MyString
124+
"""
125+
When I run `rspec spec/models/thing_spec.rb`
126+
Then the examples should all pass

lib/rspec/rails/fixture_support.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ module Fixtures
4343
if ::Rails.version.to_f >= 7.1
4444
def fixtures(*args)
4545
super.tap do
46-
fixture_sets.each_key do |fixture_name|
47-
proxy_method_warning_if_called_in_before_context_scope(fixture_name)
46+
fixture_sets.each_pair do |method_name, fixture_name|
47+
proxy_method_warning_if_called_in_before_context_scope(method_name, fixture_name)
4848
end
4949
end
5050
end
5151

52-
def proxy_method_warning_if_called_in_before_context_scope(fixture_name)
53-
define_method(fixture_name) do |*args, **kwargs, &blk|
52+
def proxy_method_warning_if_called_in_before_context_scope(method_name, fixture_name)
53+
define_method(method_name) do |*args, **kwargs, &blk|
5454
if RSpec.current_scope == :before_context_hook
5555
RSpec.warn_with("Calling fixture method in before :context ")
5656
else

0 commit comments

Comments
 (0)