aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/test/observing_test.rb34
-rw-r--r--activemodel/test/state_machine/event_test.rb10
-rw-r--r--activemodel/test/state_machine/state_test.rb38
-rw-r--r--activemodel/test/state_machine/state_transition_test.rb104
-rw-r--r--activemodel/test/state_machine_test.rb170
5 files changed, 167 insertions, 189 deletions
diff --git a/activemodel/test/observing_test.rb b/activemodel/test/observing_test.rb
index 34bf260d69..dc41c9f881 100644
--- a/activemodel/test/observing_test.rb
+++ b/activemodel/test/observing_test.rb
@@ -40,24 +40,22 @@ class ObservingTest < ActiveModel::TestCase
assert ObservedModel.observers.include?(:bar), ":bar not in #{ObservedModel.observers.inspect}"
end
- uses_mocha "observer instantiation" do
- test "instantiates observer names passed as strings" do
- ObservedModel.observers << 'foo_observer'
- FooObserver.expects(:instance)
- ObservedModel.instantiate_observers
- end
-
- test "instantiates observer names passed as symbols" do
- ObservedModel.observers << :foo_observer
- FooObserver.expects(:instance)
- ObservedModel.instantiate_observers
- end
-
- test "instantiates observer classes" do
- ObservedModel.observers << ObservedModel::Observer
- ObservedModel::Observer.expects(:instance)
- ObservedModel.instantiate_observers
- end
+ test "instantiates observer names passed as strings" do
+ ObservedModel.observers << 'foo_observer'
+ FooObserver.expects(:instance)
+ ObservedModel.instantiate_observers
+ end
+
+ test "instantiates observer names passed as symbols" do
+ ObservedModel.observers << :foo_observer
+ FooObserver.expects(:instance)
+ ObservedModel.instantiate_observers
+ end
+
+ test "instantiates observer classes" do
+ ObservedModel.observers << ObservedModel::Observer
+ ObservedModel::Observer.expects(:instance)
+ ObservedModel.instantiate_observers
end
test "passes observers to subclasses" do
diff --git a/activemodel/test/state_machine/event_test.rb b/activemodel/test/state_machine/event_test.rb
index 7f4a9afdd8..45adb4298a 100644
--- a/activemodel/test/state_machine/event_test.rb
+++ b/activemodel/test/state_machine/event_test.rb
@@ -20,12 +20,10 @@ class EventTest < ActiveModel::TestCase
assert_equal @success, new_event.success
end
- uses_mocha 'StateTransition creation' do
- test 'should create StateTransitions' do
- ActiveModel::StateMachine::StateTransition.expects(:new).with(:to => :closed, :from => :open)
- ActiveModel::StateMachine::StateTransition.expects(:new).with(:to => :closed, :from => :received)
- new_event
- end
+ test 'should create StateTransitions' do
+ ActiveModel::StateMachine::StateTransition.expects(:new).with(:to => :closed, :from => :open)
+ ActiveModel::StateMachine::StateTransition.expects(:new).with(:to => :closed, :from => :received)
+ new_event
end
end
diff --git a/activemodel/test/state_machine/state_test.rb b/activemodel/test/state_machine/state_test.rb
index daaf0829f0..319ac82d9b 100644
--- a/activemodel/test/state_machine/state_test.rb
+++ b/activemodel/test/state_machine/state_test.rb
@@ -43,32 +43,30 @@ class StateTest < ActiveModel::TestCase
assert_equal new_state, new_state
end
- uses_mocha 'state actions' do
- 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)
+ 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)
+ record = stub
+ record.expects(:foo)
- state.call_action(:entering, record)
- end
+ 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')
+ 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)
+ record = stub
+ record.expects(:foo)
- state.call_action(:entering, record)
- end
+ 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})
+ 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
+ record = stub
+ record.expects(:foobar)
+
+ state.call_action(:entering, record)
end
end
diff --git a/activemodel/test/state_machine/state_transition_test.rb b/activemodel/test/state_machine/state_transition_test.rb
index 5165bb1c97..b59ff5a6a7 100644
--- a/activemodel/test/state_machine/state_transition_test.rb
+++ b/activemodel/test/state_machine/state_transition_test.rb
@@ -10,39 +10,37 @@ class StateTransitionTest < ActiveModel::TestCase
assert_equal opts, st.options
end
- uses_mocha 'checking ActiveModel StateMachine transitions' do
- test 'should pass equality check if from and to are the same' do
- opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
- st = ActiveModel::StateMachine::StateTransition.new(opts)
+ test 'should pass equality check if from and to are the same' do
+ opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
+ st = ActiveModel::StateMachine::StateTransition.new(opts)
- obj = stub
- obj.stubs(:from).returns(opts[:from])
- obj.stubs(:to).returns(opts[:to])
+ obj = stub
+ obj.stubs(:from).returns(opts[:from])
+ obj.stubs(:to).returns(opts[:to])
- assert_equal st, obj
- end
+ assert_equal st, obj
+ end
- test 'should fail equality check if from are not the same' do
- opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
- st = ActiveModel::StateMachine::StateTransition.new(opts)
+ test 'should fail equality check if from are not the same' do
+ opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
+ st = ActiveModel::StateMachine::StateTransition.new(opts)
- obj = stub
- obj.stubs(:from).returns('blah')
- obj.stubs(:to).returns(opts[:to])
+ obj = stub
+ obj.stubs(:from).returns('blah')
+ obj.stubs(:to).returns(opts[:to])
- assert_not_equal st, obj
- end
-
- test 'should fail equality check if to are not the same' do
- opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
- st = ActiveModel::StateMachine::StateTransition.new(opts)
+ assert_not_equal st, obj
+ end
+
+ test 'should fail equality check if to are not the same' do
+ opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
+ st = ActiveModel::StateMachine::StateTransition.new(opts)
- obj = stub
- obj.stubs(:from).returns(opts[:from])
- obj.stubs(:to).returns('blah')
+ obj = stub
+ obj.stubs(:from).returns(opts[:from])
+ obj.stubs(:to).returns('blah')
- assert_not_equal st, obj
- end
+ assert_not_equal st, obj
end
end
@@ -54,35 +52,33 @@ class StateTransitionGuardCheckTest < ActiveModel::TestCase
assert st.perform(nil)
end
- uses_mocha 'checking ActiveModel StateMachine transition guard checks' do
- test 'should call the method on the object if guard is a symbol' do
- opts = {:from => 'foo', :to => 'bar', :guard => :test_guard}
- st = ActiveModel::StateMachine::StateTransition.new(opts)
-
- obj = stub
- obj.expects(:test_guard)
-
- st.perform(obj)
- end
-
- test 'should call the method on the object if guard is a string' do
- opts = {:from => 'foo', :to => 'bar', :guard => 'test_guard'}
- st = ActiveModel::StateMachine::StateTransition.new(opts)
-
- obj = stub
- obj.expects(:test_guard)
-
- st.perform(obj)
- end
-
- test 'should call the proc passing the object if the guard is a proc' do
- opts = {:from => 'foo', :to => 'bar', :guard => Proc.new {|o| o.test_guard}}
- st = ActiveModel::StateMachine::StateTransition.new(opts)
+ test 'should call the method on the object if guard is a symbol' do
+ opts = {:from => 'foo', :to => 'bar', :guard => :test_guard}
+ st = ActiveModel::StateMachine::StateTransition.new(opts)
+
+ obj = stub
+ obj.expects(:test_guard)
- obj = stub
- obj.expects(:test_guard)
+ st.perform(obj)
+ end
+
+ test 'should call the method on the object if guard is a string' do
+ opts = {:from => 'foo', :to => 'bar', :guard => 'test_guard'}
+ st = ActiveModel::StateMachine::StateTransition.new(opts)
+
+ obj = stub
+ obj.expects(:test_guard)
- st.perform(obj)
- end
+ st.perform(obj)
+ end
+
+ test 'should call the proc passing the object if the guard is a proc' do
+ opts = {:from => 'foo', :to => 'bar', :guard => Proc.new {|o| o.test_guard}}
+ st = ActiveModel::StateMachine::StateTransition.new(opts)
+
+ obj = stub
+ obj.expects(:test_guard)
+
+ st.perform(obj)
end
end
diff --git a/activemodel/test/state_machine_test.rb b/activemodel/test/state_machine_test.rb
index fb150671e0..312d8728ba 100644
--- a/activemodel/test/state_machine_test.rb
+++ b/activemodel/test/state_machine_test.rb
@@ -122,24 +122,22 @@ class StateMachineEventFiringWithPersistenceTest < ActiveModel::TestCase
assert_equal :closed, @subj.current_state
end
- uses_mocha "StateMachineEventFiringWithPersistenceTest with callbacks" do
- test 'fires the Event' do
- @subj.class.state_machine.events[:close].expects(:fire).with(@subj)
- @subj.close!
- end
-
- test 'calls the success callback if one was provided' do
- @subj.expects(:success_callback)
- @subj.close!
- end
+ test 'fires the Event' do
+ @subj.class.state_machine.events[:close].expects(:fire).with(@subj)
+ @subj.close!
+ end
- test 'attempts to persist if write_state is defined' do
- def @subj.write_state
- end
+ test 'calls the success callback if one was provided' do
+ @subj.expects(:success_callback)
+ @subj.close!
+ end
- @subj.expects(:write_state)
- @subj.close!
+ test 'attempts to persist if write_state is defined' do
+ def @subj.write_state
end
+
+ @subj.expects(:write_state)
+ @subj.close!
end
end
@@ -151,98 +149,90 @@ class StateMachineEventFiringWithoutPersistence < ActiveModel::TestCase
assert_equal :closed, subj.current_state
end
- uses_mocha 'StateMachineEventFiringWithoutPersistence' do
- test 'fires the Event' do
- subj = StateMachineSubject.new
+ test 'fires the Event' do
+ subj = StateMachineSubject.new
- StateMachineSubject.state_machine.events[:close].expects(:fire).with(subj)
- subj.close
- end
+ StateMachineSubject.state_machine.events[:close].expects(:fire).with(subj)
+ subj.close
+ end
- test 'attempts to persist if write_state is defined' do
- subj = StateMachineSubject.new
+ test 'attempts to persist if write_state is defined' do
+ subj = StateMachineSubject.new
- def subj.write_state
- end
+ def subj.write_state
+ end
- subj.expects(:write_state_without_persistence)
+ subj.expects(:write_state_without_persistence)
- subj.close
- end
+ subj.close
end
end
-uses_mocha 'StateMachinePersistenceTest' do
- class StateMachinePersistenceTest < ActiveModel::TestCase
- test 'reads the state if it has not been set and read_state is defined' do
- subj = StateMachineSubject.new
- def subj.read_state
- end
+class StateMachinePersistenceTest < ActiveModel::TestCase
+ test 'reads the state if it has not been set and read_state is defined' do
+ subj = StateMachineSubject.new
+ def subj.read_state
+ end
- subj.expects(:read_state).with(StateMachineSubject.state_machine)
+ subj.expects(:read_state).with(StateMachineSubject.state_machine)
- subj.current_state
- end
+ subj.current_state
end
end
-uses_mocha 'StateMachineEventCallbacksTest' do
- class StateMachineEventCallbacksTest < ActiveModel::TestCase
- test 'should call aasm_event_fired if defined and successful for bang fire' do
- subj = StateMachineSubject.new
- def subj.aasm_event_fired(from, to)
- end
-
- subj.expects(:event_fired)
-
- subj.close!
+class StateMachineEventCallbacksTest < ActiveModel::TestCase
+ test 'should call aasm_event_fired if defined and successful for bang fire' do
+ subj = StateMachineSubject.new
+ def subj.aasm_event_fired(from, to)
end
- test 'should call aasm_event_fired if defined and successful for non-bang fire' do
- subj = StateMachineSubject.new
- def subj.aasm_event_fired(from, to)
- end
+ subj.expects(:event_fired)
- subj.expects(:event_fired)
+ subj.close!
+ end
- subj.close
+ test 'should call aasm_event_fired if defined and successful for non-bang fire' do
+ subj = StateMachineSubject.new
+ def subj.aasm_event_fired(from, to)
end
- test 'should call aasm_event_failed if defined and transition failed for bang fire' do
- subj = StateMachineSubject.new
- def subj.event_failed(event)
- end
+ subj.expects(:event_fired)
- subj.expects(:event_failed)
+ subj.close
+ end
- subj.null!
+ test 'should call aasm_event_failed if defined and transition failed for bang fire' do
+ subj = StateMachineSubject.new
+ def subj.event_failed(event)
end
- test 'should call aasm_event_failed if defined and transition failed for non-bang fire' do
- subj = StateMachineSubject.new
- def subj.aasm_event_failed(event)
- end
+ subj.expects(:event_failed)
- subj.expects(:event_failed)
+ subj.null!
+ end
- subj.null
+ test 'should call aasm_event_failed if defined and transition failed for non-bang fire' do
+ subj = StateMachineSubject.new
+ def subj.aasm_event_failed(event)
end
+
+ subj.expects(:event_failed)
+
+ subj.null
end
end
-uses_mocha 'StateMachineStateActionsTest' do
- class StateMachineStateActionsTest < ActiveModel::TestCase
- test "calls enter when entering state" do
- subj = StateMachineSubject.new
- subj.expects(:enter)
- subj.close
- end
+class StateMachineStateActionsTest < ActiveModel::TestCase
+ test "calls enter when entering state" do
+ subj = StateMachineSubject.new
+ subj.expects(:enter)
+ subj.close
+ end
- test "calls exit when exiting state" do
- subj = StateMachineSubject.new
- subj.expects(:exit)
- subj.close
- end
+ test "calls exit when exiting state" do
+ subj = StateMachineSubject.new
+ subj.expects(:exit)
+ subj.close
end
end
@@ -306,19 +296,17 @@ class StateMachineWithComplexTransitionsTest < ActiveModel::TestCase
assert_equal :working, @subj.current_state(:chetan_patil)
end
- uses_mocha "StateMachineWithComplexTransitionsTest on_transition tests" do
- test 'calls on_transition method with args' do
- @subj.wakeup! :showering
-
- @subj.expects(:wear_clothes).with('blue', 'jeans')
- @subj.dress! :working, 'blue', 'jeans'
- end
-
- test 'calls on_transition proc' do
- @subj.wakeup! :showering
-
- @subj.expects(:wear_clothes).with('purple', 'slacks')
- @subj.dress!(:dating, 'purple', 'slacks')
- end
+ test 'calls on_transition method with args' do
+ @subj.wakeup! :showering
+
+ @subj.expects(:wear_clothes).with('blue', 'jeans')
+ @subj.dress! :working, 'blue', 'jeans'
+ end
+
+ test 'calls on_transition proc' do
+ @subj.wakeup! :showering
+
+ @subj.expects(:wear_clothes).with('purple', 'slacks')
+ @subj.dress!(:dating, 'purple', 'slacks')
end
end