date_validator 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ pkg
6
6
  *.rbc
7
7
  doc/*
8
8
  .yardoc/*
9
+ Gemfile.lock
@@ -0,0 +1,8 @@
1
+ # http://about.travis-ci.org/docs/user/build-configuration/
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - ree
6
+ - ruby-head
7
+ - rbx
8
+ - rbx-2.0
data/Rakefile CHANGED
@@ -1,43 +1,48 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
- require 'rspec/core/rake_task'
5
- desc "Run superrtext specs"
6
- RSpec::Core::RakeTask.new
7
-
8
- require 'yard'
9
- YARD::Rake::YardocTask.new(:docs) do |t|
10
- t.files = ['lib/**/*.rb']
11
- t.options = ['-m', 'markdown', '--no-private', '-r', 'Readme.md', '--title', 'Date Validator documentation']
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = true
12
9
  end
13
10
 
14
- site = 'doc'
15
- source_branch = 'master'
16
- deploy_branch = 'gh-pages'
11
+ begin
12
+ require 'yard'
13
+ YARD::Rake::YardocTask.new(:docs) do |t|
14
+ t.files = ['lib/**/*.rb']
15
+ t.options = ['-m', 'markdown', '--no-private', '-r', 'Readme.md', '--title', 'Date Validator documentation']
16
+ end
17
17
 
18
- desc "generate and deploy documentation website to github pages"
19
- multitask :pages do
20
- puts ">>> Deploying #{deploy_branch} branch to Github Pages <<<"
21
- require 'git'
22
- repo = Git.open('.')
23
- puts "\n>>> Checking out #{deploy_branch} branch <<<\n"
24
- repo.branch("#{deploy_branch}").checkout
25
- (Dir["*"] - [site]).each { |f| rm_rf(f) }
26
- Dir["#{site}/*"].each {|f| mv(f, "./")}
27
- rm_rf(site)
28
- puts "\n>>> Moving generated site files <<<\n"
29
- Dir["**/*"].each {|f| repo.add(f) }
30
- repo.status.deleted.each {|f, s| repo.remove(f)}
31
- puts "\n>>> Commiting: Site updated at #{Time.now.utc} <<<\n"
32
- message = ENV["MESSAGE"] || "Site updated at #{Time.now.utc}"
33
- repo.commit(message)
34
- puts "\n>>> Pushing generated site to #{deploy_branch} branch <<<\n"
35
- repo.push
36
- puts "\n>>> Github Pages deploy complete <<<\n"
37
- repo.branch("#{source_branch}").checkout
38
- end
18
+ site = 'doc'
19
+ source_branch = 'master'
20
+ deploy_branch = 'gh-pages'
39
21
 
40
- task :doc => [:docs]
22
+ desc "generate and deploy documentation website to github pages"
23
+ multitask :pages do
24
+ puts ">>> Deploying #{deploy_branch} branch to Github Pages <<<"
25
+ require 'git'
26
+ repo = Git.open('.')
27
+ puts "\n>>> Checking out #{deploy_branch} branch <<<\n"
28
+ repo.branch("#{deploy_branch}").checkout
29
+ (Dir["*"] - [site]).each { |f| rm_rf(f) }
30
+ Dir["#{site}/*"].each {|f| mv(f, "./")}
31
+ rm_rf(site)
32
+ puts "\n>>> Moving generated site files <<<\n"
33
+ Dir["**/*"].each {|f| repo.add(f) }
34
+ repo.status.deleted.each {|f, s| repo.remove(f)}
35
+ puts "\n>>> Commiting: Site updated at #{Time.now.utc} <<<\n"
36
+ message = ENV["MESSAGE"] || "Site updated at #{Time.now.utc}"
37
+ repo.commit(message)
38
+ puts "\n>>> Pushing generated site to #{deploy_branch} branch <<<\n"
39
+ repo.push
40
+ puts "\n>>> Github Pages deploy complete <<<\n"
41
+ repo.branch("#{source_branch}").checkout
42
+ end
43
+
44
+ task :doc => [:docs]
45
+ rescue LoadError
46
+ end
41
47
 
42
- task :default => :spec
43
- task :test => [:spec]
48
+ task :default => :test
data/Readme.md CHANGED
@@ -39,6 +39,12 @@ validates :start_date,
39
39
 
40
40
  Pretty much self-explanatory! :)
41
41
 
42
+ If you want to make sure an attribute is before/after another attribute, use:
43
+
44
+ ```ruby
45
+ validates :start_date, :date => {:before => :end_date }
46
+ ```
47
+
42
48
  ## Note on Patches/Pull Requests
43
49
 
44
50
  * Fork the project.
@@ -14,16 +14,13 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = "date_validator"
16
16
 
17
- s.add_runtime_dependency 'activemodel', ['>= 3.0.0', '< 3.2.0']
17
+ s.add_runtime_dependency 'activemodel', ['~> 3.0']
18
18
 
19
- s.add_development_dependency 'rspec', '~> 2.5.0'
20
- s.add_development_dependency 'simplecov'
21
- s.add_development_dependency 'activesupport', '~> 3.0.0'
19
+ s.add_development_dependency 'minitest'
20
+ s.add_development_dependency 'rake'
21
+ s.add_development_dependency 'activesupport', ['~> 3.0']
22
22
  s.add_development_dependency 'tzinfo', '~> 0.3.0'
23
23
 
24
- s.add_development_dependency 'yard'
25
- s.add_development_dependency 'bluecloth'
26
-
27
24
  s.files = `git ls-files`.split("\n")
28
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29
26
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -1,4 +1,4 @@
1
1
  module DateValidator
2
2
  # The version number.
3
- VERSION = "0.6.2"
3
+ VERSION = "0.6.3"
4
4
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'test_helper'
2
2
 
3
3
  module ActiveModel
4
4
  module Validations
@@ -11,50 +11,49 @@ module ActiveModel
11
11
 
12
12
  it "checks validity of the arguments" do
13
13
  [3, "foo", 1..6].each do |wrong_argument|
14
- expect {
15
- TestRecord.validates :expiration_date,
16
- :date => {:before => wrong_argument}
17
- }.to raise_error(ArgumentError, ":before must be a time, a date, a time_with_zone, a symbol or a proc")
14
+ proc {
15
+ TestRecord.validates(:expiration_date, :date => {:before => wrong_argument})
16
+ }.must_raise(ArgumentError, ":before must be a time, a date, a time_with_zone, a symbol or a proc")
18
17
  end
19
18
  end
20
19
 
21
20
  it "complains when no options are provided" do
21
+ I18n.backend.reload!
22
22
  TestRecord.validates :expiration_date,
23
23
  :date => {:before => Time.now}
24
24
 
25
25
  model = TestRecord.new(nil)
26
- model.should_not be_valid
27
- model.errors[:expiration_date].should eq(["is not a date"])
26
+ model.valid?.must_equal false
27
+ model.errors[:expiration_date].must_equal(["is not a date"])
28
28
  end
29
29
 
30
30
  it "works with helper methods" do
31
31
  time = Time.now
32
32
  TestRecord.validates_date_of :expiration_date, :before => time
33
33
  model = TestRecord.new(time + 20000)
34
- model.should_not be_valid
34
+ model.valid?.must_equal false
35
35
  end
36
36
 
37
- [:valid,:invalid].each do |should_be|
38
- _context = should_be == :valid ? 'when value validates correctly' : 'when value does not match validation requirements'
37
+ [:valid,:invalid].each do |must_be|
38
+ _context = must_be == :valid ? 'when value validates correctly' : 'when value does not match validation requirements'
39
39
 
40
- context _context do
40
+ describe _context do
41
41
  [:after, :before, :after_or_equal_to, :before_or_equal_to].each do |check|
42
42
  now = Time.now.to_datetime
43
43
 
44
44
  model_date = case check
45
- when :after then should_be == :valid ? now + 21000 : now - 1
46
- when :before then should_be == :valid ? now - 21000 : now + 1
47
- when :after_or_equal_to then should_be == :valid ? now : now - 21000
48
- when :before_or_equal_to then should_be == :valid ? now : now + 21000
45
+ when :after then must_be == :valid ? now + 21000 : now - 1
46
+ when :before then must_be == :valid ? now - 21000 : now + 1
47
+ when :after_or_equal_to then must_be == :valid ? now : now - 21000
48
+ when :before_or_equal_to then must_be == :valid ? now : now + 21000
49
49
  end
