0.03
No commit activity in last 3 years
No release in over 3 years
Detects ActiveRecord models that are not valid.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3

Runtime

>= 0.5.8, ~> 0.5
>= 1.2.3, ~> 1.2
>= 10.1.10, ~> 10.1
 Project Readme

BrokenRecord

Provides a rake task for scanning your ActiveRecord models and detecting validation errors.

Installation

Add this line to your application's Gemfile:

gem 'broken_record'

And then execute:

bundle

Or install it yourself as:

gem install broken_record

Usage

To scan all records of all models in your project:

rake broken_record:scan

If you want to scan all records of a specific model (e.g. the User model):

rake broken_record:scan[User]

You can also specify a list of models to scan:

rake broken_record:scan[Product,User]

Configuration

BrokenRecord provides a configure method with multiple options. Here's an example:

BrokenRecord.configure do |config|
    # Skip the Foo and Bar models when scanning.
    config.classes_to_skip = [Foo, Bar]

    # Set a scope for which models should be validated
    config.default_scopes = { Foo => proc { with_bars } }

    # The follow block will be called before scanning your records.
    # This is useful for skipping validations you want to ignore.
    config.before_scan do
        User.skip_callback :validate, :before, :user_must_be_active
    end

    # BrokenRecord uses the parallelize gem to distribute work across
    # multiple cores. The following block will be called every time
    # the process is forked (useful for re-establishing connections).
    config.after_fork do
      Rails.cache.reconnect if Rails.cache.respond_to? :reconnect
    end

    # The compact_output option will report the ids of invalid records
    # but it will omit any relevant messages or backtraces.
    config.compact_output = true
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request