Skip to content

Commit 472ffb7

Browse files
author
Laurent Cobos
committed
clean as PR review
1 parent 9d304d1 commit 472ffb7

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

lib/rspec/rails/fixture_file_upload_support.rb

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,32 @@ module RSpec
22
module Rails
33
# @private
44
module FixtureFileUploadSupport
5-
extend ActiveSupport::Concern
6-
7-
included do
8-
delegate :fixture_file_upload, :to => :rails_fixture_file_wrapper
9-
end
10-
11-
private
12-
13-
def rails_fixture_file_wrapper
14-
resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '')
15-
RailsFixtureFileWrapper.fixture_path = File.join(resolved_fixture_path, '')
16-
RailsFixtureFileWrapper.instance
5+
def self.included(other)
6+
if defined?(ActionDispatch::TestProcess)
7+
other.include ActionDispatch::TestProcess
8+
end
9+
other.extend FixturePathAttribute
1710
end
1811

19-
class RailsFixtureFileWrapper
20-
class << self
21-
attr_reader :fixture_path
12+
module FixturePathAttribute
13+
def fixture_path
14+
@fixture_path ||= calculate_path
15+
end
2216

23-
# Get the instance of wrapper
24-
def instance
25-
@instance ||= new
17+
def fixture_path=(value)
18+
# Rails 3.0..3.1 are using ActionController::TestCase class to resolve fixture_path
19+
# see https://apidock.com/rails/v3.0.0/ActionDispatch/TestProcess/fixture_file_upload
20+
if ActionController::TestCase.respond_to?(:fixture_path)
21+
ActionController::TestCase.fixture_path = value
2622
end
23+
@fixture_path = value
24+
end
2725

28-
def fixture_path=(value)
29-
# Rails 3.0..3.1 are using ActionController::TestCase class to resolve fixture_path
30-
# see https://apidock.com/rails/v3.0.0/ActionDispatch/TestProcess/fixture_file_upload
31-
if ActionController::TestCase.respond_to?(:fixture_path)
32-
ActionController::TestCase.fixture_path = value
33-
end
34-
@fixture_path = value
35-
end
26+
private
3627

37-
include ActionDispatch::TestProcess if defined?(ActionDispatch::TestProcess)
28+
def calculate_fixture_path
29+
resolved_fixture_path = (fixture_path || RSpec.configuration.fixture_path || '')
30+
self.fixture_path = File.join(resolved_fixture_path, '')
3831
end
3932
end
4033
end

0 commit comments

Comments
 (0)