Forum: Ruby on Rails Unit Testing SQL

A59831714e42926c56922a24234700df?d=identicon&s=25 Gurdipe Dosanjh (Guest)
on 2012-06-22 16:08
(Received via mailing list)
Hi

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

Gurdipe
56b7e1808013614acdb73cbaaa6938a1?d=identicon&s=25 Michael Pavling (Guest)
on 2012-06-22 16:23
(Received via mailing list)
On 22 June 2012 15:07, Gurdipe Dosanjh <rhomobileapps@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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.