50
50
 
51
- it "ensures that an attribute is #{should_be} when #{should_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
51
+ it "ensures that an attribute is #{must_be} when #{must_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
52
52
  TestRecord.validates :expiration_date,
53
53
  :date => {:"#{check}" => now}
54
54
 
55
55
  model = TestRecord.new(model_date)
56
- should_be == :valid ? model.should(be_valid, "an attribute should be valid when respecting the #{check} check")\
57
- : model.should_not(be_valid, "an attribute should be invalidwhen offending the #{check} check")
56
+ must_be == :valid ? model.valid?.must_equal(true) : model.valid?.must_equal(false)
58
57
  end
59
58
 
60
59
  if _context == 'when value does not match validation requirements'
@@ -63,8 +62,8 @@ module ActiveModel
63
62
  :date => {:"#{check}" => now}
64
63
 
65
64
  model = TestRecord.new(model_date)
66
- model.should_not be_valid
67
- model.errors[:expiration_date].should eq(["must be " + check.to_s.gsub('_',' ') + " #{I18n.localize(now)}"])
65
+ model.valid?.must_equal false
66
+ model.errors[:expiration_date].must_equal(["must be " + check.to_s.gsub('_',' ') + " #{I18n.localize(now)}"])
68
67
  end
69
68
  end
70
69
  end
@@ -78,8 +77,8 @@ module ActiveModel
78
77
  :message => 'must be after Christmas'}
79
78
 
80
79
  model = TestRecord.new(now + 21000)
81
- model.should_not be_valid
82
- model.errors[:expiration_date].should eq(["must be after Christmas"])
80
+ model.valid?.must_equal false
81
+ model.errors[:expiration_date].must_equal(["must be after Christmas"])
83
82
  end
84
83
 
85
84
  it "allows custom validation message to be handled by I18n" do
@@ -89,8 +88,8 @@ module ActiveModel
89
88
  TestRecord.validates :expiration_date, :date => true
90
89
 
91
90
  model = TestRecord.new(nil)
92
- model.should_not be_valid
93
- model.errors[:expiration_date].should eq([custom_message])
91
+ model.valid?.must_equal false
92
+ model.errors[:expiration_date].must_equal([custom_message])
94
93
  end
95
94
  end
96
95
 
@@ -105,24 +104,15 @@ module ActiveModel
105
104
  it "accepts a #{type} as an argument to a check" do
106
105
  case type
107
106
  when :proc then
108
- expect {
109
- TestRecord.validates :expiration_date,
110
- :date => {:after => Proc.new{Time.now + 21000}}
111
- }.to_not raise_error
107
+ TestRecord.validates(:expiration_date, :date => {:after => Proc.new{Time.now + 21000}}).must_be_kind_of Hash
112
108
  when :symbol then
113
- expect {
114
- TestRecord.send(:define_method, :min_date, lambda { Time.now + 21000 })
115
- TestRecord.validates :expiration_date, :date => {:after => :min_date}
116
- }.to_not raise_error
109
+ TestRecord.send(:define_method, :min_date, lambda { Time.now + 21000 })
110
+ TestRecord.validates(:expiration_date, :date => {:after => :min_date}).must_be_kind_of Hash
117
111
  when :date then
118
- expect {
119
- TestRecord.validates :expiration_date, :date => {:after => Time.now.to_date}
120
- }.to_not raise_error
112
+ TestRecord.validates(:expiration_date, :date => {:after => Time.now.to_date}).must_be_kind_of Hash
121
113
  when :time_with_zone then
122
- expect {
123
- Time.zone = "Hawaii"
124
- TestRecord.validates :expiration_date, :date => {:before => Time.zone.parse((Time.now + 21000).to_s)}
125
- }.to_not raise_error
114
+ Time.zone = "Hawaii"
115
+ TestRecord.validates(:expiration_date, :date => {:before => Time.zone.parse((Time.now + 21000).to_s)}).must_be_kind_of Hash
126
116
  end
127
117
  end
128
118
  end
@@ -131,7 +121,7 @@ module ActiveModel
131
121
  TestRecord.validates :expiration_date,
132
122
  :date => {:after => Proc.new{ nil }}
133
123
 
