-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c741cf2
commit c823557
Showing
5 changed files
with
127 additions
and
3 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
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,8 @@ | ||
class Organizations::PageTextPolicy < ApplicationPolicy | ||
pre_check :verify_organization! | ||
pre_check :verify_active_staff! | ||
|
||
def manage? | ||
permission?(:manage_page_text) | ||
end | ||
end |
30 changes: 29 additions & 1 deletion
30
test/controllers/organizations/page_texts_controller_test.rb
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,82 @@ | ||
require "test_helper" | ||
|
||
# See https://actionpolicy.evilmartians.io/#/testing?id=testing-policies | ||
class Organizations::PageTextPolicyTest < ActiveSupport::TestCase | ||
include PetRescue::PolicyAssertions | ||
|
||
setup do | ||
@organization = ActsAsTenant.current_tenant | ||
@policy = -> { | ||
Organizations::PageTextPolicy.new(Pet, user: @user, | ||
organization: @organization) | ||
} | ||
end | ||
|
||
context "#manage?" do | ||
setup do | ||
@action = -> { @policy.call.apply(:manage?) } | ||
end | ||
|
||
context "when user is nil" do | ||
setup do | ||
@user = nil | ||
end | ||
|
||
should "return false" do | ||
assert_equal @action.call, false | ||
end | ||
end | ||
|
||
context "when user is adopter" do | ||
setup do | ||
@user = create(:adopter) | ||
end | ||
|
||
should "return false" do | ||
assert_equal @action.call, false | ||
end | ||
end | ||
|
||
context "when user is deactivated staff" do | ||
setup do | ||
@user = create(:staff, :deactivated) | ||
end | ||
|
||
should "return false" do | ||
assert_equal @action.call, false | ||
end | ||
end | ||
|
||
context "when user is active staff" do | ||
setup do | ||
@user = create(:staff) | ||
end | ||
|
||
should "return false" do | ||
assert_equal @action.call, false | ||
end | ||
end | ||
|
||
context "when user is staff admin" do | ||
setup do | ||
@user = create(:staff_admin) | ||
end | ||
|
||
should "return true" do | ||
assert_equal @action.call, true | ||
end | ||
end | ||
end | ||
|
||
context "#edit?" do | ||
should "be an alias to :manage?" do | ||
assert_alias_rule @policy.call, :edit?, :manage? | ||
end | ||
end | ||
|
||
context "#update?" do | ||
should "be an alias to :manage?" do | ||
assert_alias_rule @policy.call, :update?, :manage? | ||
end | ||
end | ||
end |