FEAT: init admins group
This commit is contained in:
parent
b7d6e9e30f
commit
b100c8380e
35 changed files with 604 additions and 0 deletions
|
@ -0,0 +1,12 @@
|
|||
describe AdminsGroupManagers::AdminsGroupManagerController, type: :controller do
|
||||
describe 'before actions: authenticate_admins_group_manager!' do
|
||||
it 'is present' do
|
||||
before_actions = AdminsGroupManagers::AdminsGroupManagerController
|
||||
._process_action_callbacks
|
||||
.filter { |process_action_callbacks| process_action_callbacks.kind == :before }
|
||||
.map(&:filter)
|
||||
|
||||
expect(before_actions).to include(:authenticate_admins_group_manager!)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,23 @@
|
|||
describe AdminsGroupManagers::AdminsGroupsController, type: :controller do
|
||||
let(:admins_group_manager) { create(:admins_group_manager) }
|
||||
|
||||
describe "#index" do
|
||||
subject { get :index }
|
||||
|
||||
context "when not logged" do
|
||||
before { subject }
|
||||
it { expect(response).to redirect_to(new_user_session_path) }
|
||||
end
|
||||
|
||||
context "when logged in" do
|
||||
let!(:admins_group) { create(:admins_group, admins_group_managers: [admins_group_manager]) }
|
||||
before do
|
||||
sign_in(admins_group_manager.user)
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(response).to have_http_status(:ok) }
|
||||
it { expect(assigns(:admins_groups)).to include(admins_group) }
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
describe Manager::AdminsGroupManagersController, type: :controller do
|
||||
let(:super_admin) { create(:super_admin) }
|
||||
let(:admins_group_manager) { create(:admins_group_manager) }
|
||||
|
||||
before { sign_in super_admin }
|
||||
|
||||
describe '#index' do
|
||||
render_views
|
||||
|
||||
it 'searches admin by email' do
|
||||
get :index, params: { search: admins_group_manager.email }
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
render_views
|
||||
|
||||
before do
|
||||
get :show, params: { id: admins_group_manager.id }
|
||||
end
|
||||
|
||||
it { expect(response.body).to include(admins_group_manager.email) }
|
||||
end
|
||||
end
|
27
spec/controllers/manager/admins_groups_controller_spec.rb
Normal file
27
spec/controllers/manager/admins_groups_controller_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
describe Manager::AdminsGroupsController, type: :controller do
|
||||
let(:super_admin) { create(:super_admin) }
|
||||
let(:admins_group) { create(:admins_group) }
|
||||
|
||||
before { sign_in super_admin }
|
||||
|
||||
describe '#index' do
|
||||
render_views
|
||||
|
||||
before do
|
||||
admins_group
|
||||
get :index
|
||||
end
|
||||
|
||||
it { expect(response.body).to include(admins_group.name) }
|
||||
end
|
||||
|
||||
describe '#show' do
|
||||
render_views
|
||||
|
||||
before do
|
||||
get :show, params: { id: admins_group.id }
|
||||
end
|
||||
|
||||
it { expect(response.body).to include(admins_group.name) }
|
||||
end
|
||||
end
|
5
spec/factories/admins_group.rb
Normal file
5
spec/factories/admins_group.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryBot.define do
|
||||
factory :admins_group do
|
||||
sequence(:name) { |n| "Group #{n}" }
|
||||
end
|
||||
end
|
12
spec/factories/admins_group_manager.rb
Normal file
12
spec/factories/admins_group_manager.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
FactoryBot.define do
|
||||
sequence(:admins_group_manager_email) { |n| "admins_group_manager#{n}@demarches-simplifiees.fr" }
|
||||
|
||||
factory :admins_group_manager do
|
||||
user { association :user, email: email, password: password }
|
||||
|
||||
transient do
|
||||
email { generate(:admins_group_manager_email) }
|
||||
password { 'somethingverycomplated!' }
|
||||
end
|
||||
end
|
||||
end
|
16
spec/mailers/admins_group_mailer_spec.rb
Normal file
16
spec/mailers/admins_group_mailer_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
RSpec.describe AdminsGroupMailer, type: :mailer do
|
||||
describe '#notify_added_admins_group_managers' do
|
||||
let(:admins_group) { create(:admins_group) }
|
||||
|
||||
let(:admins_group_managers_to_add) { [create(:admins_group_manager, email: 'int3@g'), create(:admins_group_manager, email: 'int4@g')] }
|
||||
|
||||
let(:current_super_admin_email) { 'toto@email.com' }
|
||||
|
||||
subject { described_class.notify_added_admins_group_managers(admins_group, admins_group_managers_to_add, current_super_admin_email) }
|
||||
|
||||
before { admins_group_managers_to_add.each { admins_group.add(_1) } }
|
||||
|
||||
it { expect(subject.body).to include('Vous venez d’être nommé gestionnaire du groupe') }
|
||||
it { expect(subject.bcc).to match_array(['int3@g', 'int4@g']) }
|
||||
end
|
||||
end
|
14
spec/mailers/previews/admins_group_mailer_preview.rb
Normal file
14
spec/mailers/previews/admins_group_mailer_preview.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class AdminsGroupMailerPreview < ActionMailer::Preview
|
||||
def notify_added_admins_group_managers
|
||||
admins_group = AdminsGroup.new(name: 'un groupe d\'admin')
|
||||
current_super_admin_email = 'admin@dgfip.com'
|
||||
admins_group_managers = [AdminsGroupManager.new(user: user)]
|
||||
AdminsGroupMailer.notify_added_admins_group_managers(admins_group, admins_group_managers, current_super_admin_email)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user
|
||||
User.new(id: 10, email: 'test@exemple.fr')
|
||||
end
|
||||
end
|
5
spec/models/admins_group_manager_spec.rb
Normal file
5
spec/models/admins_group_manager_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
describe AdminsGroupManager, type: :model do
|
||||
describe 'associations' do
|
||||
it { is_expected.to have_and_belong_to_many(:admins_groups) }
|
||||
end
|
||||
end
|
8
spec/models/admins_group_spec.rb
Normal file
8
spec/models/admins_group_spec.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
describe AdminsGroup, type: :model do
|
||||
describe 'associations' do
|
||||
it { is_expected.to belong_to(:admins_group).optional }
|
||||
it { is_expected.to have_many(:children) }
|
||||
it { is_expected.to have_many(:administrateurs) }
|
||||
it { is_expected.to have_and_belong_to_many(:admins_group_managers) }
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue