<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/models/raises_post.rb</filename>
    </added>
    <added>
      <filename>db/migrate/001_create_raises_posts.rb</filename>
    </added>
    <added>
      <filename>test/fixtures/raises_posts.yml</filename>
    </added>
    <added>
      <filename>test/unit/raises_post_test.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,7 @@
 
+May 26
+= finished first rough implementation
+
 May 25
 = add the needed parts of the Rails framework to run tests
 = README: the raison d'&#234;tre
\ No newline at end of file</diff>
      <filename>CHANGELOG</filename>
    </modified>
    <modified>
      <diff>@@ -1,19 +1,19 @@
 = save_or_raise
 
   This plugin includes one new method for ActiveRecord::Base called
-  save_or_raise which does pretty much the same thing as
+  save_or_raise which does almost the same thing as
   ActiveRecord::Base#save!
   
-  == save() vs save!()
+  == save vs save!
   
-    The ActiveRecord::Base save() method returns true if the model save
-    is successful and false if it is not successful.  The save!() method
+    The ActiveRecord::Base save method returns true if the model save
+    is successful and false if it is not successful.  The save! method
     returns true if the model save is successful and raises an exception
     if it is not successful.
   
   == utility
   
-    The save() method is useful for control flow in cases where a failed
+    The save method is useful for control flow in cases where a failed
     save can be handled gracefully:
   
       if model.save
@@ -22,22 +22,23 @@
         ...
       end
     
-    Sometimes the control flow - often in or called by a controller -
+    Sometimes the control flow - often within or called by a controller -
     cannot handle an unsuccessful save gracefully.  The programmer's
     choices are:
   
-      1. Do not branch on the save() call and ignore failures.
+      1. Do not branch on the save call and ignore failures.
       2. Throw an exception:
     
-        raise &quot;Save failed!&quot; unless model.save
+           raise &quot;Save failed!&quot; unless model.save
       
-      3. Call save!() which does the same as 2
+      3. Call save! which does the same as 2
       
     The exception thrown by 2 and 3 will generate a 500 HTTP code for the user
     in production but it will also notify an admin by email when used in combination
-    with a plugin like exception_notification.  The alternative situation generated
-    by 1 is possible data corruption and invalid application state. Doing 1 is just
-    not a good idea.
+    with a plugin like exception_notification.  Result of choice 1 is possible data
+    corruption and invalid application state.
+    
+    So doing 1 is just not a good idea!
   
   == The problem with save!
   
@@ -52,9 +53,12 @@
       =&gt; &quot;hello&quot;
       &gt;&gt; a
       =&gt; &quot;hello&quot;
+      
+      The method strip! returns the result to b but also changes a.
     
-    The save! method does not change the ActiveRecord model it is called on.  Also
-    the name save! does not hint that it throws an exception in the failure case.
+    The save! method does not change the ActiveRecord model it is called on any more
+    than the save method does.  Also the name save! does not hint that it throws an
+    exception in the failure case.
   
     Both of these things make the code that uses save! less readable.
   
@@ -62,15 +66,16 @@
   
     This plugin implements a new ActiveRecord#Base method
     
-      save_or_raise(raiseable=RecordNotSaved)
+      save_or_raise(raiseable = ActiveRecord::RecordNotSaved)
   
     which can be used the following ways:
     
       model.save_or_raise                   # instead of model.save!
-      model.save_or_raise &quot;Save failed!&quot;
-      model.save_or_raise CustomException
+      model.save_or_raise &quot;Save failed!&quot;    # raises RuntimeError with this message on failure
+      model.save_or_raise CustomException   # raises CustomException on failure
       
     In all three cases the raised exception presents a 500 HTTP error to
-    the user in production.
+    the user in production if the save fails.
     
-    The save! method remains untouched and can still be used.
\ No newline at end of file
+    The save! method remains untouched and can still be used.
+    
\ No newline at end of file</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,2 +1 @@
-require 'save_or_raise'
-ActiveRecord::Base.send(:include, ActiveRecord::SaveOrRaise)
\ No newline at end of file
+require 'save_or_raise'
\ No newline at end of file</diff>
      <filename>init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,10 @@
-module ActiveRecord #:nodoc:
+class ActiveRecord::Base
   
-  module SaveOrRaise #:nodoc:
-    
-    def save_or_raise(raiseable = RecordNotSaved)
-      success = save
-      raise raiseable unless success
-      success
-    end
-    
+  def save_or_raise(raiseable = ActiveRecord::RecordNotSaved)
+    raiseable = ActiveRecord::RecordNotSaved if raiseable.nil?
+    success = save
+    raise raiseable unless success
+    success
   end
-
+  
 end
\ No newline at end of file</diff>
      <filename>lib/save_or_raise.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,8 @@ ENV[&quot;RAILS_ENV&quot;] = &quot;test&quot;
 require File.expand_path(File.dirname(__FILE__) + &quot;/../config/environment&quot;)
 require 'test_help'
 
+require &quot;#{File.dirname(__FILE__)}/../init&quot;
+
 class Test::Unit::TestCase
   # Transactional fixtures accelerate your tests by wrapping each test method
   # in a transaction that's rolled back on completion.  This ensures that the</diff>
      <filename>test/test_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,9 +1,189 @@
 require File.dirname(__FILE__) + '/../test_helper'
 
 class SaveOrRaiseTest &lt; Test::Unit::TestCase
+  fixtures :raises_posts
   
-  def test_stuff
-    assert true
+  #
+  # regular Rails behaviour
+  #
+  
+  def test_new_save
+    rp = RaisesPost.new
+    assert !rp.save
+    assert_raises(ActiveRecord::RecordInvalid) {
+      rp.save!
+    }
+    
+    rp.title = &quot;Title&quot;
+    assert rp.save
+    assert rp.save!
+  end
+  
+  def test_changed_save
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;&quot;
+    assert !rp.save
+    assert_raises(ActiveRecord::RecordInvalid) {
+      rp.save!
+    }
+    
+    rp.title = &quot;Goodbye&quot;
+    assert rp.save
+    assert rp.save!
+  end
+  
+  def test_unchanged_save
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;Hello World!&quot;
+    assert rp.save
+    assert rp.save!
+  end
+  
+  #
+  # save_or_raise
+  #
+  
+  def test_new_save_or_raise
+    rp = RaisesPost.new
+    assert_raises(ActiveRecord::RecordNotSaved) {
+      rp.save_or_raise
+    }
+    
+    rp.title = &quot;Title&quot;
+    assert rp.save_or_raise
+  end
+  
+  def test_changed_save_or_raise
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;&quot;
+    assert_raises(ActiveRecord::RecordNotSaved) {
+      rp.save_or_raise
+    }
+    
+    rp.title = &quot;Goodbye&quot;
+    assert rp.save_or_raise
+  end
+  
+  def test_unchanged_save_or_raise
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;Hello World!&quot;
+    assert rp.save_or_raise
+  end
+  
+  #
+  # save_or_raise(nil)
+  #
+  
+  def test_new_save_or_raise_nil
+    rp = RaisesPost.new
+    assert_raises(ActiveRecord::RecordNotSaved) {
+      rp.save_or_raise(nil)
+    }
+    
+    rp.title = &quot;Title&quot;
+    assert rp.save_or_raise(nil)
+  end
+  
+  def test_changed_save_or_raise_nil
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;&quot;
+    assert_raises(ActiveRecord::RecordNotSaved) {
+      rp.save_or_raise(nil)
+    }
+    
+    rp.title = &quot;Goodbye&quot;
+    assert rp.save_or_raise(nil)
+  end
+  
+  def test_unchanged_save_or_raise_nil
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;Hello World!&quot;
+    assert rp.save_or_raise(nil)
+  end
+  
+  #
+  # save_or_raise(&quot;woops!&quot;)
+  #
+  
+  def test_new_save_or_raise_message
+    rp = RaisesPost.new
+    assert_raises(RuntimeError,&quot;woops!&quot;) {
+      rp.save_or_raise(&quot;woops!&quot;)
+    }
+    
+    rp.title = &quot;Title&quot;
+    assert rp.save_or_raise(&quot;woops!&quot;)
+  end
+  
+  def test_changed_save_or_raise_message
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;&quot;
+    assert_raises(RuntimeError,&quot;woops!&quot;) {
+      rp.save_or_raise(&quot;woops!&quot;)
+    }
+    
+    rp.title = &quot;Goodbye&quot;
+    assert rp.save_or_raise(&quot;woops!&quot;)
+  end
+  
+  def test_unchanged_save_or_raise_message
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;Hello World!&quot;
+    assert rp.save_or_raise(&quot;woops!&quot;)
+  end
+  
+  #
+  # save_or_raise(CustomException)
+  #
+  
+  class CustomException &lt; StandardError
+  end
+  
+  def test_new_save_or_raise_exception
+    rp = RaisesPost.new
+    assert_raises(CustomException) {
+      rp.save_or_raise(CustomException)
+    }
+    
+    rp.title = &quot;Title&quot;
+    assert rp.save_or_raise(CustomException)
+  end
+  
+  def test_changed_save_or_raise_exception
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;&quot;
+    assert_raises(CustomException) {
+      rp.save_or_raise(CustomException)
+    }
+    
+    rp.title = &quot;Goodbye&quot;
+    assert rp.save_or_raise(CustomException)
+  end
+  
+  def test_unchanged_save_or_raise_exception
+    rp = raises_posts(:hello)
+    assert_equal &quot;Hello World!&quot;, rp.title
+    
+    rp.title = &quot;Hello World!&quot;
+    assert rp.save_or_raise(CustomException)
   end
   
 end
\ No newline at end of file</diff>
      <filename>test/unit/save_or_raise_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>2842215ca54d6b23fb4b15243bbda29eae499d52</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Lowe</name>
    <email>ryanlowe@gmail.com</email>
  </author>
  <url>http://github.com/ryanlowe/save_or_raise/commit/3d47934779fb8783dae85b30ef2507c6aa8eab98</url>
  <id>3d47934779fb8783dae85b30ef2507c6aa8eab98</id>
  <committed-date>2008-05-25T16:17:33-07:00</committed-date>
  <authored-date>2008-05-25T16:17:33-07:00</authored-date>
  <message>finished first rough implementation</message>
  <tree>1b2abad4ffbc3c0738fc466e25d34e59b8f112c5</tree>
  <committer>
    <name>Ryan Lowe</name>
    <email>ryanlowe@gmail.com</email>
  </committer>
</commit>
