Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a validates_confirmation_of matcher

  • Loading branch information...
commit 8b5ec06077f3e5fa20995c62c094cf9a32e46c27 1 parent f970b5d
@markkendall markkendall authored
View
1  README.markdown
@@ -36,6 +36,7 @@ Validation Matchers
it { should validate_associated(:profile) }
it { should validate_inclusion_of(:role).to_allow("admin", "member") }
it { should validate_numericality_of(:age) }
+ it { should validate_confirmation_of(:email) }
end
describe Article do
View
9 lib/matchers/validations/confirmation_of.rb
@@ -0,0 +1,9 @@
+module Mongoid
+ module Matchers
+ module Validations
+ def validate_confirmation_of(field)
+ HaveValidationMatcher.new(field, :confirmation)
+ end
+ end
+ end
+end
View
1  lib/mongoid-rspec.rb
@@ -6,6 +6,7 @@
require 'matchers/associations'
require 'matchers/validations'
require 'matchers/validations/associated'
+require 'matchers/validations/confirmation_of'
require 'matchers/validations/format_of'
require 'matchers/validations/inclusion_of'
require 'matchers/validations/length_of'
View
4 spec/models/user.rb
@@ -13,11 +13,11 @@ class User
embeds_one :profile
validates :login, :presence => true, :uniqueness => { :scope => :site }, :format => { :with => /^[\w\-]+$/ }
- validates :email, :uniqueness => { :case_sensitive => false, :scope => :site, :message => "is already taken" }
+ validates :email, :uniqueness => { :case_sensitive => false, :scope => :site, :message => "is already taken" }, :confirmation => true
validates :role, :presence => true, :inclusion => { :in => ["admin", "moderator", "member"]}
validates :profile, :presence => true, :associated => true
def admin?
false
end
-end
+end
View
3  spec/unit/validations_spec.rb
@@ -13,6 +13,7 @@
it { should validate_format_of(:login).to_allow("valid_login").not_to_allow("invalid login") }
it { should validate_associated(:profile) }
it { should validate_inclusion_of(:role).to_allow("admin", "member") }
+ it { should validate_confirmation_of(:email) }
end
describe Profile do
@@ -22,4 +23,4 @@
describe Article do
it { should validate_length_of(:title) }
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.