2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00
discourse/spec/components/file_helper_spec.rb

35 lines
914 B
Ruby
Raw Normal View History

2017-05-15 16:56:29 -04:00
require 'rails_helper'
require 'file_helper'
describe FileHelper do
let(:url) { "https://eviltrout.com/trout.png" }
let(:png) { Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==") }
before do
Excon.stub({ method: :head, hostname: 'eviltrout.com' }, {})
2017-05-15 16:56:29 -04:00
stub_request(:get, url).to_return(body: png)
end
describe "download" do
it "returns a file with the image" do
tmpfile = FileHelper.download(
url,
max_file_size: 10000,
tmp_file_name: 'trouttmp'
)
2017-05-15 16:56:29 -04:00
expect(tmpfile.read[0..5]).to eq("GIF89a")
end
it "works with a protocol relative url" do
tmpfile = FileHelper.download(
"//eviltrout.com/trout.png",
max_file_size: 10000,
tmp_file_name: 'trouttmp'
)
2017-05-15 16:56:29 -04:00
expect(tmpfile.read[0..5]).to eq("GIF89a")
end
end
end