Permalink
Browse files

git-svn-id: http://svn.viney.net.nz/things/rails/plugins/validates_da…

…te_time@74 20afb1e0-9c0e-0410-9884-91ed27886737
  • Loading branch information...
1 parent 1c1b2f0 commit d23eda26d6adcfaf9b9c0e59ed1ab599b9b1dc35 jonathan committed Jun 30, 2006
Showing with 26 additions and 2 deletions.
  1. +22 −0 Rakefile
  2. +3 −1 lib/validates_date_time.rb
  3. +1 −1 test/time_test.rb
View
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the validates_date_time plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the validates_date_time plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'validates_date_time'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
@@ -104,7 +104,9 @@ def validates_#{validator}(*attr_names)
validates_each(attr_names, configuration) do |record, attr_name, value|
value_to_parse = record.send("\#{attr_name}_before_type_cast")
- unless value_to_parse.blank? && allow_nil
+ if value_to_parse.blank? && allow_nil
+ record.send("\#{attr_name}=", nil)
+ else
value_to_parse = parse_date_time(value_to_parse) rescue value_to_parse
begin
View
@@ -57,6 +57,6 @@ def test_before
def test_blank
assert p.update_attributes(:time_of_birth => "")
- assert_nil p.time_of_birth, 'require Rails >= r4327 to pass'
+ assert_nil p.time_of_birth
end
end

0 comments on commit d23eda2

Please sign in to comment.