mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e711941744 | ||
|
|
5bed56e180 | ||
|
|
c3a591a5d8 | ||
|
|
6265b2d804 | ||
|
|
341a481231 | ||
|
|
d6ddae9977 | ||
|
|
0ea0201051 |
@@ -1,3 +1,8 @@
|
||||
= 2.3.2 [2010-11-07]
|
||||
- Fixed parser for string with timezone offset (thanks sigi)
|
||||
- Support for latest I18n interpolation tokens in locale file
|
||||
- Fixed parser allowing an hour over 12 for AM meridian
|
||||
|
||||
= 2.3.1 [2010-03-19]
|
||||
- Fixed bug where custom attribute writer method for date/times were being overriden
|
||||
|
||||
|
||||
11
README.rdoc
11
README.rdoc
@@ -31,18 +31,17 @@ time string.
|
||||
|
||||
== INSTALLATION:
|
||||
|
||||
As plugin (from master)
|
||||
|
||||
./script/plugin install git://github.com/adzap/validates_timeliness.git
|
||||
|
||||
As gem
|
||||
|
||||
sudo gem install validates_timeliness
|
||||
gem install validates_timeliness -v '~> 2.3'
|
||||
|
||||
# in environment.rb
|
||||
|
||||
config.gem 'validates_timeliness'
|
||||
config.gem 'validates_timeliness', :version => '~> 2.3'
|
||||
|
||||
As plugin (from master)
|
||||
|
||||
./script/plugin install git://github.com/adzap/validates_timeliness.git -r v2.3
|
||||
|
||||
== USAGE:
|
||||
|
||||
|
||||
@@ -2,10 +2,18 @@ require 'validates_timeliness/formats'
|
||||
require 'validates_timeliness/parser'
|
||||
require 'validates_timeliness/validator'
|
||||
require 'validates_timeliness/validation_methods'
|
||||
|
||||
require 'validates_timeliness/active_record/attribute_methods'
|
||||
require 'validates_timeliness/active_record/multiparameter_attributes'
|
||||
require 'validates_timeliness/action_view/instance_tag'
|
||||
begin
|
||||
i18n_path = $:.grep(/active_support\/vendor\/i18n-/)
|
||||
if i18n_path.empty?
|
||||
require 'i18n/version'
|
||||
else
|
||||
require i18n_path[0] + '/version'
|
||||
end
|
||||
rescue LoadError
|
||||
end if defined?(I18n)
|
||||
|
||||
module ValidatesTimeliness
|
||||
|
||||
@@ -15,7 +23,9 @@ module ValidatesTimeliness
|
||||
mattr_accessor :use_time_zones
|
||||
self.use_time_zones = false
|
||||
|
||||
LOCALE_PATH = File.expand_path(File.dirname(__FILE__) + '/validates_timeliness/locale/en.yml')
|
||||
I18N_LATEST = defined?(I18n::VERSION) && I18n::VERSION >= '0.4.0'
|
||||
locale_file = I18N_LATEST ? 'en.new.yml' : 'en.old.yml'
|
||||
LOCALE_PATH = File.expand_path(File.join(File.dirname(__FILE__),'validates_timeliness','locale',locale_file))
|
||||
|
||||
class << self
|
||||
|
||||
|
||||
@@ -209,6 +209,8 @@ module ValidatesTimeliness
|
||||
values[0..2] = dummy_date_for_time_type if type == :time
|
||||
return values
|
||||
end
|
||||
rescue
|
||||
nil
|
||||
end
|
||||
|
||||
# Delete formats of specified type. Error raised if format not found.
|
||||
@@ -255,6 +257,7 @@ module ValidatesTimeliness
|
||||
hour = hour.to_i
|
||||
return hour if meridian.nil?
|
||||
if meridian.delete('.').downcase == 'am'
|
||||
raise if hour == 0 || hour > 12
|
||||
hour == 12 ? 0 : hour
|
||||
else
|
||||
hour == 12 ? hour : hour + 12
|
||||
|
||||
18
lib/validates_timeliness/locale/en.new.yml
Normal file
18
lib/validates_timeliness/locale/en.new.yml
Normal file
@@ -0,0 +1,18 @@
|
||||
en:
|
||||
activerecord:
|
||||
errors:
|
||||
messages:
|
||||
invalid_date: "is not a valid date"
|
||||
invalid_time: "is not a valid time"
|
||||
invalid_datetime: "is not a valid datetime"
|
||||
is_at: "must be at %{restriction}"
|
||||
before: "must be before %{restriction}"
|
||||
on_or_before: "must be on or before %{restriction}"
|
||||
after: "must be after %{restriction}"
|
||||
on_or_after: "must be on or after %{restriction}"
|
||||
between: "must be between %{earliest} and %{latest}"
|
||||
validates_timeliness:
|
||||
error_value_formats:
|
||||
date: '%Y-%m-%d'
|
||||
time: '%H:%M:%S'
|
||||
datetime: '%Y-%m-%d %H:%M:%S'
|
||||
@@ -13,7 +13,7 @@ module ValidatesTimeliness
|
||||
if type == :date
|
||||
Date.new(*time_array[0..2]) rescue nil
|
||||
else
|
||||
make_time(time_array[0..7])
|
||||
make_time(time_array[0..6])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module ValidatesTimeliness
|
||||
VERSION = "2.3.1"
|
||||
VERSION = "2.3.2"
|
||||
end
|
||||
|
||||
@@ -102,6 +102,13 @@ describe ValidatesTimeliness::Formats do
|
||||
time_array.should == [2000,1,1,12,13,14,0]
|
||||
end
|
||||
|
||||
it "should return nil if time hour is out of range for AM meridian" do
|
||||
time_array = formats.parse('13:14 am', :time, :strict => true)
|
||||
time_array.should == nil
|
||||
time_array = formats.parse('00:14 am', :time, :strict => true)
|
||||
time_array.should == nil
|
||||
end
|
||||
|
||||
it "should return date array from time string" do
|
||||
time_array = formats.parse('2000-02-01', :date, :strict => true)
|
||||
time_array.should == [2000,2,1,0,0,0,0]
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# ginger spec
|
||||
#
|
||||
Ginger.configure do |config|
|
||||
rails_versions = ['2.0.2', '2.1.2', '2.2.2', '2.3.3', '2.3.4', '2.3.5']
|
||||
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']
|
||||
|
||||
rails_versions.each do |v|
|
||||
g = Ginger::Scenario.new("Rails #{v}")
|
||||
|
||||
@@ -7,6 +7,10 @@ describe ValidatesTimeliness::Parser do
|
||||
it "should return time object for valid time string" do
|
||||
parse("2000-01-01 12:13:14", :datetime).should be_kind_of(Time)
|
||||
end
|
||||
|
||||
it "should return Time object for ISO 8601 string with time zone" do
|
||||
parse("2000-01-01T12:23:42+09:00", :datetime).should be_kind_of(Time)
|
||||
end
|
||||
|
||||
it "should return nil for time string with invalid date part" do
|
||||
parse("2000-02-30 12:13:14", :datetime).should be_nil
|
||||
@@ -19,12 +23,12 @@ describe ValidatesTimeliness::Parser do
|
||||
it "should return Time object when passed a Time object" do
|
||||
parse(Time.now, :datetime).should be_kind_of(Time)
|
||||
end
|
||||
|
||||
|
||||
if RAILS_VER >= '2.1'
|
||||
it "should convert time string into current timezone" do
|
||||
Time.zone = 'Melbourne'
|
||||
time = parse("2000-01-01 12:13:14", :datetime)
|
||||
Time.zone.utc_offset.should == 10.hours
|
||||
time = parse("2000-06-01 12:13:14", :datetime)
|
||||
time.utc_offset.should == 10.hours
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,14 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
describe ValidatesTimeliness::Validator do
|
||||
attr_accessor :person, :validator
|
||||
|
||||
if ValidatesTimeliness::I18N_LATEST
|
||||
I18N_REGEXP = /\%\{\w*\}/
|
||||
I18N_INTERPOLATION = '%{%s}'
|
||||
else
|
||||
I18N_REGEXP = /\{\{\w*\}\}/
|
||||
I18N_INTERPOLATION = '{{%s}}'
|
||||
end
|
||||
|
||||
before :all do
|
||||
# freezes time using time_travel plugin
|
||||
Time.now = Time.utc(2000, 1, 1, 0, 0, 0)
|
||||
@@ -513,8 +521,9 @@ describe ValidatesTimeliness::Validator do
|
||||
|
||||
describe "localized error messages" do
|
||||
before(:all) do
|
||||
message = "retfa #{I18N_INTERPOLATION}" % 'restriction'
|
||||
translations = {
|
||||
:activerecord => {:errors => {:messages => { :after => 'retfa {{restriction}}' }}},
|
||||
:activerecord => {:errors => {:messages => { :after => message }}},
|
||||
:validates_timeliness => {:error_value_formats => {}}
|
||||
}
|
||||
I18n.backend.store_translations 'zz', translations
|
||||
@@ -616,7 +625,8 @@ describe ValidatesTimeliness::Validator do
|
||||
|
||||
describe "I18n" do
|
||||
it "should use global default if locale format missing" do
|
||||
I18n.backend.store_translations 'zz', :activerecord => {:errors => {:messages => { :after => 'after {{restriction}}' }}}
|
||||
message = "after #{I18N_INTERPOLATION}" % 'restriction'
|
||||
I18n.backend.store_translations 'zz', :activerecord => {:errors => {:messages => { :after => message }}}
|
||||
I18n.locale = :zz
|
||||
configure_validator(:type => :datetime, :after => 1.day.from_now)
|
||||
validate_with(:birth_date_and_time, Time.now)
|
||||
@@ -708,6 +718,6 @@ describe ValidatesTimeliness::Validator do
|
||||
def error_messages
|
||||
return @error_messages if defined?(@error_messages)
|
||||
messages = defined?(I18n) ? I18n.t('activerecord.errors.messages') : validator.send(:error_messages)
|
||||
@error_messages = messages.inject({}) {|h, (k, v)| h[k] = v.sub(/ (\%s|\{\{\w*\}\}).*/, ''); h }
|
||||
@error_messages = messages.inject({}) {|h, (k, v)| h[k] = v.sub(/ (\%s|#{I18N_REGEXP}).*/, ''); h }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,27 +2,27 @@
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{validates_timeliness}
|
||||
s.version = "2.3.1"
|
||||
s.version = "2.3.2"
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Adam Meehan"]
|
||||
s.autorequire = %q{validates_timeliness}
|
||||
s.date = %q{2010-03-19}
|
||||
s.date = %q{2010-11-07}
|
||||
s.description = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
|
||||
s.email = %q{adam.meehan@gmail.com}
|
||||
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "TODO", "CHANGELOG"]
|
||||
s.files = ["LICENSE", "README.rdoc", "Rakefile", "TODO", "CHANGELOG", "lib/validates_timeliness", "lib/validates_timeliness/action_view", "lib/validates_timeliness/action_view/instance_tag.rb", "lib/validates_timeliness/active_record", "lib/validates_timeliness/active_record/attribute_methods.rb", "lib/validates_timeliness/active_record/multiparameter_attributes.rb", "lib/validates_timeliness/formats.rb", "lib/validates_timeliness/locale", "lib/validates_timeliness/locale/en.yml", "lib/validates_timeliness/matcher.rb", "lib/validates_timeliness/parser.rb", "lib/validates_timeliness/spec", "lib/validates_timeliness/spec/rails", "lib/validates_timeliness/spec/rails/matchers", "lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb", "lib/validates_timeliness/validation_methods.rb", "lib/validates_timeliness/validator.rb", "lib/validates_timeliness/version.rb", "lib/validates_timeliness.rb", "spec/action_view", "spec/action_view/instance_tag_spec.rb", "spec/active_record", "spec/active_record/attribute_methods_spec.rb", "spec/active_record/multiparameter_attributes_spec.rb", "spec/formats_spec.rb", "spec/ginger_scenarios.rb", "spec/parser_spec.rb", "spec/resources", "spec/resources/application.rb", "spec/resources/person.rb", "spec/resources/schema.rb", "spec/resources/sqlite_patch.rb", "spec/spec", "spec/spec/rails", "spec/spec/rails/matchers", "spec/spec/rails/matchers/validate_timeliness_spec.rb", "spec/spec_helper.rb", "spec/time_travel", "spec/time_travel/MIT-LICENSE", "spec/time_travel/time_extensions.rb", "spec/time_travel/time_travel.rb", "spec/validator_spec.rb"]
|
||||
s.files = ["LICENSE", "README.rdoc", "Rakefile", "TODO", "CHANGELOG", "lib/validates_timeliness", "lib/validates_timeliness/action_view", "lib/validates_timeliness/action_view/instance_tag.rb", "lib/validates_timeliness/active_record", "lib/validates_timeliness/active_record/attribute_methods.rb", "lib/validates_timeliness/active_record/multiparameter_attributes.rb", "lib/validates_timeliness/formats.rb", "lib/validates_timeliness/locale", "lib/validates_timeliness/locale/en.new.yml", "lib/validates_timeliness/locale/en.old.yml", "lib/validates_timeliness/matcher.rb", "lib/validates_timeliness/parser.rb", "lib/validates_timeliness/spec", "lib/validates_timeliness/spec/rails", "lib/validates_timeliness/spec/rails/matchers", "lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb", "lib/validates_timeliness/validation_methods.rb", "lib/validates_timeliness/validator.rb", "lib/validates_timeliness/version.rb", "lib/validates_timeliness.rb", "spec/action_view", "spec/action_view/instance_tag_spec.rb", "spec/active_record", "spec/active_record/attribute_methods_spec.rb", "spec/active_record/multiparameter_attributes_spec.rb", "spec/formats_spec.rb", "spec/ginger_scenarios.rb", "spec/parser_spec.rb", "spec/resources", "spec/resources/application.rb", "spec/resources/person.rb", "spec/resources/schema.rb", "spec/resources/sqlite_patch.rb", "spec/spec", "spec/spec/rails", "spec/spec/rails/matchers", "spec/spec/rails/matchers/validate_timeliness_spec.rb", "spec/spec_helper.rb", "spec/time_travel", "spec/time_travel/MIT-LICENSE", "spec/time_travel/time_extensions.rb", "spec/time_travel/time_travel.rb", "spec/validator_spec.rb"]
|
||||
s.homepage = %q{http://github.com/adzap/validates_timeliness}
|
||||
s.require_paths = ["lib"]
|
||||
s.rubyforge_project = %q{validatestime}
|
||||
s.rubygems_version = %q{1.3.5}
|
||||
s.rubygems_version = %q{1.3.7}
|
||||
s.summary = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
|
||||
|
||||
if s.respond_to? :specification_version then
|
||||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
||||
s.specification_version = 3
|
||||
|
||||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
||||
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
||||
else
|
||||
end
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user