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 +4 -4
- data/Gemfile.lock +11 -13
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/date_validator.gemspec +2 -2
- data/lib/date_validator.rb +5 -3
- data/locales/ca.yml +5 -5
- data/locales/en.yml +6 -6
- data/locales/es.yml +4 -4
- data/spec/date_validator_spec.rb +9 -0
- data/spec/spec_helper.rb +0 -2
- metadata +4 -4
data/Gemfile
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
source :gemcutter
|
3
3
|
|
4
4
|
group :development do
|
5
|
-
gem "rspec", "2.
|
6
|
-
gem "jeweler"
|
5
|
+
gem "rspec", "~> 2.5.0"
|
7
6
|
gem "simplecov"
|
8
|
-
gem "
|
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"
|
data/Gemfile.lock
CHANGED
@@ -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.
|
20
|
-
rspec-core (
|
21
|
-
rspec-expectations (
|
22
|
-
rspec-mocks (
|
23
|
-
rspec-core (2.
|
24
|
-
rspec-expectations (2.
|
25
|
-
diff-lcs (
|
26
|
-
rspec-mocks (2.
|
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 (
|
42
|
-
activesupport (
|
39
|
+
activemodel (~> 3.0.0)
|
40
|
+
activesupport (~> 3.0.0)
|
43
41
|
jeweler
|
44
|
-
rspec (
|
42
|
+
rspec (~> 2.5.0)
|
45
43
|
simplecov
|
46
44
|
tzinfo
|
data/README.rdoc
CHANGED
@@ -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 =>
|
12
|
-
# Using
|
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.
|
1
|
+
0.6.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.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{
|
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 = [
|
data/lib/date_validator.rb
CHANGED
@@ -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,
|
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
|
-
|
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]
|
data/locales/ca.yml
CHANGED
@@ -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
|
-
|
4
|
+
ca:
|
5
5
|
errors:
|
6
6
|
messages:
|
7
7
|
not_a_date: "is not a date"
|
8
|
-
after: "must be after %{
|
9
|
-
after_or_equal_to: "must be after or equal to %{
|
10
|
-
before: "must be before %{
|
11
|
-
before_or_equal_to: "must be before or equal to %{
|
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}"
|
data/locales/en.yml
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
en:
|
2
2
|
errors:
|
3
3
|
messages:
|
4
|
-
not_a_date: "
|
5
|
-
after: "
|
6
|
-
after_or_equal_to: "
|
7
|
-
before: "
|
8
|
-
before_or_equal_to: "
|
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}"
|
data/locales/es.yml
CHANGED
@@ -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 %{
|
6
|
-
after_or_equal_to: "tiene que ser posterior o igual a %{
|
7
|
-
before: "tiene que ser antes de %{
|
8
|
-
before_or_equal_to: "tiene que ser antes o igual a %{
|
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}"
|
data/spec/date_validator_spec.rb
CHANGED
@@ -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
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
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:
|
19
|
+
date: 2011-02-10 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|