validates_timeliness 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,7 @@ if vendored = File.exists?(vendored_rails)
13
13
  Dir.glob(vendored_rails + "/**/lib").each { |dir| $:.unshift dir }
14
14
  else
15
15
  begin
16
- require 'ginger'
16
+ require 'ginger'
17
17
  rescue LoadError
18
18
  end
19
19
  if ENV['VERSION']
@@ -47,6 +47,8 @@ end
47
47
  require 'validates_timeliness'
48
48
  require 'validates_timeliness/matcher'
49
49
 
50
+ ValidatesTimeliness.enable_datetime_select_extension!
51
+
50
52
  ActiveRecord::Migration.verbose = false
51
53
  ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'})
52
54
 
@@ -12,13 +12,17 @@ describe ValidatesTimeliness::Validator do
12
12
  Time.now = nil
13
13
  end
14
14
 
15
- before :each do
16
- @person = Person.new
15
+ def person
16
+ @person ||= Person.new
17
17
  end
18
18
 
19
19
  describe "option keys validation" do
20
+ before(:all) do
21
+ ActiveSupport::Deprecation.silenced = true
22
+ end
23
+
20
24
  before do
21
- keys = ValidatesTimeliness::Validator::VALID_OPTIONS - [:invalid_date_message, :invalid_time_message, :with_date, :with_time]
25
+ keys = ValidatesTimeliness::Validator::VALID_OPTION_KEYS - [:invalid_date_message, :invalid_time_message, :with_date, :with_time]
22
26
  @valid_options = keys.inject({}) {|hash, opt| hash[opt] = nil; hash }
23
27
  end
24
28
 
@@ -30,6 +34,15 @@ describe ValidatesTimeliness::Validator do
30
34
  it "should not raise error if option keys are valid" do
31
35
  lambda { Person.validates_datetime(@valid_options) }.should_not raise_error(ArgumentError)
32
36
  end
37
+
38
+ it "should display deprecation notice for :equal_to" do
39
+ ::ActiveSupport::Deprecation.should_receive(:warn)
40
+ Person.validates_datetime :equal_to => Time.now
41
+ end
42
+
43
+ after(:all) do
44
+ ActiveSupport::Deprecation.silenced = false
45
+ end
33
46
  end
34
47
 
35
48
  describe "evaluate_option_value" do
@@ -305,7 +318,7 @@ describe ValidatesTimeliness::Validator do
305
318
  validate_with(:birth_date, 1.day.from_now.to_date)
306
319
  should_have_no_error(:birth_date, :between)
307
320
  end
308
-
321
+
309
322
  it "should allow a range for between restriction" do
310
323
  configure_validator(:type => :date, :between => (1.day.ago.to_date)..(1.day.from_now.to_date))
311
324
  validate_with(:birth_date, 1.day.from_now.to_date)
@@ -346,53 +359,53 @@ describe ValidatesTimeliness::Validator do
346
359
  end
347
360
  end
348
361
 
349
- describe "instance with :equal_to restriction" do
362
+ describe "instance with :is_at restriction" do
350
363
 
351
364
  describe "for datetime type" do
352
365
  before do
353
- configure_validator(:equal_to => Time.now)
366
+ configure_validator(:is_at => Time.now)
354
367
  end
355
368
 
356
- it "should have error when value not equal to :equal_to restriction" do
369
+ it "should have error when value not equal to :is_at restriction" do
357
370
  validate_with(:birth_date_and_time, Time.now + 1)
358
- should_have_error(:birth_date_and_time, :equal_to)
371
+ should_have_error(:birth_date_and_time, :is_at)
359
372
  end
360
373
 
361
- it "should be valid when value is equal to :equal_to restriction" do
374
+ it "should be valid when value is equal to :is_at restriction" do
362
375
  validate_with(:birth_date_and_time, Time.now)
363
- should_have_no_error(:birth_date_and_time, :equal_to)
376
+ should_have_no_error(:birth_date_and_time, :is_at)
364
377
  end
365
378
  end
366
379
 
367
380
  describe "for date type" do
368
381
  before do
369
- configure_validator(:type => :date, :equal_to => Date.today)
382
+ configure_validator(:type => :date, :is_at => Date.today)
370
383
  end
371
384
 
372
- it "should have error when value is not equal to :equal_to restriction" do
385
+ it "should have error when value is not equal to :is_at restriction" do
373
386
  validate_with(:birth_date, Date.today + 1)
374
- should_have_error(:birth_date, :equal_to)
387
+ should_have_error(:birth_date, :is_at)
375
388
  end
