Commit b1d4f13059a48eb6d7f4e79c97410e8d85c1cb3d
1 parent
d9861a69
Exists in
master
and in
29 other branches
ActionItem5: being able to know which profile an article belongs to
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@567 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
26 additions
and
0 deletions
Show diff stats
app/models/article.rb
| ... | ... | @@ -12,4 +12,10 @@ class Article < Comatose::Page |
| 12 | 12 | def has_keyword?(keyword) |
| 13 | 13 | tags.map{|t| t.name.downcase}.include?(keyword.downcase) |
| 14 | 14 | end |
| 15 | + | |
| 16 | + def profile(reload = false) | |
| 17 | + @profile = nil if reload | |
| 18 | + @profile ||= Profile.find_by_identifier(self.full_path.split(/\//).first) | |
| 19 | + end | |
| 20 | + | |
| 15 | 21 | end | ... | ... |
test/unit/article_test.rb
| ... | ... | @@ -16,4 +16,24 @@ class ArticleTest < Test::Unit::TestCase |
| 16 | 16 | assert article.has_keyword?('three') |
| 17 | 17 | end |
| 18 | 18 | |
| 19 | + should 'have an associated profile' do | |
| 20 | + article = Article.new(:title => 'someuser', :body => "some text") | |
| 21 | + article.parent = Comatose::Page.root | |
| 22 | + article.save! | |
| 23 | + | |
| 24 | + Profile.expects(:find_by_identifier).with("someuser") | |
| 25 | + article.profile | |
| 26 | + end | |
| 27 | + | |
| 28 | + should 'get associated profile from name of root page' do | |
| 29 | + article = Article.new(:title => "test article", :body => 'some sample text') | |
| 30 | + article.parent = Article.find_by_path('ze') | |
| 31 | + article.save! | |
| 32 | + | |
| 33 | + assert_equal 'ze/test-article', article.full_path | |
| 34 | + | |
| 35 | + Profile.expects(:find_by_identifier).with("ze") | |
| 36 | + article.profile | |
| 37 | + end | |
| 38 | + | |
| 19 | 39 | end | ... | ... |