Thanks for looking into this quick.

Yes this works. However, if I change fetch to other table name, it will not.

$sequel -E
Your database is stored in DB...
irb(main):001:0> DB = Sequel.mock(:a_table=>[{:id=>1, :name=>'name'}])
=> #<Sequel::Mock::Database: {:adapter=>:mock, :a_table=>[{:id=>1, 
:name=>"name"}]}>
irb(main):002:0> class FetchSomething < Sequel::Model(:a_table); end
I, [2016-03-10T11:48:19.944334 #6292]  INFO -- : SELECT * FROM a_table 
LIMIT 1
I, [2016-03-10T11:48:19.945511 #6292]  INFO -- : SELECT * FROM a_table 
LIMIT 1
=> nil
irb(main):003:0> fetchedData = FetchSomething.first
I, [2016-03-10T11:48:45.673094 #6292]  INFO -- : SELECT * FROM a_table 
LIMIT 1
=> nil
irb(main):005:0> fetchedData = FetchSomething[:name => 'name']
I, [2016-03-10T11:49:19.438946 #6292]  INFO -- : SELECT * FROM a_table 
WHERE (name = 'name') LIMIT 1
=> nil
irb(main):006:0> 



Thanks,
Denny

On Wednesday, March 9, 2016 at 9:57:22 PM UTC-8, Jeremy Evans wrote:
>
> On Wednesday, March 9, 2016 at 9:49:24 PM UTC-8, Denny Wang wrote:
>>
>> Hi, I am trying to mock some data for unit testing.
>>
>> DB = Sequel.mock(:fetch=>[{:id => 1, :name => 'name'}])
>> Sequel::Model.db = DB
>>
>> This is find and I can get the mocked data.
>> fetchedData = DB[:fetch].where(:name => 'name')
>>
>> However, I also have a model:
>>
>> class FetchSomething < Sequel::Model(:fetch)
>>
>> I can't retrieve the mocked data then:
>>
>> fetchedData = :FetchSomething[:name => 'name']
>>
>> Could someone please point out what I had done wrong or what am I missing?
>> Thanks.
>>
>
> I can't reproduce your issue: 
>
> $ bin/sequel -E 
> Your database is stored in DB...
> irb(main):001:0> DB.fetch = [{:id => 1, :name => 'name'}]
> => [{:id=>1, :name=>"name"}]
> irb(main):002:0> class FetchSomething < Sequel::Model(:fetch); end
> I, [2016-03-09T21:56:35.045716 #12796]  INFO -- : SELECT * FROM fetch 
> LIMIT 1
> I, [2016-03-09T21:56:35.046314 #12796]  INFO -- : SELECT * FROM fetch 
> LIMIT 1
> => nil
> irb(main):003:0> fetchedData = FetchSomething[:name => 'name']
> I, [2016-03-09T21:56:40.903413 #12796]  INFO -- : SELECT * FROM fetch 
> WHERE (name = 'name') LIMIT 1
> => #<FetchSomething @values={:id=>1, :name=>"name"}>
>
> 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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to