Hi, Jeremy
Thanks for reply. I have read the RDoc.
I have a rake task that executes something like:
def self.perform
a = DB[:table1].filter(xxx)
b = DB[:table2].filter(yyy)
DB[:table3].insert(do_magic(a,b))
end
I need to mock :table1 and :table2 with different output. I can't
override _fetch_ between this two calls
Now I found some solution for that, looks ugly but works :). It will
be great if you know some correct solution for this problem
before(:all) do
output = Proc.new do |query|
case query
when /SELECT.*table1/ then {:id => 1, :foo => 5, :bar => 1}
when /SELECT.*table2/ then [{:id => 6, :foobar => "xxx"}]
end
end
DB = Sequel.mock(:fetch => output)
end
ds = DB[:items]
ds._fetch = [{:id => 1, :name =>2}]
Can't be used because I call direcly DB[:items] in rake task
On Tue, Dec 20, 2011 at 10:47 PM, Jeremy Evans <[email protected]> wrote:
> On Dec 20, 6:09 am, Alex Sergeyev <[email protected]> wrote:
>> Hi,
>>
>> How to setup columns and values for Dataset mock?
>> DB = Sequel.mock
>> DB[:items].all => [{:id => 1, :name =>2}]
>> DB[:foo].all => [{:id => 1, :foo =>25}]
>
> Did you read the RDoc for the mock adapter (http://
> sequel.rubyforge.org/rdoc-adapters/classes/Sequel/Mock.html)? This is
> a serious question, because if you did and you still don't understand
> how to use it, the RDoc needs to be improved. Here's an example:
>
> # When initializing the Database
> DB = Sequel.mock(:fetch=>[{:id => 1, :name =>2}])
>
> or:
>
> # After initializing the Database
> DB.fetch = [{:id => 1, :name =>2}]
>
> or:
>
> # Override per dataset
> ds = DB[:items]
> ds._fetch = [{:id => 1, :name =>2}]
>
> Jeremy
>
> --
> You received this message because you are subscribed to the Google Groups
> "sequel-talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sequel-talk?hl=en.
>
--
Alex Sergeyev
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.