meskyanichi/parelation — pull request #2 by as-cii (2014-09-12 15:59:56+00:00)
Title: Use ActiveRecord to generate queries for specs

First of all, congratulations for the project as I find it very interesting.

Today I had the opportunity to dig a bit into the source code and in this Pull–Request you'll find out my thoughts, specifically about tests.

Parelation is about converting an HTTP request into a suitable ActiveRecord query, but the tests didn't reflect that. The highlight was more on the SQL, rather than showing which query the library should have come up with.

So, here's what I made:

1. First, I tried to give specs a better structure so that it's easy to recognize the input and the output (`criteria` and `ar_query` variables make this contrast really evident)
2. I constructed the queries via ActiveRecord API, calling `to_sql` after the query building

I believe the code has improved and to me it feels more readable. One added benefit is that, in this way, your tests won't break if there's some change in the way ActiveRecord construct queries.

What do you think? :smile: