No commit activity in last 3 years
No release in over 3 years
ActiveRecord::MySQL::Strict adds validations to ActiveRecord models to make sure they do not trigger errors in MySQL strict mode.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
~> 2.14

Runtime

>= 3.0.0
>= 3.0.0
 Project Readme

ActiveRecord::StrictValidations

ActiveRecord::StrictValidations adds validations to ActiveRecord models to make sure they do not trigger database errors.

Installation

Add this line to your application's Gemfile:

gem 'activerecord_strict_validations'

Usage

create_table "events" do |t|
  t.string   "name"
  t.string   "email", limit: 128
  t.text     "description"
  t.integer  "people_count"
end

class Event < ActiveRecord::Base
  validates_strict_columns
end

# String columns

event = Event.new(name: '.' * 400)
event.valid? # => false

event = Event.new(name: '.' * 255)
event.valid? # => true

event = Event.new(email: '.' * 200)
event.valid? # => false

event = Event.new(email: '.' * 100)
event.valid? # => true

# Text columns

event = Event.new(description: '.' * 70000)
event.valid? # => false

event = Event.new(description: '.' * 65535)
event.valid? # => true

# Integer columns

event = Event.new(people_count: 9999999999)
event.valid? # => false

event = Event.new(people_count: 2147483647)
event.valid? # => true

Options

You can use a few options when calling validates_strict_columns:

class Event < ActiveRecord::Base
  validates_strict_columns, only: [:name]
end

class Event < ActiveRecord::Base
  validates_strict_columns, except: [:people_count]
end

Todo

  • Support other database column types that raise an exception when given a wrong value.

License

ActiveRecord::StrictValidations is © 2013-2015 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

About Mirego

Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.