Commit 7ea7efc5ed27dfbd47ff8df7e5bd927dd0ed8859

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent cb67a972

making spread from blog to blog

app/models/published_article.rb
1 class PublishedArticle < Article 1 class PublishedArticle < Article
2 belongs_to :reference_article, :class_name => "Article" 2 belongs_to :reference_article, :class_name => "Article"
3 3
  4 + before_create do |article|
  5 + parent = article.reference_article.parent
  6 + if parent && parent.blog? && article.profile.has_blog?
  7 + article.parent = article.profile.blog
  8 + end
  9 + end
  10 +
4 def self.short_description 11 def self.short_description
5 _('Reference to other article') 12 _('Reference to other article')
6 end 13 end
test/unit/blog_test.rb
@@ -90,7 +90,7 @@ class BlogTest &lt; ActiveSupport::TestCase @@ -90,7 +90,7 @@ class BlogTest &lt; ActiveSupport::TestCase
90 90
91 should 'list posts ordered by created at' do 91 should 'list posts ordered by created at' do
92 p = create_user('testusermerda').person 92 p = create_user('testusermerda').person
93 - blog = Blog.create!(:profile => p, :name => 'Blog test', :profile => p) 93 + blog = Blog.create!(:profile => p, :name => 'Blog test')
94 newer = TextileArticle.create!(:name => 'Post 2', :parent => blog, :profile => p) 94 newer = TextileArticle.create!(:name => 'Post 2', :parent => blog, :profile => p)
95 older = TextileArticle.create!(:name => 'Post 1', :parent => blog, :profile => p, :created_at => Time.now - 1.month) 95 older = TextileArticle.create!(:name => 'Post 1', :parent => blog, :profile => p, :created_at => Time.now - 1.month)
96 assert_equal [newer, older], blog.posts 96 assert_equal [newer, older], blog.posts
@@ -98,7 +98,7 @@ class BlogTest &lt; ActiveSupport::TestCase @@ -98,7 +98,7 @@ class BlogTest &lt; ActiveSupport::TestCase
98 98
99 should 'has filter' do 99 should 'has filter' do
100 p = create_user('testusermerda').person 100 p = create_user('testusermerda').person
101 - blog = Blog.create!(:profile => p, :name => 'Blog test', :profile => p) 101 + blog = Blog.create!(:profile => p, :name => 'Blog test')
102 blog.filter = {:param => 'value'} 102 blog.filter = {:param => 'value'}
103 assert_equal 'value', blog.filter[:param] 103 assert_equal 'value', blog.filter[:param]
104 end 104 end
test/unit/published_article_test.rb
@@ -39,4 +39,39 @@ class PublishedArticleTest &lt; ActiveSupport::TestCase @@ -39,4 +39,39 @@ class PublishedArticleTest &lt; ActiveSupport::TestCase
39 39
40 assert_equal @article.name, p.name 40 assert_equal @article.name, p.name
41 end 41 end
  42 +
  43 + should 'not be created in blog if community does not have a blog' do
  44 + parent = mock
  45 + @article.expects(:parent).returns(parent)
  46 + parent.expects(:blog?).returns(true)
  47 + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
  48 + p = PublishedArticle.create!(:reference_article => @article, :profile => prof)
  49 +
  50 + assert !prof.has_blog?
  51 + assert_nil p.parent
  52 + end
  53 +
  54 + should 'be created in community blog if came from a blog' do
  55 + parent = mock
  56 + @article.expects(:parent).returns(parent)
  57 + parent.expects(:blog?).returns(true)
  58 + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
  59 + blog = Blog.create!(:profile => prof, :name => 'Blog test')
  60 + p = PublishedArticle.create!(:reference_article => @article, :profile => prof)
  61 +
  62 + assert_equal p.parent, blog
  63 + end
  64 +
  65 + should 'not be created in community blog if did not come from a blog' do
  66 + parent = mock
  67 + @article.expects(:parent).returns(parent)
  68 + parent.expects(:blog?).returns(false)
  69 + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
  70 + blog = Blog.create!(:profile => prof, :name => 'Blog test')
  71 + p = PublishedArticle.create!(:reference_article => @article, :profile => prof)
  72 +
  73 + assert_nil p.parent
  74 + end
  75 +
  76 +
42 end 77 end