Attributes method not working?


#1

rspec-users mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/rspec-users


#2

On Thu, Nov 27, 2008 at 9:06 AM, removed_email_address@domain.invalid
wrote:

validates_presence_of :client_id
module AdtagSpecHelper

describe Adtag do
include AdtagSpecHelper

before(:each) do
@adtag = Adtag.create( valid_adtag_attributes )
@adtag.should be_valid
end

it “should be invalid without an approved size” do
@adtag.attributes = valid_adtag_attributes.except(:size) # ONE

attributes= does NOT set any attributes that are not included in the
hash. In this case it does not try to assign the value of :size.

As for not showing in the test log, I believe (but I’m not sure) that
AR will not run an SQL update unless attributes= changes the value of
any of the attributes it assigns. In this case, that is not happening,
so no query.

Cheers,
David


#3

On Thu, Nov 27, 2008 at 11:03 AM, David C.
removed_email_address@domain.invalidwrote:

AR will not run an SQL update unless attributes= changes the value of
any of the attributes it assigns. In this case, that is not happening,
so no query.

@adtag.errors.on(:size).should eql("is not included in the list")  #

TWO

@adtag.should have(1).error_on(:size)   # THREE
@adtag.should_not be_valid

And since it’s the valid? call which sets the errors, even if you
address
the problems pointed out by David, those errors expectations won’t be
met if
you do things in this order.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/