-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Showing
2 changed files
with
60 additions
and
1 deletion.
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,51 @@ | ||
require "rails_helper" | ||
|
||
describe Administrate::NotAuthorizedError do | ||
context "when the resource is a class or module" do | ||
it "produces a message mentioning it directly" do | ||
error = described_class.new( | ||
resource: Administrate, | ||
action: "foo", | ||
) | ||
expect(error.message).to eq( | ||
%{Not allowed to perform "foo" on Administrate} | ||
) | ||
end | ||
end | ||
|
||
context "when the resource is a string" do | ||
it "produces a message mentioning it directly" do | ||
error = described_class.new( | ||
resource: "User", | ||
action: "foo", | ||
) | ||
expect(error.message).to eq(%{Not allowed to perform "foo" on "User"}) | ||
end | ||
end | ||
|
||
context "when the resource is a symbol" do | ||
it "produces a message mentioning it directly" do | ||
error = described_class.new( | ||
resource: :user, | ||
action: "foo", | ||
) | ||
expect(error.message).to eq(%{Not allowed to perform "foo" on :user}) | ||
end | ||
end | ||
|
||
context "when the resource is something else" do | ||
it "produces a message that refers to the class of the resource" do | ||
class TestStuff; end | ||
|
||
error = described_class.new( | ||
resource: TestStuff.new, | ||
action: "foo", | ||
) | ||
expect(error.message).to eq( | ||
%{Not allowed to perform "foo" on the given TestStuff} | ||
) | ||
ensure | ||
remove_constants :TestStuff | ||
end | ||
end | ||
end |