Compare commits

..

7 Commits

Author SHA1 Message Date
Adam Meehan
00ce472d3e Merge pull request #99 from softace/fixing_build
Fix for running tests in non-Australian timezones
2013-06-16 15:22:33 -07:00
Jarl Friis
0d2c7ce554 Fix for running tests in non-Australian timezones 2013-04-30 19:56:19 +02:00
Adam Meehan
3d798697e1 Merge pull request #98 from 907th/master
Range with excluded end passed to :between option should be split into :on_or_after and :before options
2013-04-30 04:45:54 -07:00
Alexey Chernenkov
dc0fdc0340 Range with excluded end passed to :between option should be split into :on_or_after and :before options 2013-04-30 15:37:44 +06:00
Adam Meehan
dd3b6b5514 Merge pull request #95 from will-ob/fix/require-active-model
Require 'active_model'
2013-04-25 22:01:51 -07:00
Will O'Brien
609fafe7bb Require 'active_model'
Apparently classes are lazily required when using autoload. Prompted by
'uninitialized constant ActiveModel::Validations'
2013-04-25 22:42:28 -04:00
Adam Meehan
df9677f5bf timeliness minimum dep 0.3.7 2012-10-15 20:37:05 +11:00
13 changed files with 40 additions and 104 deletions

View File

@@ -25,7 +25,3 @@ end
appraise "mongoid_2_4" do appraise "mongoid_2_4" do
gem "mongoid", "~> 2.4.0" gem "mongoid", "~> 2.4.0"
end end
appraise "mongoid_3_0" do
gem "mongoid", "~> 3.0.0"
end

View File

@@ -13,8 +13,7 @@ gem 'appraisal'
gem 'sqlite3' gem 'sqlite3'
group :mongoid do group :mongoid do
gem 'mongoid', '~> 3.0.0' gem 'mongoid', '~> 2.3.0'
gem 'mongo'
gem 'bson_ext' gem 'bson_ext'
gem 'system_timer', :platforms => [:ruby_18] gem 'system_timer', :platforms => [:ruby_18]
end end

View File

@@ -55,7 +55,10 @@ 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_datetime :finish_time, :after => :start_time # Method symbol
validates_date :booked_at, :on => :create, :on_or_after => :today # See Restriction Shorthand. validates_date :booked_at, :on => :create, :on_or_after => :today # See Restriction Shorthand.
validates_time :booked_at, :between => ['9.00am', '5:00pm']
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 :breakfast_time, :on_or_after => '6:00am', validates_time :breakfast_time, :on_or_after => '6:00am',
:on_or_after_message => 'must be after opening time', :on_or_after_message => 'must be after opening time',
@@ -173,8 +176,8 @@ You can also use validation options for custom error messages. The following opt
:after_message :after_message
:on_or_after_message :on_or_after_message
Note: There is no :between_message option. The between error message should be defined using the Note: There is no :between_message option. The between error message should be defined using the :on_or_after and :on_or_before
:on_or_before and :on_or_after messages. (:before in case when :between argument is a Range with excluded high value, see Examples) messages.
It is highly recommended you use the I18n system for error messages. It is highly recommended you use the I18n system for error messages.

View File

@@ -1,16 +0,0 @@
# 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=>"../"

View File

@@ -1,16 +0,0 @@
# 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=>"../"

View File

@@ -1,3 +1,4 @@
require 'active_model'
require 'active_model/validator' require 'active_model/validator'
module ValidatesTimeliness module ValidatesTimeliness
@@ -32,7 +33,12 @@ module ValidatesTimeliness
if range = options.delete(:between) if range = options.delete(:between)
raise ArgumentError, ":between must be a Range or an Array" unless range.is_a?(Range) || range.is_a?(Array) raise ArgumentError, ":between must be a Range or an Array" unless range.is_a?(Range) || range.is_a?(Array)
options[:on_or_after], options[:on_or_before] = range.first, range.last 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
end end
@restrictions_to_check = RESTRICTIONS.keys & options.keys @restrictions_to_check = RESTRICTIONS.keys & options.keys

View File

@@ -57,6 +57,7 @@ class PersonWithShim < Person
include TestModelShim include TestModelShim
end end
ActiveRecord::Base.default_timezone = :utc
ActiveRecord::Base.time_zone_aware_attributes = true ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'}) ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'})
ActiveRecord::Migration.verbose = false ActiveRecord::Migration.verbose = false

