Skip to content

Fix fixture_file_upload for active record not present #2364

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

Merged
merged 1 commit into from
Jul 28, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example_app_generator/generate_stuff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def setup_tasks
def final_tasks
copy_file 'spec/verify_no_active_record_spec.rb'
copy_file 'spec/verify_no_fixture_setup_spec.rb'
copy_file 'spec/verify_fixture_file_upload_spec.rb'
end

def skip_active_record?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rails_helper'

RSpec.describe 'Example App', :use_fixtures, type: :model do
it 'supports fixture file upload' do
file = fixture_file_upload(__FILE__)
expect(file.read).to match(/RSpec\.describe 'Example App'/im)
end
end
7 changes: 6 additions & 1 deletion lib/rspec/rails/fixture_file_upload_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ module FixtureFileUploadSupport

def rails_fixture_file_wrapper
RailsFixtureFileWrapper.fixture_path = nil
resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '').to_s
resolved_fixture_path =
if respond_to?(:fixture_path) && !fixture_path.nil?
fixture_path.to_s
else
(RSpec.configuration.fixture_path || '').to_s
end
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '') unless resolved_fixture_path.strip.empty?
RailsFixtureFileWrapper.instance
end
Expand Down