Skip to content

Commit

Permalink
Merge pull request #2671 from jaywhy/main
Browse files Browse the repository at this point in the history
Fixes issue with ActiveStorage::FixtureSet.blob causing a TypeError
  • Loading branch information
JonRowe committed May 12, 2023
1 parent 3e3e757 commit 4192990
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions features/file_fixture.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,22 @@ Feature: Using `file_fixture`
"""
When I run `rspec spec/lib/file_spec.rb`
Then the examples should all pass

@rails_post_7
Scenario: Creating a ActiveStorage::Blob from a file fixture
Given a file named "spec/fixtures/files/sample.txt" with:
"""
Hello
"""
And a file named "spec/lib/fixture_set_blob.rb" with:
"""ruby
require "rails_helper"
RSpec.describe "blob" do
it "creates a blob from a sample file" do
expect(ActiveStorage::FixtureSet.blob(filename: "sample.txt")).to include("sample.txt")
end
end
"""
When I run `rspec spec/lib/fixture_set_blob.rb`
Then the examples should all pass
15 changes: 15 additions & 0 deletions features/support/rails_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def rails_version
string_version = ENV.fetch("RAILS_VERSION", "~> 7.0.0")
if string_version == "main" || string_version.nil?
Float::INFINITY
else
string_version[/\d[.-]\d/].tr('-', '.')
end
end

Before "@rails_post_7" do |scenario|
if rails_version.to_f < 7.0
warn "Skipping scenario #{scenario.name} on Rails v#{rails_version}"
skip_this_scenario
end
end
3 changes: 3 additions & 0 deletions lib/rspec/rails/file_fixture_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module FileFixtureSupport

included do
self.file_fixture_path = RSpec.configuration.file_fixture_path
if defined?(ActiveStorage::FixtureSet)
ActiveStorage::FixtureSet.file_fixture_path = RSpec.configuration.file_fixture_path
end
end
end
end
Expand Down

0 comments on commit 4192990

Please sign in to comment.