date_validator 0.5.4 → 0.5.5

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.4
1
+ 0.5.5
@@ -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.4"
8
+ s.version = "0.5.5"
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"]
@@ -47,7 +47,7 @@ module ActiveModel
47
47
 
48
48
 
49
49
  unless is_time?(option_value) && value.to_i.send(CHECKS[option], option_value.to_i)
50
- record.errors.add(attr_name, option, :default => options[:message], :value => original_value, :date => original_option_value)
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)
51
51
  end
52
52
  end
53
53
  end
data/locales/en.yml CHANGED
@@ -5,7 +5,7 @@ en:
5
5
  errors:
6
6
  messages:
7
7
  not_a_date: "is not a date"
8
- after: "must be after {{value}}"
9
- after_or_equal_to: "must be after or equal to {{value}}"
10
- before: "must be before {{value}}"
11
- before_or_equal_to: "must be before or equal to {{value}}"
8
+ after: "must be after %{value}"
9
+ after_or_equal_to: "must be after or equal to %{value}"
10
+ before: "must be before %{value}"
11
+ before_or_equal_to: "must be before or equal to %{value}"
@@ -16,25 +16,44 @@ describe "DateValidator" do
16
16
  end
17
17
  end
18
18
 
19
- [:after, :before, :after_or_equal_to, :before_or_equal_to].each do |check|
20
- [:valid,:invalid].each do |should_be|
19
+ [:valid,:invalid].each do |should_be|
21
20
 
22
- now = Time.now.to_datetime
21
+ _context = should_be == :valid ? 'when value validates correctly' : 'when value does not match validation requirements'
23
22
 
24
- model_date = case check
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
29
- end
23
+ context _context do
24
+
25
+ [:after, :before, :after_or_equal_to, :before_or_equal_to].each do |check|
26
+
27
+ now = Time.now.to_datetime
28
+
29
+ model_date = case check
30
+ when :after then should_be == :valid ? now + 21000 : now - 1
31
+ when :before then should_be == :valid ? now - 21000 : now + 1
32
+ when :after_or_equal_to then should_be == :valid ? now : now - 21000
33
+ when :before_or_equal_to then should_be == :valid ? now : now + 21000
34
+ end
35
+
36
+ it "should ensure that an attribute is #{should_be} when #{should_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
37
+ TestRecord.validates :expiration_date, :date => {:"#{check}" => Time.now}
38
+ model = TestRecord.new(model_date)
39
+ should_be == :valid ? model.should(be_valid, "an attribute should be valid when respecting the #{check} check") : model.should_not(be_valid, "an attribute should be invalidwhen offending the #{check} check")
40
+ end
41
+
42
+ if _context == 'when value does not match validation requirements'
43
+
44
+ it "should yield an error message indicating that value must be #{check} validation requirements" do
45
+ TestRecord.validates :expiration_date, :date => {:"#{check}" => Time.now}
46
+ model = TestRecord.new(model_date)
47
+ model.should_not be_valid
48
+ model.errors[:expiration_date].should == ["must be " + check.to_s.gsub('_',' ') + " #{Time.now}"]
49
+ end
50
+
51
+ end
30
52
 
31
- it "should ensure that an attribute is #{should_be} when #{should_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
32
- TestRecord.validates :expiration_date, :date => {:"#{check}" => Time.now}
33
- model = TestRecord.new(model_date)
34
- should_be == :valid ? model.should(be_valid, "an attribute should be valid when respecting the #{check} check") : model.should(be_invalid, "an attribute should be invalid when offending the #{check} check")
35
53
  end
36
54
 
37
55
  end
56
+
38
57
  end
39
58
 
40
59
  extra_types = [:proc, :symbol]
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,8 @@ require 'lib/date_validator'
8
8
  require 'rspec'
9
9
  require 'rspec/autorun'
10
10
 
11
+ I18n.load_path += Dir[File.join('locales', '*.{rb,yml}')]
12
+
11
13
  class TestRecord
12
14
  include ActiveModel::Validations
13
15
  attr_accessor :expiration_date
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: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 4
10
- version: 0.5.4
9
+ - 5
10
+ version: 0.5.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oriol Gual