Skip to content

Commit

Permalink
this takes care of the spanned_link cases (as far as relative urls)
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Oct 29, 2008
1 parent 2f5421c commit 0bba974
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion app/models/post.rb
Expand Up @@ -43,7 +43,8 @@ def deleted?
end

def link(root='')
"#{root}/#{type.tableize}/#{to_param}"
relative_url = ActionController::Base.respond_to?('relative_url_root=') ? ActionController::Base.relative_url_root : ActionController::AbstractRequest.relative_url_root
"#{relative_url}#{root}/#{type.tableize}/#{to_param}"
end

def to_html
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/posts/types/_snippet.html.erb
@@ -1,5 +1,5 @@
<%- unless post.header.blank? -%>
<h3 class="entry-title"><%= spanned_link post.header, "/snippets/#{post.permalink}" %></h3>
<h3 class="entry-title"><%= spanned_link post.header, snippet_path(post.permalink) %></h3>
<%- end -%>

<div class="date">
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/types/_snippet.html.erb
@@ -1,5 +1,5 @@
<%- unless post.header.blank? -%>
<h3 class="entry-title"><%= spanned_link post.header, "/snippets/#{post.permalink}" %></h3>
<h3 class="entry-title"><%= spanned_link post.header, snippet_path(post.permalink) %></h3>
<%- end -%>

<div class="date">
Expand Down
7 changes: 7 additions & 0 deletions test/unit/article_test.rb
Expand Up @@ -52,6 +52,13 @@ def test_should_provide_proper_link
article = posts(:article).becomes(Article)
assert_equal "/articles/#{article.permalink}", article.link
end

def test_should_provide_proper_link_even_for_relative_urls
set_relative_url do
article = posts(:article).becomes(Article)
assert_equal "/relative/articles/#{article.permalink}", article.link
end
end

protected

Expand Down

0 comments on commit 0bba974

Please sign in to comment.