From b1d4f13059a48eb6d7f4e79c97410e8d85c1cb3d Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 26 Sep 2007 20:34:59 +0000 Subject: [PATCH] ActionItem5: being able to know which profile an article belongs to --- app/models/article.rb | 6 ++++++ test/unit/article_test.rb | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/app/models/article.rb b/app/models/article.rb index 9561876..737eb84 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -12,4 +12,10 @@ class Article < Comatose::Page def has_keyword?(keyword) tags.map{|t| t.name.downcase}.include?(keyword.downcase) end + + def profile(reload = false) + @profile = nil if reload + @profile ||= Profile.find_by_identifier(self.full_path.split(/\//).first) + end + end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 9e0db70..c8d1c66 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -16,4 +16,24 @@ class ArticleTest < Test::Unit::TestCase assert article.has_keyword?('three') end + should 'have an associated profile' do + article = Article.new(:title => 'someuser', :body => "some text") + article.parent = Comatose::Page.root + article.save! + + Profile.expects(:find_by_identifier).with("someuser") + article.profile + end + + should 'get associated profile from name of root page' do + article = Article.new(:title => "test article", :body => 'some sample text') + article.parent = Article.find_by_path('ze') + article.save! + + assert_equal 'ze/test-article', article.full_path + + Profile.expects(:find_by_identifier).with("ze") + article.profile + end + end -- libgit2 0.21.2