Commit 7ea7efc5ed27dfbd47ff8df7e5bd927dd0ed8859
Committed by
Antonio Terceiro
1 parent
cb67a972
Exists in
master
and in
29 other branches
making spread from blog to blog
Showing
3 changed files
with
44 additions
and
2 deletions
Show diff stats
app/models/published_article.rb
1 | 1 | class PublishedArticle < Article |
2 | 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 | 11 | def self.short_description |
5 | 12 | _('Reference to other article') |
6 | 13 | end | ... | ... |
test/unit/blog_test.rb
... | ... | @@ -90,7 +90,7 @@ class BlogTest < ActiveSupport::TestCase |
90 | 90 | |
91 | 91 | should 'list posts ordered by created at' do |
92 | 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 | 94 | newer = TextileArticle.create!(:name => 'Post 2', :parent => blog, :profile => p) |
95 | 95 | older = TextileArticle.create!(:name => 'Post 1', :parent => blog, :profile => p, :created_at => Time.now - 1.month) |
96 | 96 | assert_equal [newer, older], blog.posts |
... | ... | @@ -98,7 +98,7 @@ class BlogTest < ActiveSupport::TestCase |
98 | 98 | |
99 | 99 | should 'has filter' do |
100 | 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 | 102 | blog.filter = {:param => 'value'} |
103 | 103 | assert_equal 'value', blog.filter[:param] |
104 | 104 | end | ... | ... |
test/unit/published_article_test.rb
... | ... | @@ -39,4 +39,39 @@ class PublishedArticleTest < ActiveSupport::TestCase |
39 | 39 | |
40 | 40 | assert_equal @article.name, p.name |
41 | 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 | 77 | end | ... | ... |