-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
61 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ Gemfile.lock | |
pkg | ||
.idea | ||
.DS_Store | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module PostcodeAnywhere | ||
module EmailValidation | ||
VERSION = '0.0.3' | ||
VERSION = '0.0.4' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module PostcodeAnywhere | ||
module Matchers | ||
RSpec::Matchers.define :validate_email_with_postcode_anywhere do | ||
chain :on_attribute do |attribute| | ||
@attribute = attribute | ||
end | ||
|
||
match do |model| | ||
model_validators = model.class.validators_on(attribute) | ||
model_validators.any? { |validator| validator.instance_of?(PostcodeAnywhere::EmailValidation::Validator) } | ||
end | ||
|
||
def attribute | ||
@attribute || :email | ||
end | ||
|
||
failure_message_for_should do |model| | ||
failure_message(model, 'should') | ||
end | ||
|
||
failure_message_for_should_not do |model| | ||
failure_message(model, 'snould not') | ||
end | ||
|
||
def failure_message(model, should_or_should_not) | ||
"#{model.class} #{should_or_should_not} have 'PostcodeAnywhere::EmailValidation::Validator' on attribute #{attribute}" | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
spec/lib/postcode_anywhere/matchers/email_validator_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'spec_helper' | ||
|
||
module PostcodeAnywhere::EmailValidation | ||
|
||
describe 'Validator Matcher' do | ||
|
||
context 'when Validator is defined' do | ||
subject { ::ValidatedClass.new } | ||
|
||
it { should validate_email_with_postcode_anywhere } | ||
|
||
it { should validate_email_with_postcode_anywhere.on_attribute(:email) } | ||
|
||
it { should_not validate_email_with_postcode_anywhere.on_attribute(:email_address) } | ||
end | ||
|
||
context 'when Validator is not defined' do | ||
subject { ::NotValidatedClass.new } | ||
|
||
it { should_not validate_email_with_postcode_anywhere } | ||
end | ||
|
||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class NotValidatedClass | ||
include ActiveModel::Validations | ||
end | ||
|