diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-06-02 12:36:36 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-06-02 12:36:36 -0300 |
commit | fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90 (patch) | |
tree | 89f6b8eeae81ba9e9f3c43667b234b64a776e649 /activemodel/test/cases/state_machine/state_test.rb | |
parent | 5255a81b808c2c947d58df979e6436b1fe1d8157 (diff) | |
parent | 196f780e30fcece25e4d09c12f9b9f7374ebed29 (diff) | |
download | rails-fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90.tar.gz rails-fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90.tar.bz2 rails-fd3c55f09fdfb45c33a5383af2c0b9ddf8f63e90.zip |
Merge commit 'rails/master'
Conflicts:
activerecord/lib/active_record.rb
Diffstat (limited to 'activemodel/test/cases/state_machine/state_test.rb')
-rw-r--r-- | activemodel/test/cases/state_machine/state_test.rb | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/activemodel/test/cases/state_machine/state_test.rb b/activemodel/test/cases/state_machine/state_test.rb new file mode 100644 index 0000000000..527bfd4c04 --- /dev/null +++ b/activemodel/test/cases/state_machine/state_test.rb @@ -0,0 +1,72 @@ +require 'cases/helper' + +class StateTestSubject + include ActiveModel::StateMachine + + state_machine do + end +end + +class StateTest < ActiveModel::TestCase + def setup + @state_name = :astate + @machine = StateTestSubject.state_machine + @options = { :crazy_custom_key => 'key', :machine => @machine } + end + + def new_state(options={}) + ActiveModel::StateMachine::State.new(@state_name, @options.merge(options)) + end + + test 'sets the name' do + assert_equal :astate, new_state.name + end + + test 'sets the display_name from name' do + assert_equal "Astate", new_state.display_name + end + + test 'sets the display_name from options' do + assert_equal "A State", new_state(:display => "A State").display_name + end + + test 'sets the options and expose them as options' do + @options.delete(:machine) + assert_equal @options, new_state.options + end + + test 'equals a symbol of the same name' do + assert_equal new_state, :astate + end + + test 'equals a State of the same name' do + assert_equal new_state, new_state + end + + test 'should send a message to the record for an action if the action is present as a symbol' do + state = new_state(:entering => :foo) + + record = stub + record.expects(:foo) + + state.call_action(:entering, record) + end + + test 'should send a message to the record for an action if the action is present as a string' do + state = new_state(:entering => 'foo') + + record = stub + record.expects(:foo) + + state.call_action(:entering, record) + end + + test 'should call a proc, passing in the record for an action if the action is present' do + state = new_state(:entering => Proc.new {|r| r.foobar}) + + record = stub + record.expects(:foobar) + + state.call_action(:entering, record) + end +end |