From 7ea7efc5ed27dfbd47ff8df7e5bd927dd0ed8859 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Fri, 13 Mar 2009 19:50:37 -0300 Subject: [PATCH] making spread from blog to blog --- app/models/published_article.rb | 7 +++++++ test/unit/blog_test.rb | 4 ++-- test/unit/published_article_test.rb | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/models/published_article.rb b/app/models/published_article.rb index 3363c82..d0f8325 100644 --- a/app/models/published_article.rb +++ b/app/models/published_article.rb @@ -1,6 +1,13 @@ class PublishedArticle < Article belongs_to :reference_article, :class_name => "Article" + before_create do |article| + parent = article.reference_article.parent + if parent && parent.blog? && article.profile.has_blog? + article.parent = article.profile.blog + end + end + def self.short_description _('Reference to other article') end diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb index d13e0ec..9ff34a6 100644 --- a/test/unit/blog_test.rb +++ b/test/unit/blog_test.rb @@ -90,7 +90,7 @@ class BlogTest < ActiveSupport::TestCase should 'list posts ordered by created at' do p = create_user('testusermerda').person - blog = Blog.create!(:profile => p, :name => 'Blog test', :profile => p) + blog = Blog.create!(:profile => p, :name => 'Blog test') newer = TextileArticle.create!(:name => 'Post 2', :parent => blog, :profile => p) older = TextileArticle.create!(:name => 'Post 1', :parent => blog, :profile => p, :created_at => Time.now - 1.month) assert_equal [newer, older], blog.posts @@ -98,7 +98,7 @@ class BlogTest < ActiveSupport::TestCase should 'has filter' do p = create_user('testusermerda').person - blog = Blog.create!(:profile => p, :name => 'Blog test', :profile => p) + blog = Blog.create!(:profile => p, :name => 'Blog test') blog.filter = {:param => 'value'} assert_equal 'value', blog.filter[:param] end diff --git a/test/unit/published_article_test.rb b/test/unit/published_article_test.rb index 474a060..70ee5de 100644 --- a/test/unit/published_article_test.rb +++ b/test/unit/published_article_test.rb @@ -39,4 +39,39 @@ class PublishedArticleTest < ActiveSupport::TestCase assert_equal @article.name, p.name end + + should 'not be created in blog if community does not have a blog' do + parent = mock + @article.expects(:parent).returns(parent) + parent.expects(:blog?).returns(true) + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + p = PublishedArticle.create!(:reference_article => @article, :profile => prof) + + assert !prof.has_blog? + assert_nil p.parent + end + + should 'be created in community blog if came from a blog' do + parent = mock + @article.expects(:parent).returns(parent) + parent.expects(:blog?).returns(true) + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + blog = Blog.create!(:profile => prof, :name => 'Blog test') + p = PublishedArticle.create!(:reference_article => @article, :profile => prof) + + assert_equal p.parent, blog + end + + should 'not be created in community blog if did not come from a blog' do + parent = mock + @article.expects(:parent).returns(parent) + parent.expects(:blog?).returns(false) + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + blog = Blog.create!(:profile => prof, :name => 'Blog test') + p = PublishedArticle.create!(:reference_article => @article, :profile => prof) + + assert_nil p.parent + end + + end -- libgit2 0.21.2