From 6bed71152a1cd945e5a2739c0a660b8518e3a8d0 Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Tue, 3 Aug 2010 14:56:59 +1000 Subject: [PATCH] add validation methods as instance methods as well per AM --- lib/validates_timeliness/helper_methods.rb | 7 ++++++- spec/validates_timeliness/helper_methods_spec.rb | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 spec/validates_timeliness/helper_methods_spec.rb diff --git a/lib/validates_timeliness/helper_methods.rb b/lib/validates_timeliness/helper_methods.rb index bea4ed6..c208300 100644 --- a/lib/validates_timeliness/helper_methods.rb +++ b/lib/validates_timeliness/helper_methods.rb @@ -2,7 +2,12 @@ module ValidatesTimeliness module HelperMethods extend ActiveSupport::Concern - module ClassMethods + included do + include ValidationMethods + extend ValidationMethods + end + + module ValidationMethods def validates_date(*attr_names) validates_with Validator, _merge_attributes(attr_names).merge(:type => :date) end diff --git a/spec/validates_timeliness/helper_methods_spec.rb b/spec/validates_timeliness/helper_methods_spec.rb new file mode 100644 index 0000000..bc480a4 --- /dev/null +++ b/spec/validates_timeliness/helper_methods_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +describe ValidatesTimeliness::HelperMethods do + it 'should define class validation methods on extended classes' do + ActiveRecord::Base.should respond_to(:validates_date) + ActiveRecord::Base.should respond_to(:validates_time) + ActiveRecord::Base.should respond_to(:validates_datetime) + end + + it 'should define instance validation methods on extended classes' do + ActiveRecord::Base.instance_methods.should include('validates_date') + ActiveRecord::Base.instance_methods.should include('validates_time') + ActiveRecord::Base.instance_methods.should include('validates_datetime') + end +end