1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Add specs to verify may_*? methods for ActiveRecord

This commit is contained in:
Anil Maurya 2017-04-30 02:25:35 +05:30
parent cf21c8b583
commit 1830393726
2 changed files with 22 additions and 1 deletions

View file

@ -7,7 +7,7 @@ class ComplexActiveRecordExample < ActiveRecord::Base
state :three
event :increment do
transitions :from => :one, :to => :two
transitions :from => :one, :to => :two, guard: :allowed?
transitions :from => :two, :to => :three
end
event :reset do
@ -15,6 +15,10 @@ class ComplexActiveRecordExample < ActiveRecord::Base
end
end
def allowed?
true
end
aasm :right, :column => 'right' do
state :alpha, :initial => true
state :beta

View file

@ -70,3 +70,20 @@ describe "event guards" do
end
end
if defined?(ActiveRecord)
Dir[File.dirname(__FILE__) + "/../models/active_record/*.rb"].sort.each do |f|
require File.expand_path(f)
end
load_schema
describe "ActiveRecord per-transition guards" do
let(:example) { ComplexActiveRecordExample.new }
it "should be able to increment" do
expect(example.may_increment?).to be true
end
end
end