transitions 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,16 +10,6 @@ Just paste the following line into the Gemfile:
10
10
 
11
11
  gem "transitions"
12
12
 
13
- == Note on Patches/Pull Requests
14
-
15
- * Fork the project.
16
- * Make your feature addition or bug fix.
17
- * Add tests for it. This is important so I don't break it in a
18
- future version unintentionally.
19
- * Commit, do not mess with rakefile, version, or history.
20
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
21
- * Send me a pull request. Bonus points for topic branches.
22
-
23
13
  == Copyright
24
14
 
25
15
  Copyright (c) 2010 Jakub Kuźma. See LICENSE for details.
data/lib/transitions.rb CHANGED
@@ -26,6 +26,8 @@ require "transitions/state"
26
26
  require "transitions/state_transition"
27
27
 
28
28
  module Transitions
29
+ VERSION = "0.0.6"
30
+
29
31
  class InvalidTransition < Exception
30
32
 
31
33
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Jakub Ku\xC5\xBAma"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-14 00:00:00 +01:00
17
+ date: 2010-04-20 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +26,8 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 2
29
- version: "2"
29
+ - 0
30
+ version: "2.0"
30
31
  type: :development
31
32
  version_requirements: *id001
32
33
  - !ruby/object:Gem::Dependency
@@ -65,45 +66,30 @@ dependencies:
65
66
  version: "0"
66
67
  type: :development
67
68
  version_requirements: *id004
68
- description:
69
+ description: Lightweight state machine extracted from ActiveModel
69
70
  email: qoobaa@gmail.com
70
71
  executables: []
71
72
 
72
73
  extensions: []
73
74
 
74
- extra_rdoc_files:
75
- - LICENSE
76
- - README.rdoc
75
+ extra_rdoc_files: []
76
+
77
77
  files:
78
- - .document
79
- - .gitignore
80
- - LICENSE
81
- - README.rdoc
82
- - Rakefile
83
- - VERSION
84
- - lib/active_record/transitions.rb
85
- - lib/transitions.rb
86
- - lib/transitions/event.rb
87
- - lib/transitions/machine.rb
88
78
  - lib/transitions/state.rb
79
+ - lib/transitions/machine.rb
80
+ - lib/transitions/event.rb
89
81
  - lib/transitions/state_transition.rb
90
- - test/helper.rb
91
- - test/test_active_record.rb
92
- - test/test_event.rb
93
- - test/test_event_arguments.rb
94
- - test/test_event_being_fired.rb
95
- - test/test_machine.rb
96
- - test/test_state.rb
97
- - test/test_state_transition.rb
98
- - test/test_state_transition_guard_check.rb
99
- - transitions.gemspec
82
+ - lib/transitions.rb
83
+ - lib/active_record/transitions.rb
84
+ - LICENSE
85
+ - README.rdoc
100
86
  has_rdoc: true
101
87
  homepage: http://github.com/qoobaa/transitions
102
88
  licenses: []
103
89
 
104
90
  post_install_message:
105
- rdoc_options:
106
- - --charset=UTF-8
91
+ rdoc_options: []
92
+
107
93
  require_paths:
108
94
  - lib
109
95
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -118,8 +104,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
104
  - - ">="
119
105
  - !ruby/object:Gem::Version
120
106
  segments:
121
- - 0
122
- version: "0"
107
+ - 1
108
+ - 3
109
+ - 6
110
+ version: 1.3.6
123
111
  requirements: []
124
112
 
125
113
  rubyforge_project:
@@ -127,13 +115,5 @@ rubygems_version: 1.3.6
127
115
  signing_key:
128
116
  specification_version: 3
129
117
  summary: State machine extracted from ActiveModel
