InviteUser → Invite

This commit is contained in:
gregoirenovel 2018-10-10 09:23:08 +02:00
parent ed11852300
commit c8f872c566
12 changed files with 25 additions and 52 deletions

View file

@ -5,7 +5,7 @@ class InvitesController < ApplicationController
email = params[:invite_email].downcase
dossier = current_user.dossiers.find(params[:dossier_id])
invite = InviteUser.create(
invite = Invite.create(
dossier: dossier,
user: User.find_by(email: email),
email: email,

View file

@ -35,7 +35,7 @@ class Commentaire < ApplicationRecord
def notify
dossier_user_email = dossier.user.email
invited_users_emails = dossier.invites_user.pluck(:email).to_a
invited_users_emails = dossier.invites.pluck(:email).to_a
# - If the email is the contact email, the commentaire is a copy
# of an automated notification email we sent to a user, so do nothing.

View file

@ -24,7 +24,6 @@ class Dossier < ApplicationRecord
has_many :cadastres, dependent: :destroy
has_many :commentaires, dependent: :destroy
has_many :invites, dependent: :destroy
has_many :invites_user, class_name: 'InviteUser', dependent: :destroy
has_many :follows
has_many :followers_gestionnaires, through: :follows, source: :gestionnaire
has_many :avis, dependent: :destroy
@ -159,7 +158,7 @@ class Dossier < ApplicationRecord
end
def invite_for_user(user)
invites_user.find_by(user_id: user.id)
invites.find_by(user_id: user.id)
end
def can_be_en_construction?

View file

@ -1,2 +0,0 @@
class InviteUser < Invite
end

View file

@ -44,7 +44,7 @@ describe InvitesController, type: :controller do
sign_in(user)
end
it { expect { subject }.to change(InviteUser, :count).by(1) }
it { expect { subject }.to change(Invite, :count).by(1) }
end
end
end
@ -54,7 +54,7 @@ describe InvitesController, type: :controller do
shared_examples_for "he can not create a invite" do
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject rescue nil }.to change(InviteUser, :count).by(0) }
it { expect { subject rescue nil }.to change(Invite, :count).by(0) }
end
context 'when user has no access to dossier' do
@ -73,7 +73,7 @@ describe InvitesController, type: :controller do
dossier.update(user: signed_in_profile)
end
it { expect { subject }.to change(InviteUser, :count).by(1) }
it { expect { subject }.to change(Invite, :count).by(1) }
it "redirects to the previous URL" do
expect(subject).to redirect_to("/dossiers/#{dossier.id}/brouillon")

View file

