date_validator 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64c74e7124cae4c859430982336b626a78ed31a9
4
- data.tar.gz: b7d7eb4581f8455351639780b4e7484062d1630c
3
+ metadata.gz: 2d06600bd79d2376bdf394d1347266e7cc5079fd
4
+ data.tar.gz: 99f22f60af52d7323f6d7d5aefc77718df94b7f9
5
5
  SHA512:
6
- metadata.gz: c1211d0270a5b4e047c7c2fa6d15f4da30ce401e7a633df01f468a32b1257ed2f67f1dad7b28c1ca693d1a9ccfdcc6c6e65fdf031099c50b0532871f063baf34
7
- data.tar.gz: 2244976f32203b9a077260674f57d736dc2e8fbfc37886176955a62344e904ee4b22a43248040450770876cd533998f678cd29777f418e25e27bd393765990e9
6
+ metadata.gz: 130c376d4a561b1ad84abd8080c98b5f82085f1d2fd79ab6327ec9ee9746d5ff4f5a838b81eb752ea1e9b9f119017f162290f9be2c1eef2d3ea91ab3527694d0
7
+ data.tar.gz: 3b1f7a559b9448c59b0b4317edf44e3c8bdb4e37f7374a41c3f8d6dae04950c7a55b0a0e6dd9913c16352feb4f9f62925b172826c58ba8516b02dd180166d74f
@@ -1,10 +1,13 @@
1
1
  # http://about.travis-ci.org/docs/user/build-configuration/
2
2
  langauge: ruby
3
+ before_install:
4
+ - gem update bundler
3
5
  env:
4
6
  - ACTIVE_MODEL_VERSION=3.2
5
7
  - ACTIVE_MODEL_VERSION=4.0
6
8
  - ACTIVE_MODEL_VERSION=4.2
7
9
  rvm:
8
10
  - 1.9.3
9
- - 2.2.2
11
+ - 2.2
12
+ - 2.3.0
10
13
  - jruby-19mode
data/Readme.md CHANGED
@@ -32,6 +32,14 @@ validates :expiration_date,
32
32
  date: { after: :packaging_date }
33
33
  ```
34
34
 
35
+ or access attributes via the object being validated directly (the input to the Proc):
36
+
37
+ ```ruby
38
+ validates :due_date,
39
+ date: { after_or_equal_to: Proc.new { |obj| obj.created_at.to_date }
40
+ # The object being validated is available in the Proc
41
+ ```
42
+
35
43
  For now the available options you can use are `:after`, `:before`,
36
44
  `:after_or_equal_to`, `:before_or_equal_to` and `:equal_to`.
37
45
 
@@ -15,10 +15,10 @@ Gem::Specification.new do |s|
15
15
  s.rubyforge_project = "date_validator"
16
16
 
17
17
  s.add_runtime_dependency 'activemodel'
18
+ s.add_runtime_dependency 'activesupport'
18
19
 
19
20
  s.add_development_dependency 'minitest'
20
21
  s.add_development_dependency 'rake'
21
- s.add_development_dependency 'activesupport'
22
22
  s.add_development_dependency 'tzinfo'
23
23
 
24
24
  s.files = `git ls-files`.split("\n")
@@ -1,4 +1,6 @@
1
1
  require 'active_model/validations'
2
+ require 'active_support/core_ext/date_time/conversions'
3
+ require 'active_support/core_ext/hash/conversions'
2
4
 
3
5
  # ActiveModel Rails module.
4
6
  module ActiveModel
@@ -68,6 +70,11 @@ module ActiveModel
68
70
  return
69
71
  end
70
72
 
73
+ unless is_time?(value)
74
+ record.errors.add(attr_name, :not_a_date, options)
75
+ return
76
+ end
77
+
71
78
  options.slice(*CHECKS.keys).each do |option, option_value|
72
79
  option_value = option_value.call(record) if option_value.is_a?(Proc)
73
80
  option_value = record.send(option_value) if option_value.is_a?(Symbol)
@@ -1,6 +1,8 @@
1
1
  module DateValidator
2
2
  class Engine < Rails::Engine
3
- files = Dir[Pathname.new(File.dirname(__FILE__)).join('../..', 'locales', '*.yml')]
4
- config.i18n.load_path += files
3
+ initializer 'date_validator' do
4
+ files = Dir[Pathname.new(File.dirname(__FILE__)).join('../..', 'locales', '*.yml')]
5
+ config.i18n.load_path += files
6
+ end
5
7
  end
6
8
  end
@@ -1,4 +1,4 @@
1
1
  module DateValidator
2
2
  # The version number.
3
- VERSION = "0.8.1"
3
+ VERSION = "0.9.0"
4
4
  end
@@ -0,0 +1,9 @@
1
+ tr:
2
+ errors:
3
+ messages:
4
+ not_a_date: "geçerli tarih değil"
5
+ after: "%{date} den ileri bir tarih olmalı"
6
+ after_or_equal_to: "%{date} ile aynı veya ileri bir tarih olmalı"
7
+ before: "%{date} den öncesi bir tarih olmalı"
8
+ before_or_equal_to: "%{date} ile aynı veya öncesi bir tarih olmalı"
9
+ equal_to: "%{date} ile aynı tarihte olmalı"
@@ -148,6 +148,13 @@ module ActiveModel
148
148
  TestRecord.new(nil).valid?.must_equal false
149
149
  end
150
150
  end
151
+
152
+ describe 'with garbage input' do
153
+ it 'is invalid' do
154
+ TestRecord.validates(:expiration_date, date: true, allow_nil: true)
155
+ TestRecord.new('not a date').valid?.must_equal false
156
+ end
157
+ end
151
158
  end
152
159
 
153
160
  end
@@ -11,7 +11,6 @@ begin; require 'turn'; rescue LoadError; end
11
11
  gem 'minitest'
12
12
  require 'minitest/autorun'
13
13
 
14
- require 'active_support/all'
15
14
  require 'active_model'
16
15
  require 'date_validator'
17
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oriol Gual
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-06-09 00:00:00.000000000 Z
13
+ date: 2016-01-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -27,13 +27,13 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
- name: minitest
30
+ name: activesupport
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
- type: :development
36
+ type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
@@ -41,7 +41,7 @@ dependencies:
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
- name: rake
44
+ name: minitest
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
@@ -55,7 +55,7 @@ dependencies:
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
- name: activesupport
58
+ name: rake
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
@@ -117,6 +117,7 @@ files:
117
117
  - locales/pl.yml
118
118
  - locales/pt-BR.yml
119
119
  - locales/ru.yml
120
+ - locales/tr.yml
120
121
  - test/date_validator_test.rb
121
122
  - test/test_helper.rb
122
123
  homepage: http://github.com/codegram/date_validator