No commit activity in last 3 years
No release in over 3 years
Test doublecheck 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.11
~> 5.0
~> 10.0

Runtime

 Project Readme

Doublecheck View

doublecheck_view is a Ruby gem that makes it easy to validate doublecheck views during automated tests. See https://github.com/jackc/doublecheck for more information about the doublecheck view pattern.

Installation

Add this line to your application's Gemfile:

gem 'doublecheck_view'

And then execute:

$ bundle

Or install it yourself as:

$ gem install doublecheck_view

Usage

You can check for errors manually at any time. The following code will select from every view in the doublecheck schema and check_result will only be valid if no rows are returned from any view.

doublecheck = DoublecheckView::Doublecheck.new
check_result = doublecheck.check
assert check_result.valid?, check_result.errors

However, the preferred approach is to run doublecheck after every test that uses the database.

# Inside a MiniTest or ActiveSupport::TestCase class body

  def before_teardown
    doublecheck = DoublecheckView::Doublecheck.new
    check_result = doublecheck.check
    assert check_result.valid?, check_result.errors
    super
  end

Or for RSpec:

RSpec.configure do |config|
  # ...
  config.before(:each) do
    doublecheck = DoublecheckView::Doublecheck.new
    check_result = doublecheck.check
    expect(check_result).to be_valid, "doublecheck views: #{check_result.errors}"
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jackc/doublecheck.

License

The gem is available as open source under the terms of the MIT License.