Permalink
Browse files

Removed transaction support, you can still add it manually, see activ…

…e_record_spec.rb
  • Loading branch information...
1 parent cda0240 commit 3da4b50f0e7b800166add8caf6bcd2ce3a9d2ee4 @mdh committed Jun 29, 2011
Showing with 19 additions and 23 deletions.
  1. +17 −21 lib/simple_state_machine/active_record.rb
  2. +2 −2 spec/active_record_spec.rb
@@ -26,16 +26,14 @@ def decorate_save event_name
@subject.send(:define_method, event_name_and_save) do |*args|
result = false
old_state = self.send(self.class.state_machine_definition.state_method)
- transaction do
- send "with_managed_state_#{event_name}", *args
- if !self.errors.entries.empty?
- self.send("#{self.class.state_machine_definition.state_method}=", old_state)
+ send "with_managed_state_#{event_name}", *args
+ if !self.errors.entries.empty?
+ self.send("#{self.class.state_machine_definition.state_method}=", old_state)
+ else
+ if save
+ result = true
else
- if save
- result = true
- else
- self.send("#{self.class.state_machine_definition.state_method}=", old_state)
- end
+ self.send("#{self.class.state_machine_definition.state_method}=", old_state)
end
end
return result
@@ -50,18 +48,16 @@ def decorate_save! event_name
@subject.send(:define_method, event_name_and_save_bang) do |*args|
result = nil
old_state = self.send(self.class.state_machine_definition.state_method)
- transaction do
- send "with_managed_state_#{event_name}", *args
- if !self.errors.entries.empty?
- self.send("#{self.class.state_machine_definition.state_method}=", old_state)
- raise ActiveRecord::RecordInvalid.new(self)
- end
- begin
- result = save!
- rescue ActiveRecord::RecordInvalid
- self.send("#{self.class.state_machine_definition.state_method}=", old_state)
- raise #re raise
- end
+ send "with_managed_state_#{event_name}", *args
+ if !self.errors.entries.empty?
+ self.send("#{self.class.state_machine_definition.state_method}=", old_state)
+ raise ActiveRecord::RecordInvalid.new(self)
+ end
+ begin
+ result = save!
+ rescue ActiveRecord::RecordInvalid
+ self.send("#{self.class.state_machine_definition.state_method}=", old_state)
+ raise #re raise
end
return result
end
@@ -122,7 +122,7 @@ def after_initialize
user_class.count.should == 0
user = user_class.create!(:name => 'name')
expect {
- user.invite_and_save
+ user.transaction { user.invite_and_save }
}.to raise_error(ActiveRecord::RecordInvalid,
"Validation failed: Name can't be blank")
user_class.count.should == 1
@@ -190,7 +190,7 @@ def after_initialize
user_class.count.should == 0
user = user_class.create!(:name => 'name')
expect {
- user.invite_and_save!
+ user.transaction { user.invite_and_save! }
}.to raise_error(ActiveRecord::RecordInvalid,
"Validation failed: Name can't be blank")
user_class.count.should == 1

0 comments on commit 3da4b50

Please sign in to comment.