mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Merge pull request #3991 from xfalcox/patch-4
FIX: Local onebox on subfolder installs
This commit is contained in:
commit
d43a693654
2 changed files with 59 additions and 2 deletions
|
@ -14,7 +14,7 @@ module Onebox
|
||||||
if other.kind_of?(URI)
|
if other.kind_of?(URI)
|
||||||
uri = other
|
uri = other
|
||||||
begin
|
begin
|
||||||
route = Rails.application.routes.recognize_path(uri.path)
|
route = Rails.application.routes.recognize_path(uri.path.sub(Discourse.base_uri, ""))
|
||||||
case route[:controller]
|
case route[:controller]
|
||||||
when 'uploads'
|
when 'uploads'
|
||||||
super
|
super
|
||||||
|
@ -34,7 +34,7 @@ module Onebox
|
||||||
|
|
||||||
def to_html
|
def to_html
|
||||||
uri = URI::parse(@url)
|
uri = URI::parse(@url)
|
||||||
route = Rails.application.routes.recognize_path(uri.path)
|
route = Rails.application.routes.recognize_path(uri.path.sub(Discourse.base_uri, ""))
|
||||||
url = @url.sub(/[&?]source_topic_id=(\d+)/, "")
|
url = @url.sub(/[&?]source_topic_id=(\d+)/, "")
|
||||||
source_topic_id = $1.to_i
|
source_topic_id = $1.to_i
|
||||||
|
|
||||||
|
|
|
@ -94,4 +94,61 @@ describe Onebox::Engine::DiscourseLocalOnebox do
|
||||||
expect(html).to eq("<video width='100%' height='100%' controls><source src='#{url}'><a href='#{url}'>#{url}</a></video>")
|
expect(html).to eq("<video width='100%' height='100%' controls><source src='#{url}'><a href='#{url}'>#{url}</a></video>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "When deployed to a subfolder" do
|
||||||
|
let(:base_url) { "http://test.localhost/subfolder" }
|
||||||
|
let(:base_uri) { "/subfolder" }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Discourse.stubs(:base_url).returns(base_url)
|
||||||
|
Discourse.stubs(:base_uri).returns(base_uri)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "matches for a topic url" do
|
||||||
|
url = "#{Discourse.base_url}/t/hot-topic"
|
||||||
|
expect(Onebox.has_matcher?(url)).to eq(true)
|
||||||
|
expect(Onebox::Matcher.new(url).oneboxed).to eq(described_class)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "matches for a post url" do
|
||||||
|
url = "#{Discourse.base_url}/t/hot-topic/23/2"
|
||||||
|
expect(Onebox.has_matcher?(url)).to eq(true)
|
||||||
|
expect(Onebox::Matcher.new(url).oneboxed).to eq(described_class)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for a link to a post" do
|
||||||
|
let(:post) { Fabricate(:post) }
|
||||||
|
let(:post2) { Fabricate(:post, topic: post.topic, post_number: 2) }
|
||||||
|
|
||||||
|
it "returns a link if post isn't found" do
|
||||||
|
url = "#{Discourse.base_url}/t/not-exist/3/2"
|
||||||
|
expect(Onebox.preview(url).to_s).to eq("<a href='#{url}'>#{url}</a>")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a link if not allowed to see the post" do
|
||||||
|
url = "#{Discourse.base_url}#{post2.url}"
|
||||||
|
Guardian.any_instance.stubs(:can_see?).returns(false)
|
||||||
|
expect(Onebox.preview(url).to_s).to eq("<a href='#{url}'>#{url}</a>")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a link if post is hidden" do
|
||||||
|
hidden_post = Fabricate(:post, topic: post.topic, post_number: 2, hidden: true, hidden_reason_id: Post.hidden_reasons[:flag_threshold_reached])
|
||||||
|
url = "#{Discourse.base_url}#{hidden_post.url}"
|
||||||
|
expect(Onebox.preview(url).to_s).to eq("<a href='#{url}'>#{url}</a>")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns some onebox goodness if post exists and can be seen" do
|
||||||
|
url = "#{Discourse.base_url}#{post2.url}?source_topic_id=#{post2.topic_id+1}"
|
||||||
|
Guardian.any_instance.stubs(:can_see?).returns(true)
|
||||||
|
html = Onebox.preview(url).to_s
|
||||||
|
expect(html).to include(post2.excerpt)
|
||||||
|
expect(html).to include(post2.topic.title)
|
||||||
|
|
||||||
|
url = "#{Discourse.base_url}#{post2.url}"
|
||||||
|
html = Onebox.preview(url).to_s
|
||||||
|
expect(html).to include(post2.user.username)
|
||||||
|
expect(html).to include(post2.excerpt)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue