simple_state_machine 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -74,8 +74,8 @@ You can rescue exceptions and specify the failure state
74
74
  event :download_data, :pending => :downloaded,
75
75
  Service::ConnectionError => :download_failed
76
76
 
77
- download_data! # catches Service::ConnectionError
78
- state # => "download_failed"
77
+ download_data # catches Service::ConnectionError
78
+ state # => "download_failed"
79
79
 
80
80
  === Catching all from states
81
81
  If an event should transition from all states you can use :all
@@ -115,6 +115,7 @@ To add a state machine with ActiveRecord persistence:
115
115
  end
116
116
 
117
117
  This generates the following event methods
118
+ - invite
118
119
  - invite!
119
120
  - confirm_invitation!
120
121
 
@@ -124,7 +125,7 @@ And the following methods to query the state:
124
125
  - active?
125
126
 
126
127
  If you want to be more verbose you can also use:
127
- - invite_and_save (behave like ActiveRecord save)
128
+ - invite_and_save (is equal to invite and behaves like ActiveRecord save)
128
129
  - invite_and_save! (is equal to invite! and behaves like save!)
129
130
 
130
131
  == Mountable Example
@@ -10,6 +10,7 @@ module SimpleStateMachine::ActiveRecord
10
10
  # * {event_name}_and_save
11
11
  # * {event_name}_and_save!
12
12
  # * {event_name}!
13
+ # * {event_name}
13
14
  def decorate transition
14
15
  super transition
15
16
  event_name = transition.event_name.to_s
@@ -30,6 +31,7 @@ module SimpleStateMachine::ActiveRecord
30
31
  end
31
32
  end
32
33
  end
34
+ @subject.send :alias_method, "#{transition.event_name}", event_name_and_save
33
35
  end
34
36
  event_name_and_save_bang = "#{event_name_and_save}!"
35
37
  unless @subject.method_defined?(event_name_and_save_bang)
@@ -54,11 +56,7 @@ module SimpleStateMachine::ActiveRecord
54
56
  protected
55
57
 
56
58
  def alias_event_methods event_name
57
- @subject.send(:define_method, "cannot_call_#{event_name}") do |*args|
58
- raise "You cannot call #{event_name}. Use #{event_name}! instead"
59
- end
60
59
  @subject.send :alias_method, "without_managed_state_#{event_name}", event_name
61
- @subject.send :alias_method, event_name, "cannot_call_#{event_name}"
62
60
  end
63
61
 
64
62
  def define_state_setter_method; end
@@ -1,3 +1,3 @@
1
1
  module SimpleStateMachine
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -164,10 +164,20 @@ describe ActiveRecord do
164
164
  end
165
165
 
166
166
  describe "event" do
167
+ it "persists transitions" do
168
+ user = User.create!(:name => 'name')
169
+ user.invite.should == true
170
+ User.find(user.id).should be_invited
171
+ User.find(user.id).activation_code.should_not be_nil
172
+ end
167
173
 
168
- it "raises an error" do
174
+ it "returns false, keeps state and keeps errors if event adds errors" do
169
175
  user = User.create!(:name => 'name')
170
- expect { user.invite }.to raise_error(RuntimeError, "You cannot call invite. Use invite! instead")
176
+ user.invite_and_save!
177
+ user.should be_invited
178
+ user.confirm_invitation('x').should == false
179
+ user.should be_invited
180
+ user.errors.entries.should == [['activation_code', 'is invalid']]
171
181
  end
172
182
 
173
183
  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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 2
10
- version: 0.5.2
9
+ - 3
10
+ version: 0.5.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marek de Heus