state-fu 0.13.3 → 0.13.4

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.
@@ -12,6 +12,19 @@ module StateFu
12
12
 
13
13
  # it's usually a good idea to do this:
14
14
  # validates_presence_of _field_name
15
+
16
+ klass.class_eval do
17
+ # this is a hack to ensure that when you use the same field for the database
18
+ # column and the machine name, you don't end up with an unserializable
19
+ # StateFu::Binding in record#changes() ...
20
+ def attribute_change(column)
21
+ change = super
22
+ if self.class.respond_to?(:machines) && self.class.machines.keys.include?(column.to_sym)
23
+ change[1] = read_attribute(column)
24
+ end
25
+ change
26
+ end
27
+ end
15
28
  end
16
29
 
17
30
  private
@@ -26,6 +26,26 @@ describe "an ActiveRecord model with StateFu included:" do
26
26
  # end class ExampleRecord
27
27
  end
28
28
 
29
+ describe 'a machine with the same name as the database field' do
30
+ before do
31
+ make_pristine_class( 'IdentityCrisis', ActiveRecord::Base )
32
+ IdentityCrisis.class_eval do
33
+ set_table_name 'example_records'
34
+ validates_presence_of :name
35
+ machine(:state_fu_field, :field_name => :state_fu_field) do
36
+ connect :a, :b, :c
37
+ end
38
+ end
39
+ end
40
+
41
+ it 'should not include a StateFu::Binding in record#changes' do
42
+ record = IdentityCrisis.new :name => 'coexisting field and machine name'
43
+ record.save!
44
+ record.state_fu_field.next!
45
+ record.changes['state_fu_field'].last.class.should == String
46
+ end
47
+ end
48
+
29
49
  it "should be a subclass of ActiveRecord::Base" do
30
50
  ExampleRecord.superclass.should == ActiveRecord::Base
31
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Lee