parent
15b186518c
commit
c2c6ed5dea
3 changed files with 18 additions and 3 deletions
|
|
@ -91,7 +91,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_unless_moderator
|
def redirect_unless_moderator
|
||||||
return if current_user.moderator? || current_user.admin?
|
return if current_user.moderator?
|
||||||
redirect_to stream_url, notice: "you need to be an admin or moderator to do that"
|
redirect_to stream_url, notice: "you need to be an admin or moderator to do that"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class Role < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.moderator?(person)
|
def self.moderator?(person)
|
||||||
exists?(person_id: person.id, name: "moderator")
|
moderators.exists?(person_id: person.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.add_moderator(person)
|
def self.add_moderator(person)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ describe Role do
|
||||||
describe "validations" do
|
describe "validations" do
|
||||||
it { should validate_presence_of(:person) }
|
it { should validate_presence_of(:person) }
|
||||||
it { should validate_uniqueness_of(:name).scoped_to(:person_id) }
|
it { should validate_uniqueness_of(:name).scoped_to(:person_id) }
|
||||||
it { should validate_inclusion_of(:name).in_array(%w(admin spotlight)) }
|
it { should validate_inclusion_of(:name).in_array(%w(admin spotlight moderator)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "associations" do
|
describe "associations" do
|
||||||
|
|
@ -15,6 +15,7 @@ describe Role do
|
||||||
|
|
||||||
describe "scopes" do
|
describe "scopes" do
|
||||||
let!(:admin_role) { person.roles.create(name: "admin") }
|
let!(:admin_role) { person.roles.create(name: "admin") }
|
||||||
|
let!(:moderator_role) { person.roles.create(name: "moderator") }
|
||||||
let!(:spotlight_role) { person.roles.create(name: "spotlight") }
|
let!(:spotlight_role) { person.roles.create(name: "spotlight") }
|
||||||
|
|
||||||
describe ".admins" do
|
describe ".admins" do
|
||||||
|
|
@ -22,6 +23,20 @@ describe Role do
|
||||||
expect(Role.admins).to match_array([admin_role])
|
expect(Role.admins).to match_array([admin_role])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".moderators" do
|
||||||
|
it "should include admins" do
|
||||||
|
expect(Role.moderators).to include(admin_role)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should include moderators" do
|
||||||
|
expect(Role.moderators).to include(moderator_role)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should not include normal users" do
|
||||||
|
expect(Role.moderators).to_not include(person)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".is_admin?" do
|
describe ".is_admin?" do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue