[rspec-users] spec'ing the :conditions argument of a find
Nick Hoffman
nick at deadorange.com
Thu Oct 30 11:06:31 EDT 2008
On 2008-10-28, at 10:52, Rémi Gagnon wrote:
> Let's see, I want to spec the :conditions args to make sure the right
> args is passed to the query.
>
> Product.find(:all,
> :conditions => ["inte_no = ? and vaat_id_type_statut_pcpa = ?",
> inte_no, 7],
> :limit => 2,
> :order => "trns_dt_appl_prod desc")
>
>
> Product.should_receive(:find).with(:conditions =>
> 'vaat_id_type_statut_pcpa == 7)
>
> I'm pretty sure this is not the right synthax.
>
> Any suggestions?
>
> Rémi
Hi Rémi. You have two options here:
1) Pass each argument to #with that #find receives;
2) Use #any_args to not specify some arguments that #find receives.
I'd do something like this:
find_conditions = []
find_conditions << "inte_no = ? and vaat_id_type_statut_pcpa = ?"
find_conditions << inte_no
find_conditions << 7
Product.should_receive(:find).with(:all,
:conditions => find_conditions,
:limit => 2,
:order => 'trns_dt_appl_prod desc'
)
More information about the rspec-users
mailing list