From 805dd4973761b2c2f5ccae327359052effd822c7 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Fri, 25 Sep 2015 10:46:09 +0200 Subject: [PATCH] =?UTF-8?q?Gestion=20des=20=C3=A9tats=20dans=20le=20post?= =?UTF-8?q?=20des=20commentaires?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commentaires_controller.rb | 11 ++++++++-- config/deploy.rb | 2 +- .../commentaires_controller_spec.rb | 18 +++++++++++++++++ .../commentaires_controller_spec.rb | 20 ++++++++++++++++++- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/controllers/commentaires_controller.rb b/app/controllers/commentaires_controller.rb index cbaf6c678..00e0d81ab 100644 --- a/app/controllers/commentaires_controller.rb +++ b/app/controllers/commentaires_controller.rb @@ -1,10 +1,17 @@ class CommentairesController < ApplicationController def create @commentaire = Commentaire.new - @commentaire.email = params['email_commentaire'] - @commentaire.body = params['texte_commentaire'] @commentaire.dossier = Dossier.find(params['dossier_id']) + if is_gestionnaire? + @commentaire.email = current_gestionnaire.email + @commentaire.dossier.next_step! 'gestionnaire', 'comment' + else #is_user + @commentaire.email = current_user.email + @commentaire.dossier.next_step! 'user', 'comment' + end + + @commentaire.body = params['texte_commentaire'] @commentaire.save if is_gestionnaire? diff --git a/config/deploy.rb b/config/deploy.rb index 3da98d51e..57ce33cd7 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -76,7 +76,7 @@ set :rbenv_path, "/usr/local/rbenv/bin/rbenv" # Optional settings: # set :user, 'foobar' # Username in the server to SSH to. # set :port, '30000' # SSH port number. -# set :forward_agent, true # SSH forward_agent. + set :forward_agent, true # SSH forward_agent. # This task is the environment that is loaded for most commands, such as # `mina deploy` or `mina rake`. diff --git a/spec/controllers/backoffice/commentaires_controller_spec.rb b/spec/controllers/backoffice/commentaires_controller_spec.rb index 5fe9d900a..7cb2a4017 100644 --- a/spec/controllers/backoffice/commentaires_controller_spec.rb +++ b/spec/controllers/backoffice/commentaires_controller_spec.rb @@ -16,5 +16,23 @@ describe Backoffice::CommentairesController, type: :controller do expect(response).to redirect_to("/backoffice/dossiers/#{dossier_id}") end end + + describe 'change dossier state after post a comment' do + context 'gestionnaire is connected' do + context 'when dossier is at state updated' do + before do + sign_in create(:gestionnaire) + dossier.updated! + + post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire + dossier.reload + end + + subject { dossier.state } + + it {is_expected.to eq('reply')} + end + end + end end end diff --git a/spec/controllers/commentaires_controller_spec.rb b/spec/controllers/commentaires_controller_spec.rb index 3ba3d8dd0..9e120d3ed 100644 --- a/spec/controllers/commentaires_controller_spec.rb +++ b/spec/controllers/commentaires_controller_spec.rb @@ -10,9 +10,27 @@ describe Users::CommentairesController, type: :controller do context 'création correct d\'un commentaire' do it 'depuis la page récapitulatif' do sign_in dossier.user - post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire + post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif") end end + + describe 'change dossier state after post a comment' do + context 'when user is connected' do + context 'when dossier is at state reply' do + before do + sign_in dossier.user + dossier.reply! + + post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire + dossier.reload + end + + subject { dossier.state } + + it {is_expected.to eq('updated')} + end + end + end end end