adzap-validates_timeliness 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ = 1.1.2 [2009-01-12]
2
+ - Fixed bugs
3
+ - matcher failing for custom error message without interpolation keys using I18n
4
+ - validator custom error messages not being extracted
5
+
1
6
  = 1.1.1 [2009-01-03]
2
7
  - Fixed bug in matcher for options local variable
3
8
 
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'date'
5
5
  require 'spec/rake/spectask'
6
6
 
7
7
  GEM = "validates_timeliness"
8
- GEM_VERSION = "1.1.1"
8
+ GEM_VERSION = "1.1.2"
9
9
  AUTHOR = "Adam Meehan"
10
10
  EMAIL = "adam.meehan@gmail.com"
11
11
  HOMEPAGE = "http://github.com/adzap/validates_timeliness"
data/TODO CHANGED
@@ -1,7 +1,5 @@
1
1
  - :format option
2
2
  - :with_date and :with_time options
3
- - Merb and Data Mapper support
4
- - does it have before_type_cast
5
- - timezone handling
6
- - view helper support
7
3
  - valid formats could come from locale file
4
+ - formats to use month and day names from i18n
5
+ - add replace_formats instead add_formats :before
@@ -123,7 +123,8 @@ module Spec
123
123
  restriction = [restriction] unless restriction.is_a?(Array)
124
124
  restriction.map! {|r| @validator.send(:type_cast_value, r) }
125
125
  interpolate = @validator.send(:interpolation_values, option, restriction )
126
- if defined?(I18n)
126
+ # get I18n message if defined and has interpolation keys in msg
127
+ if defined?(I18n) && !@validator.send(:custom_error_messages).include?(option)
127
128
  msg = @record.errors.generate_message(@expected, option, interpolate)
128
129
  else
129
130
  msg = msg % interpolate
@@ -115,7 +115,7 @@ module ValidatesTimeliness
115
115
  return @custom_error_messages if defined?(@custom_error_messages)
116
116
  @custom_error_messages = configuration.inject({}) {|msgs, (k, v)|
117
117
  if md = /(.*)_message$/.match(k.to_s)
118
- msgs[md[0].to_sym] = v
118
+ msgs[md[1].to_sym] = v
119
119
  end
120
120
  msgs
121
121
  }
@@ -5,27 +5,39 @@ end
5
5
 
6
6
  class WithValidation < Person
7
7
  validates_date :birth_date,
8
- :before => '2000-01-10', :after => '2000-01-01',
9
- :on_or_before => '2000-01-09', :on_or_after => '2000-01-02',
8
+ :before => '2000-01-10',
9
+ :after => '2000-01-01',
10
+ :on_or_before => '2000-01-09',
11
+ :on_or_after => '2000-01-02',
10
12
  :between => ['2000-01-01', '2000-01-03']
11
13
 
12
14
  validates_time :birth_time,
13
- :before => '23:00', :after => '09:00',
14
- :on_or_before => '22:00', :on_or_after => '10:00',
15
+ :before => '23:00',
16
+ :after => '09:00',
17
+ :on_or_before => '22:00',
18
+ :on_or_after => '10:00',
15
19
  :between => ['09:00', '17:00']
20
+
16
21
  validates_datetime :birth_date_and_time,
17
- :before => '2000-01-10 23:00', :after => '2000-01-01 09:00',
18
- :on_or_before => '2000-01-09 23:00', :on_or_after => '2000-01-02 09:00',
22
+ :before => '2000-01-10 23:00',
23
+ :after => '2000-01-01 09:00',
24
+ :on_or_before => '2000-01-09 23:00',
25
+ :on_or_after => '2000-01-02 09:00',
19
26
  :between => ['2000-01-01 09:00', '2000-01-01 17:00']
20
27
 
21
28
  end
22
29
 
23
30
  class CustomMessages < Person
24
- validates_date :birth_date, :invalid_date_message => 'is not really a date',
25
- :before => '2000-01-10', :before_message => 'is too late',
26
- :after => '2000-01-01', :after_message => 'is too early',
27
- :on_or_before=> '2000-01-09', :on_or_before_message => 'is just too late',
28
- :on_or_after => '2000-01-02', :on_or_after_message => 'is just too early'
31
+ validates_date :birth_date,
32
+ :invalid_date_message => 'is not really a date',
33
+ :before => '2000-01-10',
34
+ :before_message => 'is too late',
35
+ :after => '2000-01-01',
36
+ :after_message => 'is too early',
37
+ :on_or_before => '2000-01-09',
38
+ :on_or_before_message => 'is just too late',
39
+ :on_or_after => '2000-01-02',
40
+ :on_or_after_message => 'is just too early'
29
41
  end
30
42
 
31
43
  describe "ValidateTimeliness matcher" do
@@ -363,6 +363,40 @@ describe ValidatesTimeliness::Validator do
363
363
  end
364
364
  end
365
365
 
366
+ describe "custom_error_messages" do
367
+ it "should return hash of custom error messages from configuration with _message truncated from keys" do
368
+ configure_validator(:type => :date, :invalid_date_message => 'thats no date')
369
+ validator.send(:custom_error_messages)[:invalid_date].should == 'thats no date'
370
+ end
371
+
372
+ it "should return empty hash if no custom error messages in configuration" do
373
+ configure_validator(:type => :date)
374
+ validator.send(:custom_error_messages).should be_empty
375
+ end
376
+ end
377
+
378
+ describe "interpolation_values" do
379
+ if defined?(I18n)
380
+ it "should return hash of interpolation keys with restriction values" do
381
+ before = '1900-01-01'
382
+ configure_validator(:type => :date, :before => before)
383
+ validator.send(:interpolation_values, :before, before.to_date).should == {:restriction => before}
384
+ end
385
+
386
+ it "should return empty hash if no interpolation keys are in message" do
387
+ before = '1900-01-01'
388
+ configure_validator(:type => :date, :before => before, :before_message => 'too late')
389
+ validator.send(:interpolation_values, :before, before.to_date).should be_empty
390
+ end
391
+ else
392
+ it "should return array of interpolation values" do
393
+ before = '1900-01-01'
394
+ configure_validator(:type => :date, :before => before)
395
+ validator.send(:interpolation_values, :before, before.to_date).should == [before]
396
+ end
397
+ end
398
+ end
399
+
366
400
  describe "restriction errors" do
367
401
  before :each do
368
402
  configure_validator(:type => :date, :before => lambda { raise })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adzap-validates_timeliness
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Meehan
@@ -9,7 +9,7 @@ autorequire: validates_timeliness
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-03 00:00:00 -08:00
12
+ date: 2009-01-12 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15