date_validator 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,11 +2,11 @@
2
2
  source :gemcutter
3
3
 
4
4
  group :development do
5
- gem "rspec", "2.0.0"
6
- gem "jeweler"
5
+ gem "rspec", "~> 2.5.0"
7
6
  gem "simplecov"
8
- gem "activesupport", "3.0.0"
7
+ gem "jeweler"
8
+ gem "activesupport", "~> 3.0.0"
9
9
  gem "tzinfo"
10
10
  end
11
11
 
12
- gem "activemodel", "3.0.0"
12
+ gem "activemodel", "~> 3.0.0"
@@ -16,16 +16,14 @@ GEM
16
16
  git (>= 1.2.5)
17
17
  rubyforge (>= 2.0.0)
18
18
  json_pure (1.4.6)
19
- rspec (2.0.0)
20
- rspec-core (= 2.0.0)
21
- rspec-expectations (= 2.0.0)
22
- rspec-mocks (= 2.0.0)
23
- rspec-core (2.0.0)
24
- rspec-expectations (2.0.0)
25
- diff-lcs (>= 1.1.2)
26
- rspec-mocks (2.0.0)
27
- rspec-core (= 2.0.0)
28
- rspec-expectations (= 2.0.0)
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)
29
27
  rubyforge (2.0.4)
30
28
  json_pure (>= 1.1.7)
31
29
  simplecov (0.3.6)
@@ -38,9 +36,9 @@ PLATFORMS
38
36
  ruby
39
37
 
40
38
  DEPENDENCIES
41
- activemodel (= 3.0.0)
42
- activesupport (= 3.0.0)
39
+ activemodel (~> 3.0.0)
40
+ activesupport (~> 3.0.0)
43
41
  jeweler
44
- rspec (= 2.0.0)
42
+ rspec (~> 2.5.0)
45
43
  simplecov
46
44
  tzinfo
@@ -8,8 +8,8 @@ and Rubinius 1.1.
8
8
 
9
9
  And I mean simple. In your model:
10
10
 
11
- validates :expiration_date, :date => {:after => lambda { Time.now } :before => lambda { Time.now + 1.year } }
12
- # Using lambda prevents production cache issues
11
+ validates :expiration_date, :date => {:after => Proc.new { Time.now } :before => Proc.new { Time.now + 1.year } }
12
+ # Using Proc.new prevents production cache issues
13
13
 
14
14
  For now these are the available options you can use:
15
15
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.9
1
+ 0.6.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{date_validator}
8
- s.version = "0.5.9"
8
+ s.version = "0.6.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. Bach", "Josep Jaume Rey"]
12
- s.date = %q{2010-10-14}
12
+ s.date = %q{2011-02-10}
13
13
  s.description = %q{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.}
14
14
  s.email = %q{info@codegram.com}
15
15
  s.extra_rdoc_files = [
@@ -23,7 +23,7 @@ module ActiveModel
23
23
  return if options[:allow_nil] && value.nil?
24
24
 
25
25
  unless value
26
- record.errors.add(attr_name, I18n.t("errors.messages.not_a_date"), :value => value, :default => options[:message])
26
+ record.errors.add(attr_name, :not_a_date, options)
27
27
  return
28
28
  end
29
29
 
@@ -46,8 +46,7 @@ module ActiveModel
46
46
  end
47
47
 
48
48
  unless is_time?(option_value) && value.to_i.send(CHECKS[option], option_value.to_i)
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)
49
+ record.errors.add(attr_name, option, options.merge(:value => original_value, :date => original_option_value))
51
50
  end
52
51
  end
53
52
  end
@@ -59,3 +58,6 @@ module ActiveModel
59
58
  end
60
59
  end
61
60
  end
61
+
62
+ require 'active_support/i18n'
63
+ I18n.load_path += Dir[File.expand_path(File.join(File.dirname(__FILE__), '../locales', '*.yml')).to_s]
@@ -1,11 +1,11 @@
1
1
  # Sample localization file for English. Add more files in this directory for other locales.
2
2
  # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
3
 
4
- en:
4
+ ca:
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 %{date}"
9
+ after_or_equal_to: "must be after or equal to %{date}"
10
+ before: "must be before %{date}"
11
+ before_or_equal_to: "must be before or equal to %{date}"
@@ -1,8 +1,8 @@
1
- ca:
1
+ en:
2
2
  errors:
3
3
  messages:
4
- not_a_date: "no és una data"
5
- after: "ha de ser posterior a %{value}"
6
- after_or_equal_to: "ha de ser posterior o igual a %{value}"
7
- before: "ha de ser abans de %{value}"
8
- before_or_equal_to: "ha de ser abans o igual a %{value}"
4
+ not_a_date: "is not a date"
5
+ after: "must be after %{date}"
6
+ after_or_equal_to: "must be after or equal to %{date}"
7
+ before: "must be before %{date}"
8
+ before_or_equal_to: "must be before or equal to %{date}"
@@ -2,7 +2,7 @@ es:
2
2
  errors:
3
3
  messages:
4
4
  not_a_date: "no es una fecha"
5
- after: "tiene que ser posterior a %{value}"
6
- after_or_equal_to: "tiene que ser posterior o igual a %{value}"
7
- before: "tiene que ser antes de %{value}"
8
- before_or_equal_to: "tiene que ser antes o igual a %{value}"
5
+ after: "tiene que ser posterior a %{date}"
6
+ after_or_equal_to: "tiene que ser posterior o igual a %{date}"
7
+ before: "tiene que ser antes de %{date}"
8
+ before_or_equal_to: "tiene que ser antes o igual a %{date}"
@@ -68,6 +68,15 @@ describe "DateValidator" do
68
68
  model.errors[:expiration_date].should == ["must be after Christmas"]
69
69
  end
70
70
 
71
+ it "allows custom validation message to be handled by I18n" do
72
+ custom_message = 'Custom Date Message'
73
+ I18n.backend.store_translations('en', {:errors => {:messages => {:not_a_date => custom_message}}})
74
+ TestRecord.validates :expiration_date, :date => true
75
+ model = TestRecord.new(nil)
76
+ model.should_not be_valid
77
+ model.errors[:expiration_date].should == [custom_message]
78
+ end
79
+
71
80
  end
72
81
 
73
82
  end
@@ -11,8 +11,6 @@ require 'active_model'
11
11
  require 'date_validator'
12
12
  require 'rspec'
13
13
 
14
- I18n.load_path += Dir[File.join('locales', '*.{rb,yml}')]
15
-
16
14
  class TestRecord
17
15
  include ActiveModel::Validations
18
16
  attr_accessor :expiration_date
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 5
8
- - 9
9
- version: 0.5.9
7
+ - 6
8
+ - 0
9
+ version: 0.6.0
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-10-14 00:00:00 +02:00
19
+ date: 2011-02-10 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency