Commit 41bbd3c5cb03cf00c5c0f5ef1f4703b6f357d5e3

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 33d03675

ActionItem1155: removal of reference article should not crash published article

When the reference article of a published article is deleted, the published articles will display "Original text was removed"
app/models/published_article.rb
@@ -14,10 +14,6 @@ class PublishedArticle < Article @@ -14,10 +14,6 @@ class PublishedArticle < Article
14 _('A reference to another article published in another profile') 14 _('A reference to another article published in another profile')
15 end 15 end
16 16
17 - def body  
18 - reference_article.body  
19 - end  
20 -  
21 before_validation_on_create :update_name 17 before_validation_on_create :update_name
22 def update_name 18 def update_name
23 self.name ||= self.reference_article.name 19 self.name ||= self.reference_article.name
@@ -32,6 +28,6 @@ class PublishedArticle < Article @@ -32,6 +28,6 @@ class PublishedArticle < Article
32 end 28 end
33 29
34 def to_html(options={}) 30 def to_html(options={})
35 - reference_article.to_html 31 + reference_article ? reference_article.to_html : _('Original text was removed.')
36 end 32 end
37 end 33 end
test/unit/published_article_test.rb
@@ -17,13 +17,6 @@ class PublishedArticleTest < ActiveSupport::TestCase @@ -17,13 +17,6 @@ class PublishedArticleTest < ActiveSupport::TestCase
17 assert_equal @article, p.reference_article 17 assert_equal @article, p.reference_article
18 end 18 end
19 19
20 - should 'have same content as reference article' do  
21 - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')  
22 - p = PublishedArticle.create(:reference_article => @article, :profile => prof)  
23 -  
24 - assert_equal @article.body, p.body  
25 - end  
26 -  
27 should 'have a different name than reference article' do 20 should 'have a different name than reference article' do
28 prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') 21 prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
29 p = PublishedArticle.create(:reference_article => @article, :profile => prof, :name => 'other title') 22 p = PublishedArticle.create(:reference_article => @article, :profile => prof, :name => 'other title')
@@ -107,4 +100,14 @@ class PublishedArticleTest < ActiveSupport::TestCase @@ -107,4 +100,14 @@ class PublishedArticleTest < ActiveSupport::TestCase
107 100
108 assert_equal textile_article.to_html, p.to_html 101 assert_equal textile_article.to_html, p.to_html
109 end 102 end
  103 +
  104 + should 'display message when reference_article does not exist' do
  105 + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm')
  106 + textile_article = TextileArticle.new(:name => 'textile_article', :body => '*my text*', :profile => prof)
  107 + p = PublishedArticle.create!(:reference_article => textile_article, :profile => prof)
  108 + textile_article.destroy
  109 + p.reload
  110 +
  111 + assert_match /removed/, p.to_html
  112 + end
110 end 113 end