[Git][noosfero/noosfero][master] 2 commits: suggest_an_article: Fix crash when article type or author are blank

Antonio Terceiro gitlab at mg.gitlab.com
Thu Feb 11 14:38:07 BRST 2016


Antonio Terceiro pushed to branch master at Noosfero / noosfero


Commits:
a1e84d51 by Larissa Reis at 2016-02-11T01:20:56-03:00
suggest_an_article: Fix crash when article type or author are blank

  - 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

- - - - -
ee2b501a by Antonio Terceiro at 2016-02-11T16:37:53+00:00
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
- - - - -


3 changed files:

- app/models/suggest_article.rb
- test/functional/tasks_controller_test.rb
- test/unit/suggest_article_test.rb


Changes:

=====================================
app/models/suggest_article.rb
=====================================
--- a/app/models/suggest_article.rb
+++ b/app/models/suggest_article.rb
@@ -23,6 +23,10 @@ class SuggestArticle < Task
     requestor ? "#{requestor.name}" : "#{name} (#{email})"
   end
 
+  def author_name
+    sender
+  end
+
   def article_object
     if @article_object.nil?
       @article_object = article_type.new(article.merge(target.present? ? {:profile => target} : {}).except(:type))
@@ -41,7 +45,6 @@ class SuggestArticle < Task
       return type if type < Article
     end
     TinyMceArticle
-    (article[:type] || 'TinyMceArticle').constantize
   end
 
   def perform


=====================================
test/functional/tasks_controller_test.rb
=====================================
--- a/test/functional/tasks_controller_test.rb
+++ b/test/functional/tasks_controller_test.rb
@@ -329,6 +329,19 @@ class TasksControllerTest < ActionController::TestCase
     assert_select "#tasks_#{t.id}_task_name"
   end
 
+  should "not crash when article suggestion task fails" do
+    TinyMceArticle.destroy_all
+    c = fast_create(Community)
+    c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id))
+    @controller.stubs(:profile).returns(c)
+    t = SuggestArticle.create!(:article => {:name => 'test name', :abstract => 'test abstract', :body => 'test body'}, :name => 'some name', :email => 'test at localhost.com', :target => c)
+
+    SuggestArticle.any_instance.stubs(:perform).raises('erro')
+    assert_nothing_raised do
+      post :close, :tasks => {t.id => { :task => {}, :decision => "finish"}}
+    end
+  end
+
   should "append hidden tag with type value from article suggestion" do
     Task.destroy_all
     c = fast_create(Community)


=====================================
test/unit/suggest_article_test.rb
=====================================
--- a/test/unit/suggest_article_test.rb
+++ b/test/unit/suggest_article_test.rb
@@ -242,4 +242,9 @@ class SuggestArticleTest < ActiveSupport::TestCase
     t.article_type == TinyMceArticle
   end
 
+  should 'fallback to tinymce when type parameter is blank' do
+    t = SuggestArticle.new
+    t.article = {:name => 'name', :body => 'body', :type => ''}
+    t.article_type == TinyMceArticle
+  end
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/6a203a5b8efc263db1961593280c8f775f20bbeb...ee2b501a2e2bf2f58d2fa3475a13cde8b27df9b5
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160211/68b79508/attachment.html>


More information about the Noosfero-dev mailing list