diff --git a/app/models/article.rb b/app/models/article.rb index cf2209c..6549e29 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -66,8 +66,12 @@ class Article < ActiveRecord::Base name end - def public_path - "/" + [profile.identifier, path].join('/') + def public_path(with_profile = true) + elements = [path] + if with_profile + elements.unshift(profile.identifier) + end + "/" + elements.join('/') end def self.short_description @@ -90,4 +94,9 @@ class Article < ActiveRecord::Base self.name.gsub(/article$/i, '') end + include ActionController::UrlWriter + def url + self.profile.url + self.public_path(false) + end + end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index f6087ff..f13ce6a 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -163,7 +163,10 @@ class ArticleTest < Test::Unit::TestCase end should 'provide a url to itself' do - flunk 'pending' + article = profile.articles.build(:name => 'myarticle') + article.save! + + assert_equal(profile.url + "/myarticle", article.url) end end -- libgit2 0.21.2