transitions 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +18 -1
- data/.travis.yml +5 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +7 -6
- data/LICENSE.txt +21 -0
- data/README.md +9 -4
- data/Rakefile +9 -4
- data/bin/console +7 -0
- data/lib/active_model/transitions.rb +19 -12
- data/lib/transitions.rb +15 -15
- data/lib/transitions/event.rb +19 -15
- data/lib/transitions/machine.rb +23 -22
- data/lib/transitions/presenter.rb +2 -6
- data/lib/transitions/state.rb +10 -7
- data/lib/transitions/state_transition.rb +37 -6
- data/lib/transitions/version.rb +1 -1
- data/transitions.gemspec +23 -24
- metadata +39 -45
- data/.ruby-gemset +0 -1
- data/MIT-LICENSE.txt +0 -21
- data/test/active_record/test_active_record.rb +0 -326
- data/test/active_record/test_active_record_scopes.rb +0 -64
- data/test/active_record/test_active_record_timestamps.rb +0 -132
- data/test/active_record/test_custom_select.rb +0 -33
- data/test/event/test_event.rb +0 -72
- data/test/event/test_event_arguments.rb +0 -29
- data/test/event/test_event_being_fired.rb +0 -26
- data/test/event/test_event_checks.rb +0 -33
- data/test/helper.rb +0 -18
- data/test/machine/machine_template.rb +0 -27
- data/test/machine/test_available_states_listing.rb +0 -24
- data/test/machine/test_fire_event_machine.rb +0 -29
- data/test/machine/test_machine.rb +0 -66
- data/test/state/test_state.rb +0 -71
- data/test/state/test_state_predicate_method.rb +0 -32
- data/test/state_transition/test_state_transition.rb +0 -45
- data/test/state_transition/test_state_transition_event_failed_callback.rb +0 -36
- data/test/state_transition/test_state_transition_event_fired_callback.rb +0 -44
- data/test/state_transition/test_state_transition_guard_check.rb +0 -66
- data/test/state_transition/test_state_transition_on_transition_callback.rb +0 -48
- data/test/state_transition/test_state_transition_success_callback.rb +0 -49
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class DrivingInstructor
|
4
|
-
def self.applause!
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
class DrivingSchoolCar
|
9
|
-
include Transitions
|
10
|
-
|
11
|
-
state_machine do
|
12
|
-
state :parked
|
13
|
-
state :running
|
14
|
-
state :driving
|
15
|
-
state :switched_off
|
16
|
-
|
17
|
-
event :start_driving, success: lambda { |_car| DrivingInstructor.applause! } do
|
18
|
-
transitions from: :parked, to: :driving, on_transition: [:start_engine, :loosen_handbrake, :push_gas_pedal]
|
19
|
-
end
|
20
|
-
|
21
|
-
event :switch_off_engine do
|
22
|
-
transitions from: :parked, to: :switched_off
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
%w(start_engine loosen_handbrake push_gas_pedal).each do |m|
|
27
|
-
define_method(m) {}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class TestStateTransitionSuccessCallback < Test::Unit::TestCase
|
32
|
-
def setup
|
33
|
-
@car = DrivingSchoolCar.new
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'should execute the success callback after successfull event execution' do
|
37
|
-
DrivingInstructor.expects(:applause!)
|
38
|
-
|
39
|
-
@car.start_driving!
|
40
|
-
end
|
41
|
-
|
42
|
-
test 'should not execute the success callback after event execution failed' do
|
43
|
-
DrivingInstructor.expects(:applause!).never
|
44
|
-
|
45
|
-
@car.stubs(:event_failed)
|
46
|
-
@car.expects(:loosen_handbrake).raises('Drive with handbrake fail!')
|
47
|
-
@car.start_driving!
|
48
|
-
end
|
49
|
-
end
|