From 60b94fc41b8394a3996ba89f66f5d5a9622ff909 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 13 Sep 2016 15:54:26 +0200 Subject: [PATCH] Specialize Invite object --- app/controllers/invites_controller.rb | 4 +++- app/models/invite_gestionnaire.rb | 3 +++ app/models/invite_user.rb | 3 +++ app/views/dossiers/_infos_dossier.html.haml | 4 ++-- app/views/users/dossiers/_list.html.haml | 4 ++-- .../20160913093948_add_type_attr_in_invite_table.rb | 5 +++++ db/schema.rb | 3 ++- spec/controllers/invites_controller_spec.rb | 10 +++++++++- 8 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 app/models/invite_gestionnaire.rb create mode 100644 app/models/invite_user.rb create mode 100644 db/migrate/20160913093948_add_type_attr_in_invite_table.rb diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index e729a84cd..3c550f6d4 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -4,8 +4,10 @@ class InvitesController < ApplicationController def create email_sender = @current_devise_profil.email + class_var = @current_devise_profil.class == User ? InviteUser : InviteGestionnaire + user = User.find_by_email(params[:email]) - invite = Invite.create(dossier_id: params[:dossier_id], user: user, email: params[:email].downcase, email_sender: email_sender) + invite = class_var.create(dossier_id: params[:dossier_id], user: user, email: params[:email].downcase, email_sender: email_sender) if invite.valid? InviteMailer.invite_user(invite).deliver_now! unless invite.user.nil? diff --git a/app/models/invite_gestionnaire.rb b/app/models/invite_gestionnaire.rb new file mode 100644 index 000000000..6021286da --- /dev/null +++ b/app/models/invite_gestionnaire.rb @@ -0,0 +1,3 @@ +class InviteGestionnaire < Invite + +end diff --git a/app/models/invite_user.rb b/app/models/invite_user.rb new file mode 100644 index 000000000..05ec141e9 --- /dev/null +++ b/app/models/invite_user.rb @@ -0,0 +1,3 @@ +class InviteUser < Invite + +end diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index 8f97562e6..19e6c8551 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -55,9 +55,9 @@ -if @facade.dossier.procedure.module_api_carto.use_api_carto %a#maj_carte.btn.btn-primary{href: "/users/dossiers/#{@facade.dossier.id}/carte"} - = 'Modifier ma carte' + = 'Modifier la carte' %a#maj_infos.btn.btn-info{href: "/users/dossiers/#{@facade.dossier.id}/description"} - = 'Modifier mon dossier' + = 'Modifier le dossier' -if gestionnaire_signed_in? -if !@facade.dossier.read_only? diff --git a/app/views/users/dossiers/_list.html.haml b/app/views/users/dossiers/_list.html.haml index e8bdcc86d..61121ff96 100644 --- a/app/views/users/dossiers/_list.html.haml +++ b/app/views/users/dossiers/_list.html.haml @@ -6,9 +6,9 @@ %th.col-md-2.col-lg-2= smart_listing.sortable 'État', 'state' %th.col-md-2.col-lg-2= smart_listing.sortable 'Date de mise à jour', 'updated_at' - @dossiers.each do |dossier| - - if dossier.class == Invite + - if dossier.kind_of? Invite -invite = dossier - -dossier = dossier.dossier.decorate + -dossier = invite.dossier.decorate - else - dossier = dossier.decorate %tr diff --git a/db/migrate/20160913093948_add_type_attr_in_invite_table.rb b/db/migrate/20160913093948_add_type_attr_in_invite_table.rb new file mode 100644 index 000000000..a71813a9b --- /dev/null +++ b/db/migrate/20160913093948_add_type_attr_in_invite_table.rb @@ -0,0 +1,5 @@ +class AddTypeAttrInInviteTable < ActiveRecord::Migration + def change + add_column :invites, :type, :string, default: 'InviteGestionnaire' + end +end diff --git a/db/schema.rb b/db/schema.rb index 7533be06e..837be6fb9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160906134155) do +ActiveRecord::Schema.define(version: 20160913093948) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -225,6 +225,7 @@ ActiveRecord::Schema.define(version: 20160906134155) do t.string "email_sender" t.integer "dossier_id" t.integer "user_id" + t.string "type", default: "InviteGestionnaire" end create_table "mail_templates", force: :cascade do |t| diff --git a/spec/controllers/invites_controller_spec.rb b/spec/controllers/invites_controller_spec.rb index 4d8cba09b..e528188cd 100644 --- a/spec/controllers/invites_controller_spec.rb +++ b/spec/controllers/invites_controller_spec.rb @@ -13,7 +13,15 @@ describe InvitesController, type: :controller do subject { post :create, dossier_id: dossier.id, email: email } - it { expect { subject }.to change(Invite, :count).by(1) } + it { expect { subject }.to change(InviteGestionnaire, :count).by(1) } + + context 'when is a user who is loged' do + before do + sign_in create(:user) + end + + it { expect { subject }.to change(InviteGestionnaire, :count).by(1) } + end context 'when email is assign to an user' do let! (:user) { create(:user, email: email) }