-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
account for aliased attributes when attribute methods are mixed in (#28)
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 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,33 @@ | ||
require_relative 'test_helper' | ||
|
||
class MachineWithInitializedAliasedAttributeTest < BaseTestCase | ||
def test_should_match_original_attribute_value_with_attribute_methods | ||
model = new_model do | ||
include ActiveModel::AttributeMethods | ||
alias_attribute :custom_status, :state | ||
end | ||
|
||
machine = StateMachines::Machine.new(model, initial: :parked, integration: :active_model) | ||
machine.other_states(:started) | ||
|
||
record = model.new(custom_status: 'started') | ||
|
||
refute record.state?(:parked) | ||
assert record.state?(:started) | ||
end | ||
|
||
def test_should_not_match_original_attribute_value_without_attribute_methods | ||
model = new_model do | ||
alias_attribute :custom_status, :state | ||
end | ||
|
||
machine = StateMachines::Machine.new(model, initial: :parked, integration: :active_model) | ||
machine.other_states(:started) | ||
|
||
record = model.new(custom_status: 'started') | ||
|
||
assert record.state?(:parked) | ||
refute record.state?(:started) | ||
end | ||
end | ||
|