title: Override setter doesn't work with update_attributes
body: <p>I'm making an task-manager and have an boolean attribute for 'finished'. I've tried to override the setter to implement an 'finished_at' date when i toggle 'finished' to true.</p>
  
  <p>But i getting some mixed result. It doesn't work in browser but it will work in my rspec test.</p>
  
  <p>Please help me out.</p>
  
  <pre><code>class TasksController &lt; ApplicationController 
  # ...
  def update
    # ..
    if @task.update_attributes(params[:task]) # where params[:task][:finished] is true
  # ...
  end
  
  class Task &lt; ActiveRecord::Base
  #...
    def finished=(f)
     write_attribute :finished, f
     write_attribute :finished_at, f == true ? DateTime.now : nil
    end
  end
  
  # and in rspec i have
  describe "when marked as finished" do
    before { @task.update_attributes(finished: true) }
  
    its(:finished_at) { should_not be_nil }
    its(:finished_at) { should &gt; (DateTime.now - 1.minute) }
  
    describe "and then marked as unfinished" do 
      before { @task.update_attributes(finished: false) }
      its(:finished_at) { should be_nil }
    end
  end
  </code></pre>
  
  <p>in browser it executes "UPDATE "tasks" SET "finished" = 't', "updated_at" = '2012-10-02 18:55:07.220361' WHERE "tasks"."id" = 17"</p>
  
  <p>and in rails console i got the same with update_attributes.</p>
  
  <p>But in rspec with update_attributes i get "UPDATE "tasks" SET "finished" = 't', "finished_at" = '2012-10-02 18:36:47.725813', "updated_at" = '2012-10-02 18:36:51.607143' WHERE "tasks"."id" = 1"</p>
  
  <p>So I use the same method but it's only working in rspec for some reson...</p>
  
  <hr>
  
  <p>using latest rails and latest spec (not any rc or beta).</p>
  
  <h2>Solution</h2>
  
  <p>Not mush i did need to edit. Thanks @Frederick Cheung for the hint.
  I did notice i did like "self[:attr]" more than "write_attribute". Looks better imo.</p>
  
  <pre><code>def finished=(value)
    self[:finished] = value
    self[:finished_at] = (self.finished? ? Time.now.utc : nil)
  end
  </code></pre>