Merge pull request #5282 from vinothkannans/local_onebox_slash
FIX: Topic links onebox differently if end in /
This commit is contained in:
commit
8f560f0bf4
|
@ -12,8 +12,7 @@ module Onebox
|
||||||
url = other.to_s
|
url = other.to_s
|
||||||
return false unless url[Discourse.base_url]
|
return false unless url[Discourse.base_url]
|
||||||
|
|
||||||
path = url.sub(Discourse.base_url, "")
|
route = Discourse.route_for(url)
|
||||||
route = Rails.application.routes.recognize_path(path)
|
|
||||||
|
|
||||||
!!(route[:controller] =~ /topics|uploads/)
|
!!(route[:controller] =~ /topics|uploads/)
|
||||||
rescue ActionController::RoutingError
|
rescue ActionController::RoutingError
|
||||||
|
@ -21,8 +20,9 @@ module Onebox
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_html
|
def to_html
|
||||||
path = @url.sub(Discourse.base_url, "")
|
uri = URI(@url)
|
||||||
route = Rails.application.routes.recognize_path(path)
|
path = uri.path || ""
|
||||||
|
route = Discourse.route_for(uri)
|
||||||
|
|
||||||
case route[:controller]
|
case route[:controller]
|
||||||
when "uploads" then upload_html(path)
|
when "uploads" then upload_html(path)
|
||||||
|
|
|
@ -35,6 +35,11 @@ describe Onebox::Engine::DiscourseLocalOnebox do
|
||||||
expect(html).to include(post2.excerpt)
|
expect(html).to include(post2.excerpt)
|
||||||
expect(html).to include(post2.topic.title)
|
expect(html).to include(post2.topic.title)
|
||||||
|
|
||||||
|
url = "#{Discourse.base_url}#{post2.url}/?source_topic_id=#{post2.topic_id + 1}"
|
||||||
|
html = Onebox.preview(url).to_s
|
||||||
|
expect(html).to include(post2.excerpt)
|
||||||
|
expect(html).to include(post2.topic.title)
|
||||||
|
|
||||||
html = Onebox.preview("#{Discourse.base_url}#{post2.url}").to_s
|
html = Onebox.preview("#{Discourse.base_url}#{post2.url}").to_s
|
||||||
expect(html).to include(post2.user.username)
|
expect(html).to include(post2.user.username)
|
||||||
expect(html).to include(post2.excerpt)
|
expect(html).to include(post2.excerpt)
|
||||||
|
@ -65,6 +70,10 @@ describe Onebox::Engine::DiscourseLocalOnebox do
|
||||||
html = Onebox.preview(topic.url).to_s
|
html = Onebox.preview(topic.url).to_s
|
||||||
expect(html).to include(topic.ordered_posts.first.user.username)
|
expect(html).to include(topic.ordered_posts.first.user.username)
|
||||||
expect(html).to include("<blockquote>")
|
expect(html).to include("<blockquote>")
|
||||||
|
|
||||||
|
html = Onebox.preview("#{topic.url}/?u=codinghorror").to_s
|
||||||
|
expect(html).to include(topic.ordered_posts.first.user.username)
|
||||||
|
expect(html).to include("<blockquote>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue