Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…e_record_spec.rb
  • Loading branch information...
commit 3da4b50f0e7b800166add8caf6bcd2ce3a9d2ee4 1 parent cda0240
@mdh authored
View
38 lib/simple_state_machine/active_record.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
View
4 spec/active_record_spec.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.