simple_state_machine 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -41,7 +41,7 @@ module SimpleStateMachine
41
41
  end
42
42
 
43
43
  def next_state(event_name)
44
- transitions[event_name.to_s][@subject.state]
44
+ transitions[event_name.to_s][@subject.state.to_s]
45
45
  end
46
46
 
47
47
  def transition(event_name)
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{simple_state_machine}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marek de Heus", "Petrik de Heus"]
@@ -50,6 +50,13 @@ describe User do
50
50
  User.find(user.id).activation_code.should_not be_nil
51
51
  end
52
52
 
53
+ it "persists transitions when using send and a symbol" do
54
+ user = User.create!(:name => 'name')
55
+ user.send(:invite_and_save).should == true
56
+ User.find(user.id).should be_invited
57
+ User.find(user.id).activation_code.should_not be_nil
58
+ end
59
+
53
60
  it "raises an error if an invalid state_transition is called" do
54
61
  user = User.create!(:name => 'name')
55
62
  l = lambda { user.confirm_invitation_and_save 'abc' }
@@ -90,7 +97,6 @@ describe User do
90
97
  l.should raise_error(RuntimeError, "You cannot 'confirm_invitation' when state is 'new'")
91
98
  end
92
99
 
93
-
94
100
  it "raises a RecordInvalid and keeps state if record is invalid" do
95
101
  user = User.new
96
102
  user.should be_new
@@ -3,10 +3,10 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  class SimpleExample
4
4
  extend SimpleStateMachine
5
5
  attr_reader :event2_called
6
- def initialize
7
- self.state = 'state1'
6
+ def initialize(state = 'state1')
7
+ @state = state
8
8
  end
9
- event :event1, :state1 => :state2
9
+ event :event1, :state1 => :state2, :state2 => :state3
10
10
  def event2
11
11
  @event2_called = true
12
12
  'event2'
@@ -21,6 +21,23 @@ describe SimpleStateMachine do
21
21
  end
22
22
 
23
23
  describe "events" do
24
+
25
+ it "changes state" do
26
+ example = SimpleExample.new
27
+ example.should be_state1
28
+ example.event1
29
+ example.should be_state2
30
+ example.event1
31
+ example.should be_state3
32
+ end
33
+
34
+ it "changes state when state is a symbol instead of a string" do
35
+ example = SimpleExample.new :state1
36
+ example.state.should == :state1
37
+ example.send(:event1)
38
+ example.should be_state2
39
+ end
40
+
24
41
  it "raise an error if an invalid state_transition is called" do
25
42
  example = SimpleExample.new
26
43
  lambda { example.event2 }.should raise_error(RuntimeError, "You cannot 'event2' when state is 'state1'")
@@ -49,4 +66,4 @@ describe SimpleStateMachine do
49
66
  end
50
67
  end
51
68
 
52
- end
69
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_state_machine
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marek de Heus