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