state_machine 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,10 @@
1
1
  == master
2
2
 
3
+ == 0.7.4 / 2009-05-23
4
+
5
+ * Fix #save! not firing event attributes properly in ActiveRecord integrations
6
+ * Fix log files being included in gems
7
+
3
8
  == 0.7.3 / 2009-04-25
4
9
 
5
10
  * Require DataMapper version be >= 0.9.4
data/Rakefile CHANGED
@@ -5,11 +5,12 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'state_machine'
8
- s.version = '0.7.3'
8
+ s.version = '0.7.4'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Adds support for creating state machines for attributes on any Ruby class'
11
+ s.description = s.summary
11
12
 
12
- s.files = FileList['{examples,lib,tasks,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
13
+ s.files = FileList['{examples,lib,tasks,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/*.log']
13
14
  s.require_path = 'lib'
14
15
  s.has_rdoc = true
15
16
  s.test_files = Dir['test/**/*_test.rb']
@@ -327,7 +327,7 @@ module StateMachine
327
327
 
328
328
  # Adds hooks into validation for automatically firing events
329
329
  def define_action_helpers
330
- if super && action == :save
330
+ if super(:create_or_update) && action == :save
331
331
  @instance_helper_module.class_eval do
332
332
  define_method(:valid?) do |*args|
333
333
  self.class.state_machines.fire_attribute_events(self, :save, false) { super(*args) }
@@ -1268,18 +1268,21 @@ module StateMachine
1268
1268
 
1269
1269
  # Adds helper methods for automatically firing events when an action
1270
1270
  # is invoked
1271
- def define_action_helpers
1271
+ def define_action_helpers(action_hook = self.action)
1272
1272
  action = self.action
1273
+ private_method = owner_class.private_method_defined?(action_hook)
1273
1274
 
1274
- if owner_class.method_defined?(action) && !owner_class.state_machines.any? {|attribute, machine| machine.action == action && machine != self}
1275
+ if (owner_class.method_defined?(action_hook) || private_method) && !owner_class.state_machines.any? {|attribute, machine| machine.action == action && machine != self}
1275
1276
  # Action is defined and hasn't already been overridden by another machine
1276
1277
  @instance_helper_module.class_eval do
1277
1278
  # Override the default action to invoke the before / after hooks
1278
- define_method(action) do |*args|
1279
+ define_method(action_hook) do |*args|
1279
1280
  value = nil
1280
1281
  result = self.class.state_machines.fire_attribute_events(self, action) { value = super(*args) }
1281
1282
  value.nil? ? result : value
1282
1283
  end
1284
+
1285
+ private action_hook if private_method
1283
1286
  end
1284
1287
 
1285
1288
  true
@@ -662,6 +662,55 @@ begin
662
662
  end
663
663
  end
664
664
 
665
+ class MachineWithEventAttributesOnSaveBangTest < ActiveRecord::TestCase
666
+ def setup
667
+ @model = new_model
668
+ @machine = StateMachine::Machine.new(@model)
669
+ @machine.event :ignite do
670
+ transition :parked => :idling
671
+ end
672
+
673
+ @record = @model.new
674
+ @record.state = 'parked'
675
+ @record.state_event = 'ignite'
676
+ end
677
+
678
+ def test_should_fail_if_event_is_invalid
679
+ @record.state_event = 'invalid'
680
+ assert_raise(ActiveRecord::RecordInvalid) { @record.save! }
681
+ end
682
+
683
+ def test_should_fail_if_event_has_no_transition
684
+ @record.state = 'idling'
685
+ assert_raise(ActiveRecord::RecordInvalid) { @record.save! }
686
+ end
687
+
688
+ def test_should_be_successful_if_event_has_transition
689
+ assert @record.save!
690
+ end
691
+
692
+ def test_should_run_before_callbacks
693
+ ran_callback = false
694
+ @machine.before_transition { ran_callback = true }
695
+
696
+ @record.save!
697
+ assert ran_callback
698
+ end
699
+
700
+ def test_should_persist_new_state
701
+ @record.save!
702
+ assert_equal 'idling', @record.state
703
+ end
704
+
705
+ def test_should_run_after_callbacks
706
+ ran_callback = false
707
+ @machine.after_transition { ran_callback = true }
708
+
709
+ @record.save!
710
+ assert ran_callback
711
+ end
712
+ end
713
+
665
714
  class MachineWithObserversTest < ActiveRecord::TestCase
666
715
  def setup
667
716
  @model = new_model
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.7.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-25 00:00:00 -04:00
12
+ date: 2009-05-23 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description:
16
+ description: Adds support for creating state machines for attributes on any Ruby class
17
17
  email: aaron@pluginaweek.org
18
18
  executables: []
19
19
 
@@ -22,90 +22,88 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
+ - examples/Car_state.png
26
+ - examples/AutoShop_state.png
25
27
  - examples/rails-rest
26
- - examples/rails-rest/view_edit.html.erb
27
- - examples/rails-rest/migration.rb
28
28
  - examples/rails-rest/view_show.html.erb
29
29
  - examples/rails-rest/controller.rb
30
30
  - examples/rails-rest/model.rb
31
- - examples/rails-rest/view_new.html.erb
32
31
  - examples/rails-rest/view_index.html.erb
33
- - examples/car.rb
34
- - examples/Vehicle_state.png
35
- - examples/AutoShop_state.png
36
- - examples/vehicle.rb
32
+ - examples/rails-rest/view_new.html.erb
33
+ - examples/rails-rest/view_edit.html.erb
34
+ - examples/rails-rest/migration.rb
37
35
  - examples/merb-rest
38
- - examples/merb-rest/view_edit.html.erb
39
36
  - examples/merb-rest/view_show.html.erb
40
37
  - examples/merb-rest/controller.rb
41
38
  - examples/merb-rest/model.rb
42
- - examples/merb-rest/view_new.html.erb
43
39
  - examples/merb-rest/view_index.html.erb
44
- - examples/traffic_light.rb
40
+ - examples/merb-rest/view_new.html.erb
41
+ - examples/merb-rest/view_edit.html.erb
42
+ - examples/vehicle.rb
45
43
  - examples/TrafficLight_state.png
46
44
  - examples/auto_shop.rb
47
- - examples/Car_state.png
45
+ - examples/traffic_light.rb
46
+ - examples/Vehicle_state.png
47
+ - examples/car.rb
48
+ - lib/state_machine.rb
48
49
  - lib/state_machine
49
- - lib/state_machine/node_collection.rb
50
- - lib/state_machine/event.rb
51
- - lib/state_machine/guard.rb
52
- - lib/state_machine/integrations.rb
50
+ - lib/state_machine/condition_proxy.rb
51
+ - lib/state_machine/machine_collection.rb
52
+ - lib/state_machine/machine.rb
53
+ - lib/state_machine/event_collection.rb
53
54
  - lib/state_machine/integrations
54
- - lib/state_machine/integrations/data_mapper
55
- - lib/state_machine/integrations/data_mapper/observer.rb
56
- - lib/state_machine/integrations/sequel.rb
57
55
  - lib/state_machine/integrations/active_record
58
- - lib/state_machine/integrations/active_record/observer.rb
59
56
  - lib/state_machine/integrations/active_record/locale.rb
60
- - lib/state_machine/integrations/active_record.rb
57
+ - lib/state_machine/integrations/active_record/observer.rb
61
58
  - lib/state_machine/integrations/data_mapper.rb
62
- - lib/state_machine/eval_helpers.rb
59
+ - lib/state_machine/integrations/sequel.rb
60
+ - lib/state_machine/integrations/active_record.rb
61
+ - lib/state_machine/integrations/data_mapper
62
+ - lib/state_machine/integrations/data_mapper/observer.rb
63
63
  - lib/state_machine/matcher_helpers.rb
64
- - lib/state_machine/transition.rb
64
+ - lib/state_machine/assertions.rb
65
+ - lib/state_machine/matcher.rb
66
+ - lib/state_machine/eval_helpers.rb
67
+ - lib/state_machine/guard.rb
68
+ - lib/state_machine/integrations.rb
65
69
  - lib/state_machine/callback.rb
66
- - lib/state_machine/machine_collection.rb
70
+ - lib/state_machine/event.rb
67
71
  - lib/state_machine/extensions.rb
68
72
  - lib/state_machine/state.rb
73
+ - lib/state_machine/transition.rb
74
+ - lib/state_machine/node_collection.rb
69
75
  - lib/state_machine/state_collection.rb
70
- - lib/state_machine/assertions.rb
71
- - lib/state_machine/matcher.rb
72
- - lib/state_machine/condition_proxy.rb
73
- - lib/state_machine/machine.rb
74
- - lib/state_machine/event_collection.rb
75
- - lib/state_machine.rb
76
76
  - tasks/state_machine.rb
77
77
  - tasks/state_machine.rake
78
- - test/sequel.log
79
- - test/active_record.log
80
- - test/test_helper.rb
81
- - test/functional
82
- - test/functional/state_machine_test.rb
83
- - test/classes
84
- - test/classes/switch.rb
85
78
  - test/unit
86
- - test/unit/matcher_helpers_test.rb
79
+ - test/unit/assertions_test.rb
80
+ - test/unit/integrations_test.rb
87
81
  - test/unit/node_collection_test.rb
88
- - test/unit/matcher_test.rb
82
+ - test/unit/invalid_event_test.rb
83
+ - test/unit/event_test.rb
84
+ - test/unit/state_collection_test.rb
85
+ - test/unit/callback_test.rb
86
+ - test/unit/condition_proxy_test.rb
89
87
  - test/unit/integrations
88
+ - test/unit/integrations/sequel_test.rb
90
89
  - test/unit/integrations/data_mapper_test.rb
91
90
  - test/unit/integrations/active_record_test.rb
92
- - test/unit/integrations/sequel_test.rb
93
- - test/unit/machine_collection_test.rb
94
- - test/unit/state_machine_test.rb
95
- - test/unit/state_collection_test.rb
96
- - test/unit/invalid_event_test.rb
97
- - test/unit/callback_test.rb
98
- - test/unit/invalid_transition_test.rb
99
- - test/unit/transition_test.rb
100
91
  - test/unit/eval_helpers_test.rb
101
- - test/unit/event_collection_test.rb
102
- - test/unit/event_test.rb
103
- - test/unit/state_test.rb
104
92
  - test/unit/guard_test.rb
105
- - test/unit/assertions_test.rb
106
- - test/unit/condition_proxy_test.rb
93
+ - test/unit/state_test.rb
94
+ - test/unit/transition_test.rb
95
+ - test/unit/matcher_test.rb
96
+ - test/unit/invalid_transition_test.rb
107
97
  - test/unit/machine_test.rb
108
- - test/unit/integrations_test.rb
98
+ - test/unit/machine_collection_test.rb
99
+ - test/unit/state_machine_test.rb
100
+ - test/unit/event_collection_test.rb
101
+ - test/unit/matcher_helpers_test.rb
102
+ - test/test_helper.rb
103
+ - test/classes
104
+ - test/classes/switch.rb
105
+ - test/functional
106
+ - test/functional/state_machine_test.rb
109
107
  - CHANGELOG.rdoc
110
108
  - init.rb
111
109
  - LICENSE
@@ -138,26 +136,26 @@ signing_key:
138
136
  specification_version: 2
139
137
  summary: Adds support for creating state machines for attributes on any Ruby class
140
138
  test_files:
141
- - test/functional/state_machine_test.rb
142
- - test/unit/matcher_helpers_test.rb
139
+ - test/unit/assertions_test.rb
140
+ - test/unit/integrations_test.rb
143
141
  - test/unit/node_collection_test.rb
144
- - test/unit/matcher_test.rb
145
- - test/unit/integrations/data_mapper_test.rb
146
- - test/unit/integrations/active_record_test.rb
147
- - test/unit/integrations/sequel_test.rb
148
- - test/unit/machine_collection_test.rb
149
- - test/unit/state_machine_test.rb
150
- - test/unit/state_collection_test.rb
151
142
  - test/unit/invalid_event_test.rb
143
+ - test/unit/event_test.rb
144
+ - test/unit/state_collection_test.rb
152
145
  - test/unit/callback_test.rb
153
- - test/unit/invalid_transition_test.rb
154
- - test/unit/transition_test.rb
146
+ - test/unit/condition_proxy_test.rb
147
+ - test/unit/integrations/sequel_test.rb
148
+ - test/unit/integrations/data_mapper_test.rb
149
+ - test/unit/integrations/active_record_test.rb
155
150
  - test/unit/eval_helpers_test.rb
156
- - test/unit/event_collection_test.rb
157
- - test/unit/event_test.rb
158
- - test/unit/state_test.rb
159
151
  - test/unit/guard_test.rb
160
- - test/unit/assertions_test.rb
161
- - test/unit/condition_proxy_test.rb
152
+ - test/unit/state_test.rb
153
+ - test/unit/transition_test.rb
154
+ - test/unit/matcher_test.rb
155
+ - test/unit/invalid_transition_test.rb
162
156
  - test/unit/machine_test.rb
163
- - test/unit/integrations_test.rb
157
+ - test/unit/machine_collection_test.rb
158
+ - test/unit/state_machine_test.rb
159
+ - test/unit/event_collection_test.rb
160
+ - test/unit/matcher_helpers_test.rb
161
+ - test/functional/state_machine_test.rb