# MissingValidators [![Build Status](https://travis-ci.org/andrewgr/missing_validators.png)](https://travis-ci.org/andrewgr/missing_validators) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/andrewgr/missing_validators) MissingValidators is a collection of custom validators that are often required in Rails applications plus shoulda-style RSpec matchers to test the validation rules. ## Installation Add this line to your application's Gemfile: gem 'missing_validators' And then execute: $ bundle Or install it yourself as: $ gem install missing_validators ## Usage ### EmailValidator With an ActiveRecord model: class User < ActiveRecord::Base attr_accessor :email, :name validates :email, email: true end Or any ruby class: class User include ActiveModel::Validations attr_accessor :email, :name validates :email, email: true end You can specify domains to which the email domain should belong in one of the folowing ways: validates :email, email: { domains: 'com' } validates :email, email: { domains: :com } validates :email, email: { domains: [:com, 'edu'] } RSpec matcher is also available for your convenience: describe User do it { should ensure_valid_email_format_of(:email) } end ### UrlValidator With an ActiveRecord model: class User < ActiveRecord::Base attr_accessor :blog, :name validates :blog, url: true end Or any ruby class: class User include ActiveModel::Validations attr_accessor :blog, :name validates :blog, url: true end You can specify domains to which the URL domain should belong in one of the folowing ways: validates :url, url: { domains: 'com' } validates :url, url: { domains: :com } validates :url, url: { domains: [:com, 'edu'] } validates :url, url: { root: true } validates :url, url: { scheme: :http } validates :url, url: { scheme: [:http, 'https'] } RSpec matcher is also available for your convenience: describe User do it { should ensure_valid_url_format_of(:url) } end ### InequalityValidator With an ActiveRecord model: class Flight < ActiveRecord::Base attr_accessor :origin, :destination validates :origin, inequality: { to: :destination } end Or any ruby class: class Flight include ActiveModel::Validations attr_accessor :origin, :destination validates :origin, inequality: { to: :destination } end RSpec matcher is also available for your convenience: describe Flight do it { should ensure_inequality_of(:origin).to(:destination) } end ## Contributing Your contribution is welcome. 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request