postcode_anywhere-email_validation 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YzQzODgyZDZhM2Y1ZDkwZmVmMjMxZDBiMzM3ZjEyMDY3MzNmMjUwMQ==
5
- data.tar.gz: !binary |-
6
- YWE0MGMxMjliOWQzMTg4OTU1Mzc2MWRkYjc2NTc1ZTYzYmQ3YTExYg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZWIxZGZmY2M0ZTlhMDYwNWNlZjc0MzBmMDg2ZjMxYjgyMTc0ZGJkNWFkMzlj
10
- ZjI5OWRiZDMyYTkxNjRiNTQ1ZmFmOTAyMjJhMjgyMGM2NmFmYzllOWUyYjcw
11
- ZjdmNWIxMDJjYThlOWNjMTA3YWNiYTdhNzk1ZjJiMTc2NTUwMDk=
12
- data.tar.gz: !binary |-
13
- MjFiM2JjN2UxZDAwMzIwODI4NmFhMzM5ZTkxMDcyZjYzMGM1MWI4ODg2YzYz
14
- MjI0YzNjM2VlMjUyYzIwMWM5ZTNlZmMzZDFkNGI1MzU2M2FiOWU3Y2VlNmRk
15
- ZDU3M2FkZTMwNGM0ZGNiZWQyNzZlYmNiZTU5MzI0YjQ3NzM0MmY=
2
+ SHA1:
3
+ metadata.gz: 6d4d019cee86c4a0ba5c2f2b6e39453d46fb36cb
4
+ data.tar.gz: cc4e8be9c412e37083a14c1d1642258eb241ce94
5
+ SHA512:
6
+ metadata.gz: c9e3151a9655e9b02cf90929ba60395b2dd8a02b26e0a2db66451222d7f8e95009d947187b6ae9ba09a4f0e39a946e6c8cf2bca4132f648395950a1580cc3e0f
7
+ data.tar.gz: b8877f6ee3dad316078da55c08f36aa4ce72d9f77a5af2fcaae3a8b5fe90b05db36c5ab2dd8dead3538bae0cb27703ea068615ebc381c55cd3eadf39e332f371
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ Gemfile.lock
5
5
  pkg
6
6
  .idea
7
7
  .DS_Store
8
+ coverage
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
7
+ - ruby-head
8
+ - jruby-head
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # PostcodeAnywhere::EmailValidation
2
2
 
3
+ [![Build Status][build-status-badge]] [build-status]
4
+ [![Code Climate][code-climate-badge]] [code-climate-feed]
5
+ [![Coverage Status][coverage-status-badge]] [coverage-status]
6
+
3
7
  Verifies the existence of an email address using the
4
8
  [Email Validation web services] [email-validation]
5
9
  from [PostcodeAnywhere].
@@ -31,6 +35,32 @@ PostcodeAnywhere::EmailValidation.key = 'AA11-AA11-AA11-AA11'
31
35
  PostcodeAnywhere::EmailValidation.valid?('info@google.com') #=> true
