date_validator 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.5
1
+ 0.5.6
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{date_validator}
8
- s.version = "0.5.5"
8
+ s.version = "0.5.6"
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"]
@@ -23,10 +23,10 @@ module ActiveModel
23
23
  return if options[:allow_nil] && value.nil?
24
24
 
25
25
  unless value
26
- record.errors.add(attr_name, :not_a_date, :value => value, :default => options[:message])
26
+ record.errors.add(attr_name, I18n.t("errors.messages.not_a_date"), :value => value, :default => options[:message])
27
27
  return
28
28
  end
29
-
29
+
30
30
  options.slice(*CHECKS.keys).each do |option, option_value|
31
31
  option_value = option_value.call(record) if option_value.is_a?(Proc)
32
32
  option_value = record.send(option_value) if option_value.is_a?(Symbol)
@@ -45,9 +45,9 @@ module ActiveModel
45
45
  value = value.to_datetime if value.is_a?(Date)
46
46
  end
47
47
 
48
-
49
48
  unless is_time?(option_value) && value.to_i.send(CHECKS[option], option_value.to_i)
50
- record.errors.add(attr_name, I18n.t("errors.messages.#{option}", :value => original_option_value), :default => options[:message], :value => original_value, :date => original_option_value)
49
+ error_msg = options[:message] || I18n.t("errors.messages.#{option}", :value => original_option_value)
50
+ record.errors.add(attr_name, error_msg, :default => options[:message], :value => original_value, :date => original_option_value)
51
51
  end
52
52
  end
53
53
  end
@@ -41,17 +41,28 @@ describe "DateValidator" do
41
41
 
42
42
  if _context == 'when value does not match validation requirements'
43
43
 
44
- it "should yield an error message indicating that value must be #{check} validation requirements" do
44
+ it "should yield a default error message indicating that value must be #{check} validation requirements" do
45
45
  TestRecord.validates :expiration_date, :date => {:"#{check}" => Time.now}
46
46
  model = TestRecord.new(model_date)
47
47
  model.should_not be_valid
48
48
  model.errors[:expiration_date].should == ["must be " + check.to_s.gsub('_',' ') + " #{Time.now}"]
49
49
  end
50
-
50
+
51
51
  end
52
52
 
53
53
  end
54
54
 
55
+ if _context == 'when value does not match validation requirements'
56
+
57
+ it "should allow for a custom validation message" do
58
+ TestRecord.validates :expiration_date, :date => {:before_or_equal_to => Time.now, :message => 'must be after Christmas'}
59
+ model = TestRecord.new(Time.now + 21000)
60
+ model.should_not be_valid
61
+ model.errors[:expiration_date].should == ["must be after Christmas"]
62
+ end
63
+
64
+ end
65
+
55
66
  end
56
67
 
57
68
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_validator
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 5
10
- version: 0.5.5
9
+ - 6
10
+ version: 0.5.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oriol Gual