So, I'm attempting to make sure that the associated user_id of an object
cannot be changed on update and I'm doing this with a before_update
callback and this method in the model:

    before_update :lock_user_id

    def lock_user_id
      if self.user_id_changed?
        self.user_id = self.user_id_was unless self.user_id_was == nil
      end
      true
    end

but this spec fails:

  it "user_id cannot be changed once QR has been created" do
    @qr.update_attributes(:user_id => -1)
    @qr.user_id.should == @user.id
  end

at first I thought it was that update_attributes did not do a complete
save (not that i've ever enabled partial saves), but this alternate spec
also fails:

  it "user_id cannot be changed once QR has been created" do
    @qr.user_id = 99
    @qr.save
    @qr.user_id.should == @user.id
  end

even stranger is that a method in another model which does the same
thing for another attribute passes its test.

Anybody have any idea what i'm doing wrong/alternate suggestions?

Thanks.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" 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-talk?hl=en.

Reply via email to