0.0
No commit activity in last 3 years
No release in over 3 years
Easier way to mantain Database Views with ActiveRecord
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1
 Project Readme

Verifiable View

Keep your database view definitions in sync with your named scopes and associations' definitions.

Installation

gem install verifiable_view

Usage

class RegularProduct
  extend VerifiableView

  definition do
    Product.
      not_deprecated.
      where(Product.arel_table[:price].gt(150)).
      select(:id, :name, :price)
  end
end

Then in your tests you'll have a

test "regular_products view is up-to-date" do
  RegularProduct.verify
end

That will check that you have a regular_products view defined in your database and that the query matches with your definition (Products that are not deprecated, with prices superior to 150, etc)

Why

Named scopes and named associations are easy to write with Arel and easy to maintain. Every time you write a view by crafting your SQL by hand you risk forgetting a condition. If you already have already defined associations or named scopes why to violate DRYness and duplicate their definitions?

Also when updating the definition of a named scope, you will notice immediately that your view got out of your sync.

Testing

gem install dep dep install cutest test/*.rb