From b55cda261bed13d84803aafbcf598734643e5235 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 30 Nov 2007 14:52:33 +0000 Subject: [PATCH] ActionItem21: to display the public path of the article --- app/models/article.rb | 4 ++++ test/unit/article_test.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index f2ac2c9..91e4bae 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -45,4 +45,8 @@ class Article < ActiveRecord::Base name end + def public_path + "/" + [profile.identifier, path].join('/') + end + end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 259c883..e60002c 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -104,4 +104,17 @@ class ArticleTest < Test::Unit::TestCase assert a4.errors.invalid?(:slug) end + should 'calculate public path' do + # top level + a = profile.articles.build(:name => 'aaa') + a.save! + assert_equal "/#{profile.identifier}/aaa", a.public_path + + # child articles + b = profile.articles.build(:name => 'bbb') + b.parent = a + b.save! + assert_equal "/#{profile.identifier}/aaa/bbb", b.public_path + end + end -- libgit2 0.21.2