Forum: RSpec what's the meaning of to_param?

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.
Zhenning G. (Guest)
on 2009-03-19 14:46
usually, I just use this way.

=====
@weather = mock_model(Weather)
=====

but recently I saw this. so what's the :to_param and :save options
meaning?

======
@weather = mock_model(Weather, :to_param => "1", :save => true)
======
Zach D. (Guest)
on 2009-03-19 15:18
(Received via mailing list)
On Thu, Mar 19, 2009 at 8:46 AM, Zhenning G. 
<removed_email_address@domain.invalid>
wrote:
> @weather = mock_model(Weather, :to_param => "1", :save => true)
> ======

http://www.railsbrain.com/api/rails-2.2.2/doc/inde...

It's a Rails thing, used when converting an object to a URL
representation.


> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> removed_email_address@domain.invalid
> http://rubyforge.org/mailman/listinfo/rspec-users
>



--
Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com
Zach D. (Guest)
on 2009-03-19 15:26
(Received via mailing list)
On Thu, Mar 19, 2009 at 9:15 AM, Zach D. <removed_email_address@domain.invalid>
wrote:
>> ======
>> @weather = mock_model(Weather, :to_param => "1", :save => true)
>> ======
>
> http://www.railsbrain.com/api/rails-2.2.2/doc/inde...
>
> It's a Rails thing, used when converting an object to a URL representation.
>

Oops, sorry, I misread your question.

mock_model will provide you with #to_param so the only thing I can
think w/o knowing more is if whoever wrote the spec wanted to
specifically expect, look for, or somehow use the "1" that came from
to_param. They wanted to know that specific the result of
@weater.to_param was being used (which will be used be number of Rails
helpers).

My best guess on the save call is that the implementation is going to
call save, and the author of the spec by default wants it to be
successful for any subsequent examples.

>
> --
> Zach D.
> http://www.continuousthinking.com
> http://www.mutuallyhuman.com
>



--
Zach D.
http://www.continuousthinking.com
http://www.mutuallyhuman.com
This topic is locked and can not be replied to.