vinnyglennon / valid_items

Check that all your Rails ActiveRecord Objects still pass their model validations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Valid Items

Goes through all your Rails ActiveRecord objects and check if they are all still pass your model validations. You may have added new validations to your model since creating your object, or ran update_column in your console to solve a production issue. Inspired by a RailsConf talk by Ryan Laughlin and his talk at http://www.rofreg.com/talks/railsconf2018'

Installation

ValidItem's installation is pretty standard:

$ gem install valid_items

If you'd rather install ValidItem using bundler, don't require it in your Gemfile:

gem 'valid_items', require: false

Example usage

require 'valid_items'
ValidItems.checkup
 => User id 203: {:name=>["can't be blank"]}
require 'valid_items'
ValidItems.checkup(email: 'example@example.com')
 => User id 203: {:name=>["can't be blank"]}  
# and an email gets sent
require 'valid_items'
ValidItems.checkup(updated_at: 1.day.ago)
 => 'ok'
Arguments:
 email: (String)
 updated_at: (ActiveSupport::TimeWithZone)

Running in development

Eager Load is required on development, so that valid_items can query all AR models

Rails.application.eager_load!

You must have upgraded your Rails app so that all your models inherit from ApplicationRecord rather than ActiveRecord::Base.

About

Check that all your Rails ActiveRecord Objects still pass their model validations


Languages

Language:Ruby 100.0%