From 41bbd3c5cb03cf00c5c0f5ef1f4703b6f357d5e3 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Tue, 7 Jul 2009 15:35:24 -0300 Subject: [PATCH] ActionItem1155: removal of reference article should not crash published article --- app/models/published_article.rb | 6 +----- test/unit/published_article_test.rb | 17 ++++++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/models/published_article.rb b/app/models/published_article.rb index 7b3ffbd..c891a63 100644 --- a/app/models/published_article.rb +++ b/app/models/published_article.rb @@ -14,10 +14,6 @@ class PublishedArticle < Article _('A reference to another article published in another profile') end - def body - reference_article.body - end - before_validation_on_create :update_name def update_name self.name ||= self.reference_article.name @@ -32,6 +28,6 @@ class PublishedArticle < Article end def to_html(options={}) - reference_article.to_html + reference_article ? reference_article.to_html : _('Original text was removed.') end end diff --git a/test/unit/published_article_test.rb b/test/unit/published_article_test.rb index f2e3852..3642cf0 100644 --- a/test/unit/published_article_test.rb +++ b/test/unit/published_article_test.rb @@ -17,13 +17,6 @@ class PublishedArticleTest < ActiveSupport::TestCase assert_equal @article, p.reference_article end - should 'have same content as reference article' do - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') - p = PublishedArticle.create(:reference_article => @article, :profile => prof) - - assert_equal @article.body, p.body - end - should 'have a different name than reference article' do prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') p = PublishedArticle.create(:reference_article => @article, :profile => prof, :name => 'other title') @@ -107,4 +100,14 @@ class PublishedArticleTest < ActiveSupport::TestCase assert_equal textile_article.to_html, p.to_html end + + should 'display message when reference_article does not exist' do + prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + textile_article = TextileArticle.new(:name => 'textile_article', :body => '*my text*', :profile => prof) + p = PublishedArticle.create!(:reference_article => textile_article, :profile => prof) + textile_article.destroy + p.reload + + assert_match /removed/, p.to_html + end end -- libgit2 0.21.2