parent
81084cde46
commit
3a3c881735
2 changed files with 13 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue