Commit fd9ed84e2b1b5b5cb4815143330fee124c27b327
Committed by
Antonio Terceiro
1 parent
737bb9ad
Exists in
master
and in
28 other branches
ActionItem1185: published article handles blanl names
Showing
4 changed files
with
40 additions
and
2 deletions
Show diff stats
app/models/approve_article.rb
@@ -52,7 +52,7 @@ class ApproveArticle < Task | @@ -52,7 +52,7 @@ class ApproveArticle < Task | ||
52 | end | 52 | end |
53 | 53 | ||
54 | def article_parent= value | 54 | def article_parent= value |
55 | - article_parent_id = value.id | 55 | + self.article_parent_id = value.id |
56 | end | 56 | end |
57 | 57 | ||
58 | def highlighted= value | 58 | def highlighted= value |
app/models/published_article.rb
@@ -18,7 +18,7 @@ class PublishedArticle < Article | @@ -18,7 +18,7 @@ class PublishedArticle < Article | ||
18 | 18 | ||
19 | before_validation_on_create :update_name | 19 | before_validation_on_create :update_name |
20 | def update_name | 20 | def update_name |
21 | - self.name ||= self.reference_article.name | 21 | + self.name = self.reference_article.name if self.name.blank? |
22 | end | 22 | end |
23 | 23 | ||
24 | def author | 24 | def author |
test/functional/tasks_controller_test.rb
@@ -203,4 +203,24 @@ class TasksControllerTest < Test::Unit::TestCase | @@ -203,4 +203,24 @@ class TasksControllerTest < Test::Unit::TestCase | ||
203 | assert_not_nil PublishedArticle.find(:first) | 203 | assert_not_nil PublishedArticle.find(:first) |
204 | end | 204 | end |
205 | 205 | ||
206 | + should 'handle blank names for published articles' do | ||
207 | + c = Community.create!(:name => 'test comm') | ||
208 | + @controller.stubs(:profile).returns(c) | ||
209 | + c.affiliate(profile, Profile::Roles.all_roles(c.environment)) | ||
210 | + person = create_user('test_user').person | ||
211 | + p_blog = Blog.create!(:profile => person) | ||
212 | + c_blog1 = Blog.create!(:profile => c) | ||
213 | + c_blog2 = Blog.new(:profile => c); c_blog2.name = 'blog2'; c_blog2.save! | ||
214 | + | ||
215 | + article = person.articles.create!(:name => 'test article', :parent => p_blog) | ||
216 | + a = ApproveArticle.create!(:article => article, :target => c, :requestor => person) | ||
217 | + assert_includes c.tasks, a | ||
218 | + | ||
219 | + assert_difference PublishedArticle, :count do | ||
220 | + post :close, {"commit"=>"Ok!", "id"=> a.id.to_s, "task"=>{"name"=>"", "closing_statment"=>"", "highlighted"=>"0", "article_parent_id"=>c_blog2.id.to_s}, "decision"=>"finish"} | ||
221 | + end | ||
222 | + assert p_article = PublishedArticle.find_by_reference_article_id(article.id) | ||
223 | + assert_includes c_blog2.children(true), p_article | ||
224 | + end | ||
225 | + | ||
206 | end | 226 | end |
test/unit/approve_article_test.rb
@@ -63,4 +63,22 @@ class ApproveArticleTest < ActiveSupport::TestCase | @@ -63,4 +63,22 @@ class ApproveArticleTest < ActiveSupport::TestCase | ||
63 | assert_match /text was removed/, a.description | 63 | assert_match /text was removed/, a.description |
64 | end | 64 | end |
65 | 65 | ||
66 | + should 'preserve article_parent' do | ||
67 | + profile = create_user('test_user').person | ||
68 | + article = profile.articles.create!(:name => 'test article') | ||
69 | + a = ApproveArticle.new(:article_parent => article) | ||
70 | + | ||
71 | + assert_equal article, a.article_parent | ||
72 | + end | ||
73 | + | ||
74 | + should 'handle blank names' do | ||
75 | + profile = create_user('test_user').person | ||
76 | + article = profile.articles.create!(:name => 'test article') | ||
77 | + community = Community.create!(:name => 'test comm') | ||
78 | + a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) | ||
79 | + | ||
80 | + assert_difference PublishedArticle, :count do | ||
81 | + a.finish | ||
82 | + end | ||
83 | + end | ||
66 | end | 84 | end |