state_machine 0.3.0 → 0.3.1

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.3.1 / 2008-10-26
4
+
5
+ * Fix the initial state not getting set when the state attribute is mass-assigned but protected
6
+ * Change how the base module is included to prevent namespacing conflicts
7
+
3
8
  == 0.3.0 / 2008-09-07
4
9
 
5
10
  * No longer allow additional arguments to be passed into event actions
data/README.rdoc CHANGED
@@ -44,7 +44,7 @@ Below is an example of many of the features offered by this plugin, including
44
44
  * Conditional transitions
45
45
 
46
46
  class Vehicle < ActiveRecord::Base
47
- state_machine :state, :initial => 'idling' do
47
+ state_machine :state, :initial => 'parked' do
48
48
  before_transition :from => %w(parked idling), :do => :put_on_seatbelt
49
49
  after_transition :to => 'parked', :do => lambda {|vehicle| vehicle.update_attribute(:seatbelt_on, false)}
50
50
  after_transition :on => 'crash', :do => :tow!
@@ -127,7 +127,7 @@ states can be transparently stored using record ids in the database like so:
127
127
  class Vehicle < ActiveRecord::Base
128
128
  belongs_to :state, :class_name => 'VehicleState'
129
129
 
130
- state_machine :state, :initial => 'idling' do
130
+ state_machine :state, :initial => 'parked' do
131
131
  ...
132
132
 
133
133
  event :park do
data/Rakefile CHANGED
@@ -5,11 +5,11 @@ require 'rake/contrib/sshpublisher'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'state_machine'
8
- s.version = '0.3.0'
8
+ s.version = '0.3.1'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.summary = 'Adds support for creating state machines for attributes within a model'
11
11
 
12
- s.files = FileList['{lib,test}/**/*'].to_a - FileList['test/app_root/log/*'].to_a + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc)
12
+ s.files = FileList['{lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
13
13
  s.require_path = 'lib'
14
14
  s.has_rdoc = true
15
15
  s.test_files = Dir['test/**/*_test.rb']
data/lib/state_machine.rb CHANGED
@@ -5,12 +5,6 @@ module PluginAWeek #:nodoc:
5
5
  # transitions. This helper adds support for defining this type of
6
6
  # functionality within ActiveRecord models.
7
7
  module StateMachine
8
- def self.included(base) #:nodoc:
9
- base.class_eval do
10
- extend PluginAWeek::StateMachine::MacroMethods
11
- end
12
- end
13
-
14
8
  module MacroMethods
15
9
  # Creates a state machine for the given attribute. The default attribute
16
10
  # is "state".
@@ -113,7 +107,7 @@ module PluginAWeek #:nodoc:
113
107
 
114
108
  # Set the initial value of each state machine as long as the value wasn't
115
109
  # included in the initial attributes
116
- attributes = (attributes || {}).stringify_keys
110
+ attributes = remove_attributes_protected_from_mass_assignment((attributes || {}).stringify_keys)
117
111
  self.class.state_machines.each do |attribute, machine|
118
112
  send("#{attribute}=", machine.initial_state(self)) unless attributes.include?(attribute)
119
113
  end
@@ -125,5 +119,5 @@ module PluginAWeek #:nodoc:
125
119
  end
126
120
 
127
121
  ActiveRecord::Base.class_eval do
128
- include PluginAWeek::StateMachine
122
+ extend PluginAWeek::StateMachine::MacroMethods
129
123
  end
data/test/factory.rb CHANGED
@@ -13,12 +13,16 @@ module Factory
13
13
  def valid_attributes_for(model, attributes = {})
14
14
  name = model.to_s.underscore
15
15
  send("#{name}_attributes", attributes)
16
+ attributes.stringify_keys!
16
17
  attributes
17
18
  end
18
19
 
19
20
  # Build an unsaved record
20
21
  def new_record(model, *args)
21
- model.new(valid_attributes_for(model, *args))
22
+ attributes = valid_attributes_for(model, *args)
23
+ record = model.new(attributes)
24
+ attributes.each {|attr, value| record.send("#{attr}=", value) if model.accessible_attributes && !model.accessible_attributes.include?(attr) || model.protected_attributes && model.protected_attributes.include?(attr)}
25
+ record
22
26
  end
23
27
 
24
28
  # Build and save/reload a record
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Pfeifer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-07 00:00:00 -04:00
12
+ date: 2008-10-26 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -38,9 +38,6 @@ files:
38
38
  - test/app_root/app/models/car.rb
39
39
  - test/app_root/app/models/switch_observer.rb
40
40
  - test/app_root/app/models/auto_shop.rb
41
- - test/app_root/script
42
- - test/app_root/script/rails_framework_root.rb
43
- - test/app_root/script/console
44
41
  - test/app_root/config
45
42
  - test/app_root/config/environment.rb
46
43
  - test/app_root/db
@@ -49,7 +46,6 @@ files:
49
46
  - test/app_root/db/migrate/003_create_highways.rb
50
47
  - test/app_root/db/migrate/004_create_vehicles.rb
51
48
  - test/app_root/db/migrate/001_create_switches.rb
52
- - test/app_root/log
53
49
  - test/functional
54
50
  - test/functional/state_machine_test.rb
55
51
  - test/test_helper.rb
@@ -1,8 +0,0 @@
1
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
2
- libs = " -r irb/completion"
3
- libs << " -r test/app_root/script/rails_framework_root"
4
- libs << " -r test/test_helper"
5
- libs << " -r plugin_test_helper/console_with_fixtures"
6
- libs << " -r console_app"
7
- libs << " -r console_with_helpers"
8
- exec "#{irb} #{libs} --simple-prompt"
@@ -1 +0,0 @@
1
- RAILS_FRAMEWORK_ROOT = '/home/aaron/Projects/Vendor/rails'