From a1e84d51a34b63ea1a4f846a0b3efec69b68e57d Mon Sep 17 00:00:00 2001 From: Larissa Reis Date: Thu, 11 Feb 2016 01:11:54 -0300 Subject: [PATCH] suggest_an_article: Fix crash when article type or author are blank --- app/models/suggest_article.rb | 5 ++++- test/functional/tasks_controller_test.rb | 13 +++++++++++++ test/unit/suggest_article_test.rb | 5 +++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/models/suggest_article.rb b/app/models/suggest_article.rb index 38d7df1..a858b83 100644 --- 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 diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index d1fdbc6..947509c 100644 --- 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@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) diff --git a/test/unit/suggest_article_test.rb b/test/unit/suggest_article_test.rb index 892d0a5..6572563 100644 --- 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 -- libgit2 0.21.2