376
389
 
377
- it "should be valid when value is equal to :equal_to restriction" do
390
+ it "should be valid when value is equal to :is_at restriction" do
378
391
  validate_with(:birth_date, Date.today)
379
- should_have_no_error(:birth_date, :equal_to)
392
+ should_have_no_error(:birth_date, :is_at)
380
393
  end
381
394
  end
382
395
 
383
396
  describe "for time type" do
384
397
  before do
385
- configure_validator(:type => :time, :equal_to => "09:00:00")
398
+ configure_validator(:type => :time, :is_at => "09:00:00")
386
399
  end
387
400
 
388
- it "should have error when value is not equal to :equal_to restriction" do
401
+ it "should have error when value is not equal to :is_at restriction" do
389
402
  validate_with(:birth_time, "09:00:01")
390
- should_have_error(:birth_time, :equal_to)
403
+ should_have_error(:birth_time, :is_at)
391
404
  end
392
405
 
393
- it "should be valid when value is equal to :equal_to restriction" do
406
+ it "should be valid when value is equal to :is_at restriction" do
394
407
  validate_with(:birth_time, "09:00:00")
395
- should_have_no_error(:birth_time, :equal_to)
408
+ should_have_no_error(:birth_time, :is_at)
396
409
  end
397
410
  end
398
411
  end
@@ -400,9 +413,9 @@ describe ValidatesTimeliness::Validator do
400
413
  describe "instance with :ignore_usec option" do
401
414
 
402
415
  it "should ignore usec on time values when evaluated" do
403
- configure_validator(:equal_to => Time.utc(2000, 1, 1, 0, 0, 0, 0), :ignore_usec => true)
416
+ configure_validator(:is_at => Time.utc(2000, 1, 1, 0, 0, 0, 0), :ignore_usec => true)
404
417
  validate_with(:birth_date_and_time, Time.utc(2000, 1, 1, 0, 0, 0, 500))
405
- should_have_no_error(:birth_date_and_time, :equal_to)
418
+ should_have_no_error(:birth_date_and_time, :is_at)
406
419
  end
407
420
 
408
421
  end
@@ -422,9 +435,9 @@ describe ValidatesTimeliness::Validator do
422
435
  end
423
436
 
424
437
  it "should should ignore usec value on combined value if :ignore_usec option is true" do
425
- configure_validator(:type => :date, :with_time => Time.mktime(2000,1,1,12,30,0,500), :equal_to => Time.mktime(2000,1,1,12,30), :ignore_usec => true)
438
+ configure_validator(:type => :date, :with_time => Time.mktime(2000,1,1,12,30,0,500), :is_at => Time.mktime(2000,1,1,12,30), :ignore_usec => true)
426
439
  validate_with(:birth_date, "2000-01-01")
427
- should_have_no_error(:birth_date, :equal_to)
440
+ should_have_no_error(:birth_date, :is_at)
428
441
  end
429
442
  end
430
443
 
@@ -496,6 +509,38 @@ describe ValidatesTimeliness::Validator do
496
509
  end
497
510
  end
498
511
 
512
+ if defined?(I18n)
513
+
514
+ describe "localized error messages" do
515
+ before(:all) do
516
+ translations = {
517
+ :activerecord => {:errors => {:messages => { :after => 'retfa {{restriction}}' }}},
518
+ :validates_timeliness => {:error_value_formats => {}}
519
+ }
520
+ I18n.backend.store_translations 'zz', translations
521
+ I18n.locale = :zz
522
+ end
523
+
524
+ it "should be used if defined" do
525
+ configure_validator(:type => :date, :after => Date.today)
526
+ validate_with(:birth_date, 1.day.ago)
527
+ person.errors.on(:birth_date).should match(/retfa/)
528
+ end
529
+
530
+ it "should use I18n translation missing message when not defined" do
531
+ configure_validator(:type => :date, :on_or_after => Date.today)
532
+ validate_with(:birth_date, 1.day.ago)
533
+ person.errors.on(:birth_date).should match(/translation missing/)
534
+ end
535
+
536
+ after(:all) do
537
+ I18n.locale = :en
538
+ end
539
+
540
+ end
541
+
542
+ end
543
+
499
544
  describe "custom_error_messages" do
500
545
  it "should return hash of custom error messages from configuration with _message truncated from keys" do
501
546
  configure_validator(:type => :date, :invalid_date_message => 'thats no date')
@@ -566,6 +611,24 @@ describe ValidatesTimeliness::Validator do
566
611
  validate_with(:birth_time, '11:59')
