Add super_admin? method to User

This commit is contained in:
Eric Schultz 2021-02-18 18:05:05 -06:00 committed by Eric Schultz
parent 7f9e643915
commit 9264297a51
2 changed files with 40 additions and 0 deletions

View file

@ -47,6 +47,15 @@ class User < ApplicationRecord
self self
end end
#
# Is this user a super_admin?
#
# @return [boolean] True if the user is, false otherwise
#
def super_admin?
roles.super_admins.any?
end
# This creates the user in the normal way, but also sends the devise email confirmation email, which we don't want to send to np admins or anyone else # This creates the user in the normal way, but also sends the devise email confirmation email, which we don't want to send to np admins or anyone else
def self.register_donor!(params) def self.register_donor!(params)
u = User.create!(params) u = User.create!(params)

31
spec/models/user_spec.rb Normal file
View file

@ -0,0 +1,31 @@
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
require 'rails_helper'
RSpec.describe User, type: :model do
describe 'super_admin?' do
let(:super_admin) {
sa = create(:user)
sa.roles.create(name: 'super_admin')
sa
}
let(:not_super_admin) {
sa = create(:user)
sa.roles.create(name: 'nonprofit_admin')
sa.roles.create(name: 'nonprofit_associate')
sa
}
it 'returns true for super admin' do
expect(super_admin).to be_super_admin
end
it 'returns false for not super admin' do
expect(not_super_admin).to_not be_super_admin
end
end
end