mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 09:10:25 +08:00
Fix onebox loading on every keystroke after a request fails.
This commit is contained in:
parent
016634d1d9
commit
e4277757c4
5 changed files with 158 additions and 89 deletions
|
@ -2,14 +2,46 @@ require 'spec_helper'
|
|||
|
||||
describe OneboxController do
|
||||
|
||||
it 'asks the oneboxer for the preview' do
|
||||
Oneboxer.expects(:preview).with('http://google.com')
|
||||
xhr :get, :show, url: 'http://google.com'
|
||||
end
|
||||
let(:url) { "http://google.com" }
|
||||
|
||||
it 'invalidates the cache if refresh is passed' do
|
||||
Oneboxer.expects(:invalidate).with('http://google.com')
|
||||
xhr :get, :show, url: 'http://google.com', refresh: true
|
||||
Oneboxer.expects(:invalidate).with(url)
|
||||
xhr :get, :show, url: url, refresh: true
|
||||
end
|
||||
|
||||
describe "found onebox" do
|
||||
|
||||
let(:body) { "this is the onebox body"}
|
||||
|
||||
before do
|
||||
Oneboxer.expects(:preview).with(url).returns(body)
|
||||
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
|
||||
Oneboxer.expects(:preview).with(url).returns(nil)
|
||||
xhr :get, :show, url: url
|
||||
response.response_code.should == 404
|
||||
end
|
||||
|
||||
it "returns 404 if the onebox is an empty string" do
|
||||
Oneboxer.expects(:preview).with(url).returns(" \t ")
|
||||
xhr :get, :show, url: url
|
||||
response.response_code.should == 404
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -2,19 +2,22 @@
|
|||
|
||||
describe("Discourse.Onebox", function() {
|
||||
|
||||
var anchor;
|
||||
|
||||
beforeEach(function() {
|
||||
spyOn(jQuery, 'ajax').andCallThrough();
|
||||
anchor = $("<a href='http://bla.com'></a>")[0];
|
||||
});
|
||||
|
||||
it("Stops rapid calls with cache true", function() {
|
||||
Discourse.Onebox.lookup('http://bla.com', true, function(c) { return c; });
|
||||
Discourse.Onebox.lookup('http://bla.com', true, function(c) { return c; });
|
||||
Discourse.Onebox.load(anchor, true);
|
||||
Discourse.Onebox.load(anchor, true);
|
||||
expect(jQuery.ajax.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
it("Stops rapid calls with cache false", function() {
|
||||
Discourse.Onebox.lookup('http://bla.com/a', false, function(c) { return c; });
|
||||
Discourse.Onebox.lookup('http://bla.com/a', false, function(c) { return c; });
|
||||
Discourse.Onebox.load(anchor, false);
|
||||
Discourse.Onebox.load(anchor, false);
|
||||
expect(jQuery.ajax.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue