<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -11,13 +11,11 @@ class AccountsController &lt; ApplicationController
   end
 
   def create
-    @account = subscription.accounts.create_for(user, params[:account])
-
-    if @account.valid?
-      redirect_to(subscription_url(subscription))
-    else
-      render :action =&gt; &quot;new&quot;
-    end
+    @account = subscription.accounts.create!(params[:account], :author =&gt; user)
+    redirect_to(subscription_url(subscription))
+  rescue ActiveRecord::RecordInvalid =&gt; error
+    @account = error.record
+    render :action =&gt; &quot;new&quot;
   end
 
   def destroy</diff>
      <filename>app/controllers/accounts_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,7 +13,7 @@ class EventsController &lt; ApplicationController
   end
 
   def create
-    @event = subscription.events.create_for(user, params[:event])
+    @event = subscription.events.create(params[:event], :user =&gt; user)
   end
 
   def update</diff>
      <filename>app/controllers/events_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -12,16 +12,9 @@ class Account &lt; ActiveRecord::Base
   validates_uniqueness_of :name, :scope =&gt; :subscription_id, :case_sensitive =&gt; false
 
   has_many :buckets do
-    def create_for(author, attributes)
-      returning build(attributes) do |bucket|
-        bucket.author = author
-        bucket.save
-      end
-    end
-
     def for_role(role, user)
       role = role.downcase
-      find_by_role(role) || create_for(user, :name =&gt; role.capitalize, :role =&gt; role)
+      find_by_role(role) || create({:name =&gt; role.capitalize, :role =&gt; role}, :author =&gt; user)
     end
 
     def sorted
@@ -100,15 +93,16 @@ class Account &lt; ActiveRecord::Base
   protected
 
     def create_default_buckets
-      buckets.create_for(author, :name =&gt; DEFAULT_BUCKET_NAME, :role =&gt; &quot;default&quot;)
+      buckets.create({:name =&gt; DEFAULT_BUCKET_NAME, :role =&gt; &quot;default&quot;}, :author =&gt; author)
     end
 
     def set_starting_balance
       if starting_balance &amp;&amp; !starting_balance[:amount].to_i.zero?
-        subscription.events.create_for(author,
-          :occurred_on =&gt; starting_balance[:occurred_on], :actor =&gt; &quot;Starting balance&quot;,
-          :line_items =&gt; [{:account_id =&gt; id, :bucket_id =&gt; buckets.default.id,
-            :amount =&gt; starting_balance[:amount], :role =&gt; &quot;deposit&quot;}])
+        subscription.events.create({:occurred_on =&gt; starting_balance[:occurred_on],
+            :actor =&gt; &quot;Starting balance&quot;,
+            :line_items =&gt; [{:account_id =&gt; id, :bucket_id =&gt; buckets.default.id,
+              :amount =&gt; starting_balance[:amount], :role =&gt; &quot;deposit&quot;}]
+          }, :user =&gt; author)
         reload # make sure the balance is set correctly
       end
     end</diff>
      <filename>app/models/account.rb</filename>
    </modified>
    <modified>
      <diff>@@ -103,7 +103,7 @@ class Event &lt; ActiveRecord::Base
 
           bucket_id = item.delete(:bucket_id)
           item[:bucket] = if bucket_id =~ /^n:(.*)/
-            account.buckets.find_by_name($1) || account.buckets.create_for(user, :name =&gt; $1)
+            account.buckets.find_by_name($1) || account.buckets.create({:name =&gt; $1}, :author =&gt; user)
           elsif bucket_id =~ /^r:(.*)/
             account.buckets.for_role($1, user)
           else</diff>
      <filename>app/models/event.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,25 +1,10 @@
 class Subscription &lt; ActiveRecord::Base
   belongs_to :owner, :class_name =&gt; &quot;User&quot;
 
-  has_many :accounts do
-    def create_for(author, attributes)
-      returning build(attributes) do |account|
-        account.author = author
-        account.save
-      end
-    end
-  end
-
+  has_many :accounts
   has_many :tags
 
   has_many :events do
-    def create_for(user, attributes)
-      returning build(attributes) do |event|
-        event.user = user
-        event.save
-      end
-    end
-
     def recent(n=5)
       find(:all, :order =&gt; &quot;created_at DESC&quot;, :limit =&gt; n, :include =&gt; :account_items)
     end</diff>
      <filename>app/models/subscription.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,3 +14,7 @@ vendor/plugins/project_search:
   :type: git
   :repository: git://github.com/37signals/project_search.git
   :revision: 5d243711fbbd69ac08ba86418316bd15cffa0642
+vendor/plugins/safe_mass_assignment:
+  :type: git
+  :repository: git://github.com/jamis/safe_mass_assignment.git
+  :revision: 7d7e24e551254e0651f5cfb93d876beaed9ed7f7</diff>
      <filename>config/externals.yml</filename>
    </modified>
    <modified>
      <diff>@@ -4,14 +4,15 @@ class AccountItemTest &lt; ActiveSupport::TestCase
   test &quot;create should update balance on account record&quot; do
     initial_amount = accounts(:john_checking).balance
 
-    subscriptions(:john).events.create_for(users(:john),
-        :occurred_on =&gt; 3.days.ago.to_date, :actor =&gt; &quot;Something&quot;,
+    subscriptions(:john).events.create({:occurred_on =&gt; 3.days.ago.to_date,
+        :actor =&gt; &quot;Something&quot;,
         :line_items =&gt; [
           { :account_id =&gt; accounts(:john_checking).id,
             :bucket_id  =&gt; buckets(:john_checking_groceries).id,
             :amount     =&gt; -25_75,
             :role       =&gt; 'payment_source' },
-        ])
+        ]
+      }, :user =&gt; users(:john))
 
     assert_equal initial_amount - 25_75, accounts(:john_checking, :reload).balance
   end</diff>
      <filename>test/unit/account_item_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -104,6 +104,6 @@ class AccountTest &lt; ActiveSupport::TestCase
       options = {:name =&gt; &quot;Visa&quot;,
                  :role =&gt; &quot;credit-card&quot;}.merge(options)
 
-      subscription.accounts.create_for(users(:john), options)
+      subscription.accounts.create(options, :author =&gt; users(:john))
     end
 end</diff>
      <filename>test/unit/account_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -10,7 +10,7 @@ class EventTest &lt; ActiveSupport::TestCase
     @event_base[:line_items][0][:account_id] = 12345
     assert_no_difference &quot;Event.count&quot; do
       assert_raise(ActiveRecord::RecordNotFound) do
-        subscriptions(:john).events.create_for(users(:john), @event_base)
+        subscriptions(:john).events.create(@event_base, :user =&gt; users(:john))
       end
     end
   end
@@ -19,7 +19,7 @@ class EventTest &lt; ActiveSupport::TestCase
     @event_base[:line_items][0][:account_id] = accounts(:tim_checking).id
     assert_no_difference &quot;Event.count&quot; do
       assert_raise(ActiveRecord::RecordNotFound) do
-        subscriptions(:john).events.create_for(users(:john), @event_base)
+        subscriptions(:john).events.create(@event_base, :user =&gt; users(:john))
       end
     end
   end
@@ -29,7 +29,7 @@ class EventTest &lt; ActiveSupport::TestCase
     @event_base[:line_items][0][:bucket_id] = 12345
     assert_no_difference &quot;Event.count&quot; do
       assert_raise(ActiveRecord::RecordNotFound) do
-        subscriptions(:john).events.create_for(users(:john), @event_base)
+        subscriptions(:john).events.create(@event_base, :user =&gt; users(:john))
       end
     end
   end
@@ -38,13 +38,13 @@ class EventTest &lt; ActiveSupport::TestCase
     @event_base[:line_items][0][:bucket_id] = buckets(:tim_checking_general).id
     assert_no_difference &quot;Event.count&quot; do
       assert_raise(ActiveRecord::RecordNotFound) do
-        subscriptions(:john).events.create_for(users(:john), @event_base)
+        subscriptions(:john).events.create(@event_base, :user =&gt; users(:john))
       end
     end
   end
 
   test &quot;create with existing buckets should associate line items with those buckets&quot; do
-    event = subscriptions(:john).events.create_for(users(:john), @event_base)
+    event = subscriptions(:john).events.create(@event_base, :user =&gt; users(:john))
     assert_equal [-25_75, -15_25], event.line_items.map(&amp;:amount)
     assert_equal [buckets(:john_checking_groceries), buckets(:john_checking_household)], event.line_items.map(&amp;:bucket)
     assert buckets(:john_checking_groceries, :reload).updated_at &gt; 1.second.ago.utc
@@ -55,7 +55,7 @@ class EventTest &lt; ActiveSupport::TestCase
     @event_base[:line_items][0][:bucket_id] = &quot;n:Dining&quot;
     @event_base[:line_items][1][:bucket_id] = &quot;n:Gambling&quot;
     assert_difference &quot;accounts(:john_checking).buckets.count&quot; do
-      event = subscriptions(:john).events.create_for(users(:john), @event_base)
+      event = subscriptions(:john).events.create(@event_base, :user =&gt; users(:john))
       assert_equal [-25_75, -15_25], event.line_items.map(&amp;:amount)
       gambling = accounts(:john_checking).buckets.detect { |b| b.name == &quot;Gambling&quot; }
       assert gambling
@@ -68,7 +68,7 @@ class EventTest &lt; ActiveSupport::TestCase
     @event_base[:line_items][0][:bucket_id] = &quot;r:default&quot;
     @event_base[:line_items][1][:bucket_id] = &quot;r:custom&quot;
     assert_difference &quot;accounts(:john_checking).buckets.count&quot; do
-      event = subscriptions(:john).events.create_for(users(:john), @event_base)
+      event = subscriptions(:john).events.create(@event_base, :user =&gt; users(:john))
       assert_equal [-25_75, -15_25], event.line_items.map(&amp;:amount)
       custom = accounts(:john_checking).buckets.for_role(&quot;custom&quot;, users(:john))
       assert custom
@@ -93,23 +93,25 @@ class EventTest &lt; ActiveSupport::TestCase
         :role       =&gt; 'aside' }
     ]
 
-    event = subscriptions(:john).events.create_for(users(:john), @event_base)
+    event = subscriptions(:john).events.create(@event_base, :user =&gt; users(:john))
     assert_equal [[&quot;Checking&quot;, 0], [&quot;Mastercard&quot;, -25_00]],
       event.account_items.map { |i| [i.account.name, i.amount] }.sort
   end
 
   test &quot;create with tagged_items should generate tagged_items for event&quot; do
-    event = subscriptions(:john).events.create_for(users(:john), @event_base.merge(
-      :tagged_items =&gt; [ { :tag_id =&gt; tags(:john_lunch).id, :amount =&gt; 500 } ]))
+    event = subscriptions(:john).events.create(@event_base.merge(
+        :tagged_items =&gt; [ { :tag_id =&gt; tags(:john_lunch).id, :amount =&gt; 500 } ]),
+      :user =&gt; users(:john))
     assert_equal 1, event.tagged_items.length
     assert_equal [500], event.tagged_items.map(&amp;:amount)
     assert_equal [tags(:john_lunch)], event.tagged_items.map(&amp;:tag)
   end
 
   test &quot;create with named tagged_items should find or create tagged_items&quot; do
-    event = subscriptions(:john).events.create_for(users(:john), @event_base.merge(
-      :tagged_items =&gt; [ { :tag_id =&gt; &quot;n:milk&quot;, :amount =&gt; 500 },
-                         { :tag_id =&gt; &quot;n:fruit&quot;, :amount =&gt; 750 } ]))
+    event = subscriptions(:john).events.create(@event_base.merge(
+        :tagged_items =&gt; [ { :tag_id =&gt; &quot;n:milk&quot;, :amount =&gt; 500 },
+                           { :tag_id =&gt; &quot;n:fruit&quot;, :amount =&gt; 750 } ]),
+      :user =&gt; users(:john))
     assert_equal 2, event.tagged_items.length
     assert_equal [500, 750], event.tagged_items.map(&amp;:amount)
     milk = subscriptions(:john).tags.detect { |t| t.name == &quot;milk&quot; }</diff>
      <filename>test/unit/event_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,14 +4,15 @@ class LineItemTest &lt; ActiveSupport::TestCase
   test &quot;create should update balance on bucket record&quot; do
     initial_amount = buckets(:john_checking_groceries).balance
 
-    subscriptions(:john).events.create_for(users(:john),
-        :occurred_on =&gt; 3.days.ago.to_date, :actor =&gt; &quot;Something&quot;,
+    subscriptions(:john).events.create({:occurred_on =&gt; 3.days.ago.to_date,
+        :actor =&gt; &quot;Something&quot;,
         :line_items =&gt; [
           { :account_id =&gt; accounts(:john_checking).id,
             :bucket_id  =&gt; buckets(:john_checking_groceries).id,
             :amount     =&gt; -25_75,
             :role       =&gt; 'payment_source' },
-        ])
+        ]},
+      :user =&gt; users(:john))
 
     assert_equal initial_amount - 25_75, buckets(:john_checking_groceries, :reload).balance
   end</diff>
      <filename>test/unit/line_item_test.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,4 @@
 calendar_date_select
 haml
 project_search
+safe_mass_assignment</diff>
      <filename>vendor/plugins/.gitignore</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>06e40255dcc4282f843d3410336a7e292286a353</id>
    </parent>
  </parents>
  <author>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </author>
  <url>http://github.com/jamis/bucketwise/commit/18e2419f05a498b397c535f3e2e9be5f55ecad44</url>
  <id>18e2419f05a498b397c535f3e2e9be5f55ecad44</id>
  <committed-date>2009-04-12T15:36:09-07:00</committed-date>
  <authored-date>2009-04-12T15:36:09-07:00</authored-date>
  <message>use safe_mass_assignment plugin</message>
  <tree>a004d462dc2fd7a520cddc722c5fa6b579cb9fe1</tree>
  <committer>
    <name>Jamis Buck</name>
    <email>jamis@37signals.com</email>
  </committer>
</commit>
