Commit 41bbd3c5cb03cf00c5c0f5ef1f4703b6f357d5e3
Committed by
Antonio Terceiro
1 parent
33d03675
Exists in
master
and in
22 other branches
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"
Showing
2 changed files
with
11 additions
and
12 deletions
Show diff stats
app/models/published_article.rb
| ... | ... | @@ -14,10 +14,6 @@ class PublishedArticle < Article |
| 14 | 14 | _('A reference to another article published in another profile') |
| 15 | 15 | end |
| 16 | 16 | |
| 17 | - def body | |
| 18 | - reference_article.body | |
| 19 | - end | |
| 20 | - | |
| 21 | 17 | before_validation_on_create :update_name |
| 22 | 18 | def update_name |
| 23 | 19 | self.name ||= self.reference_article.name |
| ... | ... | @@ -32,6 +28,6 @@ class PublishedArticle < Article |
| 32 | 28 | end |
| 33 | 29 | |
| 34 | 30 | def to_html(options={}) |
| 35 | - reference_article.to_html | |
| 31 | + reference_article ? reference_article.to_html : _('Original text was removed.') | |
| 36 | 32 | end |
| 37 | 33 | end | ... | ... |
test/unit/published_article_test.rb
| ... | ... | @@ -17,13 +17,6 @@ class PublishedArticleTest < ActiveSupport::TestCase |
| 17 | 17 | assert_equal @article, p.reference_article |
| 18 | 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 | 20 | should 'have a different name than reference article' do |
| 28 | 21 | prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') |
| 29 | 22 | p = PublishedArticle.create(:reference_article => @article, :profile => prof, :name => 'other title') |
| ... | ... | @@ -107,4 +100,14 @@ class PublishedArticleTest < ActiveSupport::TestCase |
| 107 | 100 | |
| 108 | 101 | assert_equal textile_article.to_html, p.to_html |
| 109 | 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 | 113 | end | ... | ... |