validates_timeliness 2.3.1 → 2.3.2
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/CHANGELOG +5 -0
- data/README.rdoc +5 -6
- data/lib/validates_timeliness/formats.rb +3 -0
- data/lib/validates_timeliness/locale/en.new.yml +18 -0
- data/lib/validates_timeliness/locale/{en.yml → en.old.yml} +0 -0
- data/lib/validates_timeliness/parser.rb +1 -1
- data/lib/validates_timeliness/version.rb +1 -1
- data/lib/validates_timeliness.rb +12 -2
- data/spec/formats_spec.rb +7 -0
- data/spec/ginger_scenarios.rb +1 -1
- data/spec/parser_spec.rb +7 -3
- data/spec/validator_spec.rb +13 -3
- metadata +19 -6
    
        data/CHANGELOG
    CHANGED
    
    | @@ -1,3 +1,8 @@ | |
| 1 | 
            +
            = 2.3.2 [2010-11-07]
         | 
| 2 | 
            +
            - Fixed parser for string with timezone offset (thanks sigi)
         | 
| 3 | 
            +
            - Support for latest I18n interpolation tokens in locale file
         | 
| 4 | 
            +
            - Fixed parser allowing an hour over 12 for AM meridian
         | 
| 5 | 
            +
             | 
| 1 6 | 
             
            = 2.3.1 [2010-03-19]
         | 
| 2 7 | 
             
            - Fixed bug where custom attribute writer method for date/times were being overriden
         | 
| 3 8 |  | 
    
        data/README.rdoc
    CHANGED
    
    | @@ -31,18 +31,17 @@ time string. | |
| 31 31 |  | 
| 32 32 | 
             
            == INSTALLATION:
         | 
| 33 33 |  | 
| 34 | 
            -
            As plugin (from master)
         | 
| 35 | 
            -
             | 
| 36 | 
            -
              ./script/plugin install git://github.com/adzap/validates_timeliness.git
         | 
| 37 | 
            -
             | 
| 38 34 | 
             
            As gem
         | 
| 39 35 |  | 
| 40 | 
            -
               | 
| 36 | 
            +
              gem install validates_timeliness -v '~> 2.3'
         | 
| 41 37 |  | 
| 42 38 | 
             
              # in environment.rb
         | 
| 43 39 |  | 
| 44 | 
            -
              config.gem 'validates_timeliness'
         | 
| 40 | 
            +
              config.gem 'validates_timeliness', :version => '~> 2.3'
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            As plugin (from master)
         | 
| 45 43 |  | 
| 44 | 
            +
              ./script/plugin install git://github.com/adzap/validates_timeliness.git -r v2.3
         | 
| 46 45 |  | 
| 47 46 | 
             
            == USAGE:
         | 
| 48 47 |  | 
| @@ -209,6 +209,8 @@ module ValidatesTimeliness | |
| 209 209 | 
             
                      values[0..2] = dummy_date_for_time_type if type == :time
         | 
| 210 210 | 
             
                      return values
         | 
| 211 211 | 
             
                    end
         | 
| 212 | 
            +
                  rescue
         | 
| 213 | 
            +
                    nil
         | 
| 212 214 | 
             
                  end
         | 
| 213 215 |  | 
| 214 216 | 
             
                  # Delete formats of specified type. Error raised if format not found.
         | 
| @@ -255,6 +257,7 @@ module ValidatesTimeliness | |
| 255 257 | 
             
                    hour = hour.to_i
         | 
| 256 258 | 
             
                    return hour if meridian.nil?
         | 
| 257 259 | 
             
                    if meridian.delete('.').downcase == 'am'
         | 
| 260 | 
            +
                      raise if hour == 0 || hour > 12
         | 
| 258 261 | 
             
                      hour == 12 ? 0 : hour
         | 
| 259 262 | 
             
                    else
         | 
| 260 263 | 
             
                      hour == 12 ? hour : hour + 12
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            en:
         | 
| 2 | 
            +
              activerecord:
         | 
| 3 | 
            +
                errors:
         | 
| 4 | 
            +
                  messages:
         | 
| 5 | 
            +
                    invalid_date: "is not a valid date"
         | 
| 6 | 
            +
                    invalid_time: "is not a valid time"
         | 
| 7 | 
            +
                    invalid_datetime: "is not a valid datetime"
         | 
| 8 | 
            +
                    is_at: "must be at %{restriction}"
         | 
| 9 | 
            +
                    before: "must be before %{restriction}"
         | 
| 10 | 
            +
                    on_or_before: "must be on or before %{restriction}"
         | 
| 11 | 
            +
                    after: "must be after %{restriction}"
         | 
