2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe TopicRetriever do
|
2013-12-31 14:37:43 -05:00
|
|
|
let(:embed_url) { "http://eviltrout.com/2013/02/10/why-discourse-uses-emberjs.html" }
|
2023-02-28 07:31:59 -05:00
|
|
|
let(:topic_retriever) { TopicRetriever.new(embed_url) }
|
2014-04-24 12:48:45 -04:00
|
|
|
|
2020-04-20 14:16:34 -04:00
|
|
|
it "can initialize without optional parameters" do
|
|
|
|
t = TopicRetriever.new(embed_url)
|
|
|
|
expect(t).to be_present
|
|
|
|
end
|
|
|
|
|
2014-04-24 12:48:45 -04:00
|
|
|
describe "#retrieve" do
|
|
|
|
context "when host is invalid" do
|
2016-08-23 14:55:52 -04:00
|
|
|
before { topic_retriever.stubs(:invalid_url?).returns(true) }
|
2014-04-24 12:48:45 -04:00
|
|
|
|
|
|
|
it "does not perform_retrieve" do
|
|
|
|
topic_retriever.expects(:perform_retrieve).never
|
|
|
|
topic_retriever.retrieve
|
|
|
|
end
|
2013-12-31 14:37:43 -05:00
|
|
|
end
|
|
|
|
|
2021-05-20 21:43:47 -04:00
|
|
|
context "when topics have been retrieved recently" do
|
2014-04-24 12:48:45 -04:00
|
|
|
before { topic_retriever.stubs(:retrieved_recently?).returns(true) }
|
2013-12-31 14:37:43 -05:00
|
|
|
|
2014-04-24 12:48:45 -04:00
|
|
|
it "does not perform_retrieve" do
|
|
|
|
topic_retriever.expects(:perform_retrieve).never
|
|
|
|
topic_retriever.retrieve
|
|
|
|
end
|
2013-12-31 14:37:43 -05:00
|
|
|
end
|
|
|
|
|
2021-07-16 14:25:49 -04:00
|
|
|
context "when host is valid" do
|
|
|
|
before { Fabricate(:embeddable_host, host: "http://eviltrout.com/") }
|
2014-04-24 12:48:45 -04:00
|
|
|
|
2021-05-20 21:43:47 -04:00
|
|
|
context "when topics have been retrieved recently" do
|
2014-04-24 12:48:45 -04:00
|
|
|
before { topic_retriever.stubs(:retrieved_recently?).returns(true) }
|
|
|
|
|
|
|
|
it "does not perform_retrieve" do
|
|
|
|
topic_retriever.expects(:perform_retrieve).never
|
|
|
|
topic_retriever.retrieve
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-20 21:43:47 -04:00
|
|
|
context "when topics have not been retrieved recently" do
|
2014-04-24 12:48:45 -04:00
|
|
|
before { topic_retriever.stubs(:retrieved_recently?).returns(false) }
|
|
|
|
|
|
|
|
it "does perform_retrieve" do
|
|
|
|
topic_retriever.expects(:perform_retrieve).once
|
|
|
|
topic_retriever.retrieve
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-02-25 06:31:38 -05:00
|
|
|
|
2021-07-16 14:25:49 -04:00
|
|
|
context "when host is invalid" do
|
|
|
|
before { Fabricate(:embeddable_host, host: "http://not-eviltrout.com/") }
|
|
|
|
|
|
|
|
it "does not perform_retrieve" do
|
|
|
|
topic_retriever.expects(:perform_retrieve).never
|
|
|
|
topic_retriever.retrieve
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-25 06:31:38 -05:00
|
|
|
it "works with URLs with whitespaces" do
|
|
|
|
expect { TopicRetriever.new(" https://example.com ").retrieve }.not_to raise_error
|
|
|
|
end
|
2013-12-31 14:37:43 -05:00
|
|
|
end
|
|
|
|
end
|