On Sat, Dec 31, 2011 at 10:59 PM, Ken Collins <[email protected]> wrote:

> I've been getting the SQL Server adapter up to passing for 3.2 and I wanted 
> to test our explain printer. It will be very much like mysql2's printer. But 
> I think my brain is mush and my meta-fu weak at the moment and I need some 
> help. I tried stubbing ActiveRecord::Base.logger.warn but to no avail. Any 
> thoughts?

Fantastic!

The high-level API is implemented in Active Record. You do not need to
test via the logger, at the adapter level you only need to write
#explain, which should return a string[*], and test that very return
value. Just ensure the string itself is correct.

The caller code takes that string and does stuff with it, but that's
handled above and it's tested in Active Record itself in an agnostic
way.

For example, this is the implementation in the SQLite adapter:

    
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb#L219-236

and these are its tests:

    
https://github.com/rails/rails/blob/master/activerecord/test/cases/adapters/sqlite3/explain_test.rb

Your adapter should do something like that.

Remember also to define a predicate #supports_explain? that returns true.

Hope that helps, please write again if more questions arise.

Xavier

[*] This string should ideally be a carbon copy of the one users are
familiar with. I don't know if that makes sense for SQL Server, maybe
they are used to some GUI output there?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" 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/rubyonrails-core?hl=en.

Reply via email to