Skip to content
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

Fixes issue with ActiveStorage::FixtureSet.blob causing a TypeError #2671

Merged
merged 1 commit into from May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions features/file_fixture.feature
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
@@ -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
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