-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate to Rails 7.1's
file_fixture_upload
naming approach
rails/rails#48857 renamed `fixture_file_upload` to `file_fixture_upload` to reduce "confusion and surprise". With this change, `file_fixture_upload` now works in RSpec, with `fixture_file_upload` still functional to maintain backwards compatibility.
- Loading branch information
Showing
9 changed files
with
124 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
example_app_generator/no_active_record/spec/verify_file_fixture_upload_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'Example App', :use_fixtures, type: :model do | ||
if ::Rails::VERSION::STRING < "7.1.0" | ||
it 'supports fixture_file_upload' do | ||
file = fixture_file_upload(__FILE__) | ||
expect(file.read).to match(/RSpec\.describe 'Example App'/im) | ||
end | ||
else | ||
it 'supports file_fixture_upload' do | ||
file = file_fixture_upload(__FILE__) | ||
expect(file.read).to match(/RSpec\.describe 'Example App'/im) | ||
end | ||
|
||
it 'supports fixture_file_upload' do | ||
file = fixture_file_upload(__FILE__) | ||
expect(file.read).to match(/RSpec\.describe 'Example App'/im) | ||
end | ||
end | ||
end |
8 changes: 0 additions & 8 deletions
8
example_app_generator/no_active_record/spec/verify_fixture_file_upload_spec.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
module RSpec::Rails | ||
RSpec.describe FileFixtureUploadSupport do | ||
if ::Rails::VERSION::STRING < "7.1.0" | ||
context 'with fixture path set in config' do | ||
it 'resolves fixture file' do | ||
RSpec.configuration.fixture_path = File.dirname(__FILE__) | ||
expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb') | ||
end | ||
|
||
it 'resolves supports `Pathname` objects' do | ||
RSpec.configuration.fixture_path = Pathname(File.dirname(__FILE__)) | ||
expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb') | ||
end | ||
end | ||
|
||
context 'with fixture path set in spec' do | ||
it 'resolves fixture file' do | ||
expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb', File.dirname(__FILE__)) | ||
end | ||
end | ||
|
||
context 'with fixture path not set' do | ||
it 'resolves fixture using relative path' do | ||
RSpec.configuration.fixture_path = nil | ||
expect_to_pass file_fixture_upload_resolved('spec/rspec/rails/file_fixture_upload_support_spec.rb') | ||
end | ||
end | ||
|
||
def file_fixture_upload_resolved(fixture_name, file_fixture_path = nil) | ||
RSpec::Core::ExampleGroup.describe do | ||
include RSpec::Rails::FileFixtureUploadSupport | ||
|
||
self.file_fixture_path = file_fixture_path | ||
|
||
it 'supports fixture_file_upload' do | ||
file = fixture_file_upload(fixture_name) | ||
expect(file.read).to match(/describe FileFixtureUploadSupport/im) | ||
end | ||
end | ||
end | ||
else | ||
context 'with fixture paths set in config' do | ||
it 'resolves fixture file' do | ||
RSpec.configuration.fixture_paths = [File.dirname(__FILE__)] | ||
expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb') | ||
end | ||
|
||
it 'resolves supports `Pathname` objects' do | ||
RSpec.configuration.fixture_paths = [Pathname(File.dirname(__FILE__))] | ||
expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb') | ||
end | ||
end | ||
|
||
context 'with fixture path set in spec' do | ||
it 'resolves fixture file' do | ||
expect_to_pass file_fixture_upload_resolved('file_fixture_upload_support_spec.rb', File.dirname(__FILE__)) | ||
end | ||
end | ||
|
||
context 'with fixture path not set' do | ||
it 'resolves fixture using relative path' do | ||
RSpec.configuration.fixture_path = nil | ||
expect_to_pass file_fixture_upload_resolved('spec/rspec/rails/file_fixture_upload_support_spec.rb') | ||
end | ||
end | ||
|
||
def file_fixture_upload_resolved(fixture_name, file_fixture_path = nil) | ||
RSpec::Core::ExampleGroup.describe do | ||
include RSpec::Rails::FileFixtureUploadSupport | ||
|
||
self.file_fixture_path = file_fixture_path | ||
|
||
it 'supports file_fixture_upload' do | ||
file = file_fixture_upload(fixture_name) | ||
expect(file.read).to match(/describe FileFixtureUploadSupport/im) | ||
end | ||
|
||
it 'supports fixture_file_upload' do | ||
file = fixture_file_upload(fixture_name) | ||
expect(file.read).to match(/describe FileFixtureUploadSupport/im) | ||
end | ||
end | ||
end | ||
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 |
This file was deleted.
Oops, something went wrong.