Unit Testing SQL

13 views
Skip to first unread message

Gurdipe Dosanjh

unread,
Jun 22, 2012, 10:07:04 AM6/22/12
to rubyonra...@googlegroups.com
Hi

What is the best way to unit test hard coded sql in a rails application.

Gurdipe

Michael Pavling

unread,
Jun 22, 2012, 10:19:50 AM6/22/12
to rubyonra...@googlegroups.com
On 22 June 2012 15:07, Gurdipe Dosanjh <rhomob...@gmail.com> wrote:
> What is the best way to unit test hard coded sql in a rails application.

You don't test SQL, you test methods. Whether the method gets it's
results through ActiveRecord, raw SQL, or fairies rummaging around the
hard drive, it's irrelevant to the tests. They should just be testing
that the expected values are returned by the method.

So the answer to your question may be "move the SQL to be wrapped by
methods, and test those", but without seeing some source code it would
be hard to say.
Reply all
Reply to author
Forward
0 new messages