130
- test_files:
131
- - test/helper.rb
132
- - test/test_state_transition_guard_check.rb
133
- - test/test_active_record.rb
134
- - test/test_machine.rb
135
- - test/test_state_transition.rb
136
- - test/test_event_arguments.rb
137
- - test/test_state.rb
138
- - test/test_event_being_fired.rb
139
- - test/test_event.rb
118
+ test_files: []
119
+
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## GEM
22
- *.gem
23
-
24
- ## PROJECT::SPECIFIC
data/Rakefile DELETED
@@ -1,58 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require "rubygems"
4
- require "rake"
5
-
6
- begin
7
- require "jeweler"
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = "transitions"
10
- gem.summary = %Q{State machine extracted from ActiveModel}
11
- # gem.description = %Q{TODO: longer description of your gem}
12
- gem.email = "qoobaa@gmail.com"
13
- gem.homepage = "http://github.com/qoobaa/transitions"
14
- gem.authors = ["Jakub Kuźma"]
15
- gem.add_development_dependency "test-unit", ">= 2"
16
- gem.add_development_dependency "mocha"
17
- gem.add_development_dependency "sqlite3-ruby"
18
- gem.add_development_dependency "activerecord"
19
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
- end
21
- Jeweler::GemcutterTasks.new
22
- rescue LoadError
23
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
24
- end
25
-
26
- require "rake/testtask"
27
- Rake::TestTask.new(:test) do |test|
28
- test.libs << "lib" << "test"
29
- test.pattern = "test/**/test_*.rb"
30
- test.verbose = true
31
- end
32
-
33
- begin
34
- require "rcov/rcovtask"
35
- Rcov::RcovTask.new do |test|
36
- test.libs << "test"
37
- test.pattern = "test/**/test_*.rb"
38
- test.verbose = true
39
- end
40
- rescue LoadError
41
- task :rcov do
42
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
43
- end
44
- end
45
-
46
- task :test => :check_dependencies
47
-
48
- task :default => :test
49
-
50
- require "rake/rdoctask"
51
- Rake::RDocTask.new do |rdoc|
52
- version = File.exist?("VERSION") ? File.read("VERSION") : ""
53
-
54
- rdoc.rdoc_dir = "rdoc"
55
- rdoc.title = "state_machine #{version}"
56
- rdoc.rdoc_files.include("README*")
57
- rdoc.rdoc_files.include("lib/**/*.rb")
58
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.5
data/test/helper.rb DELETED
@@ -1,14 +0,0 @@
1
- require "rubygems"
2
- gem "test-unit" # enforce gem usage on 1.8.x
3
- require "test/unit"
4
- require "active_record"
5
- require "mocha"
6
-
7
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
8
- $LOAD_PATH.unshift(File.dirname(__FILE__))
9
- require "transitions"
10
- require "active_record/transitions"
11
-
12
- class Test::Unit::TestCase
13
-
14
- end
@@ -1,79 +0,0 @@
1
- require "helper"
2
-
3
- class CreateTrafficLights < ActiveRecord::Migration
4
- def self.up
5
- create_table(:traffic_lights) { |t| t.string :state }
6
- end
7
- end
8
-
9
- class TrafficLight < ActiveRecord::Base
10
- include ActiveRecord::Transitions
11
-
12
- state_machine do
13
- state :off
14
-
15
- state :red
16
- state :green
17
- state :yellow
18
-
19
- event :red_on do
20
- transitions :to => :red, :from => [:yellow]
21
- end
22
-
23
- event :green_on do
24
- transitions :to => :green, :from => [:red]
25
- end
26
-
27
- event :yellow_on do
28
- transitions :to => :yellow, :from => [:green]
29
- end
30
-
31
- event :reset do
32
- transitions :to => :red, :from => [:off]
33
- end
34
- end
35
- end
36
-
37
- class TestActiveRecord < Test::Unit::TestCase
38
- def setup
39
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
40
- ActiveRecord::Migration.verbose = false
41
- CreateTrafficLights.migrate(:up)
42
-
43
- @light = TrafficLight.create!
44
- end
45
-
46
- test "states initial state" do
47
- assert @light.off?
48
- assert_equal :off, @light.current_state
49
- end
50
-
51
- test "transition to a valid state" do
52
- @light.reset
53
- assert @light.red?
54
- assert_equal :red, @light.current_state
55
-
56
- @light.green_on
57
- assert @light.green?
58
- assert_equal :green, @light.current_state
59
- end
60
-
61
- test "transition does not persist state" do
62
- @light.reset
63
- assert_equal :red, @light.current_state
64
- @light.reload
65
- assert_equal "off", @light.state
66
- end
67
-
68
- test "transition does persists state" do
69
- @light.reset!
70
- assert_equal :red, @light.current_state
71
- @light.reload
72
- assert_equal "red", @light.state
73
- end
74
-
75
- test "transition to an invalid state" do
76
- assert_raise(Transitions::InvalidTransition) { @light.yellow_on }
77
- assert_equal :off, @light.current_state
78
- end
79
- end
data/test/test_event.rb DELETED
@@ -1,28 +0,0 @@
1
- require "helper"
2
-
3
- class TestEvent < Test::Unit::TestCase
4
- def setup
5
- @state_name = :close_order
6
- @success = :success_callback
7
- end
8
-
9
- def new_event
10
- @event = Transitions::Event.new(nil, @state_name, {:success => @success}) do
11
- transitions :to => :closed, :from => [:open, :received]
12
- end
13
- end
14
-
15
- test "should set the name" do
16
- assert_equal @state_name, new_event.name
17
- end
18
-
19
- test "should set the success option" do
20
- assert_equal @success, new_event.success
21
- end
22
-
23
- test "should create StateTransitions" do
24
- Transitions::StateTransition.expects(:new).with(:to => :closed, :from => :open)
25
- Transitions::StateTransition.expects(:new).with(:to => :closed, :from => :received)
26
- new_event
27
- end
28
- end
@@ -1,30 +0,0 @@
1
- require "helper"
2
-
3
- class ArgumentsTestSubject
4
- include Transitions
5
- attr_accessor :date
6
-
7
- state_machine do
8
- state :initial
9
- state :opened
10
-
11
- event :open do
12
- transitions :from => :initial, :to => :opened, :on_transition => :update_date
13
- end
14
- end
15
-
16
- def update_date(date = Date.today)
17
- self.date = date
18
- end
19
- end
20
-
21
- class StateMachineMachineTest < Test::Unit::TestCase
22
- test "pass arguments to transition method" do
23
- subject = ArgumentsTestSubject.new
24
- assert_equal :initial, subject.current_state
25
- subject.open!(Date.yesterday)
26
- assert_equal :opened, subject.current_state
27
- assert_equal Date.yesterday, subject.date
28
- end
29
- end
30
-
@@ -1,22 +0,0 @@
1
- require "helper"
2
-
3
- class TestEventBeingFired < Test::Unit::TestCase
4
- test "should raise an Transitions::InvalidTransition error if the transitions are empty" do
5
- event = Transitions::Event.new(nil, :event)
6
-
7
- assert_raise Transitions::InvalidTransition do
8
- event.fire(nil)
9
- end
10
- end
11
-
12
- test "should return the state of the first matching transition it finds" do
13
- event = Transitions::Event.new(nil, :event) do
14
- transitions :to => :closed, :from => [:open, :received]
15
- end
16
-
17
- obj = stub
18
- obj.stubs(:current_state).returns(:open)
19
-
20
- assert_equal :closed, event.fire(obj)
21
- end
22
- end
data/test/test_machine.rb DELETED
@@ -1,43 +0,0 @@
1
- require "helper"
2
-
3
- class MachineTestSubject
4
- include Transitions
5
-
6
- state_machine do
7
- state :open
8
- state :closed
9
- end
10
-
11
- state_machine :initial => :foo do
12
- event :shutdown do
13
- transitions :from => :open, :to => :closed
14
- end
15
-
16
- event :timeout do
17
- transitions :from => :open, :to => :closed
18
- end
19
- end
20
-
21
- state_machine :extra, :initial => :bar do
22
- end
23
- end
24
-
25
- class TransitionsMachineTest < Test::Unit::TestCase
26
- test "allows reuse of existing machines" do
27
- assert_equal 2, MachineTestSubject.state_machines.size
28
- end
29
-
30
- test "sets #initial_state from :initial option" do
31
- assert_equal :bar, MachineTestSubject.state_machine(:extra).initial_state
32
- end
33
-
34
- test "accesses non-default state machine" do
35
- assert_kind_of Transitions::Machine, MachineTestSubject.state_machine(:extra)
36
- end
37
-
38
- test "finds events for given state" do
39
- events = MachineTestSubject.state_machine.events_for(:open)
40
- assert events.include?(:shutdown)
41
- assert events.include?(:timeout)
42
- end
43
- end
data/test/test_state.rb DELETED
@@ -1,72 +0,0 @@
1
- require "helper"
2
-
3
- class StateTestSubject
4
- include Transitions
5
-
6
- state_machine do
7
- end
8
- end
9
-
10
- class TestState < Test::Unit::TestCase
11
- def setup
12
- @state_name = :astate
13
- @machine = StateTestSubject.state_machine
14
- @options = { :crazy_custom_key => "key", :machine => @machine }
15
- end
16
-
17
- def new_state(options={})
18
- Transitions::State.new(@state_name, @options.merge(options))
19
- end
20
-
21
- test "sets the name" do
22
- assert_equal :astate, new_state.name
23
- end
24
-
25
- test "sets the display_name from name" do
26
- assert_equal "Astate", new_state.display_name
27
- end
28
-
29
- test "sets the display_name from options" do
30
- assert_equal "A State", new_state(:display => "A State").display_name
31
- end
32
-
33
- test "sets the options and expose them as options" do
34
- @options.delete(:machine)
35
- assert_equal @options, new_state.options
36
- end
37
-
38
- test "equals a symbol of the same name" do
39
- assert_equal new_state, :astate
40
- end
41
-
42
- test "equals a State of the same name" do
43
- assert_equal new_state, new_state
44
- end
45
-
46
- test "should send a message to the record for an action if the action is present as a symbol" do
47
- state = new_state(:entering => :foo)
48
-
49
- record = stub
50
- record.expects(:foo)
51
-
52
- state.call_action(:entering, record)
53
- end
54
-
55
- test "should send a message to the record for an action if the action is present as a string" do
56
- state = new_state(:entering => "foo")
57
-
58
- record = stub
59
- record.expects(:foo)
60
-
61
- state.call_action(:entering, record)
62
- end
63
-
64
- test "should call a proc, passing in the record for an action if the action is present" do
65
- state = new_state(:entering => Proc.new {|r| r.foobar})
66
-
67
- record = stub
68
- record.expects(:foobar)
69
-
70
- state.call_action(:entering, record)
71
- end
72
- end
@@ -1,45 +0,0 @@
1
- require "helper"
2
-
3
- class TestStateTransition < Test::Unit::TestCase
4
- test "should set from, to, and opts attr readers" do
5
- opts = {:from => "foo", :to => "bar", :guard => "g"}
6
- st = Transitions::StateTransition.new(opts)
7
-
8
- assert_equal opts[:from], st.from
9
- assert_equal opts[:to], st.to
10
- assert_equal opts, st.options
11
- end
12
-
13
- test "should pass equality check if from and to are the same" do
14
- opts = {:from => "foo", :to => "bar", :guard => "g"}
15
- st = Transitions::StateTransition.new(opts)
16
-
17
- obj = stub
18
- obj.stubs(:from).returns(opts[:from])
19
- obj.stubs(:to).returns(opts[:to])
20
-
21
- assert_equal st, obj
22
- end
23
-
24
- test "should fail equality check if from are not the same" do
25
- opts = {:from => "foo", :to => "bar", :guard => "g"}
26
- st = Transitions::StateTransition.new(opts)
27
-
28
- obj = stub
29
- obj.stubs(:from).returns("blah")
30
- obj.stubs(:to).returns(opts[:to])
31
-
32
- assert_not_equal st, obj
33
- end
34
-
35
- test "should fail equality check if to are not the same" do
36
- opts = {:from => "foo", :to => "bar", :guard => "g"}
37
- st = Transitions::StateTransition.new(opts)
38
-
39
- obj = stub
40
- obj.stubs(:from).returns(opts[:from])
41
- obj.stubs(:to).returns("blah")
42
-
43
- assert_not_equal st, obj
44
- end
45
- end
@@ -1,40 +0,0 @@
1
- require "helper"
2
-
3
- class TestStateTransitionGuardCheck < Test::Unit::TestCase
4
- test "should return true of there is no guard" do
5
- opts = {:from => "foo", :to => "bar"}
6
- st = Transitions::StateTransition.new(opts)
7
-
8
- assert st.perform(nil)
9
- end
10
-
11
- test "should call the method on the object if guard is a symbol" do
12
- opts = {:from => "foo", :to => "bar", :guard => :test_guard}
13
- st = Transitions::StateTransition.new(opts)
14
-
15
- obj = stub
16
- obj.expects(:test_guard)
17
-
18
- st.perform(obj)
19
- end
20
-
21
- test "should call the method on the object if guard is a string" do
22
- opts = {:from => "foo", :to => "bar", :guard => "test_guard"}
23
- st = Transitions::StateTransition.new(opts)
24
-
25
- obj = stub
26
- obj.expects(:test_guard)
27
-
28
- st.perform(obj)
29
- end
30
-
31
- test "should call the proc passing the object if the guard is a proc" do
32
- opts = {:from => "foo", :to => "bar", :guard => Proc.new {|o| o.test_guard}}
33
- st = Transitions::StateTransition.new(opts)
34
-
35
- obj = stub
36
- obj.expects(:test_guard)
37
-
38
- st.perform(obj)
39
- end
40
- end
data/transitions.gemspec DELETED
@@ -1,81 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{transitions}
8
- s.version = "0.0.5"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Jakub Kuźma"]
12
- s.date = %q{2010-03-14}
13
- s.email = %q{qoobaa@gmail.com}
14
- s.extra_rdoc_files = [
15
- "LICENSE",
16
- "README.rdoc"
17
- ]
18
- s.files = [
19
- ".document",
20
- ".gitignore",
21
- "LICENSE",
22
- "README.rdoc",
23
- "Rakefile",
24
- "VERSION",
25
- "lib/active_record/transitions.rb",
26
- "lib/transitions.rb",
27
- "lib/transitions/event.rb",
28
- "lib/transitions/machine.rb",
29
- "lib/transitions/state.rb",
30
- "lib/transitions/state_transition.rb",
31
- "test/helper.rb",
32
- "test/test_active_record.rb",
33
- "test/test_event.rb",
34
- "test/test_event_arguments.rb",
35
- "test/test_event_being_fired.rb",
36
- "test/test_machine.rb",
37
- "test/test_state.rb",
38
- "test/test_state_transition.rb",
39
- "test/test_state_transition_guard_check.rb",
40
- "transitions.gemspec"
41
- ]
42
- s.homepage = %q{http://github.com/qoobaa/transitions}
43
- s.rdoc_options = ["--charset=UTF-8"]
44
- s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.3.6}
46
- s.summary = %q{State machine extracted from ActiveModel}
47
- s.test_files = [
48
- "test/helper.rb",
49
- "test/test_state_transition_guard_check.rb",
50
- "test/test_active_record.rb",
51
- "test/test_machine.rb",
52
- "test/test_state_transition.rb",
53
- "test/test_event_arguments.rb",
54
- "test/test_state.rb",
55
- "test/test_event_being_fired.rb",
56
- "test/test_event.rb"
57
- ]
58
-
59
- if s.respond_to? :specification_version then
60
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
61
- s.specification_version = 3
62
-
63
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
64
- s.add_development_dependency(%q<test-unit>, [">= 2"])
65
- s.add_development_dependency(%q<mocha>, [">= 0"])
66
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
67
- s.add_development_dependency(%q<activerecord>, [">= 0"])
68
- else
69
- s.add_dependency(%q<test-unit>, [">= 2"])
70
- s.add_dependency(%q<mocha>, [">= 0"])
71
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
72
- s.add_dependency(%q<activerecord>, [">= 0"])
73
- end
74
- else
75
- s.add_dependency(%q<test-unit>, [">= 2"])
76
- s.add_dependency(%q<mocha>, [">= 0"])
77
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
78
- s.add_dependency(%q<activerecord>, [">= 0"])
79
- end
80
- end
81
-