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 274 task.finish
275 275 rescue Exception => ex
276 276 @failed[ex.message] ? @failed[ex.message] << @article.name : @failed[ex.message] = [@article.name]
  277 + task.cancel
277 278 end
278 279 if @failed.blank?
279 280 session[:notice] = _("Your publish request was sent successfully")
... ... @@ -304,6 +305,7 @@ class CmsController &lt; MyProfileController
304 305 task.finish unless item.moderated_articles?
305 306 rescue Exception => ex
306 307 @failed[ex.message] ? @failed[ex.message] << item.name : @failed[ex.message] = [item.name]
  308 + task.cancel
307 309 end
308 310 end
309 311 if @failed.blank?
... ... @@ -313,6 +315,9 @@ class CmsController &lt; MyProfileController
313 315 else
314 316 redirect_to @article.view_url
315 317 end
  318 + else
  319 + session[:notice] = _("Some of your publish requests couldn't be sent.")
  320 + render :action => 'publish'
316 321 end
317 322 end
318 323 end
... ... @@ -324,12 +329,13 @@ class CmsController &lt; MyProfileController
324 329 task = ApproveArticle.create!(:article => @article, :name => params[:name], :target => environment.portal_community, :requestor => user)
325 330 begin
326 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 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 336 end
331 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 339 end
334 340  
335 341 if @back_to
... ...