32
36
  ```
33
37
 
38
+ Or use the provided ActiveModel validator:
39
+
40
+ ```ruby
41
+ class ValidatedClass
42
+ include ActiveModel::Validations
43
+
44
+ attr_accessor :email
45
+
46
+ validates_with PostcodeAnywhere::EmailValidation::Validator, attributes: %w{ email }
47
+ end
48
+ ```
49
+
50
+ ## Usage with RSpec
51
+
52
+ With default attribute: :email
53
+
54
+ ```ruby
55
+ it { should validate_email_with_postcode_anywhere }
56
+ ```
57
+
58
+ With custom attribute.
59
+
60
+ ```ruby
61
+ it { should validate_email_with_postcode_anywhere.on_attribute(:email) }
62
+ ```
63
+
34
64
  ## Contributing
35
65
 
36
66
  1. Fork it
@@ -44,3 +74,21 @@ PostcodeAnywhere::EmailValidation.valid?('info@google.com') #=> true
44
74
 
45
75
  [email-validation]: http://www.postcodeanywhere.co.uk/email-validation/
46
76
  "PostcodeAnywhere's Email Validation web services"
77
+
78
+ [build-status]: https://travis-ci.org/moneyadviceservice/postcode_anywhere-email_validation
79
+ "Build Status"
80
+
81
+ [build-status-badge]: https://travis-ci.org/moneyadviceservice/postcode_anywhere-email_validation.png
82
+ "Build Status"
83
+
84
+ [code-climate-feed]: https://codeclimate.com/github/moneyadviceservice/postcode_anywhere-email_validation
85
+ "Code Climate"
86
+
87
+ [code-climate-badge]: https://codeclimate.com/github/moneyadviceservice/postcode_anywhere-email_validation.png
88
+ "Code Climate"
89
+
90
+ [coverage-status]: https://coveralls.io/r/moneyadviceservice/postcode_anywhere-email_validation
91
+ "Coverage Status"
92
+
93
+ [coverage-status-badge]: https://coveralls.io/repos/moneyadviceservice/postcode_anywhere-email_validation/badge.png
94
+ "Coverage Status"
@@ -2,6 +2,7 @@ require 'postcode_anywhere/email_validation/response'
2
2
  require 'postcode_anywhere/email_validation/validation_error'
3
3
  require 'postcode_anywhere/email_validation/validator'
4
4
  require 'postcode_anywhere/email_validation/version'
5
+ require 'postcode_anywhere/matchers/email_validator' if defined?(RSpec)
5
6
 
6
7
  require 'rest_client'
7
8
 
@@ -4,7 +4,9 @@ module PostcodeAnywhere
4
4
  module EmailValidation
5
5
  class Validator < ActiveModel::EachValidator
6
6
  def validate_each(record, attribute, value)
7
- unless PostcodeAnywhere::EmailValidation.valid?(value)
7
+ if value.blank?
8
+ record.errors.add(attribute, :blank, value: value)
9
+ elsif !PostcodeAnywhere::EmailValidation.valid?(value)
8
10
  record.errors.add(attribute, :invalid, value: value)
9
11
  end
10
12
  end
@@ -1,5 +1,5 @@
1
1
  module PostcodeAnywhere
2
2
  module EmailValidation
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.4'
4
4
  end
5
5
  end
@@ -0,0 +1,30 @@
1
+ module PostcodeAnywhere
2
+ module Matchers
3
+ RSpec::Matchers.define :validate_email_with_postcode_anywhere do
4
+ chain :on_attribute do |attribute|
5
+ @attribute = attribute
6
+ end
7
+
8
+ match do |model|
9
+ model_validators = model.class.validators_on(attribute)
10
+ model_validators.any? { |validator| validator.instance_of?(PostcodeAnywhere::EmailValidation::Validator) }
11
+ end
12
+
13
+ def attribute
14
+ @attribute || :email
15
+ end
16
+
17
+ failure_message_for_should do |model|
18
+ failure_message(model, 'should')
19
+ end
20
+
21
+ failure_message_for_should_not do |model|
22
+ failure_message(model, 'snould not')
23
+ end
24
+
25
+ def failure_message(model, should_or_should_not)
26
+ "#{model.class} #{should_or_should_not} have 'PostcodeAnywhere::EmailValidation::Validator' on attribute #{attribute}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -11,18 +11,19 @@ Gem::Specification.new do |spec|
11
11
  spec.description = %q{Verify the existence of an email address.}
12
12
  spec.summary = %q{Verifies the existence of an email address using the Email Validation web services from PostcodeAnywhere.}
13
13
  spec.homepage = 'https://github.com/moneyadviceservice/postcode_anywhere-email_validation'
14
- spec.date = "2013-06-04"
14
+ spec.date = '2013-06-04'
15
15
  spec.files = `git ls-files`.split($/)
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
- spec.required_ruby_version = '>= 1.9.2'
19
+ spec.required_ruby_version = '>= 1.9.3'
20
20
 
21
21
  spec.add_dependency 'rest-client', '~> 1.6'
22
22
  spec.add_dependency 'activemodel', '~> 3.2'
23
23
 
24
- spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'bundler', '~> 1.2'
25
25
  spec.add_development_dependency 'capybara', '~> 2.1'
26
+ spec.add_development_dependency 'coveralls'
26
27
  spec.add_development_dependency 'rake'
27
28
  spec.add_development_dependency 'rspec', '~> 2.0'
28
29
  spec.add_development_dependency 'vcr', '~> 2.4'
@@ -7,6 +7,13 @@ module PostcodeAnywhere
7
7
 
8
8
  subject { ::ValidatedClass.new }
9
9
 
10
+ context 'blank email' do
11
+ it 'is not valid' do
12
+ PostcodeAnywhere::EmailValidation.should_not_receive(:valid?)
13
+ expect(subject).to_not be_valid
14
+ end
15
+ end
16
+
10
17
  context 'Using Postcode Anywhere' do
11
18
  before { subject.email = 'an_email' }
12
19
 
@@ -21,6 +28,14 @@ module PostcodeAnywhere
21
28
  end
22
29
  end
23
30
 
31
+ describe 'RSpec Matcher' do
32
+ context 'with default attribute' do
33
+ it { should validate_email_with_postcode_anywhere }
34
+ end
35
+ context 'with custom attribute' do
36
+ it { should validate_email_with_postcode_anywhere.on_attribute(:email) }
37
+ end
38
+ end
24
39
  end
25
40
  end
26
41
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module PostcodeAnywhere::EmailValidation
4
+
5
+ describe 'Validator Matcher' do
6
+
7
+ context 'when Validator is defined' do
8
+ subject { ::ValidatedClass.new }
9
+
10
+ it { should validate_email_with_postcode_anywhere }
11
+
12
+ it { should validate_email_with_postcode_anywhere.on_attribute(:email) }
13
+
14
+ it { should_not validate_email_with_postcode_anywhere.on_attribute(:email_address) }
15
+ end
16
+
17
+ context 'when Validator is not defined' do
18
+ subject { ::NotValidatedClass.new }
19
+
20
+ it { should_not validate_email_with_postcode_anywhere }
21
+ end
22
+
23
+ end
24
+ end
@@ -3,12 +3,12 @@ ENV['POSTCODE_ANYWHERE_KEY'] ||= 'AA11-AA11-AA11-AA11'
3
3
  require 'postcode_anywhere/email_validation'
4
4
 
5
5
  require 'capybara/rspec'
6
+ require 'coveralls'
6
7
  require 'vcr'
7
8
  require 'pry'
8
9
 
9
10
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
10
11
 
11
-
12
12
  RSpec.configure do |config|
13
13
  config.treat_symbols_as_metadata_keys_with_true_values = true
14
14
 
@@ -30,3 +30,5 @@ VCR.configure do |config|
30
30
  config.hook_into :webmock
31
31
  config.filter_sensitive_data('{{Key}}') { ENV['POSTCODE_ANYWHERE_KEY'] }
32
32
  end
33
+
34
+ Coveralls.wear!
@@ -0,0 +1,4 @@
1
+ class NotValidatedClass
2
+ include ActiveModel::Validations
3
+ end
4
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postcode_anywhere-email_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Garner
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - ~>
47
47
  - !ruby/object:Gem::Version
48
- version: '1.3'
48
+ version: '1.2'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ~>
54
54
  - !ruby/object:Gem::Version
55
- version: '1.3'
55
+ version: '1.2'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: capybara
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -67,18 +67,32 @@ dependencies:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  version: '2.1'
70
+ - !ruby/object:Gem::Dependency
71
+ name: coveralls
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: rake
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - ! '>='
88
+ - - '>='
75
89
  - !ruby/object:Gem::Version
76
90
  version: '0'
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
- - - ! '>='
95
+ - - '>='
82
96
  - !ruby/object:Gem::Version
83
97
  version: '0'
84
98
  - !ruby/object:Gem::Dependency
@@ -133,6 +147,7 @@ extra_rdoc_files: []
133
147
  files:
134
148
  - .gitignore
135
149
  - .rspec
150
+ - .travis.yml
136
151
  - Gemfile
137
152
  - LICENSE.txt
138
153
  - README.md
@@ -142,6 +157,7 @@ files:
142
157
  - lib/postcode_anywhere/email_validation/validation_error.rb
143
158
  - lib/postcode_anywhere/email_validation/validator.rb
144
159
  - lib/postcode_anywhere/email_validation/version.rb
160
+ - lib/postcode_anywhere/matchers/email_validator.rb
145
161
  - postcodeanywhere-emailvalidation.gemspec
146
162
  - spec/features/email_validation_spec.rb
147
163
  - spec/features/email_validator_spec.rb
@@ -149,6 +165,7 @@ files:
149
165
  - spec/lib/postcode_anywhere/email_validation/validation_error_spec.rb
150
166
  - spec/lib/postcode_anywhere/email_validation/validator_spec.rb
151
167
  - spec/lib/postcode_anywhere/email_validation_spec.rb
168
+ - spec/lib/postcode_anywhere/matchers/email_validator_spec.rb
152
169
  - spec/spec_helper.rb
153
170
  - spec/support/fixtures/vcr_cassettes/activemodel_validator_with_invalid_values_is_not_valid_on_value_example_com_.yml
154
171
  - spec/support/fixtures/vcr_cassettes/activemodel_validator_with_invalid_values_is_not_valid_on_value_john_doe_.yml
@@ -158,6 +175,7 @@ files:
158
175
  - spec/support/fixtures/vcr_cassettes/validating_an_email_address_with_invalid_format.yml
159
176
  - spec/support/fixtures/vcr_cassettes/validating_an_email_address_with_valid_format_and_valid_dns_record.yml
160
177
  - spec/support/fixtures/vcr_cassettes/validating_an_email_address_without_api_key.yml
178
+ - spec/support/not_validated_class.rb
161
179
  - spec/support/validated_class.rb
162
180
  homepage: https://github.com/moneyadviceservice/postcode_anywhere-email_validation
163
181
  licenses: []
@@ -168,12 +186,12 @@ require_paths:
168
186
  - lib
169
187
  required_ruby_version: !ruby/object:Gem::Requirement
170
188
  requirements:
171
- - - ! '>='
189
+ - - '>='
172
190
  - !ruby/object:Gem::Version
173
- version: 1.9.2
191
+ version: 1.9.3
174
192
  required_rubygems_version: !ruby/object:Gem::Requirement
175
193
  requirements:
176
- - - ! '>='
194
+ - - '>='
177
195
  - !ruby/object:Gem::Version
178
196
  version: '0'
179
197
  requirements: []
@@ -190,6 +208,7 @@ test_files:
190
208
  - spec/lib/postcode_anywhere/email_validation/validation_error_spec.rb
191
209
  - spec/lib/postcode_anywhere/email_validation/validator_spec.rb
192
210
  - spec/lib/postcode_anywhere/email_validation_spec.rb
211
+ - spec/lib/postcode_anywhere/matchers/email_validator_spec.rb
193
212
  - spec/spec_helper.rb
194
213
  - spec/support/fixtures/vcr_cassettes/activemodel_validator_with_invalid_values_is_not_valid_on_value_example_com_.yml
195
214
  - spec/support/fixtures/vcr_cassettes/activemodel_validator_with_invalid_values_is_not_valid_on_value_john_doe_.yml
@@ -199,4 +218,5 @@ test_files:
199
218
  - spec/support/fixtures/vcr_cassettes/validating_an_email_address_with_invalid_format.yml
200
219
  - spec/support/fixtures/vcr_cassettes/validating_an_email_address_with_valid_format_and_valid_dns_record.yml
201
220
  - spec/support/fixtures/vcr_cassettes/validating_an_email_address_without_api_key.yml
221
+ - spec/support/not_validated_class.rb
202
222
  - spec/support/validated_class.rb