Commit 4c09e30e598a7aabd326fd5a7191d2c56026c0b6
1 parent
1249a774
Exists in
master
and in
29 other branches
ActionItem24: adding description methods on Article
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1125 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
35 additions
and
0 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -70,4 +70,24 @@ class Article < ActiveRecord::Base |
70 | 70 | "/" + [profile.identifier, path].join('/') |
71 | 71 | end |
72 | 72 | |
73 | + def self.short_description | |
74 | + if self == Article | |
75 | + _('Article') | |
76 | + else | |
77 | + _('"%s" article') % self.article_type_name | |
78 | + end | |
79 | + end | |
80 | + | |
81 | + def self.description | |
82 | + if self == Article | |
83 | + _('An ordinary article') | |
84 | + else | |
85 | + _('An article of type "%s"') % self.article_type_name | |
86 | + end | |
87 | + end | |
88 | + | |
89 | + def self.article_type_name | |
90 | + self.name.gsub(/article$/i, '') | |
91 | + end | |
92 | + | |
73 | 93 | end | ... | ... |
test/unit/article_test.rb
... | ... | @@ -143,4 +143,19 @@ class ArticleTest < Test::Unit::TestCase |
143 | 143 | |
144 | 144 | end |
145 | 145 | |
146 | + should 'provied proper descriptions' do | |
147 | + assert_equal "Article", Article.short_description | |
148 | + assert_equal "An ordinary article", Article.description | |
149 | + end | |
150 | + | |
151 | + should 'provide a usable descriptions to subclasses that don\'t override them' do | |
152 | + klass = Class.new(Article) | |
153 | + klass.stubs(:name).returns("MyClass") | |
154 | + klass.expects(:_).with('"%s" article').returns('"%s" article') | |
155 | + klass.expects(:_).with('An article of type "%s"').returns('An article of type "%s"') | |
156 | + | |
157 | + assert_equal '"MyClass" article', klass.short_description | |
158 | + assert_equal 'An article of type "MyClass"', klass.description | |
159 | + end | |
160 | + | |
146 | 161 | end | ... | ... |