2021-05-26 05:41:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Onebox::Engine::GithubBlobOnebox do
|
2021-05-26 05:41:35 -04:00
|
|
|
before do
|
|
|
|
@link =
|
|
|
|
"https://github.com/discourse/onebox/blob/master/lib/onebox/engine/github_blob_onebox.rb"
|
2022-01-19 07:45:36 -05:00
|
|
|
@uri = URI.parse(@link)
|
2021-05-26 05:41:35 -04:00
|
|
|
stub_request(
|
|
|
|
:get,
|
|
|
|
"https://raw.githubusercontent.com/discourse/onebox/master/lib/onebox/engine/github_blob_onebox.rb",
|
|
|
|
).to_return(status: 200, body: onebox_response(described_class.onebox_name))
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
include_context "with engines"
|
2021-05-26 05:41:35 -04:00
|
|
|
it_behaves_like "an engine"
|
|
|
|
|
|
|
|
describe "#to_html" do
|
|
|
|
it "includes file name" do
|
|
|
|
expect(html).to include("github_blob_onebox.rb")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes blob contents" do
|
|
|
|
expect(html).to include("module Oneboxer")
|
|
|
|
end
|
2022-01-19 07:45:36 -05:00
|
|
|
|
|
|
|
it "does not include blob contents if it is binary" do
|
|
|
|
# stub_request if the response must be binary (ASCII-8BIT)
|
|
|
|
uri = mock("object")
|
|
|
|
uri.stubs(:open).returns(File.open("#{Rails.root}/spec/fixtures/pdf/small.pdf", "rb"))
|
|
|
|
URI.stubs(:parse).with(@link).returns(@uri)
|
|
|
|
URI
|
|
|
|
.stubs(:parse)
|
|
|
|
.with(
|
|
|
|
"https://raw.githubusercontent.com/discourse/onebox/master/lib/onebox/engine/github_blob_onebox.rb",
|
2023-01-09 06:18:21 -05:00
|
|
|
)
|
2022-01-19 07:45:36 -05:00
|
|
|
.returns(uri)
|
|
|
|
|
|
|
|
expect(html).not_to include("/Pages")
|
|
|
|
expect(html).to include("This file is binary.")
|
|
|
|
end
|
2021-05-26 05:41:35 -04:00
|
|
|
end
|
|
|
|
end
|