Commit fb7ddece50f690b437b2a22474003dcdc8d3695d

Authored by Larissa Reis
1 parent b853d6c3

[publish] Fixes last cucumber tests

  Now all tests pass.

  A couple aditional changes:
    - Replacing flash notice for session notice;
    - Cancel a task if it fails. A task can fail for many reasons,
    including for validation, so I thought it would make sense to cancel
    a task to publish an article if it fails. For example if the title
    is too big validation will fail, the task will fail and the user
    will get a message saying publish request couldn't be sent, so
    naturally the user will try to publish again, hopefully this time
    succeding.
Showing 1 changed file with 9 additions and 3 deletions   Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -274,6 +274,7 @@ class CmsController < MyProfileController @@ -274,6 +274,7 @@ class CmsController < MyProfileController
274 task.finish 274 task.finish
275 rescue Exception => ex 275 rescue Exception => ex
276 @failed[ex.message] ? @failed[ex.message] << @article.name : @failed[ex.message] = [@article.name] 276 @failed[ex.message] ? @failed[ex.message] << @article.name : @failed[ex.message] = [@article.name]
  277 + task.cancel
277 end 278 end
278 if @failed.blank? 279 if @failed.blank?
279 session[:notice] = _("Your publish request was sent successfully") 280 session[:notice] = _("Your publish request was sent successfully")
@@ -304,6 +305,7 @@ class CmsController &lt; MyProfileController @@ -304,6 +305,7 @@ class CmsController &lt; MyProfileController
304 task.finish unless item.moderated_articles? 305 task.finish unless item.moderated_articles?
305 rescue Exception => ex 306 rescue Exception => ex
306 @failed[ex.message] ? @failed[ex.message] << item.name : @failed[ex.message] = [item.name] 307 @failed[ex.message] ? @failed[ex.message] << item.name : @failed[ex.message] = [item.name]
  308 + task.cancel
307 end 309 end
308 end 310 end
309 if @failed.blank? 311 if @failed.blank?
@@ -313,6 +315,9 @@ class CmsController &lt; MyProfileController @@ -313,6 +315,9 @@ class CmsController &lt; MyProfileController
313 else 315 else
314 redirect_to @article.view_url 316 redirect_to @article.view_url
315 end 317 end
  318 + else
  319 + session[:notice] = _("Some of your publish requests couldn't be sent.")
  320 + render :action => 'publish'
316 end 321 end
317 end 322 end
318 end 323 end
@@ -324,12 +329,13 @@ class CmsController &lt; MyProfileController @@ -324,12 +329,13 @@ class CmsController &lt; MyProfileController
324 task = ApproveArticle.create!(:article => @article, :name => params[:name], :target => environment.portal_community, :requestor => user) 329 task = ApproveArticle.create!(:article => @article, :name => params[:name], :target => environment.portal_community, :requestor => user)
325 begin 330 begin
326 task.finish unless environment.portal_community.moderated_articles? 331 task.finish unless environment.portal_community.moderated_articles?
327 - flash[:notice] = _("Your publish request was sent successfully") 332 + session[:notice] = _("Your publish request was sent successfully")
328 rescue 333 rescue
329 - flash[:error] = _("Your publish request couldn't be sent.") 334 + session[:notice] = _("Your publish request couldn't be sent.")
  335 + task.cancel
330 end 336 end
331 else 337 else
332 - flash[:notice] = _("There is no portal community to publish your article.") 338 + session[:notice] = _("There is no portal community to publish your article.")
333 end 339 end
334 340
335 if @back_to 341 if @back_to