mylescarrick-aasm 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+
3
+ class StateTransitionTest < Test::Unit::TestCase
4
+ context 'state transition' do
5
+ setup do
6
+ @opts = {:from => 'foo', :to => 'bar', :guard => 'g'}
7
+ @st = AASM::SupportingClasses::StateTransition.new(@opts)
8
+ end
9
+
10
+ should 'set from, to, and opts attr readers' do
11
+ assert_equal @opts[:from], @st.from
12
+ assert_equal @opts[:to], @st.to
13
+ assert_equal @opts, @st.options
14
+ end
15
+
16
+ should 'pass equality check if from and to are the same' do
17
+ obj = OpenStruct.new
18
+ obj.from = @opts[:from]
19
+ obj.to = @opts[:to]
20
+
21
+ assert_equal @st, obj
22
+ end
23
+
24
+ should 'fail equality check if from is not the same' do
25
+ obj = OpenStruct.new
26
+ obj.from = 'blah'
27
+ obj.to = @opts[:to]
28
+
29
+ assert_not_equal @st, obj
30
+ end
31
+
32
+ should 'fail equality check if to is not the same' do
33
+ obj = OpenStruct.new
34
+ obj.from = @opts[:from]
35
+ obj.to = 'blah'
36
+
37
+ assert_not_equal @st, obj
38
+ end
39
+
40
+ context 'when performing guard checks' do
41
+ should 'return true if there is no guard' do
42
+ opts = {:from => 'foo', :to => 'bar'}
43
+ st = AASM::SupportingClasses::StateTransition.new(opts)
44
+ assert st.perform(nil)
45
+ end
46
+
47
+ should 'call the method on the object if guard is a symbol' do
48
+ opts = {:from => 'foo', :to => 'bar', :guard => :test_guard}
49
+ st = AASM::SupportingClasses::StateTransition.new(opts)
50
+
51
+ mock(obj = Object.new).test_guard
52
+
53
+ st.perform(obj)
54
+ end
55
+
56
+ should 'call the method on the object if guard is a string' do
57
+ opts = {:from => 'foo', :to => 'bar', :guard => 'test_guard'}
58
+ st = AASM::SupportingClasses::StateTransition.new(opts)
59
+
60
+ mock(obj = Object.new).test_guard
61
+
62
+ st.perform(obj)
63
+ end
64
+
65
+ should 'call the proc passing the object if guard is a proc' do
66
+ opts = {:from => 'foo', :to => 'bar', :guard => Proc.new {|o| o.test_guard}}
67
+ st = AASM::SupportingClasses::StateTransition.new(opts)
68
+
69
+ mock(obj = Object.new).test_guard
70
+
71
+ st.perform(obj)
72
+ end
73
+ end
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mylescarrick-aasm
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Scott Barron
8
+ - Scott Petersen
9
+ - Travis Tilley
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2010-01-30 00:00:00 +11:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rspec
19
+ type: :development
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: "0"
26
+ version:
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda
29
+ type: :development
30
+ version_requirement:
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ version:
37
+ - !ruby/object:Gem::Dependency
38
+ name: sdoc
39
+ type: :development
40
+ version_requirement:
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ description: AASM is a continuation of the acts as state machine rails plugin, built for plain Ruby objects.
48
+ email: scott@elitists.net, ttilley@gmail.com
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ extra_rdoc_files:
54
+ - LICENSE
55
+ - README.rdoc
56
+ files:
57
+ - .document
58
+ - .gitignore
59
+ - LICENSE
60
+ - README.rdoc
61
+ - Rakefile
62
+ - VERSION
63
+ - lib/aasm.rb
64
+ - lib/aasm/aasm.rb
65
+ - lib/aasm/event.rb
66
+ - lib/aasm/persistence.rb
67
+ - lib/aasm/persistence/active_record_persistence.rb
68
+ - lib/aasm/state.rb
69
+ - lib/aasm/state_machine.rb
70
+ - lib/aasm/state_transition.rb
71
+ - lib/aasm/supporting_classes.rb
72
+ - spec/functional/conversation.rb
73
+ - spec/functional/conversation_spec.rb
74
+ - spec/spec_helper.rb
75
+ - spec/unit/aasm_spec.rb
76
+ - spec/unit/active_record_persistence_spec.rb
77
+ - spec/unit/before_after_callbacks_spec.rb
78
+ - spec/unit/event_spec.rb
79
+ - spec/unit/state_spec.rb
80
+ - spec/unit/state_transition_spec.rb
81
+ - test/functional/auth_machine_test.rb
82
+ - test/test_helper.rb
83
+ - test/unit/aasm_test.rb
84
+ - test/unit/event_test.rb
85
+ - test/unit/state_test.rb
86
+ - test/unit/state_transition_test.rb
87
+ has_rdoc: true
88
+ homepage: http://rubyist.github.com/aasm/
89
+ licenses: []
90
+
91
+ post_install_message:
92
+ rdoc_options:
93
+ - --charset=UTF-8
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ version:
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: "0"
107
+ version:
108
+ requirements: []
109
+
110
+ rubyforge_project:
111
+ rubygems_version: 1.3.5
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: State machine mixin for Ruby objects
115
+ test_files:
116
+ - spec/functional/conversation.rb
117
+ - spec/functional/conversation_spec.rb
118
+ - spec/spec_helper.rb
119
+ - spec/unit/aasm_spec.rb
120
+ - spec/unit/active_record_persistence_spec.rb
121
+ - spec/unit/before_after_callbacks_spec.rb
122
+ - spec/unit/event_spec.rb
123
+ - spec/unit/state_spec.rb
124
+ - spec/unit/state_transition_spec.rb
125
+ - test/functional/auth_machine_test.rb
126
+ - test/test_helper.rb
127
+ - test/unit/aasm_test.rb
128
+ - test/unit/event_test.rb
129
+ - test/unit/state_test.rb
130
+ - test/unit/state_transition_test.rb