add new role moderator analogue to admin role

#5324
This commit is contained in:
zaziemo 2015-08-20 16:22:54 +02:00 committed by Jonne Haß
parent 81084cde46
commit 3a3c881735
2 changed files with 13 additions and 2 deletions

View file

@ -1,11 +1,11 @@
#NOTE add the person object you want to attach role to...
# NOTE add the person object you want to attach role to...
class Role < ActiveRecord::Base
belongs_to :person
validates :person, presence: true
validates :name, uniqueness: {scope: :person_id}
validates :name, inclusion: {in: %w(admin spotlight)}
validates :name, inclusion: {in: %w(admin moderator spotlight)}
scope :admins, -> { where(name: "admin") }
@ -17,6 +17,10 @@ class Role < ActiveRecord::Base
find_or_create_by(person_id: person.id, name: "admin")
end
def self.add_moderator(person)
find_or_create_by(person_id: person.id, name: "moderator")
end
def self.add_spotlight(person)
find_or_create_by(person_id: person.id, name: "spotlight")
end

View file

@ -45,6 +45,13 @@ describe Role do
end
end
describe ".add_moderator" do
it "creates the moderator role" do
Role.add_moderator(person)
expect(person.roles.where(name: "moderator")).to exist
end
end
describe ".add_spotlight" do
it "creates the spotlight role" do
Role.add_spotlight(person)