mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 20:24:05 -06:00
493d437e79
* Remove outdated option
04078317ba
* Use the non-globally exposed RSpec syntax
https://github.com/rspec/rspec-core/pull/2803
* Use the non-globally exposed RSpec syntax, cont
https://github.com/rspec/rspec-core/pull/2803
* Comply to strict predicate matchers
See:
- https://github.com/rspec/rspec-expectations/pull/1195
- https://github.com/rspec/rspec-expectations/pull/1196
- https://github.com/rspec/rspec-expectations/pull/1277
83 lines
2.2 KiB
Ruby
83 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.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) }
|
|
|
|
it "can initialize without optional parameters" do
|
|
t = TopicRetriever.new(embed_url)
|
|
expect(t).to be_present
|
|
end
|
|
|
|
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 retrieved 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 valid" do
|
|
before do
|
|
Fabricate(:embeddable_host, host: 'http://eviltrout.com/')
|
|
end
|
|
|
|
context "when topics have been retrieved 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 retrieved 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
|
|
|
|
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
|
|
|
|
it "works with URLs with whitespaces" do
|
|
expect { TopicRetriever.new(" https://example.com ").retrieve }
|
|
.not_to raise_error
|
|
end
|
|
end
|
|
|
|
end
|