2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
describe OneboxController do
|
|
|
|
|
2013-03-06 03:03:50 +08:00
|
|
|
let(:url) { "http://google.com" }
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
it 'invalidates the cache if refresh is passed' do
|
2013-03-22 08:47:44 +08:00
|
|
|
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: true)
|
2013-03-22 01:11:54 +08:00
|
|
|
xhr :get, :show, url: url, refresh: 'true'
|
2013-03-06 03:03:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "found onebox" do
|
|
|
|
|
|
|
|
let(:body) { "this is the onebox body"}
|
|
|
|
|
|
|
|
before do
|
2013-03-22 08:47:44 +08:00
|
|
|
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(body)
|
2013-03-06 03:03:50 +08:00
|
|
|
xhr :get, :show, url: url
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns success' do
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(response).to be_success
|
2013-03-06 03:03:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the onebox response in the body' do
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(response.body).to eq(body)
|
2013-03-06 03:03:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "missing onebox" do
|
|
|
|
|
|
|
|
it "returns 404 if the onebox is nil" do
|
2013-03-22 08:47:44 +08:00
|
|
|
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(nil)
|
2013-03-06 03:03:50 +08:00
|
|
|
xhr :get, :show, url: url
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(response.response_code).to eq(404)
|
2013-03-06 03:03:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 if the onebox is an empty string" do
|
2013-03-22 08:47:44 +08:00
|
|
|
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(" \t ")
|
2013-03-06 03:03:50 +08:00
|
|
|
xhr :get, :show, url: url
|
2015-01-10 01:04:02 +08:00
|
|
|
expect(response.response_code).to eq(404)
|
2013-03-06 03:03:50 +08:00
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|