View File

@@ -1,6 +0,0 @@
test:
sessions:
default:
database: mongoid
hosts:
- localhost:27017

View File

@@ -10,7 +10,7 @@ describe ValidatesTimeliness::Extensions::MultiparameterHandler do
it 'should assign a Time value for valid datetimes' 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 = record_with_multiparameter_attribute(:birth_datetime, [2000, 2, 28, 12, 0, 0])
employee.birth_datetime_before_type_cast.should eq Time.local(2000, 2, 28, 12, 0, 0) employee.birth_datetime_before_type_cast.should eq Time.zone.local(2000, 2, 28, 12, 0, 0)
end end
it 'should assign a string value for incomplete time' do it 'should assign a string value for incomplete time' do

View File

@@ -221,7 +221,7 @@ describe ValidatesTimeliness, 'ActiveRecord' do
Employee.create(:birth_datetime => datetime) Employee.create(:birth_datetime => datetime)
record = Employee.last record = Employee.last
record.birth_datetime_before_type_cast.should match(/2010-01-01 00:00:00/) record.birth_datetime_before_type_cast.should match(/#{datetime.utc.to_s[0...-4]}/)
end end
context "with plugin parser" do context "with plugin parser" do

View File

@@ -4,19 +4,13 @@ require 'spec_helper'
begin begin
require 'mongoid' require 'mongoid'
require 'mongoid/version'
require 'validates_timeliness/orm/mongoid' require 'validates_timeliness/orm/mongoid'
if Mongoid::VERSION >= '3.0' Mongoid.configure do |config|
Mongoid.load!("spec/support/mongoid.yml", :test)
else
require 'mongo'
Mongoid.configure do |config|
name = "validates_timeliness_test" name = "validates_timeliness_test"
host = "localhost" host = "localhost"
config.master = Mongo::Connection.new.db(name) config.master = Mongo::Connection.new.db(name)
config.persist_in_safe_mode = false config.persist_in_safe_mode = false
end
end end
describe ValidatesTimeliness, 'Mongoid' do describe ValidatesTimeliness, 'Mongoid' do
@@ -53,19 +47,9 @@ describe ValidatesTimeliness, 'Mongoid' do
record.errors[:publish_date].should be_empty record.errors[:publish_date].should be_empty
end end
it "should validate an invalid time value string" do it "should validate a invalid value string" do
begin begin
record.publish_time = 'not valid' record.publish_date = 'not a date'
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 rescue
end end
@@ -73,36 +57,12 @@ describe ValidatesTimeliness, 'Mongoid' do
record.errors[:publish_date].should_not be_empty record.errors[:publish_date].should_not be_empty
end end
it "should validate an invalid datetime value string" do it "should validate a nil value" 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.publish_date = nil
record.valid? record.valid?
record.errors[:publish_date].should be_empty record.errors[:publish_date].should be_empty
end end
it "should accept a nil datetime value" do
record.publish_datetime = nil
record.valid?
record.errors[:publish_datetime].should be_empty
end
end end
it 'should determine type for attribute' do it 'should determine type for attribute' do
@@ -145,8 +105,6 @@ describe ValidatesTimeliness, 'Mongoid' do
Timeliness::Parser.should_receive(:parse) Timeliness::Parser.should_receive(:parse)
record.publish_date = 'not valid' record.publish_date = 'not valid'
record.publish_date.should be_nil
end end
it 'should store a Date value after parsing string' do it 'should store a Date value after parsing string' do
@@ -191,8 +149,6 @@ describe ValidatesTimeliness, 'Mongoid' do
Timeliness::Parser.should_receive(:parse) Timeliness::Parser.should_receive(:parse)
record.publish_datetime = 'not valid' record.publish_datetime = 'not valid'
record.publish_datetime.should be_nil
end end
it 'should parse string into DateTime value' do it 'should parse string into DateTime value' do

View File

@@ -115,6 +115,19 @@ describe ValidatesTimeliness::Validator do
valid!(:birth_date, on_or_before) valid!(:birth_date, on_or_before)
end end
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 end
describe ":ignore_usec option" do describe ":ignore_usec option" do

View File

@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"] s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.6"]) s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.7"])
end end