mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
Fix brokena and brittle tests
This commit is contained in:
parent
9a99c47323
commit
af9d6cdba4
@ -81,7 +81,7 @@ class Employee < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Rspec.configure do |c|
|
RSpec.configure do |c|
|
||||||
c.mock_with :rspec
|
c.mock_with :rspec
|
||||||
c.include(RspecTagMatchers)
|
c.include(RspecTagMatchers)
|
||||||
c.include(ModelHelpers)
|
c.include(ModelHelpers)
|
||||||
|
|||||||
@ -15,15 +15,15 @@ end
|
|||||||
describe ValidatesTimeliness, 'Mongoid' do
|
describe ValidatesTimeliness, 'Mongoid' do
|
||||||
|
|
||||||
class Article
|
class Article
|
||||||
::ValidatesTimeliness.use_plugin_parser = true
|
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
|
ValidatesTimeliness.use_plugin_parser = true
|
||||||
field :publish_date, :type => Date
|
field :publish_date, :type => Date
|
||||||
field :publish_time, :type => Time
|
field :publish_time, :type => Time
|
||||||
field :publish_datetime, :type => DateTime
|
field :publish_datetime, :type => DateTime
|
||||||
validates_date :publish_date, :allow_nil => true
|
validates_date :publish_date, :allow_nil => true
|
||||||
validates_time :publish_time, :allow_nil => true
|
validates_time :publish_time, :allow_nil => true
|
||||||
validates_datetime :publish_datetime, :allow_nil => true
|
validates_datetime :publish_datetime, :allow_nil => true
|
||||||
::ValidatesTimeliness.use_plugin_parser = false
|
ValidatesTimeliness.use_plugin_parser = false
|
||||||
end
|
end
|
||||||
|
|
||||||
context "validation methods" do
|
context "validation methods" do
|
||||||
@ -52,7 +52,7 @@ describe ValidatesTimeliness, 'Mongoid' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "with plugin parser" do
|
context "with plugin parser" do
|
||||||
with_config(:use_plugin_parser, false)
|
with_config(:use_plugin_parser, true)
|
||||||
|
|
||||||
it 'should parse a string value' do
|
it 'should parse a string value' do
|
||||||
Timeliness::Parser.should_receive(:parse)
|
Timeliness::Parser.should_receive(:parse)
|
||||||
@ -60,12 +60,20 @@ describe ValidatesTimeliness, 'Mongoid' do
|
|||||||
r.publish_date = '2010-01-01'
|
r.publish_date = '2010-01-01'
|
||||||
end
|
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
|
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 = Article.new
|
||||||
r.publish_date = '2010-01-01'
|
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)
|
r.publish_date.should == Date.new(2010, 1, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -138,7 +138,7 @@ describe ValidatesTimeliness::Validator do
|
|||||||
it "should be added when ignore_restriction_errors is false" do
|
it "should be added when ignore_restriction_errors is false" do
|
||||||
with_config(:ignore_restriction_errors, false) do
|
with_config(:ignore_restriction_errors, false) do
|
||||||
person.valid?
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user