mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
preliminary Mongoid support
This commit is contained in:
66
spec/validates_timeliness/orm/mongoid_spec.rb
Normal file
66
spec/validates_timeliness/orm/mongoid_spec.rb
Normal file
@@ -0,0 +1,66 @@
|
||||
require 'spec_helper'
|
||||
|
||||
require 'mongoid'
|
||||
require 'validates_timeliness/orm/mongoid'
|
||||
|
||||
Mongoid.configure do |config|
|
||||
name = "validates_timeliness_test"
|
||||
host = "localhost"
|
||||
config.master = Mongo::Connection.new.db(name)
|
||||
config.persist_in_safe_mode = false
|
||||
end
|
||||
|
||||
describe ValidatesTimeliness, 'Mongoid' do
|
||||
|
||||
class Article
|
||||
::ValidatesTimeliness.use_plugin_parser = true
|
||||
include Mongoid::Document
|
||||
field :publish_date, :type => Date
|
||||
field :publish_time, :type => Time
|
||||
field :publish_datetime, :type => DateTime
|
||||
validates_date :publish_date
|
||||
validates_time :publish_time
|
||||
validates_datetime :publish_datetime
|
||||
::ValidatesTimeliness.use_plugin_parser = false
|
||||
end
|
||||
|
||||
it 'should define _timeliness_raw_value_for instance method' do
|
||||
Article.instance_methods.should include('_timeliness_raw_value_for')
|
||||
end
|
||||
|
||||
context "attribute write method" do
|
||||
it 'should cache attribute raw value' do
|
||||
r = Article.new
|
||||
r.publish_datetime = date_string = '2010-01-01'
|
||||
r._timeliness_raw_value_for(:publish_datetime).should == date_string
|
||||
end
|
||||
|
||||
context "with plugin parser" do
|
||||
before :all do
|
||||
ValidatesTimeliness.use_plugin_parser = true
|
||||
end
|
||||
|
||||
it 'should parse a string value' do
|
||||
ValidatesTimeliness::Parser.should_receive(:parse)
|
||||
r = Article.new
|
||||
r.publish_date = '2010-01-01'
|
||||
end
|
||||
|
||||
it 'should parse string into Time value' do
|
||||
r = Article.new
|
||||
r.publish_datetime = '2010-01-01 12:00'
|
||||
r.publish_datetime.should == Time.utc(2010,1,1,12,0)
|
||||
end
|
||||
|
||||
after :all do
|
||||
ValidatesTimeliness.use_plugin_parser = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "before_type_cast method" do
|
||||
it 'should not be defined if ORM does not support it' do
|
||||
Article.instance_methods(false).should_not include("birth_datetime_before_type_cast")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user