diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ae6efae..8cc22f3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -81,7 +81,7 @@ class Employee < ActiveRecord::Base end end -Rspec.configure do |c| +RSpec.configure do |c| c.mock_with :rspec c.include(RspecTagMatchers) c.include(ModelHelpers) diff --git a/spec/validates_timeliness/orm/mongoid_spec.rb b/spec/validates_timeliness/orm/mongoid_spec.rb index b8c34ce..a978785 100644 --- a/spec/validates_timeliness/orm/mongoid_spec.rb +++ b/spec/validates_timeliness/orm/mongoid_spec.rb @@ -15,15 +15,15 @@ end describe ValidatesTimeliness, 'Mongoid' do class Article - ::ValidatesTimeliness.use_plugin_parser = true include Mongoid::Document + ValidatesTimeliness.use_plugin_parser = true field :publish_date, :type => Date field :publish_time, :type => Time field :publish_datetime, :type => DateTime validates_date :publish_date, :allow_nil => true validates_time :publish_time, :allow_nil => true validates_datetime :publish_datetime, :allow_nil => true - ::ValidatesTimeliness.use_plugin_parser = false + ValidatesTimeliness.use_plugin_parser = false end context "validation methods" do @@ -52,7 +52,7 @@ describe ValidatesTimeliness, 'Mongoid' do end context "with plugin parser" do - with_config(:use_plugin_parser, false) + with_config(:use_plugin_parser, true) it 'should parse a string value' do Timeliness::Parser.should_receive(:parse) @@ -60,12 +60,20 @@ describe ValidatesTimeliness, 'Mongoid' do r.publish_date = '2010-01-01' end + it 'should parse an invalid value as nil' do + Timeliness::Parser.should_receive(:parse) + r = Article.new + r.publish_date = 'bad value' + + r.publish_date.should be_nil + end + context "for a date column" do - it 'should store a date value after parsing string' do + it 'should store a Time value after parsing string' do r = Article.new r.publish_date = '2010-01-01' - r.publish_date.should be_kind_of(Date) + r.publish_date.should be_kind_of(Time) r.publish_date.should == Date.new(2010, 1, 1) end end diff --git a/spec/validates_timeliness/validator_spec.rb b/spec/validates_timeliness/validator_spec.rb index 2e03eb3..83f8845 100644 --- a/spec/validates_timeliness/validator_spec.rb +++ b/spec/validates_timeliness/validator_spec.rb @@ -138,7 +138,7 @@ describe ValidatesTimeliness::Validator do it "should be added when ignore_restriction_errors is false" do with_config(:ignore_restriction_errors, false) do person.valid? - person.errors[:birth_date].first.should match("Error occurred validating birth_date for :is_at restriction") + person.errors[:birth_date].first.should match("Error occurred validating birth_date") end end