134
- TestRecord.new(Time.now).should_not be_valid
124
+ TestRecord.new(Time.now).valid?.must_equal false
135
125
  end
136
126
 
137
127
  it "gracefully handles an unexpected result from a symbol argument evaluation" do
@@ -139,7 +129,7 @@ module ActiveModel
139
129
  TestRecord.validates :expiration_date,
140
130
  :date => {:after => :min_date}
141
131
 
142
- TestRecord.new(Time.now).should_not be_valid
132
+ TestRecord.new(Time.now).valid?.must_equal false
143
133
  end
144
134
  end
145
135
 
@@ -1,9 +1,15 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_group "Lib", "lib"
1
+ begin
2
+ require 'simplecov';
3
+ SimpleCov.start do
4
+ add_group "Lib", 'lib'
5
+ end
6
+ rescue LoadError
4
7
  end
5
8
 
6
- require 'rspec'
9
+ begin; require 'turn'; rescue LoadError; end
10
+
11
+ require 'minitest/spec'
12
+ require 'minitest/autorun'
7
13
 
8
14
  require 'active_support/time' # For testing Date and TimeWithZone objects
9
15
 
metadata CHANGED
@@ -1,116 +1,89 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: date_validator
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.3
4
5
  prerelease:
5
- version: 0.6.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Oriol Gual
9
9
  - Josep M. Bach
10
10
  - Josep Jaume Rey
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
-
15
- date: 2011-06-08 00:00:00 Z
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
14
+ date: 2012-01-22 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
18
17
  name: activemodel
19
- prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &70140810524120 !ruby/object:Gem::Requirement
21
19
  none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: 3.0.0
26
- - - <
27
- - !ruby/object:Gem::Version
28
- version: 3.2.0
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: '3.0'
29
24
  type: :runtime
30
- version_requirements: *id001
31
- - !ruby/object:Gem::Dependency
32
- name: rspec
33
25
  prerelease: false
34
- requirement: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *70140810524120
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: &70140810523700 !ruby/object:Gem::Requirement
35
30
  none: false
36
- requirements:
37
- - - ~>
38
- - !ruby/object:Gem::Version
39
- version: 2.5.0
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
40
35
  type: :development
41
- version_requirements: *id002
42
- - !ruby/object:Gem::Dependency
43
- name: simplecov
44
36
  prerelease: false
45
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ version_requirements: *70140810523700
38
+ - !ruby/object:Gem::Dependency
39
+ name: rake
40
+ requirement: &70140810523240 !ruby/object:Gem::Requirement
46
41
  none: false
47
- requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
51
46
  type: :development
52
- version_requirements: *id003
53
- - !ruby/object:Gem::Dependency
54
- name: activesupport
55
47
  prerelease: false
56
- requirement: &id004 !ruby/object:Gem::Requirement
48
+ version_requirements: *70140810523240
49
+ - !ruby/object:Gem::Dependency
50
+ name: activesupport
51
+ requirement: &70140810522720 !ruby/object:Gem::Requirement
57
52
  none: false
58
- requirements:
53
+ requirements:
59
54
  - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 3.0.0
55
+ - !ruby/object:Gem::Version
56
+ version: '3.0'
62
57
  type: :development
63
- version_requirements: *id004
64
- - !ruby/object:Gem::Dependency
65
- name: tzinfo
66
58
  prerelease: false
67
- requirement: &id005 !ruby/object:Gem::Requirement
59
+ version_requirements: *70140810522720
60
+ - !ruby/object:Gem::Dependency
61
+ name: tzinfo
62
+ requirement: &70140810522220 !ruby/object:Gem::Requirement
68
63
  none: false
69
- requirements:
64
+ requirements:
70
65
  - - ~>
71
- - !ruby/object:Gem::Version
66
+ - !ruby/object:Gem::Version
72
67
  version: 0.3.0
73
68
  type: :development
74
- version_requirements: *id005
75
- - !ruby/object:Gem::Dependency
76
- name: yard
77
- prerelease: false
78
- requirement: &id006 !ruby/object:Gem::Requirement
79
- none: false
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: "0"
84
- type: :development
85
- version_requirements: *id006
86
- - !ruby/object:Gem::Dependency
87
- name: bluecloth
88
69
  prerelease: false
