validate_as_email 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -25,6 +25,54 @@ Rubinius using Travis CI.
25
25
  You will need to be using Rails 3 to make use of this validator, as it
26
26
  is built on top of ActiveModel, which was introduced in Rails 3.
27
27
 
28
+ ### Usage with ActiveModel
29
+
30
+ ``` ruby
31
+ class Person
32
+ include ActiveModel::Validations
33
+ validates_as_email :email
34
+ attr_accessor :email
35
+ end
36
+
37
+ # OR
38
+
39
+ class Person
40
+ include ActiveModel::Validations
41
+ validates :email, email: true
42
+ attr_accessor :email
43
+ end
44
+ ```
45
+
46
+ ### Usage with ActiveRecord
47
+
48
+ ``` ruby
49
+ class Person < ActiveRecord::Base
50
+ validates_as_email :email
51
+ attr_accessor :email
52
+ end
53
+
54
+ # OR
55
+
56
+ class Person < ActiveRecord::Base
57
+ validates :email, email: true
58
+ attr_accessor :email
59
+ end
60
+ ```
61
+
62
+ ### Built-in RSpec Matcher
63
+
64
+ ``` ruby
65
+ class Person < ActiveRecord::Base
66
+ validates_as_email :email
67
+ attr_accessor :email
68
+ end
69
+
70
+ describe Person do
71
+ it { should have_a_valid_email_address_for(:email) }
72
+ it { should_not have_a_valid_email_address_for(:email) }
73
+ end
74
+ ```
75
+
28
76
  ## Contributing
29
77
 
30
78
  1. Fork it
@@ -0,0 +1,24 @@
1
+ Feature: RSpec matcher
2
+
3
+ Scenario: The built-in RSpec matcher covers validation of email for you
4
+ Given a file named "rspec_matcher.rb" with:
5
+ """
6
+ require 'active_model'
7
+ require 'rspec'
8
+ require 'validate_as_email'
9
+
10
+ class Person
11
+ include ActiveModel::Validations
12
+ validates_as_email :email
13
+ attr_accessor :email
14
+ end
15
+
16
+ describe Person do
17
+ it { should_not have_a_valid_email_address_for(:email) }
18
+ end
19
+ """
20
+ When I run `rspec rspec_matcher.rb`
21
+ Then it should fail with:
22
+ """
23
+ not to have a valid email address for :email
24
+ """
@@ -1,6 +1,11 @@
1
1
  require 'bundler'
2
2
  Bundler.setup
3
3
 
4
+ begin
5
+ require 'simplecov'
6
+ rescue LoadError
7
+ end
8
+
4
9
  require 'aruba/cucumber'
5
10
 
6
11
  # Borrowed from VCR
@@ -1,3 +1,7 @@
1
1
  require 'validate_as_email/version'
2
2
  require 'active_model'
3
3
  require 'active_model/validations/email_validator'
4
+
5
+ if defined?(RSpec)
6
+ require 'validate_as_email/rspec'
7
+ end
@@ -0,0 +1,48 @@
1
+ require 'rspec/rails/extensions/active_record/base'
2
+ # Adds a custom matcher to RSpec to make it easier to make sure your email
3
+ # column is valid.
4
+ #
5
+ # class Person
6
+ # include ActiveModel::Validations
7
+ #
8
+ # validates_as_email :email
9
+ #
10
+ # def initialize(attributes = {})
11
+ # @attributes = attributes
12
+ # end
13
+ #
14
+ # def email
15
+ # @attributes[:email]
16
+ # end
17
+ #
18
+ # def email=(address)
19
+ # @attributes[:email] = address
20
+ # end
21
+ # end
22
+ #
23
+ # describe Person
24
+ # it { should have_a_valid_email_address_for(:email) }
25
+ # end
26
+ RSpec::Matchers.define(:have_a_valid_email_address_for) do |column_name|
27
+ match do |klass|
28
+ %w(
29
+ matz@example.com
30
+ a@b.tld
31
+ 1@8.8.8.8
32
+ ).each do |valid|
33
+ klass.send("#{column_name}=", valid)
34
+ klass.should have(0).errors_on(column_name)
35
+ end
36
+
37
+ %w(
38
+ word
39
+ a@
40
+ @b
41
+ example.com
42
+ 8.8.8.8
43
+ ).each do |invalid|
44
+ klass.send("#{column_name}=", invalid)
45
+ klass.should have(1).error_on(column_name)
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module ValidateAsEmail
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  $: << 'lib'
2
2
 
3
+ begin
4
+ require 'simplecov'
5
+ rescue LoadError
6
+ end
7
+
3
8
  require 'validate_as_email'
4
9
  require 'rspec/rails/extensions/active_record/base'
5
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validate_as_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -163,12 +163,14 @@ extensions: []
163
163
  extra_rdoc_files: []
164
164
  files:
165
165
  - lib/active_model/validations/email_validator.rb
166
+ - lib/validate_as_email/rspec.rb
166
167
  - lib/validate_as_email/version.rb
167
168
  - lib/validate_as_email.rb
168
169
  - README.md
169
170
  - LICENSE
170
171
  - features/active_model.feature
171
172
  - features/active_record.feature
173
+ - features/rspec_matcher.feature
172
174
  - features/support/cucumber_helpers.rb
173
175
  - features/support/env.rb
174
176
  - spec/active_model/validations/email_validator_spec.rb
@@ -201,6 +203,7 @@ summary: The ultimate Rails 3 email validator. Powered by the Mail gem.
201
203
  test_files:
202
204
  - features/active_model.feature
203
205
  - features/active_record.feature
206
+ - features/rspec_matcher.feature
204
207
  - features/support/cucumber_helpers.rb
205
208
  - features/support/env.rb
206
209
  - spec/active_model/validations/email_validator_spec.rb