Commit b9b5f4ece2968bb07b9fb62f05ef0d1089428dbf
1 parent
8c31058b
Exists in
master
and in
29 other branches
ActionItem23: implementing url method in article
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1141 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
15 additions
and
3 deletions
Show diff stats
app/models/article.rb
@@ -66,8 +66,12 @@ class Article < ActiveRecord::Base | @@ -66,8 +66,12 @@ class Article < ActiveRecord::Base | ||
66 | name | 66 | name |
67 | end | 67 | end |
68 | 68 | ||
69 | - def public_path | ||
70 | - "/" + [profile.identifier, path].join('/') | 69 | + def public_path(with_profile = true) |
70 | + elements = [path] | ||
71 | + if with_profile | ||
72 | + elements.unshift(profile.identifier) | ||
73 | + end | ||
74 | + "/" + elements.join('/') | ||
71 | end | 75 | end |
72 | 76 | ||
73 | def self.short_description | 77 | def self.short_description |
@@ -90,4 +94,9 @@ class Article < ActiveRecord::Base | @@ -90,4 +94,9 @@ class Article < ActiveRecord::Base | ||
90 | self.name.gsub(/article$/i, '') | 94 | self.name.gsub(/article$/i, '') |
91 | end | 95 | end |
92 | 96 | ||
97 | + include ActionController::UrlWriter | ||
98 | + def url | ||
99 | + self.profile.url + self.public_path(false) | ||
100 | + end | ||
101 | + | ||
93 | end | 102 | end |
test/unit/article_test.rb
@@ -163,7 +163,10 @@ class ArticleTest < Test::Unit::TestCase | @@ -163,7 +163,10 @@ class ArticleTest < Test::Unit::TestCase | ||
163 | end | 163 | end |
164 | 164 | ||
165 | should 'provide a url to itself' do | 165 | should 'provide a url to itself' do |
166 | - flunk 'pending' | 166 | + article = profile.articles.build(:name => 'myarticle') |
167 | + article.save! | ||
168 | + | ||
169 | + assert_equal(profile.url + "/myarticle", article.url) | ||
167 | end | 170 | end |
168 | 171 | ||
169 | end | 172 | end |