| 12 | 
            +
                    on_or_after: "must be on or after %{restriction}"
         | 
| 13 | 
            +
                    between: "must be between %{earliest} and %{latest}"
         | 
| 14 | 
            +
              validates_timeliness:
         | 
| 15 | 
            +
                error_value_formats:
         | 
| 16 | 
            +
                  date: '%Y-%m-%d'
         | 
| 17 | 
            +
                  time: '%H:%M:%S'
         | 
| 18 | 
            +
                  datetime: '%Y-%m-%d %H:%M:%S'
         | 
| 
            File without changes
         | 
    
        data/lib/validates_timeliness.rb
    CHANGED
    
    | @@ -2,10 +2,18 @@ require 'validates_timeliness/formats' | |
| 2 2 | 
             
            require 'validates_timeliness/parser'
         | 
| 3 3 | 
             
            require 'validates_timeliness/validator'
         | 
| 4 4 | 
             
            require 'validates_timeliness/validation_methods'
         | 
| 5 | 
            -
             | 
| 6 5 | 
             
            require 'validates_timeliness/active_record/attribute_methods'
         | 
| 7 6 | 
             
            require 'validates_timeliness/active_record/multiparameter_attributes'
         | 
| 8 7 | 
             
            require 'validates_timeliness/action_view/instance_tag'
         | 
| 8 | 
            +
            begin
         | 
| 9 | 
            +
              i18n_path = $:.grep(/active_support\/vendor\/i18n-/)
         | 
| 10 | 
            +
              if i18n_path.empty?
         | 
| 11 | 
            +
                require 'i18n/version'
         | 
| 12 | 
            +
              else
         | 
| 13 | 
            +
                require i18n_path[0] + '/version'
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            rescue LoadError
         | 
| 16 | 
            +
            end if defined?(I18n)
         | 
| 9 17 |  | 
| 10 18 | 
             
            module ValidatesTimeliness
         | 
| 11 19 |  | 
| @@ -15,7 +23,9 @@ module ValidatesTimeliness | |
| 15 23 | 
             
              mattr_accessor :use_time_zones
         | 
| 16 24 | 
             
              self.use_time_zones = false
         | 
| 17 25 |  | 
| 18 | 
            -
               | 
| 26 | 
            +
              I18N_LATEST = defined?(I18n::VERSION) && I18n::VERSION >= '0.4.0'
         | 
| 27 | 
            +
              locale_file = I18N_LATEST ? 'en.new.yml' : 'en.old.yml'
         | 
| 28 | 
            +
              LOCALE_PATH = File.expand_path(File.join(File.dirname(__FILE__),'validates_timeliness','locale',locale_file))
         | 
| 19 29 |  | 
| 20 30 | 
             
              class << self
         | 
| 21 31 |  | 
    
        data/spec/formats_spec.rb
    CHANGED
    
    | @@ -102,6 +102,13 @@ describe ValidatesTimeliness::Formats do | |
| 102 102 | 
             
                  time_array.should == [2000,1,1,12,13,14,0]
         | 
| 103 103 | 
             
                end
         | 
| 104 104 |  | 
| 105 | 
            +
                it "should return nil if time hour is out of range for AM meridian" do
         | 
| 106 | 
            +
                  time_array = formats.parse('13:14 am', :time, :strict => true)
         | 
| 107 | 
            +
                  time_array.should == nil
         | 
| 108 | 
            +
                  time_array = formats.parse('00:14 am', :time, :strict => true)
         | 
| 109 | 
            +
                  time_array.should == nil
         | 
| 110 | 
            +
                end
         | 
| 111 | 
            +
             | 
| 105 112 | 
             
                it "should return date array from time string" do
         | 
| 106 113 | 
             
                  time_array = formats.parse('2000-02-01', :date, :strict => true)
         | 
| 107 114 | 
             
                  time_array.should == [2000,2,1,0,0,0,0]
         | 
    
        data/spec/ginger_scenarios.rb
    CHANGED
    
    | @@ -9,7 +9,7 @@ | |
| 9 9 | 
             
            #   ginger spec
         | 
| 10 10 | 
             
            #
         | 
| 11 11 | 
             
            Ginger.configure do |config|
         | 
| 12 | 
            -
              rails_versions = ['2.0.2', '2.1.2', '2.2.2', '2.3.3', '2.3.4', '2.3.5']
         | 
| 12 | 
            +
              rails_versions = ['2.0.2', '2.1.2', '2.2.2', '2.3.3', '2.3.4', '2.3.5', '2.3.6', '2.3.9']
         | 
| 13 13 |  | 
| 14 14 | 
             
              rails_versions.each do |v|
         | 
