mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Fix for Mongoid shim for reload which was nicely moved into a module to allow super
This commit is contained in:
parent
e44e9d2f11
commit
907fd3e439
2
Gemfile
2
Gemfile
@ -11,7 +11,7 @@ gem 'ruby-debug', :platforms => [:ruby_18, :jruby]
|
|||||||
gem 'ruby-debug19', :platforms => [:ruby_19]
|
gem 'ruby-debug19', :platforms => [:ruby_19]
|
||||||
|
|
||||||
group :mongoid do
|
group :mongoid do
|
||||||
gem 'mongoid', '2.2.0'
|
gem 'mongoid', '~> 2.3.0'
|
||||||
gem 'bson_ext'
|
gem 'bson_ext'
|
||||||
gem 'system_timer', :platforms => [:ruby_18]
|
gem 'system_timer', :platforms => [:ruby_18]
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,6 +31,10 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reload
|
||||||
|
_clear_timeliness_cache
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -39,9 +43,12 @@ module Mongoid::Document
|
|||||||
include ValidatesTimeliness::AttributeMethods
|
include ValidatesTimeliness::AttributeMethods
|
||||||
include ValidatesTimeliness::ORM::Mongoid
|
include ValidatesTimeliness::ORM::Mongoid
|
||||||
|
|
||||||
def reload_with_timeliness
|
# Pre-2.3 reload
|
||||||
_clear_timeliness_cache
|
if instance_methods.include?('reload')
|
||||||
reload_without_timeliness
|
def reload_with_timeliness
|
||||||
|
_clear_timeliness_cache
|
||||||
|
reload_without_timeliness
|
||||||
|
end
|
||||||
|
alias_method_chain :reload, :timeliness
|
||||||
end
|
end
|
||||||
alias_method_chain :reload, :timeliness
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -69,22 +69,22 @@ describe ValidatesTimeliness, 'Mongoid' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "for a date column" do
|
context "for a date column" do
|
||||||
it 'should store a Time value after parsing string' do
|
it 'should store a Date value after parsing string' do
|
||||||
r = Article.new
|
r = Article.new
|
||||||
r.publish_date = '2010-01-01'
|
r.publish_date = '2010-01-01'
|
||||||
|
|
||||||
r.publish_date.should be_kind_of(Time)
|
r.publish_date.should be_kind_of(Date)
|
||||||
r.publish_date.should == Date.new(2010, 1, 1)
|
r.publish_date.should == Date.new(2010, 1, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "for a datetime column" do
|
context "for a datetime column" do
|
||||||
it 'should parse string into Time value' do
|
it 'should parse string into DateTime value' do
|
||||||
r = Article.new
|
r = Article.new
|
||||||
r.publish_datetime = '2010-01-01 12:00'
|
r.publish_datetime = '2010-01-01 12:00'
|
||||||
|
|
||||||
r.publish_datetime.should be_kind_of(Time)
|
r.publish_datetime.should be_kind_of(DateTime)
|
||||||
r.publish_datetime.should == Time.utc(2010,1,1,12,0)
|
r.publish_datetime.should == DateTime.new(2010,1,1,12,0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -108,6 +108,6 @@ end
|
|||||||
|
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
puts "Mongoid specs skipped. Mongoid not installed"
|
puts "Mongoid specs skipped. Mongoid not installed"
|
||||||
rescue StandardError
|
rescue StandardError => e
|
||||||
puts "Mongoid specs skipped. MongoDB connection failed."
|
puts "Mongoid specs skipped. MongoDB connection failed with error: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user