-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
glossary policy and specs, glossary changed to inherit app controller
- Loading branch information
1 parent
e5ae91f
commit 0b48cca
Showing
5 changed files
with
66 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class GlossaryPolicy < ApplicationPolicy | ||
def read? | ||
true | ||
end | ||
|
||
def change? | ||
acting_user && (acting_user.admin_role? || acting_user.sys_admin_role? ) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<%= render partial: 'glossary/header' %> | ||
<%= link_to "Edit Glossary", edit_glossary_path, class: "btn" %> | ||
<% if policy(:glossary).change? %> | ||
<%= link_to "Edit Glossary", edit_glossary_path, class: "btn" %> | ||
<% end %> | ||
<hr> | ||
<%= @system_settings.glossary_content %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GlossaryPolicy do | ||
subject { GlossaryPolicy.new(user, :glossary) } | ||
|
||
context "user can edit glossary if they are" do | ||
context "an admin" do | ||
let(:user) { build(:user, :admin) } | ||
it { is_expected.to permit_action(:update) } | ||
end | ||
|
||
context "a sys_admin" do | ||
let(:user) { build(:user, :sys_admin) } | ||
it { is_expected.to permit_action(:update) } | ||
end | ||
end | ||
|
||
context "user cannot edit glossary if they are" do | ||
context "a neighbor" do | ||
let(:user) { build(:user, :neighbor) } | ||
it { is_expected.not_to permit_action(:update) } | ||
end | ||
|
||
context "not logged in" do | ||
let(:user) { nil } | ||
it { is_expected.not_to permit_action(:update) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters