-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix [#388] guard parameter for permissible states
- Loading branch information
1 parent
9866206
commit 6001f5f
Showing
5 changed files
with
70 additions
and
8 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,24 @@ | ||
class GuardWithParams | ||
include AASM | ||
aasm do | ||
state :new, :reviewed, :finalized | ||
|
||
event :mark_as_reviewed do | ||
transitions :from => :new, :to => :reviewed, :guards => [:user_is_manager?] | ||
end | ||
end | ||
|
||
def user_is_manager?(user) | ||
ok = false | ||
if user.has_role? :manager | ||
ok = true | ||
end | ||
return ok | ||
end | ||
end | ||
|
||
class GuardParamsClass | ||
def has_role?(role) | ||
true | ||
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class GuardWithParamsMultiple | ||
include AASM | ||
aasm(:left) do | ||
state :new, :reviewed, :finalized | ||
|
||
event :mark_as_reviewed do | ||
transitions :from => :new, :to => :reviewed, :guards => [:user_is_manager?] | ||
end | ||
end | ||
|
||
def user_is_manager?(user) | ||
ok = false | ||
if user.has_role? :manager | ||
ok = true | ||
end | ||
return ok | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'spec_helper' | ||
|
||
describe "guards with params" do | ||
let(:guard) { GuardWithParamsMultiple.new } | ||
let(:user) {GuardParamsClass.new} | ||
|
||
it "list permitted states" do | ||
expect(guard.aasm(:left).states({:permitted => true}, user).map(&:name)).to eql [:reviewed] | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'spec_helper' | ||
|
||
describe "guards with params" do | ||
let(:guard) { GuardWithParams.new } | ||
let(:user) {GuardParamsClass.new} | ||
|
||
it "list permitted states" do | ||
expect(guard.aasm.states({:permitted => true}, user).map(&:name)).to eql [:reviewed] | ||
end | ||
end |