567
612
  person.errors.on(:birth_time).should match(/after \d{2}:\d{2}:\d{2}\Z/)
568
613
  end
614
+
615
+ if defined?(I18n)
616
+
617
+ describe "I18n" do
618
+ it "should use global default if locale format missing" do
619
+ I18n.backend.store_translations 'zz', :activerecord => {:errors => {:messages => { :after => 'after {{restriction}}' }}}
620
+ I18n.locale = :zz
621
+ configure_validator(:type => :datetime, :after => 1.day.from_now)
622
+ validate_with(:birth_date_and_time, Time.now)
623
+ person.errors.on(:birth_date_and_time).should match(/after \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\Z/)
624
+ end
625
+
626
+ after do
627
+ I18n.locale = :en
628
+ end
629
+ end
630
+
631
+ end
569
632
  end
570
633
 
571
634
  describe "custom formats" do
@@ -644,7 +707,7 @@ describe ValidatesTimeliness::Validator do
644
707
 
645
708
  def error_messages
646
709
  return @error_messages if defined?(@error_messages)
647
- messages = validator.send(:error_messages)
710
+ messages = defined?(I18n) ? I18n.t('activerecord.errors.messages') : validator.send(:error_messages)
648
711
  @error_messages = messages.inject({}) {|h, (k, v)| h[k] = v.sub(/ (\%s|\{\{\w*\}\}).*/, ''); h }
649
712
  end
650
713
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_timeliness
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.0
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-09-19 00:00:00 +10:00
12
+ date: 2010-02-04 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -30,34 +30,34 @@ files:
30
30
  - Rakefile
31
31
  - TODO
32
32
  - CHANGELOG
33
- - lib/validates_timeliness/version.rb
34
33
  - lib/validates_timeliness/action_view/instance_tag.rb
35
- - lib/validates_timeliness/locale/en.yml
36
- - lib/validates_timeliness/validation_methods.rb
37
- - lib/validates_timeliness/matcher.rb
38
34
  - lib/validates_timeliness/active_record/attribute_methods.rb
39
35
  - lib/validates_timeliness/active_record/multiparameter_attributes.rb
40
- - lib/validates_timeliness/parser.rb
41
36
  - lib/validates_timeliness/formats.rb
42
- - lib/validates_timeliness/validator.rb
37
+ - lib/validates_timeliness/locale/en.yml
38
+ - lib/validates_timeliness/matcher.rb
39
+ - lib/validates_timeliness/parser.rb
43
40
  - lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb
41
+ - lib/validates_timeliness/validation_methods.rb
42
+ - lib/validates_timeliness/validator.rb
43
+ - lib/validates_timeliness/version.rb
44
44
  - lib/validates_timeliness.rb
45
- - spec/validator_spec.rb
46
45
  - spec/action_view/instance_tag_spec.rb
47
- - spec/ginger_scenarios.rb
48
- - spec/spec_helper.rb
49
- - spec/formats_spec.rb
50
46
  - spec/active_record/attribute_methods_spec.rb
51
47
  - spec/active_record/multiparameter_attributes_spec.rb
52
- - spec/time_travel/time_travel.rb
53
- - spec/time_travel/time_extensions.rb
54
- - spec/time_travel/MIT-LICENSE
48
+ - spec/formats_spec.rb
49
+ - spec/ginger_scenarios.rb
55
50
  - spec/parser_spec.rb
56
- - spec/spec/rails/matchers/validate_timeliness_spec.rb
51
+ - spec/resources/application.rb
57
52
  - spec/resources/person.rb
58
- - spec/resources/sqlite_patch.rb
59
53
  - spec/resources/schema.rb
60
- - spec/resources/application.rb
54
+ - spec/resources/sqlite_patch.rb
55
+ - spec/spec/rails/matchers/validate_timeliness_spec.rb
56
+ - spec/spec_helper.rb
57
+ - spec/time_travel/MIT-LICENSE
58
+ - spec/time_travel/time_extensions.rb
59
+ - spec/time_travel/time_travel.rb
60
+ - spec/validator_spec.rb
61
61
  has_rdoc: true
62
62
  homepage: http://github.com/adzap/validates_timeliness
63
63
  licenses: []
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  requirements: []
83
83
 
84
84
  rubyforge_project: validatestime
85
- rubygems_version: 1.3.4
85
+ rubygems_version: 1.3.5
86
86
  signing_key:
87
87
  specification_version: 3
88
88
  summary: Date and time validation plugin for Rails 2.x which allows custom formats