| 15 15 | 
             
                g = Ginger::Scenario.new("Rails #{v}")
         | 
    
        data/spec/parser_spec.rb
    CHANGED
    
    | @@ -7,6 +7,10 @@ describe ValidatesTimeliness::Parser do | |
| 7 7 | 
             
                it "should return time object for valid time string" do
         | 
| 8 8 | 
             
                  parse("2000-01-01 12:13:14", :datetime).should be_kind_of(Time)
         | 
| 9 9 | 
             
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                it "should return Time object for ISO 8601 string with time zone" do
         | 
| 12 | 
            +
                  parse("2000-01-01T12:23:42+09:00", :datetime).should be_kind_of(Time)
         | 
| 13 | 
            +
                end
         | 
| 10 14 |  | 
| 11 15 | 
             
                it "should return nil for time string with invalid date part" do
         | 
| 12 16 | 
             
                  parse("2000-02-30 12:13:14", :datetime).should be_nil
         | 
| @@ -19,12 +23,12 @@ describe ValidatesTimeliness::Parser do | |
| 19 23 | 
             
                it "should return Time object when passed a Time object" do
         | 
| 20 24 | 
             
                  parse(Time.now, :datetime).should be_kind_of(Time)
         | 
| 21 25 | 
             
                end
         | 
| 22 | 
            -
             | 
| 26 | 
            +
             | 
| 23 27 | 
             
                if RAILS_VER >= '2.1'
         | 
| 24 28 | 
             
                  it "should convert time string into current timezone" do
         | 
| 25 29 | 
             
                    Time.zone = 'Melbourne'
         | 
