Forum: Ruby on Rails Unit Testing SQL

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
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.
This topic is locked and can not be replied to.