Forum: RSpec attributes method not working?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2008-11-27 17:06
(Received via mailing list)
_______________________________________________
rspec-users mailing list
removed_email_address@domain.invalid
http://rubyforge.org/mailman/listinfo/rspec-users
David C. (Guest)
on 2008-11-27 18:08
(Received via mailing list)
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
Rick D. (Guest)
on 2008-11-27 22:30
(Received via mailing list)
On Thu, Nov 27, 2008 at 11:03 AM, David C.
<removed_email_address@domain.invalid>wrote:

> 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/
This topic is locked and can not be replied to.