mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 08:43:25 +08:00
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)
|
||||
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)
|
||||
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)
|
||||
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")
|
||||
tmp_file_path = File.join(concurrency_safe_tmp_dir, SecureRandom.hex << filename)
|
||||
File.write(tmp_file_path, contents)
|
||||
|
|
Loading…
Reference in New Issue
Block a user