@ -50,13 +50,13 @@ describe NewUser::DossiersController, type: :controller do
end
context 'when an invite asks for a dossier where they were invited' do
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
before { create(:invite, dossier: asked_dossier, user: user) }
it_behaves_like 'redirects and flashes'
end
context 'when an invite asks for another dossier' do
before { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
before { create(:invite, dossier: create(:dossier), user: user) }
it_behaves_like 'redirects and flashes'
end
@ -84,13 +84,13 @@ describe NewUser::DossiersController, type: :controller do
end
context 'when an invite asks for a dossier where they were invited' do
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
before { create(:invite, dossier: asked_dossier, user: user) }
it_behaves_like 'does not redirect nor flash'
end
context 'when an invite asks for another dossier' do
before { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
before { create(:invite, dossier: create(:dossier), user: user) }
it_behaves_like 'redirects and flashes'
end
@ -123,14 +123,14 @@ describe NewUser::DossiersController, type: :controller do
end
context 'when an invite save the draft for a dossier where they where invited' do
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
before { create(:invite, dossier: asked_dossier, user: user) }
let(:draft) { true }
it_behaves_like 'does not redirect nor flash'
end
context 'when an invite submit a dossier where they where invited' do
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
before { create(:invite, dossier: asked_dossier, user: user) }
let(:draft) { false }
it_behaves_like 'redirects and flashes'
@ -370,7 +370,7 @@ describe NewUser::DossiersController, type: :controller do
context 'when the user has an invitation but is not the owner' do
let(:dossier) { create(:dossier) }
let!(:invite) { create(:invite, dossier: dossier, user: user, type: 'InviteUser') }
let!(:invite) { create(:invite, dossier: dossier, user: user) }
context 'and the invite saves a draft' do
let(:payload) { submit_payload.merge(save_draft: true) }
@ -493,7 +493,7 @@ describe NewUser::DossiersController, type: :controller do
context 'when the user has an invitation but is not the owner' do
let(:dossier) { create(:dossier) }
let!(:invite) { create(:invite, dossier: dossier, user: user, type: 'InviteUser') }
let!(:invite) { create(:invite, dossier: dossier, user: user) }
before do
dossier.en_construction!
@ -525,7 +525,7 @@ describe NewUser::DossiersController, type: :controller do
end
context 'when the user only have some dossiers invites' do
let!(:invite) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
let!(:invite) { create(:invite, dossier: create(:dossier), user: user) }
before { get(:index) }
@ -535,7 +535,7 @@ describe NewUser::DossiersController, type: :controller do
context 'when the user has both' do
let!(:own_dossier) { create(:dossier, user: user) }
let!(:invite) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
let!(:invite) { create(:invite, dossier: create(:dossier), user: user) }
context 'and there is no current_tab param' do
before { get(:index) }
@ -560,8 +560,8 @@ describe NewUser::DossiersController, type: :controller do
before do
Timecop.freeze(4.days.ago) { create(:dossier, user: user) }
Timecop.freeze(2.days.ago) { create(:dossier, user: user) }
Timecop.freeze(4.days.ago) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
Timecop.freeze(2.days.ago) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
Timecop.freeze(4.days.ago) { create(:invite, dossier: create(:dossier), user: user) }
Timecop.freeze(2.days.ago) { create(:invite, dossier: create(:dossier), user: user) }
get(:index)
end

View file

@ -17,7 +17,7 @@ RSpec.describe Users::CarteController, type: :controller do
let(:adresse) { etablissement.geo_adresse }
before do
create :invite, dossier: dossier, user: invite_by_user, email: invite_by_user.email, type: 'InviteUser'
create :invite, dossier: dossier, user: invite_by_user, email: invite_by_user.email
sign_in user
end

View file

@ -20,7 +20,7 @@ describe UsersController, type: :controller do
context 'when user is invite by the owner' do
before do
create :invite, email: invite_user.email, dossier: dossier, user: invite_user, type: 'InviteUser'
create :invite, email: invite_user.email, dossier: dossier, user: invite_user
sign_in invite_user
end

View file

@ -1,24 +0,0 @@
FactoryBot.define do
factory :invite_user do
email { 'plop@octo.com' }
after(:build) do |invite, _evaluator|
if invite.dossier.nil?
invite.dossier = create(:dossier)
end
if invite.user.present?
invite.email = invite.user.email
end
end
trait :with_user do
after(:build) do |invite, _evaluator|
if invite.user.nil?
invite.user = create(:user)
invite.email = invite.user.email
end
end
end
end
end

View file

@ -5,7 +5,7 @@ feature 'Invitations' do
let(:owner) { create(:user) }
let(:invited_user) { create(:user, email: 'user_invite@exemple.fr') }
let(:procedure) { create(:simple_procedure) }
let(:invite) { create(:invite_user, user: invited_user, dossier: dossier) }
let(:invite) { create(:invite, user: invited_user, dossier: dossier) }
context 'when the dossier is a brouillon' do
let!(:dossier) { create(:dossier, :for_individual, state: Dossier.states.fetch(:brouillon), user: owner, procedure: procedure) }
@ -26,7 +26,7 @@ feature 'Invitations' do
end
context 'when inviting someone without an existing account' do
let(:invite) { create(:invite_user, dossier: dossier, user: nil) }
let(:invite) { create(:invite, dossier: dossier, user: nil) }
let(:user_password) { 'l33tus3r' }
scenario 'an invited user can register using the registration link sent in the invitation email' do

View file

@ -33,7 +33,7 @@ RSpec.describe CommentaireHelper, type: :helper do
describe '.commentaire_is_from_guest' do
let(:dossier) { create(:dossier) }
let!(:guest) { create(:invite_user, dossier: dossier) }
let!(:guest) { create(:invite, dossier: dossier) }
subject { commentaire_is_from_guest(commentaire) }

View file

@ -66,7 +66,7 @@ describe User, type: :model do
context 'when user was invited by user' do
before do
create(:invite, dossier: dossier, user: invite_user, type: 'InviteUser')
create(:invite, dossier: dossier, user: invite_user)
end
let(:user) { invite_user }
@ -116,7 +116,7 @@ describe User, type: :model do
context 'when user was invited by user' do
before do
create(:invite, dossier: dossier, user: invite_user, type: 'InviteUser')
create(:invite, dossier: dossier, user: invite_user)
end
let(:user) { invite_user }