2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-12-31 14:37:43 -05:00
|
|
|
|
|
|
|
describe TopicRetriever do
|
|
|
|
|
|
|
|
let(:embed_url) { "http://eviltrout.com/2013/02/10/why-discourse-uses-emberjs.html" }
|
2014-04-24 12:48:45 -04:00
|
|
|
let(:author_username) { "eviltrout" }
|
|
|
|
let(:topic_retriever) { TopicRetriever.new(embed_url, author_username: author_username) }
|
|
|
|
|
|
|
|
describe "#retrieve" do
|
|
|
|
context "when host is invalid" do
|
|
|
|
before do
|
2016-08-23 14:55:52 -04:00
|
|
|
topic_retriever.stubs(:invalid_url?).returns(true)
|
2014-04-24 12:48:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-04-24 12:48:45 -04:00
|
|
|
context "when topics have been retrieived recently" do
|
|
|
|
before do
|
|
|
|
topic_retriever.stubs(:retrieved_recently?).returns(true)
|
|
|
|
end
|
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
|
|
|
|
|
2014-04-24 12:48:45 -04:00
|
|
|
context "when host is not invalid" do
|
2017-07-27 21:20:09 -04:00
|
|
|
before do
|
|
|
|
topic_retriever.stubs(:invalid_url?).returns(false)
|
|
|
|
end
|
2014-04-24 12:48:45 -04:00
|
|
|
|
|
|
|
context "when topics have been retrieived recently" do
|
|
|
|
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
|
|
|
|
|
|
|
|
context "when topics have not been retrieived recently" do
|
|
|
|
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
|
2013-12-31 14:37:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|