Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using Ruby method resolution to read the current state
- Loading branch information
Showing
11 changed files
with
88 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Overwrite method to read the current state | ||
|
||
class MyClass | ||
include AASM | ||
|
||
def aasm_read_state | ||
# retrieve the current state manually | ||
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
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
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,43 @@ | ||
class DefaultState | ||
include AASM | ||
aasm do | ||
state :alpha, :initial => true | ||
state :beta | ||
state :gamma | ||
end | ||
end | ||
|
||
class ProvidedState | ||
include AASM | ||
aasm do | ||
state :alpha, :initial => true | ||
state :beta | ||
state :gamma | ||
end | ||
|
||
def aasm_read_state | ||
:beta | ||
end | ||
end | ||
|
||
class PersistedState < ActiveRecord::Base | ||
include AASM | ||
aasm do | ||
state :alpha, :initial => true | ||
state :beta | ||
state :gamma | ||
end | ||
end | ||
|
||
class ProvidedAndPersistedState < ActiveRecord::Base | ||
include AASM | ||
aasm do | ||
state :alpha, :initial => true | ||
state :beta | ||
state :gamma | ||
end | ||
|
||
def aasm_read_state | ||
:gamma | ||
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
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,20 @@ | ||
require 'spec_helper' | ||
require 'models/active_record/api.rb' | ||
|
||
describe "retrieving the current state" do | ||
it "uses the AASM default" do | ||
DefaultState.new.aasm.current_state.should eql :alpha | ||
end | ||
|
||
it "uses the provided method" do | ||
ProvidedState.new.aasm.current_state.should eql :beta | ||
end | ||
|
||
it "uses the persistence storage" do | ||
PersistedState.new.aasm.current_state.should eql :alpha | ||
end | ||
|
||
it "uses the provided method even if persisted" do | ||
ProvidedAndPersistedState.new.aasm.current_state.should eql :gamma | ||
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