| 26 | 
            -
                    time = parse("2000- | 
| 27 | 
            -
                     | 
| 30 | 
            +
                    time = parse("2000-06-01 12:13:14", :datetime)
         | 
| 31 | 
            +
                    time.utc_offset.should == 10.hours
         | 
| 28 32 | 
             
                  end
         | 
| 29 33 | 
             
                end
         | 
| 30 34 |  | 
    
        data/spec/validator_spec.rb
    CHANGED
    
    | @@ -3,6 +3,14 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | |
| 3 3 | 
             
            describe ValidatesTimeliness::Validator do
         | 
| 4 4 | 
             
              attr_accessor :person, :validator
         | 
| 5 5 |  | 
| 6 | 
            +
              if ValidatesTimeliness::I18N_LATEST
         | 
| 7 | 
            +
                I18N_REGEXP = /\%\{\w*\}/
         | 
| 8 | 
            +
                I18N_INTERPOLATION = '%{%s}'
         | 
| 9 | 
            +
              else
         | 
| 10 | 
            +
                I18N_REGEXP = /\{\{\w*\}\}/
         | 
| 11 | 
            +
                I18N_INTERPOLATION = '{{%s}}'
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 6 14 | 
             
              before :all do
         | 
| 7 15 | 
             
                # freezes time using time_travel plugin
         | 
| 8 16 | 
             
                Time.now = Time.utc(2000, 1, 1, 0, 0, 0)
         | 
| @@ -513,8 +521,9 @@ describe ValidatesTimeliness::Validator do | |
| 513 521 |  | 
| 514 522 | 
             
                describe "localized error messages" do
         | 
| 515 523 | 
             
                  before(:all) do
         | 
| 524 | 
            +
                    message = "retfa #{I18N_INTERPOLATION}" % 'restriction'
         | 
| 516 525 | 
             
                    translations = {
         | 
| 517 | 
            -
                      :activerecord => {:errors => {:messages => { :after =>  | 
| 526 | 
            +
                      :activerecord => {:errors => {:messages => { :after => message }}},
         | 
| 518 527 | 
             
                      :validates_timeliness => {:error_value_formats => {}}
         | 
| 519 528 | 
             
                    }
         | 
| 520 529 | 
             
                    I18n.backend.store_translations 'zz', translations
         | 
| @@ -616,7 +625,8 @@ describe ValidatesTimeliness::Validator do | |
| 616 625 |  | 
| 617 626 | 
             
                    describe "I18n" do
         | 
| 618 627 | 
             
                      it "should use global default if locale format missing" do
         | 
| 619 | 
            -
                         | 
| 628 | 
            +
                        message = "after #{I18N_INTERPOLATION}" % 'restriction'
         | 
| 629 | 
            +
                        I18n.backend.store_translations 'zz', :activerecord => {:errors => {:messages => { :after => message }}}
         | 
| 620 630 | 
             
                        I18n.locale = :zz
         | 
| 621 631 | 
             
                        configure_validator(:type => :datetime, :after => 1.day.from_now)
         | 
| 622 632 | 
             
                        validate_with(:birth_date_and_time, Time.now)
         | 
| @@ -708,6 +718,6 @@ describe ValidatesTimeliness::Validator do | |
| 708 718 | 
             
              def error_messages
         | 
| 709 719 | 
             
                return @error_messages if defined?(@error_messages)
         | 
| 710 720 | 
             
                messages = defined?(I18n) ? I18n.t('activerecord.errors.messages') : validator.send(:error_messages)
         | 
| 711 | 
            -
                @error_messages = messages.inject({}) {|h, (k, v)| h[k] = v.sub(/ (\%s | 
| 721 | 
            +
                @error_messages = messages.inject({}) {|h, (k, v)| h[k] = v.sub(/ (\%s|#{I18N_REGEXP}).*/, ''); h }
         | 
| 712 722 | 
             
              end
         | 
| 713 723 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: validates_timeliness
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
               | 
| 4 | 
            +
              hash: 7
         | 
| 5 | 
            +
              prerelease: false
         | 
| 6 | 
            +
              segments: 
         | 
| 7 | 
            +
              - 2
         | 
| 8 | 
            +
              - 3
         | 
| 9 | 
            +
              - 2
         | 
| 10 | 
            +
              version: 2.3.2
         | 
| 5 11 | 
             
            platform: ruby
         | 
| 6 12 | 
             
            authors: 
         | 
| 7 13 | 
             
            - Adam Meehan
         | 
| @@ -9,7 +15,7 @@ autorequire: validates_timeliness | |
| 9 15 | 
             
            bindir: bin
         | 
| 10 16 | 
             
            cert_chain: []
         | 
| 11 17 |  | 
| 12 | 
            -
            date: 2010- | 
| 18 | 
            +
            date: 2010-11-07 00:00:00 +11:00
         | 
| 13 19 | 
             
            default_executable: 
         | 
| 14 20 | 
             
            dependencies: []
         | 
| 15 21 |  | 
| @@ -34,7 +40,8 @@ files: | |
| 34 40 | 
             
            - lib/validates_timeliness/active_record/attribute_methods.rb
         | 
| 35 41 | 
             
            - lib/validates_timeliness/active_record/multiparameter_attributes.rb
         | 
| 36 42 | 
             
            - lib/validates_timeliness/formats.rb
         | 
| 37 | 
            -
            - lib/validates_timeliness/locale/en.yml
         | 
| 43 | 
            +
            - lib/validates_timeliness/locale/en.new.yml
         | 
| 44 | 
            +
            - lib/validates_timeliness/locale/en.old.yml
         | 
| 38 45 | 
             
            - lib/validates_timeliness/matcher.rb
         | 
| 39 46 | 
             
            - lib/validates_timeliness/parser.rb
         | 
| 40 47 | 
             
            - lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb
         | 
| @@ -68,21 +75,27 @@ rdoc_options: [] | |
| 68 75 | 
             
            require_paths: 
         | 
| 69 76 | 
             
            - lib
         | 
| 70 77 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement 
         | 
| 78 | 
            +
              none: false
         | 
| 71 79 | 
             
              requirements: 
         | 
| 72 80 | 
             
              - - ">="
         | 
| 73 81 | 
             
                - !ruby/object:Gem::Version 
         | 
| 82 | 
            +
                  hash: 3
         | 
| 83 | 
            +
                  segments: 
         | 
| 84 | 
            +
                  - 0
         | 
| 74 85 | 
             
                  version: "0"
         | 
| 75 | 
            -
              version: 
         | 
| 76 86 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement 
         | 
| 87 | 
            +
              none: false
         | 
| 77 88 | 
             
              requirements: 
         | 
| 78 89 | 
             
              - - ">="
         | 
| 79 90 | 
             
                - !ruby/object:Gem::Version 
         | 
| 91 | 
            +
                  hash: 3
         | 
| 92 | 
            +
                  segments: 
         | 
| 93 | 
            +
                  - 0
         | 
| 80 94 | 
             
                  version: "0"
         | 
| 81 | 
            -
              version: 
         | 
| 82 95 | 
             
            requirements: []
         | 
| 83 96 |  | 
| 84 97 | 
             
            rubyforge_project: validatestime
         | 
| 85 | 
            -
            rubygems_version: 1.3. | 
| 98 | 
            +
            rubygems_version: 1.3.7
         | 
| 86 99 | 
             
            signing_key: 
         | 
| 87 100 | 
             
            specification_version: 3
         | 
| 88 101 | 
             
            summary: Date and time validation plugin for Rails 2.x which allows custom formats
         |