Gestion des états dans le post des commentaires

This commit is contained in:
Xavier J 2015-09-25 10:46:09 +02:00
parent 92d5fb4cf3
commit 805dd49737
4 changed files with 47 additions and 4 deletions

View file

@ -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?

View file

@ -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`.

View file

@ -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

View file

@ -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