validates_timeliness 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ = 3.0.4 [2011-01-22]
2
+ * Fix :between option which was being ignored (ebeigarts)
3
+ * Use class_attribute to remove deprecated class_inheritable_accessor
4
+ * Namespace copied validator class to ActiveModel::Validations::Timeliness for :timeliness option
5
+
1
6
  = 3.0.3 [2010-12-11]
2
7
  * Fix validation of values which don't respond to to_date or to_time (renatoelias)
3
8
 
data/README.rdoc CHANGED
@@ -24,7 +24,7 @@ If you a looking for the old version for Rails 2.x go here[http://github.com/adz
24
24
 
25
25
  * Supports I18n for the error messages
26
26
 
27
- * Supports MRI 1.8.x and 1.9.x and Rubinius.
27
+ * Supports Ruby 1.8.x, 1.9.x and Rubinius.
28
28
 
29
29
  == Installation
30
30
 
@@ -3,7 +3,7 @@ module ValidatesTimeliness
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
- class_inheritable_accessor :timeliness_validated_attributes
6
+ class_attribute :timeliness_validated_attributes
7
7
  self.timeliness_validated_attributes = []
8
8
  end
9
9
 
@@ -27,12 +27,13 @@ module ValidatesTimeliness
27
27
  def initialize(options)
28
28
  @type = options.delete(:type) || :datetime
29
29
  @allow_nil, @allow_blank = options.delete(:allow_nil), options.delete(:allow_blank)
30
- @restrictions_to_check = RESTRICTIONS.keys & options.keys
31
30
 
32
31
  if range = options.delete(:between)
33
32
  raise ArgumentError, ":between must be a Range or an Array" unless range.is_a?(Range) || range.is_a?(Array)
34
33
  options[:on_or_after], options[:on_or_before] = range.first, range.last
35
34
  end
35
+
36
+ @restrictions_to_check = RESTRICTIONS.keys & options.keys
36
37
  super
37
38
  end
38
39
 
@@ -85,4 +86,4 @@ module ValidatesTimeliness
85
86
  end
86
87
 
87
88
  # Compatibility with ActiveModel validates method which matches option keys to their validator class
88
- TimelinessValidator = ValidatesTimeliness::Validator
89
+ ActiveModel::Validations::TimelinessValidator = ValidatesTimeliness::Validator
@@ -1,3 +1,3 @@
1
1
  module ValidatesTimeliness
2
- VERSION = '3.0.3'
2
+ VERSION = '3.0.4'
3
3
  end
@@ -12,10 +12,10 @@ describe ValidatesTimeliness::Validator do
12
12
  ValidatesTimeliness::Validator.kind.should == :timeliness
13
13
  end
14
14
 
15
- describe "Model.validates :timeliness option" do
15
+ describe "Model.validates with :timeliness option" do
16
16
  it 'should use plugin validator class' do
17
17
  Person.validates :birth_date, :timeliness => {:is_at => Date.new(2010,1,1), :type => :date}
18
- Person.validators.should have(1).kind_of(TimelinessValidator)
18
+ Person.validators.should have(1).kind_of(ActiveModel::Validations::TimelinessValidator)
19
19
  invalid!(:birth_date, Date.new(2010,1,2))
20
20
  valid!(:birth_date, Date.new(2010,1,1))
21
21
  end
@@ -70,18 +70,26 @@ describe ValidatesTimeliness::Validator do
70
70
  describe "array value" do
71
71
  it 'should be split option into :on_or_after and :on_or_before values' do
72
72
  on_or_after, on_or_before = Date.new(2010,1,1), Date.new(2010,1,2)
73
- Person.validates_time :birth_date, :between => [on_or_after, on_or_before]
73
+ Person.validates_date :birth_date, :between => [on_or_after, on_or_before]
74
74
  Person.validators.first.options[:on_or_after].should == on_or_after
75
75
  Person.validators.first.options[:on_or_before].should == on_or_before
76
+ invalid!(:birth_date, on_or_after - 1, "must be on or after 2010-01-01")
77
+ invalid!(:birth_date, on_or_before + 1, "must be on or before 2010-01-02")
78
+ valid!(:birth_date, on_or_after)
79
+ valid!(:birth_date, on_or_before)
76
80
  end
77
81
  end
78
82
 
79
83
  describe "range value" do
80
84
  it 'should be split option into :on_or_after and :on_or_before values' do
81
85
  on_or_after, on_or_before = Date.new(2010,1,1), Date.new(2010,1,2)
82
- Person.validates_time :birth_date, :between => on_or_after..on_or_before
86
+ Person.validates_date :birth_date, :between => on_or_after..on_or_before
83
87
  Person.validators.first.options[:on_or_after].should == on_or_after
84
88
  Person.validators.first.options[:on_or_before].should == on_or_before
89
+ invalid!(:birth_date, on_or_after - 1, "must be on or after 2010-01-01")
90
+ invalid!(:birth_date, on_or_before + 1, "must be on or before 2010-01-02")
91
+ valid!(:birth_date, on_or_after)
92
+ valid!(:birth_date, on_or_before)
85
93
  end
86
94
  end
87
95
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{validates_timeliness}
5
- s.version = "3.0.3"
5
+ s.version = "3.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Adam Meehan"]
9
- s.date = %q{2010-12-11}
9
+ s.date = %q{2011-01-22}
10
10
  s.description = %q{Date and time validation plugin for Rails which allows custom formats}
11
11
  s.email = %q{adam.meehan@gmail.com}
12
12
  s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_timeliness
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 3
10
- version: 3.0.3
9
+ - 4
10
+ version: 3.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Meehan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-11 00:00:00 +11:00
18
+ date: 2011-01-22 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency