DEV: Add plugin_file_from_fixtures helper (#26359)
This allows plugins to also easily read fixture files for tests, rather than having to do stuff like this: ``` File.open(File.join(__dir__, "../../../fixtures/100x100.jpg")) ```
This commit is contained in:
parent
ef99b97ea7
commit
0bbca318f2
|
@ -804,12 +804,16 @@ def unfreeze_time
|
||||||
TrackTimeStub.unstub(:stubbed)
|
TrackTimeStub.unstub(:stubbed)
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_from_fixtures(filename, directory = "images")
|
def file_from_fixtures(filename, directory = "images", root_path = "#{Rails.root}/spec/fixtures")
|
||||||
tmp_file_path = File.join(concurrency_safe_tmp_dir, SecureRandom.hex << filename)
|
tmp_file_path = File.join(concurrency_safe_tmp_dir, SecureRandom.hex << filename)
|
||||||
FileUtils.cp("#{Rails.root}/spec/fixtures/#{directory}/#{filename}", tmp_file_path)
|
FileUtils.cp("#{root_path}/#{directory}/#{filename}", tmp_file_path)
|
||||||
File.new(tmp_file_path)
|
File.new(tmp_file_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def plugin_file_from_fixtures(plugin_directory, filename, directory = "images")
|
||||||
|
file_from_fixtures(filename, directory, "#{Rails.root}/plugins/#{plugin_directory}/spec/fixtures")
|
||||||
|
end
|
||||||
|
|
||||||
def file_from_contents(contents, filename, directory = "images")
|
def file_from_contents(contents, filename, directory = "images")
|
||||||
tmp_file_path = File.join(concurrency_safe_tmp_dir, SecureRandom.hex << filename)
|
tmp_file_path = File.join(concurrency_safe_tmp_dir, SecureRandom.hex << filename)
|
||||||
File.write(tmp_file_path, contents)
|
File.write(tmp_file_path, contents)
|
||||||
|
|
Loading…
Reference in New Issue