Skip to content

Commit

Permalink
Removed transaction support, you can still add it manually, see activ…
Browse files Browse the repository at this point in the history
…e_record_spec.rb
  • Loading branch information
mdh committed Jun 29, 2011
1 parent cda0240 commit 3da4b50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
38 changes: 17 additions & 21 deletions lib/simple_state_machine/active_record.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/active_record_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3da4b50

Please sign in to comment.