2013-02-05 14:16:51 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe OneboxController do
|
|
|
|
|
2013-03-05 14:03:50 -05:00
|
|
|
let(:url) { "http://google.com" }
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
it 'invalidates the cache if refresh is passed' do
|
2013-03-21 20:47:44 -04:00
|
|
|
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: true)
|
2013-03-21 13:11:54 -04:00
|
|
|
xhr :get, :show, url: url, refresh: 'true'
|
2013-03-05 14:03:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "found onebox" do
|
|
|
|
|
|
|
|
let(:body) { "this is the onebox body"}
|
|
|
|
|
|
|
|
before do
|
2013-03-21 20:47:44 -04:00
|
|
|
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(body)
|
2013-03-05 14:03:50 -05:00
|
|
|
xhr :get, :show, url: url
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns success' do
|
|
|
|
response.should be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the onebox response in the body' do
|
|
|
|
response.body.should == body
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "missing onebox" do
|
|
|
|
|
|
|
|
it "returns 404 if the onebox is nil" do
|
2013-03-21 20:47:44 -04:00
|
|
|
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(nil)
|
2013-03-05 14:03:50 -05:00
|
|
|
xhr :get, :show, url: url
|
|
|
|
response.response_code.should == 404
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 if the onebox is an empty string" do
|
2013-03-21 20:47:44 -04:00
|
|
|
Oneboxer.expects(:preview).with(url, invalidate_oneboxes: false).returns(" \t ")
|
2013-03-05 14:03:50 -05:00
|
|
|
xhr :get, :show, url: url
|
|
|
|
response.response_code.should == 404
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|