date_validator 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,8 @@ Pretty much self-explanatory! :) And if you like remarkable, just install this g
20
20
 
21
21
  gem install remarkable_date_validator
22
22
 
23
+ (source on http://github.com/codegram/remarkable_date_validator/)
24
+
23
25
  == Note on Patches/Pull Requests
24
26
 
25
27
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{date_validator}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
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-04-27}
12
+ s.date = %q{2010-05-14}
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 = [
@@ -56,3 +56,4 @@ Gem::Specification.new do |s|
56
56
  s.add_dependency(%q<rspec>, [">= 0"])
57
57
  end
58
58
  end
59
+
@@ -11,7 +11,7 @@ module ActiveModel
11
11
  def check_validity!
12
12
  keys = CHECKS.keys
13
13
  options.slice(*keys).each do |option, value|
14
- next if value.is_a?(Time) || value.is_a?(Proc) || value.is_a?(Symbol) || (defined?(Date) and value.is_a?(Date))
14
+ next if is_time?(value) || value.is_a?(Proc) || value.is_a?(Symbol)
15
15
  raise ArgumentError, ":#{option} must be a time, a date, a symbol or a proc"
16
16
  end
17
17
  end
@@ -29,10 +29,14 @@ module ActiveModel
29
29
  option_value = option_value.call(record) if option_value.is_a?(Proc)
30
30
  option_value = record.send(option_value) if option_value.is_a?(Symbol)
31
31
 
32
- unless value.send(CHECKS[option], option_value)
32
+ unless is_time?(option_value) && value.send(CHECKS[option], option_value)
33
33
  record.errors.add(attr_name, option, :default => options[:message], :value => value, :date => option_value)
34
34
  end
35
- end
35
+ end
36
+ end
37
+
38
+ def is_time?(object)
39
+ object.is_a?(Time) || (defined?(Date) and object.is_a?(Date))
36
40
  end
37
41
 
38
42
  module ClassMethods
@@ -53,8 +53,18 @@ describe "DateValidator" do
53
53
  end
54
54
  # when :date then
55
55
  # TestRecord.validates :expiration_date, :date => {:after => Time.now.to_date}
56
- end
56
+ end
57
57
  end
58
58
  end
59
59
 
60
+ it "should gracefully handle an unexpected result from a proc argument evaluation" do
61
+ TestRecord.validates :expiration_date, :date => {:after => Proc.new{ nil }}
62
+ TestRecord.new(Time.now).valid?.should be_false
63
+ end
64
+
65
+ it "should gracefully handle an unexpected result from a symbol argument evaluation" do
66
+ TestRecord.send(:define_method, :min_date, lambda { nil })
67
+ TestRecord.validates :expiration_date, :date => {:after => :min_date}
68
+ TestRecord.new(Time.now).valid?.should be_false
69
+ end
60
70
  end
@@ -1,4 +1,2 @@
1
1
  --colour
2
2
  --format progress
3
- --loadby mtime
4
- --reverse
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 0
9
- version: 0.4.0
8
+ - 1
9
+ version: 0.4.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Oriol Gual
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-04-27 00:00:00 +02:00
19
+ date: 2010-05-14 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency