Skip to content

Commit 4192990

Browse files
committed
Merge pull request #2671 from jaywhy/main
Fixes issue with ActiveStorage::FixtureSet.blob causing a TypeError
1 parent 3e3e757 commit 4192990

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

features/file_fixture.feature

+19
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,22 @@ Feature: Using `file_fixture`
3636
"""
3737
When I run `rspec spec/lib/file_spec.rb`
3838
Then the examples should all pass
39+
40+
@rails_post_7
41+
Scenario: Creating a ActiveStorage::Blob from a file fixture
42+
Given a file named "spec/fixtures/files/sample.txt" with:
43+
"""
44+
Hello
45+
"""
46+
And a file named "spec/lib/fixture_set_blob.rb" with:
47+
"""ruby
48+
require "rails_helper"
49+
50+
RSpec.describe "blob" do
51+
it "creates a blob from a sample file" do
52+
expect(ActiveStorage::FixtureSet.blob(filename: "sample.txt")).to include("sample.txt")
53+
end
54+
end
55+
"""
56+
When I run `rspec spec/lib/fixture_set_blob.rb`
57+
Then the examples should all pass

features/support/rails_versions.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def rails_version
2+
string_version = ENV.fetch("RAILS_VERSION", "~> 7.0.0")
3+
if string_version == "main" || string_version.nil?
4+
Float::INFINITY
5+
else
6+
string_version[/\d[.-]\d/].tr('-', '.')
7+
end
8+
end
9+
10+
Before "@rails_post_7" do |scenario|
11+
if rails_version.to_f < 7.0
12+
warn "Skipping scenario #{scenario.name} on Rails v#{rails_version}"
13+
skip_this_scenario
14+
end
15+
end

lib/rspec/rails/file_fixture_support.rb

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module FileFixtureSupport
99

1010
included do
1111
self.file_fixture_path = RSpec.configuration.file_fixture_path
12+
if defined?(ActiveStorage::FixtureSet)
13+
ActiveStorage::FixtureSet.file_fixture_path = RSpec.configuration.file_fixture_path
14+
end
1215
end
1316
end
1417
end

0 commit comments

Comments
 (0)