mirror of
https://github.com/discourse/discourse.git
synced 2024-12-12 07:15:48 +08:00
4ea21fa2d0
This change both speeds up specs (less strings to allocate) and helps catch cases where methods in Discourse are mutating inputs. Overall we will be migrating everything to use #frozen_string_literal: true it will take a while, but this is the first and safest move in this direction
65 lines
1.7 KiB
Ruby
65 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
require_dependency 'topic_retriever'
|
|
|
|
describe TopicRetriever do
|
|
|
|
let(:embed_url) { "http://eviltrout.com/2013/02/10/why-discourse-uses-emberjs.html" }
|
|
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
|
|
topic_retriever.stubs(:invalid_url?).returns(true)
|
|
end
|
|
|
|
it "does not perform_retrieve" do
|
|
topic_retriever.expects(:perform_retrieve).never
|
|
topic_retriever.retrieve
|
|
end
|
|
end
|
|
|
|
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 host is not invalid" do
|
|
before do
|
|
topic_retriever.stubs(:invalid_url?).returns(false)
|
|
end
|
|
|
|
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
|
|
end
|
|
|
|
end
|