Commit ee2b501a2e2bf2f58d2fa3475a13cde8b27df9b5

Authored by Antonio Terceiro
2 parents 6a203a5b a1e84d51

Merge branch 'suggest-article-crash' into 'master'

Fixes crash when processing suggest an article task

- Removes an old line that was left behind during merge of support for
  different types of article. It was overriding the correct decision
  made by #article_type.
- Defines SuggestArticle#author_name the same as the sender so
  noosfero task page doesn't crash in case the processing of the task
  throws an error, since it will try to show the author name in the
  task error page.

  Fixes #166

See merge request !786
app/models/suggest_article.rb
... ... @@ -23,6 +23,10 @@ class SuggestArticle < Task
23 23 requestor ? "#{requestor.name}" : "#{name} (#{email})"
24 24 end
25 25  
  26 + def author_name
  27 + sender
  28 + end
  29 +
26 30 def article_object
27 31 if @article_object.nil?
28 32 @article_object = article_type.new(article.merge(target.present? ? {:profile => target} : {}).except(:type))
... ... @@ -41,7 +45,6 @@ class SuggestArticle < Task
41 45 return type if type < Article
42 46 end
43 47 TinyMceArticle
44   - (article[:type] || 'TinyMceArticle').constantize
45 48 end
46 49  
47 50 def perform
... ...
test/functional/tasks_controller_test.rb
... ... @@ -329,6 +329,19 @@ class TasksControllerTest &lt; ActionController::TestCase
329 329 assert_select "#tasks_#{t.id}_task_name"
330 330 end
331 331  
  332 + should "not crash when article suggestion task fails" do
  333 + TinyMceArticle.destroy_all
  334 + c = fast_create(Community)
  335 + c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
  336 + @controller.stubs(:profile).returns(c)
  337 + t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body'}, :name => 'some name', :email => 'test@localhost.com', :target => c)
  338 +
  339 + SuggestArticle.any_instance.stubs(:perform).raises('erro')
  340 + assert_nothing_raised do
  341 + post :close, :tasks => {t.id => { :task => {}, :decision => "finish"}}
  342 + end
  343 + end
  344 +
332 345 should "append hidden tag with type value from article suggestion" do
333 346 Task.destroy_all
334 347 c = fast_create(Community)
... ...
test/unit/suggest_article_test.rb
... ... @@ -242,4 +242,9 @@ class SuggestArticleTest &lt; ActiveSupport::TestCase
242 242 t.article_type == TinyMceArticle
243 243 end
244 244  
  245 + should 'fallback to tinymce when type parameter is blank' do
  246 + t = SuggestArticle.new
  247 + t.article = {:name => 'name', :body => 'body', :type => ''}
  248 + t.article_type == TinyMceArticle
  249 + end
245 250 end
... ...