format_validator 0.0.1 → 0.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b500991685c1969b800b9cfd64a6d67c1a30de82
4
+ data.tar.gz: 99a3eb3d04eb057175a128ab0ee8131f1b2d4d0f
5
+ SHA512:
6
+ metadata.gz: 7612cf1c270b37ece5591c486348ad9153c7ed3692f2d13cab60d09d1f71a16bfd6982d2b42efdf1793a792d45c6d1e56d7cc2566ff34ad095218821d2b08642
7
+ data.tar.gz: 1318734908ef9ac010cefe9e8176a0040d0cc502d091c393e6d96ae08ce31ebccf9036acbf4283d22c3e19a8002dcb0b890e003a4c1d5393c80ccacebbf79f79
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
1
  ## v0.0.1
2
2
 
3
3
  * Initial release
4
+
5
+ ## v0.0.2
6
+
7
+ * Validate date in the future
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FormatValidator
2
2
 
3
- TODO: Write a gem description
3
+ [![Build Status](https://travis-ci.org/bloc40/format_validator.png?branch=master)](https://travis-ci.org/bloc40/format_validator) [![Code Climate](https://codeclimate.com/github/bloc40/format_validator.png)](https://codeclimate.com/github/bloc40/format_validator)
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,16 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ As of today the gem validates only email, url, and zip_code.
22
+
23
+ ``` ruby
24
+ validates :email, email_format: true
25
+ validates :url, url_format: true
26
+ validates :zip_code, zip_code_format: true
27
+ ```
28
+ ## TODO
29
+
30
+ Add more validators.
22
31
 
23
32
  ## Contributing
24
33
 
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.add_development_dependency 'activemodel'
21
22
  spec.add_development_dependency 'bundler', '~> 1.3'
22
23
  spec.add_development_dependency 'rake'
23
24
  end
@@ -2,3 +2,4 @@ require 'format_validator/version'
2
2
  require 'format_validator/email_format_validator'
3
3
  require 'format_validator/url_format_validator'
4
4
  require 'format_validator/zip_code_format_validator'
5
+ require 'format_validator/future_date_validator'
@@ -0,0 +1,11 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class FutureDateValidator < ActiveModel::EachValidator
4
+ def validate_each(object, attribute, value)
5
+ if value <= Time.now
6
+ object.errors[attribute] << (options[:message] || 'must be in the future')
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module FormatValidator
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -4,8 +4,8 @@ describe 'EmailFormatValidator' do
4
4
  describe '#validate_each' do
5
5
  let(:klass) do
6
6
  Class.new do
7
- attr_accessor :email
8
7
  include ActiveModel::Validations
8
+ attr_accessor :email
9
9
  validates :email, email_format: true
10
10
  end
11
11
  end
@@ -0,0 +1,34 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe 'FutureDateValidator' do
4
+ describe '#validate_each' do
5
+ let(:klass) do
6
+ Class.new do
7
+ include ActiveModel::Validations
8
+ attr_accessor :expiration_date
9
+ validates :expiration_date, future_date: true
10
+ end
11
+ end
12
+
13
+ let(:one_day) { 60 * 60 * 24 }
14
+
15
+ subject { klass.new }
16
+
17
+ describe 'valid' do
18
+ it 'should not add any error' do
19
+ subject.expiration_date = Time.now + one_day
20
+ subject.valid?.must_equal true
21
+ subject.errors.messages.must_be_empty
22
+ end
23
+ end
24
+
25
+ describe 'invalid' do
26
+ it 'should add error when expiration date is in the past' do
27
+ subject.expiration_date = Time.now - one_day
28
+ subject.valid?.must_equal false
29
+ subject.errors.messages.size.must_equal 1
30
+ subject.errors.messages[:expiration_date].must_equal ['must be in the future']
31
+ end
32
+ end
33
+ end
34
+ end
@@ -4,8 +4,8 @@ describe 'UrlFormatValidator' do
4
4
  describe '#validate_each' do
5
5
  let(:klass) do
6
6
  Class.new do
7
- attr_accessor :url
8
7
  include ActiveModel::Validations
8
+ attr_accessor :url
9
9
  validates :url, url_format: true
10
10
  end
11
11
  end
@@ -4,8 +4,8 @@ describe 'ZipCodeFormatValidator' do
4
4
  describe '#validate_each' do
5
5
  let(:klass) do
6
6
  Class.new do
7
- attr_accessor :zip_code
8
7
  include ActiveModel::Validations
8
+ attr_accessor :zip_code
9
9
  validates :zip_code, zip_code_format: true
10
10
  end
11
11
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,8 @@
1
- gem 'minitest'
1
+ begin
2
+ gem 'minitest'
3
+ rescue LoadError
4
+ end
5
+
2
6
  require 'active_model'
3
7
  require 'format_validator'
4
8
  require 'minitest/autorun'
metadata CHANGED
@@ -1,20 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jamal El Milahi
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-10 00:00:00.000000000 Z
11
+ date: 2013-03-16 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: bundler
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
31
  - - ~>
20
32
  - !ruby/object:Gem::Version
@@ -22,7 +34,6 @@ dependencies:
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
38
  - - ~>
28
39
  - !ruby/object:Gem::Version
@@ -30,17 +41,15 @@ dependencies:
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - '>='
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  description: Active Model missing format validators
@@ -51,6 +60,7 @@ extensions: []
51
60
  extra_rdoc_files: []
52
61
  files:
53
62
  - .gitignore
63
+ - .travis.yml
54
64
  - CHANGELOG
55
65
  - Gemfile
56
66
  - LICENSE.txt
@@ -59,41 +69,43 @@ files:
59
69
  - format_validator.gemspec
60
70
  - lib/format_validator.rb
61
71
  - lib/format_validator/email_format_validator.rb
72
+ - lib/format_validator/future_date_validator.rb
62
73
  - lib/format_validator/url_format_validator.rb
63
74
  - lib/format_validator/version.rb
64
75
  - lib/format_validator/zip_code_format_validator.rb
65
76
  - spec/format_validator/email_format_validator_spec.rb
77
+ - spec/format_validator/future_date_validator_spec.rb
66
78
  - spec/format_validator/url_format_validator_spec.rb
67
79
  - spec/format_validator/zip_code_format_validator_spec.rb
68
80
  - spec/spec_helper.rb
69
81
  homepage: ''
70
82
  licenses:
71
83
  - MIT
84
+ metadata: {}
72
85
  post_install_message:
73
86
  rdoc_options: []
74
87
  require_paths:
75
88
  - lib
76
89
  required_ruby_version: !ruby/object:Gem::Requirement
77
- none: false
78
90
  requirements:
79
- - - ! '>='
91
+ - - '>='
80
92
  - !ruby/object:Gem::Version
81
93
  version: '0'
82
94
  required_rubygems_version: !ruby/object:Gem::Requirement
83
- none: false
84
95
  requirements:
85
- - - ! '>='
96
+ - - '>='
86
97
  - !ruby/object:Gem::Version
87
98
  version: '0'
88
99
  requirements: []
89
100
  rubyforge_project:
90
- rubygems_version: 1.8.24
101
+ rubygems_version: 2.0.2
91
102
  signing_key:
92
- specification_version: 3
103
+ specification_version: 4
93
104
  summary: format_validator is a gem that adds the missing format validators to Active
94
105
  Model
95
106
  test_files:
96
107
  - spec/format_validator/email_format_validator_spec.rb
108
+ - spec/format_validator/future_date_validator_spec.rb
97
109
  - spec/format_validator/url_format_validator_spec.rb
98
110
  - spec/format_validator/zip_code_format_validator_spec.rb
99
111
  - spec/spec_helper.rb