mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 23:33:00 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbb16cb093 |
@@ -25,3 +25,7 @@ end
|
||||
appraise "mongoid_2_4" do
|
||||
gem "mongoid", "~> 2.4.0"
|
||||
end
|
||||
|
||||
appraise "mongoid_3_0" do
|
||||
gem "mongoid", "~> 3.0.0"
|
||||
end
|
||||
|
||||
3
Gemfile
3
Gemfile
@@ -13,7 +13,8 @@ gem 'appraisal'
|
||||
gem 'sqlite3'
|
||||
|
||||
group :mongoid do
|
||||
gem 'mongoid', '~> 2.3.0'
|
||||
gem 'mongoid', '~> 3.0.0'
|
||||
gem 'mongo'
|
||||
gem 'bson_ext'
|
||||
gem 'system_timer', :platforms => [:ruby_18]
|
||||
end
|
||||
|
||||
@@ -55,10 +55,7 @@ NOTE: You may wish to enable the plugin parser and the extensions to start. Plea
|
||||
validates_datetime :finish_time, :after => :start_time # Method symbol
|
||||
|
||||
validates_date :booked_at, :on => :create, :on_or_after => :today # See Restriction Shorthand.
|
||||
|
||||
validates_time :booked_at, :between => ['9:00am', '5:00pm'] # On or after 9:00AM and on or before 5:00PM
|
||||
validates_time :booked_at, :between => '9:00am'..'5:00pm' # The same as previous example
|
||||
validates_time :booked_at, :between => '9:00am'...'5:00pm' # On or after 9:00AM and strictly before 5:00PM
|
||||
validates_time :booked_at, :between => ['9.00am', '5:00pm']
|
||||
|
||||
validates_time :breakfast_time, :on_or_after => '6:00am',
|
||||
:on_or_after_message => 'must be after opening time',
|
||||
@@ -176,8 +173,8 @@ You can also use validation options for custom error messages. The following opt
|
||||
:after_message
|
||||
:on_or_after_message
|
||||
|
||||
Note: There is no :between_message option. The between error message should be defined using the :on_or_after and :on_or_before
|
||||
(:before in case when :between argument is a Range with excluded high value, see Examples) messages.
|
||||
Note: There is no :between_message option. The between error message should be defined using the
|
||||
:on_or_before and :on_or_after messages.
|
||||
|
||||
It is highly recommended you use the I18n system for error messages.
|
||||
|
||||
|
||||
16
gemfiles/mongoid_3_0.gemfile
Normal file
16
gemfiles/mongoid_3_0.gemfile
Normal file
@@ -0,0 +1,16 @@
|
||||
# This file was generated by Appraisal
|
||||
|
||||
source "http://rubygems.org"
|
||||
|
||||
gem "rails", "~> 3.2.6"
|
||||
gem "rspec", "~> 2.8"
|
||||
gem "rspec-rails", "~> 2.8"
|
||||
gem "timecop"
|
||||
gem "rspec_tag_matchers"
|
||||
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
||||
gem "debugger", :platforms=>[:ruby_19]
|
||||
gem "appraisal"
|
||||
gem "sqlite3"
|
||||
gem "mongoid", "~> 3.0.0"
|
||||
|
||||
gemspec :path=>"../"
|
||||
16
gemfiles/mongoid_3_1.gemfile
Normal file
16
gemfiles/mongoid_3_1.gemfile
Normal file
@@ -0,0 +1,16 @@
|
||||
# This file was generated by Appraisal
|
||||
|
||||
source "http://rubygems.org"
|
||||
|
||||
gem "rails", "~> 3.2.6"
|
||||
gem "rspec", "~> 2.8"
|
||||
gem "rspec-rails", "~> 2.8"
|
||||
gem "timecop"
|
||||
gem "rspec_tag_matchers"
|
||||
gem "ruby-debug", :platforms=>[:ruby_18, :jruby]
|
||||
gem "debugger", :platforms=>[:ruby_19]
|
||||
gem "appraisal"
|
||||
gem "sqlite3"
|
||||
gem "mongoid", "~> 3.1.0"
|
||||
|
||||
gemspec :path=>"../"
|
||||
@@ -1,4 +1,3 @@
|
||||
require 'active_model'
|
||||
require 'active_model/validator'
|
||||
|
||||
module ValidatesTimeliness
|
||||
@@ -33,12 +32,7 @@ module ValidatesTimeliness
|
||||
|
||||
if range = options.delete(:between)
|
||||
raise ArgumentError, ":between must be a Range or an Array" unless range.is_a?(Range) || range.is_a?(Array)
|
||||
options[:on_or_after] = range.first
|
||||
if range.is_a?(Range) && range.exclude_end?
|
||||
options[:before] = range.last
|
||||
else
|
||||
options[:on_or_before] = range.last
|
||||
end
|
||||
options[:on_or_after], options[:on_or_before] = range.first, range.last
|
||||
end
|
||||
|
||||
@restrictions_to_check = RESTRICTIONS.keys & options.keys
|
||||
|
||||
@@ -57,7 +57,6 @@ class PersonWithShim < Person
|
||||
include TestModelShim
|
||||
end
|
||||
|
||||
ActiveRecord::Base.default_timezone = :utc
|
||||
ActiveRecord::Base.time_zone_aware_attributes = true
|
||||
ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'})
|
||||
ActiveRecord::Migration.verbose = false
|
||||
|
||||
6
spec/support/mongoid.yml
Normal file
6
spec/support/mongoid.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
test:
|
||||
sessions:
|
||||
default:
|
||||
database: mongoid
|
||||
hosts:
|
||||
- localhost:27017
|
||||
@@ -10,7 +10,7 @@ describe ValidatesTimeliness::Extensions::MultiparameterHandler do
|
||||
|
||||
it 'should assign a Time value for valid datetimes' do
|
||||
employee = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 28, 12, 0, 0])
|
||||
employee.birth_datetime_before_type_cast.should eq Time.zone.local(2000, 2, 28, 12, 0, 0)
|
||||
employee.birth_datetime_before_type_cast.should eq Time.local(2000, 2, 28, 12, 0, 0)
|
||||
end
|
||||
|
||||
it 'should assign a string value for incomplete time' do
|
||||
|
||||
@@ -221,7 +221,7 @@ describe ValidatesTimeliness, 'ActiveRecord' do
|
||||
Employee.create(:birth_datetime => datetime)
|
||||
|
||||
record = Employee.last
|
||||
record.birth_datetime_before_type_cast.should match(/#{datetime.utc.to_s[0...-4]}/)
|
||||
record.birth_datetime_before_type_cast.should match(/2010-01-01 00:00:00/)
|
||||
end
|
||||
|
||||
context "with plugin parser" do
|
||||
|
||||
@@ -4,14 +4,20 @@ require 'spec_helper'
|
||||
begin
|
||||
|
||||
require 'mongoid'
|
||||
require 'mongoid/version'
|
||||
require 'validates_timeliness/orm/mongoid'
|
||||
|
||||
if Mongoid::VERSION >= '3.0'
|
||||
Mongoid.load!("spec/support/mongoid.yml", :test)
|
||||
else
|
||||
require 'mongo'
|
||||
Mongoid.configure do |config|
|
||||
name = "validates_timeliness_test"
|
||||
host = "localhost"
|
||||
config.master = Mongo::Connection.new.db(name)
|
||||
config.persist_in_safe_mode = false
|
||||
end
|
||||
end
|
||||
|
||||
describe ValidatesTimeliness, 'Mongoid' do
|
||||
|
||||
@@ -47,9 +53,19 @@ describe ValidatesTimeliness, 'Mongoid' do
|
||||
record.errors[:publish_date].should be_empty
|
||||
end
|
||||
|
||||
it "should validate a invalid value string" do
|
||||
it "should validate an invalid time value string" do
|
||||
begin
|
||||
record.publish_date = 'not a date'
|
||||
record.publish_time = 'not valid'
|
||||
rescue
|
||||
end
|
||||
|
||||
record.valid?
|
||||
record.errors[:publish_time].should_not be_empty
|
||||
end
|
||||
|
||||
it "should validate an invalid date value string" do
|
||||
begin
|
||||
record.publish_date = 'not valid'
|
||||
rescue
|
||||
end
|
||||
|
||||
@@ -57,12 +73,36 @@ describe ValidatesTimeliness, 'Mongoid' do
|
||||
record.errors[:publish_date].should_not be_empty
|
||||
end
|
||||
|
||||
it "should validate a nil value" do
|
||||
it "should validate an invalid datetime value string" do
|
||||
begin
|
||||
record.publish_datetime = 'not valid'
|
||||
rescue
|
||||
end
|
||||
|
||||
record.valid?
|
||||
record.errors[:publish_datetime].should_not be_empty
|
||||
end
|
||||
|
||||
it "should accept a nil time value" do
|
||||
record.publish_date = nil
|
||||
|
||||
record.valid?
|
||||
record.errors[:publish_time].should be_empty
|
||||
end
|
||||
|
||||
it "should accept a nil date value" do
|
||||
record.publish_date = nil
|
||||
|
||||
record.valid?
|
||||
record.errors[:publish_date].should be_empty
|
||||
end
|
||||
|
||||
it "should accept a nil datetime value" do
|
||||
record.publish_datetime = nil
|
||||
|
||||
record.valid?
|
||||
record.errors[:publish_datetime].should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
it 'should determine type for attribute' do
|
||||
@@ -105,6 +145,8 @@ describe ValidatesTimeliness, 'Mongoid' do
|
||||
Timeliness::Parser.should_receive(:parse)
|
||||
|
||||
record.publish_date = 'not valid'
|
||||
|
||||
record.publish_date.should be_nil
|
||||
end
|
||||
|
||||
it 'should store a Date value after parsing string' do
|
||||
@@ -149,6 +191,8 @@ describe ValidatesTimeliness, 'Mongoid' do
|
||||
Timeliness::Parser.should_receive(:parse)
|
||||
|
||||
record.publish_datetime = 'not valid'
|
||||
|
||||
record.publish_datetime.should be_nil
|
||||
end
|
||||
|
||||
it 'should parse string into DateTime value' do
|
||||
|
||||
@@ -115,19 +115,6 @@ describe ValidatesTimeliness::Validator do
|
||||
valid!(:birth_date, on_or_before)
|
||||
end
|
||||
end
|
||||
|
||||
describe "range with excluded end value" do
|
||||
it 'should be split option into :on_or_after and :before values' do
|
||||
on_or_after, before = Date.new(2010,1,1), Date.new(2010,1,3)
|
||||
Person.validates_date :birth_date, :between => on_or_after...before
|
||||
Person.validators.first.options[:on_or_after].should == on_or_after
|
||||
Person.validators.first.options[:before].should == before
|
||||
invalid!(:birth_date, on_or_after - 1, "must be on or after 2010-01-01")
|
||||
invalid!(:birth_date, before, "must be before 2010-01-03")
|
||||
valid!(:birth_date, on_or_after)
|
||||
valid!(:birth_date, before - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ":ignore_usec option" do
|
||||
|
||||
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
|
||||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
||||
|
||||
s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.7"])
|
||||
s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.6"])
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user