89
- requirement: &id007 !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
94
- version: "0"
95
- type: :development
96
- version_requirements: *id007
97
- description: A simple, ORM agnostic, Ruby 1.9 compatible date validator for Rails 3, based on ActiveModel. Currently supporting :after, :before, :after_or_equal_to and :before_or_equal_to options.
98
- email:
70
+ version_requirements: *70140810522220
71
+ description: A simple, ORM agnostic, Ruby 1.9 compatible date validator for Rails
72
+ 3, based on ActiveModel. Currently supporting :after, :before, :after_or_equal_to
73
+ and :before_or_equal_to options.
74
+ email:
99
75
  - info@codegram.com
100
76
  executables: []
101
-
102
77
  extensions: []
103
-
104
78
  extra_rdoc_files: []
105
-
106
- files:
107
- - .bundle/config
79
+ files:
108
80
  - .document
81
+ - .gemtest
109
82
  - .gitignore
110
83
  - .rspec
111
84
  - .rvmrc
85
+ - .travis.yml
112
86
  - Gemfile
113
- - Gemfile.lock
114
87
  - LICENSE
115
88
  - Rakefile
116
89
  - Readme.md
@@ -123,35 +96,33 @@ files:
123
96
  - locales/es.yml
124
97
  - locales/nl.yml
125
98
  - locales/ru.yml
126
- - spec/date_validator_spec.rb
127
- - spec/spec_helper.rb
99
+ - test/date_validator_test.rb
100
+ - test/test_helper.rb
128
101
  homepage: http://github.com/codegram/date_validator
129
102
  licenses: []
130
-
131
103
  post_install_message:
132
104
  rdoc_options: []
133
-
134
- require_paths:
105
+ require_paths:
135
106
  - lib
136
- required_ruby_version: !ruby/object:Gem::Requirement
107
+ required_ruby_version: !ruby/object:Gem::Requirement
137
108
  none: false
138
- requirements:
139
- - - ">="
140
- - !ruby/object:Gem::Version
141
- version: "0"
142
- required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
114
  none: false
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- version: "0"
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
148
119
  requirements: []
149
-
150
120
  rubyforge_project: date_validator
151
- rubygems_version: 1.8.5
121
+ rubygems_version: 1.8.10
152
122
  signing_key:
153
123
  specification_version: 3
154
- summary: A simple, ORM agnostic, Ruby 1.9 compatible date validator for Rails 3, based on ActiveModel.
155
- test_files:
156
- - spec/date_validator_spec.rb
157
- - spec/spec_helper.rb
124
+ summary: A simple, ORM agnostic, Ruby 1.9 compatible date validator for Rails 3, based
125
+ on ActiveModel.
126
+ test_files:
127
+ - test/date_validator_test.rb
128
+ - test/test_helper.rb
@@ -1,2 +0,0 @@
1
- ---
2
- BUNDLE_DISABLE_SHARED_GEMS: "1"
@@ -1,44 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- date_validator (0.6.1)
5
- activemodel (>= 3.0.0, < 3.2.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- activemodel (3.0.0)
11
- activesupport (= 3.0.0)
12
- builder (~> 2.1.2)
13
- i18n (~> 0.4.1)
14
- activesupport (3.0.0)
15
- bluecloth (2.0.11)
16
- builder (2.1.2)
17
- diff-lcs (1.1.2)
18
- i18n (0.4.2)
19
- rspec (2.5.0)
20
- rspec-core (~> 2.5.0)
21
- rspec-expectations (~> 2.5.0)
22
- rspec-mocks (~> 2.5.0)
23
- rspec-core (2.5.1)
24
- rspec-expectations (2.5.0)
25
- diff-lcs (~> 1.1.2)
26
- rspec-mocks (2.5.0)
27
- simplecov (0.3.6)
28
- simplecov-html (>= 0.3.7)
29
- simplecov-html (0.3.8)
30
- tzinfo (0.3.23)
31
- yard (0.6.4)
32
-
33
- PLATFORMS
34
- java
35
- ruby
36
-
37
- DEPENDENCIES
38
- activesupport (~> 3.0.0)
39
- bluecloth
40
- date_validator!
41
- rspec (~> 2.5.0)
42
- simplecov
43
- tzinfo (~> 0.3.0)
44
- yard