Skip to content

Commit

Permalink
Add spec for namespaced fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
JonRowe committed Dec 11, 2023
1 parent cf2ec15 commit bbebd28
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
30 changes: 24 additions & 6 deletions spec/rspec/rails/fixture_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ module RSpec::Rails

expect_to_pass(group)
end

def expect_to_pass(group)
result = group.run(failure_reporter)
failure_reporter.exceptions.map { |e| raise e }
expect(result).to be true
end
end

it "will allow #setup_fixture to run successfully" do
Expand All @@ -54,5 +48,29 @@ def expect_to_pass(group)

expect { group.new.setup_fixtures }.to_not raise_error
end

it "handles namespaced fixtures" do
group = RSpec::Core::ExampleGroup.describe do
include FixtureSupport
fixtures 'namespaced/model'

it 'has the fixture' do
namespaced_model(:one)
end
end
if Rails.version.to_f >= 7.1
group.fixture_paths = [File.expand_path('../../support/fixtures', __dir__)]
else
group.fixture_path = File.expand_path('../../support/fixtures', __dir__)
end

expect_to_pass(group)
end

def expect_to_pass(group)
result = group.run(failure_reporter)
failure_reporter.exceptions.map { |e| raise e }
expect(result).to be true
end
end
end
10 changes: 10 additions & 0 deletions spec/support/ar_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ class AlternatePrimaryKeyModel < ActiveRecord::Base

attr_accessor :my_id
end

module Namespaced
class Model < ActiveRecord::Base
def self.connection_fields
{ name: :string }
end

extend Connections
end
end
2 changes: 2 additions & 0 deletions spec/support/fixtures/namespaced/model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
one:
name: "Model #1"

0 comments on commit bbebd28

Please sign in to comment.