Specialize Invite object
This commit is contained in:
parent
0ac23f6d96
commit
60b94fc41b
8 changed files with 29 additions and 7 deletions
|
@ -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?
|
||||
|
|
3
app/models/invite_gestionnaire.rb
Normal file
3
app/models/invite_gestionnaire.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class InviteGestionnaire < Invite
|
||||
|
||||
end
|
3
app/models/invite_user.rb
Normal file
3
app/models/invite_user.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class InviteUser < Invite
|
||||
|
||||
end
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddTypeAttrInInviteTable < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :invites, :type, :string, default: 'InviteGestionnaire'
|
||||
end
|
||||
end
|
|
@ -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|
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in a new issue