Thanks Jeremy, 
I followed the pattern in your lazy_attributes spec and it worked great!

On Wednesday, September 2, 2015 at 6:49:55 PM UTC-7, Jeremy Evans wrote:
>
> On Wednesday, September 2, 2015 at 11:07:19 AM UTC-7, Nicholas Variz wrote:
>>
>> Hi Jeremy,
>>
>> apologies for being vague.
>>
>> My Sequel model has a method called 'valid' that looks like this:
>>
>> def self.valid
>>   where { foo > 0 & (bar > 0 | fubar > 0) }
>> end
>>
>> and I want to test that in a spec
>>
>> by inserting dummy records into a dummy db so that I can a spec like
>> it 'does not return invalid rows' do
>>   expect(MyModel.valid.count).to eq(#the number of valid rows in the mock 
>> DB)
>> end
>>
>> So if i do 
>>
>> MyModel.dataset = Sequel.mock[:tablename]
>> MyModel.dataset._fetch = [{foo: 1, bar: 1, fubar: 123}, {foo: 0, bar: 0, 
>> fubar: 1}]
>>
>> Then queries via MyModel always return that stubbed data which is not 
>> what I want.
>>
>
> You can make _fetch a proc, which will be called with the SQL to be 
> executed, and can choose what to return based on the SQL.  This can be done 
> at the database or dataset level.
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to