You are describing object transactions, Rails used to have support#
for those, but it was removed [1] and is currently available
as a plugin [2].

[1] http://dev.rubyonrails.org/ticket/5637
[2] http://code.bitsweat.net/svn/object_transactions/

On N, 2007-08-02 at 09:02 -0600, Jonathan Younger wrote:
> Hey All,
> 
> Am I wrong in thinking that the id and new_record? attributes should  
> be reverted if a transaction is rolled back? They don't currently  
> revert so the id attribute is left with a value that isn't actually  
> in the database and new_record? is returning false even though it  
> should be true.
> 
> Here's a test demonstrating what I'm talking about:
> 
>    def test_should_reset_id_and_new_record_if_the_transaction_rolls_back
>      topic_count_before_save = Topic.count
> 
>      new_topic = Topic.new(
>        :title => "A new topic",
>        :author_name => "Ben",
>        :author_email_address => "[EMAIL PROTECTED]",
>        :written_on => "2003-07-16t15:28:11.2233+01:00",
>        :last_read => "2004-04-15",
>        :bonus_time => "2005-01-30t15:28:00.00+01:00",
>        :content => "Have a nice day",
>        :approved => false)
> 
>      new_record_snapshot = new_topic.new_record?
>      id_present = new_topic.has_attribute?(Topic.primary_key)
>      id_snapshot = new_topic.id
> 
>      Topic.transaction do
>        new_topic.save
>        raise ActiveRecord::Rollback
>      end
> 
>      topic_count_after_save = Topic.count
> 
>      assert_equal topic_count_before_save, topic_count_after_save
>      assert_equal new_record_snapshot, new_topic.new_record?, "The  
> topic should have its old new_record value"
>      assert_equal id_snapshot, new_topic.id, "The topic should have  
> its old id"
>      assert_equal id_present, new_topic.has_attribute? 
> (Topic.primary_key)
>    end
> 
> Thanks,
> 
> Jonathan
> 
> > 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to