date_validator 0.4.3 → 0.5.0
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/.rspec +2 -0
- data/Rakefile +12 -15
- data/VERSION +1 -1
- data/date_validator.gemspec +14 -11
- data/lib/date_validator.rb +2 -2
- data/spec/date_validator_spec.rb +28 -19
- data/spec/spec_helper.rb +2 -7
- metadata +39 -9
- data/spec/spec.opts +0 -2
data/.rspec
ADDED
data/Rakefile
CHANGED
@@ -11,30 +11,27 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/codegram/date_validator"
|
12
12
|
gem.authors = ["Oriol Gual", "Josep Mª Bach", "Josep Jaume Rey"]
|
13
13
|
|
14
|
-
gem.add_dependency 'activemodel', '>= 3.0.0.
|
14
|
+
gem.add_dependency 'activemodel', '>= 3.0.0.beta4'
|
15
15
|
|
16
|
-
gem.add_development_dependency "rspec"
|
17
|
-
|
18
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
gem.add_development_dependency "rspec", '>= 2.0.0.beta.12'
|
17
|
+
gem.add_development_dependency "activesupport", '>= 3.0.0.beta4'
|
19
18
|
end
|
20
19
|
Jeweler::GemcutterTasks.new
|
21
20
|
rescue LoadError
|
22
21
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
23
22
|
end
|
24
23
|
|
25
|
-
require 'spec/rake/spectask'
|
26
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
-
spec.libs << 'lib' << 'spec'
|
28
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
-
end
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
spec.rcov = true
|
35
|
-
end
|
25
|
+
# Rake RSpec2 task stuff
|
26
|
+
gem 'rspec', '>= 2.0.0.beta.12'
|
27
|
+
gem 'rspec-expectations'
|
36
28
|
|
37
|
-
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
|
31
|
+
desc "Run the specs under spec"
|
32
|
+
RSpec::Core::RakeTask.new do |t|
|
33
|
+
|
34
|
+
end
|
38
35
|
|
39
36
|
task :default => :spec
|
40
37
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/date_validator.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{date_validator}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Oriol Gual", "Josep M\302\252 Bach", "Josep Jaume Rey"]
|
12
|
-
s.date = %q{2010-06-
|
12
|
+
s.date = %q{2010-06-16}
|
13
13
|
s.description = %q{A simple date validator for Rails 3. Currently supporting :after, :before, :after_or_equal_to and :before_or_equal_to options. Remarkable-friendly :)}
|
14
14
|
s.email = %q{info@codegram.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".gitignore",
|
22
|
+
".rspec",
|
22
23
|
"LICENSE",
|
23
24
|
"README.rdoc",
|
24
25
|
"Rakefile",
|
@@ -27,13 +28,12 @@ Gem::Specification.new do |s|
|
|
27
28
|
"lib/date_validator.rb",
|
28
29
|
"locales/en.yml",
|
29
30
|
"spec/date_validator_spec.rb",
|
30
|
-
"spec/spec.opts",
|
31
31
|
"spec/spec_helper.rb"
|
32
32
|
]
|
33
33
|
s.homepage = %q{http://github.com/codegram/date_validator}
|
34
34
|
s.rdoc_options = ["--charset=UTF-8"]
|
35
35
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.3.
|
36
|
+
s.rubygems_version = %q{1.3.7}
|
37
37
|
s.summary = %q{A simple date validator for Rails 3.}
|
38
38
|
s.test_files = [
|
39
39
|
"spec/date_validator_spec.rb",
|
@@ -44,16 +44,19 @@ Gem::Specification.new do |s|
|
|
44
44
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
45
|
s.specification_version = 3
|
46
46
|
|
47
|
-
if Gem::Version.new(Gem::
|
48
|
-
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0.
|
49
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0.beta4"])
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.12"])
|
50
|
+
s.add_development_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
|
50
51
|
else
|
51
|
-
s.add_dependency(%q<activemodel>, [">= 3.0.0.
|
52
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
52
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.0.beta4"])
|
53
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.12"])
|
54
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
|
53
55
|
end
|
54
56
|
else
|
55
|
-
s.add_dependency(%q<activemodel>, [">= 3.0.0.
|
56
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
57
|
+
s.add_dependency(%q<activemodel>, [">= 3.0.0.beta4"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.12"])
|
59
|
+
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta4"])
|
57
60
|
end
|
58
61
|
end
|
59
62
|
|
data/lib/date_validator.rb
CHANGED
@@ -11,8 +11,8 @@ module ActiveModel
|
|
11
11
|
def check_validity!
|
12
12
|
keys = CHECKS.keys
|
13
13
|
options.slice(*keys).each do |option, value|
|
14
|
-
next if is_time?(value) || value.is_a?(Proc) || value.is_a?(Symbol)
|
15
|
-
raise ArgumentError, ":#{option} must be a time, a date, a symbol or a proc"
|
14
|
+
next if is_time?(value) || value.is_a?(Proc) || value.is_a?(Symbol) || (defined?(ActiveSupport::TimeWithZone) and value.is_a? ActiveSupport::TimeWithZone)
|
15
|
+
raise ArgumentError, ":#{option} must be a time, a date, a time_with_zone, a symbol or a proc"
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
data/spec/date_validator_spec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
+
require 'active_support/time' # For testing Date and TimeWithZone objects
|
4
|
+
|
3
5
|
describe "DateValidator" do
|
4
6
|
|
5
7
|
before(:each) do
|
@@ -8,23 +10,22 @@ describe "DateValidator" do
|
|
8
10
|
|
9
11
|
it "should check validity of the arguments" do
|
10
12
|
[3, "foo", 1..6].each do |wrong_argument|
|
11
|
-
|
13
|
+
expect {
|
12
14
|
TestRecord.validates :expiration_date, :date => {:before => wrong_argument}
|
13
|
-
|
14
|
-
rescue=>e
|
15
|
-
fail e unless e.is_a?(ArgumentError)
|
16
|
-
end
|
15
|
+
}.to raise_error(ArgumentError, ":before must be a time, a date, a time_with_zone, a symbol or a proc")
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
19
|
[:after, :before, :after_or_equal_to, :before_or_equal_to].each do |check|
|
21
20
|
[:valid,:invalid].each do |should_be|
|
22
21
|
|
22
|
+
now = Time.now.to_datetime
|
23
|
+
|
23
24
|
model_date = case check
|
24
|
-
when :after then should_be == :valid ?
|
25
|
-
when :before then should_be == :valid ?
|
26
|
-
when :after_or_equal_to then should_be == :valid ?
|
27
|
-
when :before_or_equal_to then should_be == :valid ?
|
25
|
+
when :after then should_be == :valid ? now + 21000 : now - 1
|
26
|
+
when :before then should_be == :valid ? now - 21000 : now + 1
|
27
|
+
when :after_or_equal_to then should_be == :valid ? now : now - 21000
|
28
|
+
when :before_or_equal_to then should_be == :valid ? now : now + 21000
|
28
29
|
end
|
29
30
|
|
30
31
|
it "should ensure that an attribute is #{should_be} when #{should_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
|
@@ -37,34 +38,42 @@ describe "DateValidator" do
|
|
37
38
|
end
|
38
39
|
|
39
40
|
extra_types = [:proc, :symbol]
|
40
|
-
|
41
|
+
extra_types.push(:date) if defined?(Date) and defined?(DateTime)
|
42
|
+
extra_types.push(:time_with_zone) if defined?(ActiveSupport::TimeWithZone)
|
41
43
|
|
42
44
|
extra_types.each do |type|
|
43
45
|
it "should accept a #{type} as an argument to a check" do
|
44
46
|
case type
|
45
47
|
when :proc then
|
46
|
-
|
48
|
+
expect {
|
49
|
+
TestRecord.validates :expiration_date, :date => {:after => Proc.new{Time.now + 21000}}
|
50
|
+
}.to_not raise_error
|
47
51
|
when :symbol then
|
48
|
-
|
52
|
+
expect {
|
49
53
|
TestRecord.send(:define_method, :min_date, lambda { Time.now + 21000 })
|
50
54
|
TestRecord.validates :expiration_date, :date => {:after => :min_date}
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
55
|
+
}.to_not raise_error
|
56
|
+
when :date then
|
57
|
+
expect {
|
58
|
+
TestRecord.validates :expiration_date, :date => {:after => Time.now.to_date}
|
59
|
+
}.to_not raise_error
|
60
|
+
when :time_with_zone then
|
61
|
+
expect {
|
62
|
+
Time.zone = "Hawaii"
|
63
|
+
TestRecord.validates :expiration_date, :date => {:before => Time.zone.parse((Time.now + 21000).to_s)}
|
64
|
+
}.to_not raise_error
|
56
65
|
end
|
57
66
|
end
|
58
67
|
end
|
59
68
|
|
60
69
|
it "should gracefully handle an unexpected result from a proc argument evaluation" do
|
61
70
|
TestRecord.validates :expiration_date, :date => {:after => Proc.new{ nil }}
|
62
|
-
TestRecord.new(Time.now).
|
71
|
+
TestRecord.new(Time.now).should_not be_valid
|
63
72
|
end
|
64
73
|
|
65
74
|
it "should gracefully handle an unexpected result from a symbol argument evaluation" do
|
66
75
|
TestRecord.send(:define_method, :min_date, lambda { nil })
|
67
76
|
TestRecord.validates :expiration_date, :date => {:after => :min_date}
|
68
|
-
TestRecord.new(Time.now).
|
77
|
+
TestRecord.new(Time.now).should_not be_valid
|
69
78
|
end
|
70
79
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,9 +5,8 @@ require 'rubygems'
|
|
5
5
|
require 'active_model'
|
6
6
|
|
7
7
|
require 'lib/date_validator'
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
|
8
|
+
require 'rspec'
|
9
|
+
require 'rspec/autorun'
|
11
10
|
|
12
11
|
class TestRecord
|
13
12
|
include ActiveModel::Validations
|
@@ -17,7 +16,3 @@ class TestRecord
|
|
17
16
|
@expiration_date = expiration_date
|
18
17
|
end
|
19
18
|
end
|
20
|
-
|
21
|
-
Spec::Runner.configure do |config|
|
22
|
-
|
23
|
-
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Oriol Gual
|
@@ -16,36 +17,61 @@ autorequire:
|
|
16
17
|
bindir: bin
|
17
18
|
cert_chain: []
|
18
19
|
|
19
|
-
date: 2010-06-
|
20
|
+
date: 2010-06-16 00:00:00 +02:00
|
20
21
|
default_executable:
|
21
22
|
dependencies:
|
22
23
|
- !ruby/object:Gem::Dependency
|
23
24
|
name: activemodel
|
24
25
|
prerelease: false
|
25
26
|
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
26
28
|
requirements:
|
27
29
|
- - ">="
|
28
30
|
- !ruby/object:Gem::Version
|
31
|
+
hash: 299253624
|
29
32
|
segments:
|
30
33
|
- 3
|
31
34
|
- 0
|
32
35
|
- 0
|
33
|
-
-
|
34
|
-
version: 3.0.0.
|
36
|
+
- beta4
|
37
|
+
version: 3.0.0.beta4
|
35
38
|
type: :runtime
|
36
39
|
version_requirements: *id001
|
37
40
|
- !ruby/object:Gem::Dependency
|
38
41
|
name: rspec
|
39
42
|
prerelease: false
|
40
43
|
requirement: &id002 !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
41
45
|
requirements:
|
42
46
|
- - ">="
|
43
47
|
- !ruby/object:Gem::Version
|
48
|
+
hash: 62196475
|
44
49
|
segments:
|
50
|
+
- 2
|
51
|
+
- 0
|
45
52
|
- 0
|
46
|
-
|
53
|
+
- beta
|
54
|
+
- 12
|
55
|
+
version: 2.0.0.beta.12
|
47
56
|
type: :development
|
48
57
|
version_requirements: *id002
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: activesupport
|
60
|
+
prerelease: false
|
61
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
hash: 299253624
|
67
|
+
segments:
|
68
|
+
- 3
|
69
|
+
- 0
|
70
|
+
- 0
|
71
|
+
- beta4
|
72
|
+
version: 3.0.0.beta4
|
73
|
+
type: :development
|
74
|
+
version_requirements: *id003
|
49
75
|
description: A simple date validator for Rails 3. Currently supporting :after, :before, :after_or_equal_to and :before_or_equal_to options. Remarkable-friendly :)
|
50
76
|
email: info@codegram.com
|
51
77
|
executables: []
|
@@ -58,6 +84,7 @@ extra_rdoc_files:
|
|
58
84
|
files:
|
59
85
|
- .document
|
60
86
|
- .gitignore
|
87
|
+
- .rspec
|
61
88
|
- LICENSE
|
62
89
|
- README.rdoc
|
63
90
|
- Rakefile
|
@@ -66,7 +93,6 @@ files:
|
|
66
93
|
- lib/date_validator.rb
|
67
94
|
- locales/en.yml
|
68
95
|
- spec/date_validator_spec.rb
|
69
|
-
- spec/spec.opts
|
70
96
|
- spec/spec_helper.rb
|
71
97
|
has_rdoc: true
|
72
98
|
homepage: http://github.com/codegram/date_validator
|
@@ -78,23 +104,27 @@ rdoc_options:
|
|
78
104
|
require_paths:
|
79
105
|
- lib
|
80
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
81
108
|
requirements:
|
82
109
|
- - ">="
|
83
110
|
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
84
112
|
segments:
|
85
113
|
- 0
|
86
114
|
version: "0"
|
87
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
88
117
|
requirements:
|
89
118
|
- - ">="
|
90
119
|
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
91
121
|
segments:
|
92
122
|
- 0
|
93
123
|
version: "0"
|
94
124
|
requirements: []
|
95
125
|
|
96
126
|
rubyforge_project:
|
97
|
-
rubygems_version: 1.3.
|
127
|
+
rubygems_version: 1.3.7
|
98
128
|
signing_key:
|
99
129
|
specification_version: 3
|
100
130
|
summary: A simple date validator for Rails 3.
|
data/spec/spec.opts
DELETED