[rspec-users] Proper Encapsulation of SQL WHERE / ORDER BY Clauses

Matt Wynne matt at mattwynne.net
Fri Aug 15 07:46:26 EDT 2008


On 15 Aug 2008, at 12:25, David Chelimsky wrote:

> Hey Matt - welcome!
>
> The paginate() method lives on the model class, so there's nothing
> stopping you from wrapping those calls in methods on the model,
> slinging around the params object.
>
> # CityController
>
> def get_cities
>   City.paginate_all(params)
> end
>
> # City
>
> def self.paginate_all(params)
>   self.paginate(:all, get_find_params(params).merge!(:page => params 
> [:page]))
> end
>
> etc
>

Aha. Cool, thanks.

For my next question: how do I go about driving out change to the  
model, spec-first?

I'm thinking I would call (in my spec)
	
	City.should_receive(:paginate).with(:conditions => "name like '%# 
{test_params[:name}%'" .... )
	City.paginate_all(test_params)

Thereby covering the code in get_find_params()

Is that the right approach?

cheers,
Matt


More information about the rspec-users mailing list