Forum: Ferret ActsAsFerret - what's the class of the results?

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.
73c04e9ef9ca435c5b19a2e765ae6d20?d=identicon&s=25 Max Williams (max-williams)
on 2009-02-06 12:13
I'm trying to write a test for a method that uses a ferret search, but
can't validate that the results are a_a_f results because my class test
doesn't work.  Can anyone set me straight?  Here's some console
experimentation that shows the root of the problem.

>> users = User.find_with_ferret("max", :per_page => 2)
=> [#<User ...
...
]
>> users.size
=> 2
>> users.next_page #call a ferret-results-specific method
=> 2
>> users.kind_of?(ActsAsFerret::SearchResults)
=> false

What class should i be testing against, if it's not
ActsAsFerret::SearchResults?  If i do type on the results i just get
Array.
36feb4959db6ab8259a44962f0fa761f?d=identicon&s=25 Jens Krämer (jkraemer)
on 2009-02-10 10:14
(Received via mailing list)
Hi,

SearchResults is a *really* thin wrapper around a standard Ruby Array
instance. If you really want to check it's a SearchResults instance
and not something else, check for Array and whether it behaves like it
should by looking at the 'special' methods the SearchResults class
adds, maybe like this:

assert_equal Array, results.class
%w(total_hits current_page per_page total_pages).each {|m| assert
results.respond_to?(m.to_sym) }

cheers,
Jens


On 06.02.2009, at 12:13, Max Williams wrote:

>>> users.size
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ferret-talk mailing list
> Ferret-talk@rubyforge.org
> http://rubyforge.org/mailman/listinfo/ferret-talk
>

--
Jens Krämer
Finkenlust 14, 06449 Aschersleben, Germany
VAT Id DE251962952
http://www.jkraemer.net/ - Blog
http://www.omdb.org/     - The new free film database
73c04e9ef9ca435c5b19a2e765ae6d20?d=identicon&s=25 Max Williams (max-williams)
on 2009-02-10 11:24
ah ok.  i should have thought to just put that same method that i
referred to into a 'responds_to' call in my test, like you suggest :)

Thanks Jens
max
This topic is locked and can not be replied to.