diff --git a/app/controllers/admin/dossier_controller.rb b/app/controllers/admin/dossier_controller.rb index 7cdbd4b99..4068204a2 100644 --- a/app/controllers/admin/dossier_controller.rb +++ b/app/controllers/admin/dossier_controller.rb @@ -1,5 +1,5 @@ class Admin::DossierController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_gestionnaire! def show @dossier = Dossier.find(params[:dossier_id]) @@ -8,7 +8,7 @@ class Admin::DossierController < ApplicationController @pieces_justificatives = @dossier.pieces_justificatives @commentaires = @dossier.commentaires.order(created_at: :desc) @commentaires = @commentaires.all.decorate - @commentaire_email = current_user.email + @commentaire_email = current_gestionnaire.email @procedure = @dossier.procedure diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 04911a66b..ada1fa39f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,20 +3,21 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - before_action :store_location + # before_action :store_location - def store_location - unless params[:controller] == 'devise/sessions' - url = "/admin/dossiers/#{params[:dossier_id]}" - session[:user_return_to] = url - end - end + # def store_location + # unless params[:controller] == 'devise/sessions' + # url = "/admin/dossiers/#{params[:dossier_id]}" + # session[:user_return_to] = url + # end + # end - def stored_location_for(resource_or_scope) - session[:user_return_to] || super - end + # def stored_location_for(resource_or_scope) + # session[:user_return_to] || super + # end - def after_sign_in_path_for(resource) - stored_location_for(resource) || root_path - end + # def after_sign_in_path_for(resource) + # puts "========================= coucou #{resource}" + # stored_location_for(resource) || root_path + # end end diff --git a/app/controllers/backoffice_controller.rb b/app/controllers/backoffice_controller.rb new file mode 100644 index 000000000..77a827ac2 --- /dev/null +++ b/app/controllers/backoffice_controller.rb @@ -0,0 +1,7 @@ +class BackofficeController < ApplicationController + + def index + redirect_to(controller: '/gestionnaires/sessions', action: :new) unless gestionnaire_signed_in? + end + +end \ No newline at end of file diff --git a/app/controllers/gestionnaires/sessions_controller.rb b/app/controllers/gestionnaires/sessions_controller.rb new file mode 100644 index 000000000..ccb884a45 --- /dev/null +++ b/app/controllers/gestionnaires/sessions_controller.rb @@ -0,0 +1,16 @@ +class Gestionnaires::SessionsController < Devise::SessionsController + + + def new + @gestionnaire = Gestionnaire.new + end + + def create + super + end + + def after_sign_in_path_for(resource) + # stored_location_for(resource) || + backoffice_path + end +end diff --git a/app/controllers/pros/sessions_controller.rb b/app/controllers/pros/sessions_controller.rb deleted file mode 100644 index 9cdbc9306..000000000 --- a/app/controllers/pros/sessions_controller.rb +++ /dev/null @@ -1,25 +0,0 @@ -class Pros::SessionsController < Devise::SessionsController - # before_filter :configure_sign_in_params, only: [:create] - - # GET /resource/sign_in - def new - super - end - - # POST /resource/sign_in - def create - super - end - - # DELETE /resource/sign_out - # def destroy - # super - # end - - # protected - - # You can put the params you want to permit in the empty array. - # def configure_sign_in_params - # devise_parameter_sanitizer.for(:sign_in) << :attribute - # end -end diff --git a/app/controllers/user/custom_failure.rb b/app/controllers/user/custom_failure.rb index 695a33df3..5c4ded176 100644 --- a/app/controllers/user/custom_failure.rb +++ b/app/controllers/user/custom_failure.rb @@ -1,14 +1,3 @@ class User::CustomFailure < Devise::FailureApp - def redirect_url - url_for(controller: '/start', action: :index) - end - # You need to override respond to eliminate recall - def respond - if http_auth? - http_auth - else - redirect - end - end end diff --git a/app/controllers/user/sessions_controller.rb b/app/controllers/user/sessions_controller.rb index fe29d41cb..c902fe751 100644 --- a/app/controllers/user/sessions_controller.rb +++ b/app/controllers/user/sessions_controller.rb @@ -1,25 +1,3 @@ class User::SessionsController < Devise::SessionsController - # before_filter :configure_sign_in_params, only: [:create] - # GET /resource/sign_in - def new - redirect_to url_for(controller: '/start', action: :error_login) - end - - # POST /resource/sign_in - def create - super - end - - # DELETE /resource/sign_out - def destroy - super - end - - # protected - - # You can put the params you want to permit in the empty array. - # def configure_sign_in_params - # devise_parameter_sanitizer.for(:sign_in) << :attribute - # end end diff --git a/app/models/gestionnaire.rb b/app/models/gestionnaire.rb new file mode 100644 index 000000000..4e9feccc1 --- /dev/null +++ b/app/models/gestionnaire.rb @@ -0,0 +1,6 @@ +class Gestionnaire < ActiveRecord::Base + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable +end diff --git a/app/views/backoffice/index.html.haml b/app/views/backoffice/index.html.haml new file mode 100644 index 000000000..3f08ead4e --- /dev/null +++ b/app/views/backoffice/index.html.haml @@ -0,0 +1,14 @@ +#backoffice + + + %table.table + %thead + %th Procédure + %th Dossier + %th etat + %th Date de mise à jour + %row + %td Demande de subventions + %td dossier n°34 Demande de subvention + %td Mise à jour + %td 24/12/2015 \ No newline at end of file diff --git a/app/views/gestionnaires/sessions/new.html.haml b/app/views/gestionnaires/sessions/new.html.haml new file mode 100644 index 000000000..553d80524 --- /dev/null +++ b/app/views/gestionnaires/sessions/new.html.haml @@ -0,0 +1,10 @@ +%h1 Bienvenue sur TPS +%br +#gestionnaire_login + = form_for @gestionnaire, url: {controller: 'gestionnaires/sessions', action: :create } do |f| + .form-group-lg + .form-group + = f.text_field :email, class: 'form-control', placeholder: 'Email' + .form-group + = f.password_field :password, class: 'form-control', placeholder: 'Mot de passe' + = f.submit 'Se connecter', class: %w(btn btn-lg btn-success), data: { disable_with: 'Connexion', submit: true } \ No newline at end of file diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 97199aa8f..445c8b63a 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -13,10 +13,10 @@ %a{href: '/', class:'btn btn-lg'} ='TPS' - -if user_signed_in? + -if gestionnaire_signed_in? %div{style: 'decorate:none; box-shadow:none; float:right; margin-top:8px'} - = current_user.email - = link_to "Déconnexion", '/logout', method: :delete, :class => 'btn btn-md' + = current_gestionnaire.email + = link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md' #flash_message.center - if flash.notice diff --git a/app/views/start/_admin.html.haml b/app/views/start/_admin.html.haml index 3da917b40..10a86bcc6 100644 --- a/app/views/start/_admin.html.haml +++ b/app/views/start/_admin.html.haml @@ -1,24 +1,24 @@ -%p.lead{id: 'admin_section'} - %span{class:'text-info', style:'font-weight:bold'} - -if user_signed_in? - ='Vous êtes identifié comme une administration' - -else - ='Si vous êtes une administration, ' +/ %p.lead{id: 'admin_section'} +/ %span{class:'text-info', style:'font-weight:bold'} +/ -if user_signed_in? +/ ='Vous êtes identifié comme une administration' +/ -else +/ ='Si vous êtes une administration, ' - %p.lead - -if user_signed_in? - = form_tag(url_for({controller: 'admin/dossier', action: :index}), class: 'form-inline', method: 'GET') do - .form-group.form-group-lg - = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id" - %br - = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true} - -else - = form_tag(url_for({controller: 'user/sessions', action: :create}), class: 'form-inline', method: 'POST') do - .form-group.form-group-lg - = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Identifiant", :id => "user_email", :name => "user[email]" - %br - = password_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Mot de passe", :id => "user_password", :name => "user[password]" - %br - = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id" - %br - = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true} +/ %p.lead +/ -if user_signed_in? +/ = form_tag(url_for({controller: 'admin/dossier', action: :index}), class: 'form-inline', method: 'GET') do +/ .form-group.form-group-lg +/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id" +/ %br +/ = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true} +/ -else +/ = form_tag(url_for({controller: 'user/sessions', action: :create}), class: 'form-inline', method: 'POST') do +/ .form-group.form-group-lg +/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Identifiant", :id => "user_email", :name => "user[email]" +/ %br +/ = password_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "Mot de passe", :id => "user_password", :name => "user[password]" +/ %br +/ = text_field_tag :siret, nil, :class => "form-control", :style => 'margin-bottom:10px', :placeholder => "N° de dossier", :id => "dossier_id", :name => "dossier_id" +/ %br +/ = submit_tag "Accéder", class: %w(btn btn-lg btn-success), style: 'margin-top:20px;', data: { disable_with: "Accéder", submit: true} diff --git a/app/views/start/index.html.haml b/app/views/start/index.html.haml index 15bb0de56..fe9aa62d7 100644 --- a/app/views/start/index.html.haml +++ b/app/views/start/index.html.haml @@ -3,5 +3,7 @@ %br %p{style: 'width:67%; margin-left:auto; margin-right:auto'} Site de démonstration d’un service public de saisie d’un projet ou de dépôt d’une démarche administrative, auprès d’un ou plusieurs organismes publics, simplifié des informations déjà connues des administrations, grâce à la fourniture du numéro SIRET. + .row = render partial: '/start/pro' + diff --git a/config/locales/fr.yml b/config/locales/fr.yml index d625c7280..d62c4a248 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -20,4 +20,61 @@ # available at http://guides.rubyonrails.org/i18n.html. fr: - hello: "Bonjour le monde" + devise: + confirmations: + confirmed: 'Votre compte a été confirmé avec succès.' + send_instructions: 'Vous allez recevoir un e-mail avec les instructions nécessaires à la confirmation de votre compte dans quelques minutes.' + send_paranoid_instructions: 'Si votre e-mail existe dans notre base de données, vous allez bientôt recevoir un e-mail contenant les instructions de confirmation de votre compte.' + failure: + already_authenticated: "Vous êtes déjà connecté" + inactive: "Votre compte n'est pas encore activé." + invalid: "%{authentication_keys} ou mot de passe incorrect." + locked: "Votre compte est verrouillé." + last_attempt: "Vous avez droit à une tentative avant que votre compte ne soit verrouillé." + locked: "Votre compte est verrouillé." + not_found_in_database: "%{authentication_keys} ou mot de passe incorrect." + timeout: "Votre session est expirée. Veuillez vous reconnecter pour continuer." + unauthenticated: "Vous devez vous connecter ou vous inscrire pour continuer." + unconfirmed: "Vous devez confirmer votre compte pour continuer." + mailer: + confirmation_instructions: + subject: "Instructions de confirmation" + reset_password_instructions: + subject: "Instructions pour changer le mot de passe" + unlock_instructions: + subject: "Instructions pour déverrouiller le compte" + omniauth_callbacks: + failure: "Nous n'avons pas pu vous authentifier via %{kind} : '%{reason}'." + success: 'Authentifié avec succès via %{kind}.' + passwords: + no_token: "Vous ne pouvez accéder à cette page sans passer par un e-mail de réinitialisation de mot de passe. Si vous êtes passé par un e-mail de ce type, assurez-vous d'utiliser l'URL complète." + send_instructions: 'Vous allez recevoir les instructions de réinitialisation du mot de passe dans quelques instants' + send_paranoid_instructions: "Si votre e-mail existe dans notre base de données, vous allez recevoir un lien de réinitialisation par e-mail" + updated: 'Votre mot de passe a été édité avec succès, vous êtes maintenant connecté' + updated_not_active: 'Votre mot de passe a été changé avec succès.' + registrations: + destroyed: 'Votre compte a été supprimé avec succès. Nous espérons vous revoir bientôt.' + signed_up: 'Bienvenue, vous êtes connecté.' + signed_up_but_inactive: "Vous êtes bien enregistré. Vous ne pouvez cependant pas vous connecter car votre compte n'est pas encore activé." + signed_up_but_locked: "Vous êtes bien enregistré. Vous ne pouvez cependant pas vous connecter car votre compte est verrouillé." + signed_up_but_unconfirmed: 'Un message contenant un lien de confirmation a été envoyé à votre adresse email. Ouvrez ce lien pour confirmer votre compte.' + update_needs_confirmation: "Votre compte a bien été mis à jour mais nous devons vérifier votre nouvelle adresse email. Merci de vérifier vos emails et de cliquer sur le lien de confirmation pour finaliser la validation de votre nouvelle adresse." + updated: 'Votre compte a été modifié avec succès.' + sessions: + signed_in: "Connecté avec succès." + signed_out: "Déconnecté avec succès." + already_signed_out: "Déconnecté avec succès." + unlocks: + send_instructions: 'Vous allez recevoir les instructions nécessaires au déverrouillage de votre compte dans quelques instants' + send_paranoid_instructions: 'Si votre compte existe, vous allez bientôt recevoir un email contenant les instructions pour le déverrouiller.' + unlocked: 'Votre compte a été déverrouillé avec succès, veuillez vous connecter pour continuer.' + errors: + messages: + already_confirmed: "a déjà été validé(e), veuillez essayer de vous connecter" + confirmation_period_expired: "à confirmer dans les %{period}, merci de faire une nouvelle demande" + expired: "a expiré, merci d'en faire une nouvelle demande" + not_found: "n'a pas été trouvé(e)" + not_locked: "n'était pas verrouillé(e)" + not_saved: + one: "1 erreur a empêché ce(tte) %{resource} d'être sauvegardé(e) :" + other: "%{count} erreurs ont empêché ce(tte) %{resource} d'être sauvegardé(e) :" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d0feb64cb..01a3e70d9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,21 +1,9 @@ Rails.application.routes.draw do - devise_for :pros, controllers: { - sessions: 'sessions' - }, skip: [:password] #:registrations, + devise_for :gestionnaires, controllers: { + sessions: 'gestionnaires/sessions' - devise_for :users, controllers: { - sessions: 'sessions' - }, skip: [:registrations, :password] + }, skip: [:password, :registrations] - devise_scope :user do - post 'login', to: 'user/sessions#create' - delete 'logout', to: 'user/sessions#destroy' - end - - devise_scope :pro do - post 'login_pro', to: 'pros/sessions#create' - delete 'logout_pro', to: 'pros/sessions#destroy' - end root 'start#index' @@ -47,6 +35,13 @@ Rails.application.routes.draw do post '/commentaire' => 'commentaires#create' end + + + get 'backoffice' => 'backoffice#index' + +namespace :backoffice do + get 'sign_in' => '/gestionnaires/sessions#new' +end # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20150918163159_devise_create_gestionnaires.rb b/db/migrate/20150918163159_devise_create_gestionnaires.rb new file mode 100644 index 000000000..ef56353bd --- /dev/null +++ b/db/migrate/20150918163159_devise_create_gestionnaires.rb @@ -0,0 +1,42 @@ +class DeviseCreateGestionnaires < ActiveRecord::Migration + def change + create_table(:gestionnaires) do |t| + ## Database authenticatable + t.string :email, null: false, default: "" + t.string :encrypted_password, null: false, default: "" + + ## Recoverable + t.string :reset_password_token + t.datetime :reset_password_sent_at + + ## Rememberable + t.datetime :remember_created_at + + ## Trackable + t.integer :sign_in_count, default: 0, null: false + t.datetime :current_sign_in_at + t.datetime :last_sign_in_at + t.inet :current_sign_in_ip + t.inet :last_sign_in_ip + + ## Confirmable + # t.string :confirmation_token + # t.datetime :confirmed_at + # t.datetime :confirmation_sent_at + # t.string :unconfirmed_email # Only if using reconfirmable + + ## Lockable + # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts + # t.string :unlock_token # Only if unlock strategy is :email or :both + # t.datetime :locked_at + + + t.timestamps + end + + add_index :gestionnaires, :email, unique: true + add_index :gestionnaires, :reset_password_token, unique: true + # add_index :gestionnaires, :confirmation_token, unique: true + # add_index :gestionnaires, :unlock_token, unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index ccb157c3a..e278eb946 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -84,13 +84,31 @@ ActiveRecord::Schema.define(version: 20150921101240) do t.integer "entreprise_id" end + create_table "gestionnaires", force: :cascade do |t| + t.string "email", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" + t.datetime "reset_password_sent_at" + t.datetime "remember_created_at" + t.integer "sign_in_count", default: 0, null: false + t.datetime "current_sign_in_at" + t.datetime "last_sign_in_at" + t.inet "current_sign_in_ip" + t.inet "last_sign_in_ip" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "gestionnaires", ["email"], name: "index_gestionnaires_on_email", unique: true, using: :btree + add_index "gestionnaires", ["reset_password_token"], name: "index_gestionnaires_on_reset_password_token", unique: true, using: :btree + create_table "pieces_justificatives", force: :cascade do |t| t.string "content" t.integer "dossier_id" - t.integer "type_piece_jointe_id" + t.integer "type_de_piece_justificative_id" end - add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_piece_jointe_id", using: :btree + add_index "pieces_justificatives", ["type_de_piece_justificative_id"], name: "index_pieces_justificatives_on_type_de_piece_justificative_id", using: :btree create_table "procedures", force: :cascade do |t| t.string "libelle" diff --git a/spec/controllers/admin/dossier_controller_spec.rb b/spec/controllers/admin/dossier_controller_spec.rb index 511059319..e38e7fdbe 100644 --- a/spec/controllers/admin/dossier_controller_spec.rb +++ b/spec/controllers/admin/dossier_controller_spec.rb @@ -1,14 +1,15 @@ require 'rails_helper' -RSpec.describe Admin::DossierController, type: :controller do +describe Admin::DossierController, type: :controller do let(:dossier) { create(:dossier, :with_entreprise) } let(:dossier_id) { dossier.id } let(:bad_dossier_id) { Dossier.count + 10 } + let(:gestionnaire) { create(:gestionnaire) } describe 'GET #show' do - context 'l\'utilisateur est connecté' do + context "l'utilisateur est connecté" do before do - sign_in + sign_in gestionnaire end it 'returns http success' do @@ -16,24 +17,22 @@ RSpec.describe Admin::DossierController, type: :controller do expect(response).to have_http_status(200) end - it 'le numéro de dossier n\'existe pas' do + it "le numéro de dossier n'existe pas" do get :show, dossier_id: bad_dossier_id expect(response).to redirect_to('/start/error_dossier') end end - context 'L\'utilisateur n\'est pas connecté avec un dossier_id correct' do - it do - get :show, dossier_id: dossier_id - expect(response).to redirect_to('/') - end + context "L'utilisateur n'est pas connecté mais le numéro de dossier est correct" do + subject { get :show, dossier_id: dossier_id } + it { is_expected.to redirect_to('/gestionnaires/sign_in') } end end describe 'GET #index' do let(:user) { create(:user) } before do - sign_in + sign_in gestionnaire end it 'le numéro de dossier est correct' do diff --git a/spec/factories/gestionnaire.rb b/spec/factories/gestionnaire.rb new file mode 100644 index 000000000..dcdb76c62 --- /dev/null +++ b/spec/factories/gestionnaire.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + sequence(:gestionnaire_email) { |n| "plop#{n}@plop.com" } + factory :gestionnaire do + email { generate(:gestionnaire_email) } + password 'password' + end +end \ No newline at end of file diff --git a/spec/features/admin/dossier_page/_commentaires_flux_spec.rb b/spec/features/admin/dossier_page/_commentaires_flux_spec.rb index 24d392111..c7384ffc4 100644 --- a/spec/features/admin/dossier_page/_commentaires_flux_spec.rb +++ b/spec/features/admin/dossier_page/_commentaires_flux_spec.rb @@ -5,11 +5,12 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do let(:dossier_id) { dossier.id } let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'toto@toto.com') } let(:email_commentaire) { 'test@test.com' } + let(:gestionnaire) { create(:gestionnaire) } let(:email_pre_rempli) { 'toto@sgmap.fr' } let(:body) { 'Commentaire de test' } before do - login_admin + login_as gestionnaire, scope: :gestionnaire visit "/admin/dossiers/#{dossier_id}" end @@ -41,7 +42,7 @@ feature '_Commentaires_Flux Admin/Dossier#Show Page' do end scenario 'Champs email est prérempli' do - expect(page).to have_selector("input[id=email_commentaire][value='#{email_pre_rempli}']") + expect(page).to have_selector("input[id=email_commentaire][value='#{gestionnaire.email}']") end end end diff --git a/spec/features/admin/dossier_page/show_page_spec.rb b/spec/features/admin/dossier_page/show_page_spec.rb index b0bbf83f2..8fe2a3088 100644 --- a/spec/features/admin/dossier_page/show_page_spec.rb +++ b/spec/features/admin/dossier_page/show_page_spec.rb @@ -5,7 +5,7 @@ feature 'Admin/Dossier#Show Page' do let(:dossier_id) { dossier.id } before do - login_admin + login_gestionnaire visit "/admin/dossiers/#{dossier_id}" end diff --git a/spec/features/backoffice/connection_spec.rb b/spec/features/backoffice/connection_spec.rb new file mode 100644 index 000000000..d08d13b72 --- /dev/null +++ b/spec/features/backoffice/connection_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +feature 'when gestionnaire come to /backoffice and is not authenticated' do + before do + visit backoffice_path + end + scenario 'he is redirected to /gestionnaires/sign_id' do + expect(page).to have_css('#gestionnaire_login') + end + context 'when user enter bad credentials' do + before do + page.find_by_id(:gestionnaire_email).set 'unknown@plop.com' + page.find_by_id(:gestionnaire_password).set 'password' + page.click_on 'Se connecter' + end + scenario 'he stay on the same page with an error' do + expect(page).to have_content('email ou mot de passe incorrect.') + end + end + context 'when user enter good credentials' do + let(:gestionnaire) { create(:gestionnaire) } + before do + page.find_by_id(:gestionnaire_email).set gestionnaire.email + page.find_by_id(:gestionnaire_password).set gestionnaire.password + page.click_on 'Se connecter' + end + scenario 'he is redirected to /backoffice' do + expect(page).to have_css('#backoffice') + end + end +end \ No newline at end of file diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb new file mode 100644 index 000000000..6a8a15b2a --- /dev/null +++ b/spec/models/gestionnaire_spec.rb @@ -0,0 +1,19 @@ +require 'rails_helper' + +describe Gestionnaire, type: :model do + + describe 'database column' do + it { is_expected.to have_db_column(:email) } + it { is_expected.to have_db_column(:encrypted_password) } + it { is_expected.to have_db_column(:reset_password_token) } + it { is_expected.to have_db_column(:reset_password_sent_at) } + it { is_expected.to have_db_column(:remember_created_at) } + it { is_expected.to have_db_column(:sign_in_count) } + it { is_expected.to have_db_column(:current_sign_in_at) } + it { is_expected.to have_db_column(:last_sign_in_at) } + it { is_expected.to have_db_column(:current_sign_in_ip) } + it { is_expected.to have_db_column(:last_sign_in_ip) } + it { is_expected.to have_db_column(:created_at) } + it { is_expected.to have_db_column(:updated_at) } + end +end diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index 5b7aee507..499edbc81 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -1,16 +1,6 @@ -module ControllerHelpers - def sign_in(user = double('test@localhost.com')) - if user.nil? - allow(request.env['warden']).to receive(:authenticate!).and_throw(:warden, scope: :user) - allow(controller).to receive(:current_user).and_return(nil) - else - allow(request.env['warden']).to receive(:authenticate!).and_return(user) - allow(controller).to receive(:current_user).and_return(create(:user)) - end - end -end + RSpec.configure do |config| config.include Devise::TestHelpers, type: :controller - config.include ControllerHelpers, type: :controller + end diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 339283bb5..57f7f3291 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -5,6 +5,11 @@ module FeatureHelpers user end + def login_gestionnaire + gestionnaire = create(:gestionnaire) + login_as gestionnaire, scope: :gestionnaire + end + def create_dossier dossier = FactoryGirl.create(:dossier) dossier diff --git a/spec/views/backoffice/index.html.haml_spec.rb b/spec/views/backoffice/index.html.haml_spec.rb new file mode 100644 index 000000000..192d777bd --- /dev/null +++ b/spec/views/backoffice/index.html.haml_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe 'backoffice/index.html.haml', type: :view do + before do + render + end + it { expect(rendered).to have_css('#backoffice') } + +end \ No newline at end of file