mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 10:29:35 +08:00
283b08d45f
* Move onebox gem in core library * Update template file path * Remove warning for onebox gem caching * Remove onebox version file * Remove onebox gem * Add sanitize gem * Require onebox library in lazy-yt plugin * Remove onebox web specific code This code was used in standalone onebox Sinatra application * Merge Discourse specific AllowlistedGenericOnebox engine in core * Fix onebox engine filenames to match class name casing * Move onebox specs from gem into core * DEV: Rename `response` helper to `onebox_response` Fixes a naming collision. * Require rails_helper * Don't use `before/after(:all)` * Whitespace * Remove fakeweb * Remove poor unit tests * DEV: Re-add fakeweb, plugins are using it * Move onebox helpers * Stub Instagram API * FIX: Follow additional redirect status codes (#476) Don’t throw errors if we encounter 303, 307 or 308 HTTP status codes in responses * Remove an empty file * DEV: Update the license file Using the copy from https://choosealicense.com/licenses/gpl-2.0/# Hopefully this will enable GitHub to show the license UI? * DEV: Update embedded copyrights * DEV: Add Onebox copyright notice * DEV: Add MIT license, convert COPYRIGHT.txt to md * DEV: Remove an incorrect copyright claim Co-authored-by: Jarek Radosz <jradosz@gmail.com> Co-authored-by: jbrw <jamie@goatforce5.org>
104 lines
3.3 KiB
Ruby
104 lines
3.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
describe Onebox::Engine::StackExchangeOnebox do
|
|
describe 'domains' do
|
|
[
|
|
'stackoverflow.com', 'meta.stackoverflow.com',
|
|
'superuser.com', 'meta.superuser.com',
|
|
'serverfault.com', 'meta.serverfault.com',
|
|
'askubuntu.com', 'meta.askubuntu.com',
|
|
'mathoverflow.net', 'meta.mathoverflow.net',
|
|
'money.stackexchange.com', 'meta.money.stackexchange.com',
|
|
'stackapps.com'
|
|
].each do |domain|
|
|
it "matches question with short URL on #{domain}" do
|
|
expect(described_class === URI("http://#{domain}/q/55495")).to eq(true)
|
|
end
|
|
|
|
it "matches question with long URL on #{domain}" do
|
|
expect(described_class === URI("http://#{domain}/questions/55495/title-of-question")).to eq(true)
|
|
end
|
|
|
|
it "matches answer with short URL on #{domain}" do
|
|
expect(described_class === URI("http://#{domain}/a/55503")).to eq(true)
|
|
end
|
|
|
|
it "matches question with long URL on #{domain}" do
|
|
expect(described_class === URI("http://#{domain}/questions/55495/title-of-question/55503#55503")).to eq(true)
|
|
end
|
|
end
|
|
|
|
it "doesn't match question on example.com" do
|
|
expect(described_class === URI('http://example.com/q/4711')).to eq(false)
|
|
end
|
|
|
|
it "doesn't match answer on example.com" do
|
|
expect(described_class === URI('http://example.com/a/4711')).to eq(false)
|
|
end
|
|
end
|
|
|
|
{
|
|
'long URL' => 'http://stackoverflow.com/questions/17992553/concept-behind-these-four-lines-of-tricky-c-code',
|
|
'short URL' => 'http://stackoverflow.com/q/17992553'
|
|
}.each do |name, url|
|
|
describe "question with #{name}" do
|
|
before do
|
|
@link = url
|
|
|
|
stub_request(:get, 'https://api.stackexchange.com/2.2/questions/17992553?site=stackoverflow.com&filter=!5-duuxrJa-iw9oVvOA(JNimB5VIisYwZgwcfNI')
|
|
.to_return(status: 200, body: onebox_response('stackexchange-question'))
|
|
end
|
|
|
|
include_context 'engines'
|
|
it_behaves_like 'an engine'
|
|
|
|
describe '#to_html' do
|
|
it 'includes question title' do
|
|
expect(html).to include('Concept behind these four lines of tricky C code')
|
|
end
|
|
|
|
it "includes 'asked by'" do
|
|
expect(html).to include('asked by')
|
|
end
|
|
|
|
it "doesn't include 'answered by'" do
|
|
expect(html).not_to include('answered by')
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
{
|
|
'long URL' => 'http://stackoverflow.com/questions/17992553/concept-behind-these-four-lines-of-tricky-c-code/17992906#17992906',
|
|
'short URL' => 'http://stackoverflow.com/a/17992906'
|
|
}.each do |name, url|
|
|
describe "answer with #{name}" do
|
|
before do
|
|
@link = url
|
|
|
|
stub_request(:get, 'https://api.stackexchange.com/2.2/answers/17992906?site=stackoverflow.com&filter=!.FjueITQdx6-Rq3Ue9PWG.QZ2WNdW')
|
|
.to_return(status: 200, body: onebox_response('stackexchange-answer'))
|
|
end
|
|
|
|
include_context 'engines'
|
|
it_behaves_like 'an engine'
|
|
|
|
describe '#to_html' do
|
|
it 'includes question title' do
|
|
expect(html).to include('Concept behind these four lines of tricky C code')
|
|
end
|
|
|
|
it "includes 'answered by'" do
|
|
expect(html).to include('answered by')
|
|
end
|
|
|
|
it "doesn't include 'asked by'" do
|
|
expect(html).not_to include('asked by')
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|