Compare commits

...

6 Commits

Author SHA1 Message Date
Adam Meehan
8898b8686c v3.0.12 2012-06-23 19:06:38 +10:00
Adam Meehan
aad2db8662 Remove unused cargo culted generator method 2012-06-23 18:58:33 +10:00
Adam Meehan
8e08cbf6e4 Fix load order issue for AR extension using Railite 2012-06-23 18:58:01 +10:00
Adam Meehan
8dd607975b v3.0.11 2012-04-01 16:48:53 +10:00
Adam Meehan
b6acda539f v3.0.10 2012-03-29 13:45:40 +11:00
Adam Meehan
4aa20bb002 Stricter method signature for _timeliness_raw_value_for to take string
Add basic validation specs to each ORM shim
2012-03-29 13:00:28 +11:00
11 changed files with 101 additions and 20 deletions

View File

@@ -1,3 +1,12 @@
= 3.0.12 [2012-06-23]
* Fix load order issue when relying on Railtie to load ActiveRecord extension
= 3.0.11 [2012-04-01]
* Change dependency on Timeliness version due to a broken release
= 3.0.10 [2012-03-26]
* Fix for ActiveRecord shim and validation with :allow_blank => true in AR 3.1+. Fixes issue#52.
= 3.0.9 [2012-03-26] = 3.0.9 [2012-03-26]
* ActiveRecord 3.1+ suport * ActiveRecord 3.1+ suport
* Fixes for multiparameter extension with empty date values (thanks @mogox, @Sharagoz) * Fixes for multiparameter extension with empty date values (thanks @mogox, @Sharagoz)

View File

@@ -2,13 +2,13 @@ source 'http://rubygems.org'
gemspec gemspec
gem 'rails', '~> 3.2.1' gem 'rails', '~> 3.2.6'
gem 'rspec', '~> 2.8' gem 'rspec', '~> 2.8'
gem 'rspec-rails', '~> 2.8' gem 'rspec-rails', '~> 2.8'
gem 'timecop' gem 'timecop'
gem 'rspec_tag_matchers' gem 'rspec_tag_matchers'
gem 'ruby-debug', :platforms => [:ruby_18, :jruby] gem 'ruby-debug', :platforms => [:ruby_18, :jruby]
gem 'ruby-debug19', :platforms => [:ruby_19] gem 'debugger', :platforms => [:ruby_19]
group :mongoid do group :mongoid do
gem 'mongoid', '~> 2.3.0' gem 'mongoid', '~> 2.3.0'

View File

@@ -3,7 +3,6 @@ module ValidatesTimeliness
class InstallGenerator < Rails::Generators::Base class InstallGenerator < Rails::Generators::Base
desc "Copy ValidatesTimeliness default files" desc "Copy ValidatesTimeliness default files"
source_root File.expand_path('../templates', __FILE__) source_root File.expand_path('../templates', __FILE__)
class_option :template_engine
def copy_initializers def copy_initializers
copy_file 'validates_timeliness.rb', 'config/initializers/validates_timeliness.rb' copy_file 'validates_timeliness.rb', 'config/initializers/validates_timeliness.rb'

View File

@@ -58,6 +58,10 @@ module ValidatesTimeliness
# Setup method for plugin configuration # Setup method for plugin configuration
def self.setup def self.setup
yield self yield self
load_orms
end
def self.load_orms
extend_orms.each {|orm| require "validates_timeliness/orm/#{orm}" } extend_orms.each {|orm| require "validates_timeliness/orm/#{orm}" }
end end
end end

View File

@@ -82,7 +82,7 @@ module ValidatesTimeliness
end end
def _timeliness_raw_value_for(attr_name) def _timeliness_raw_value_for(attr_name)
@timeliness_cache && @timeliness_cache[attr_name.to_s] @timeliness_cache && @timeliness_cache[attr_name]
end end
def _clear_timeliness_cache def _clear_timeliness_cache

View File

@@ -3,7 +3,8 @@ module ValidatesTimeliness
initializer "validates_timeliness.initialize_active_record", :after => 'active_record.initialize_timezone' do initializer "validates_timeliness.initialize_active_record", :after => 'active_record.initialize_timezone' do
ActiveSupport.on_load(:active_record) do ActiveSupport.on_load(:active_record) do
ValidatesTimeliness.default_timezone = ActiveRecord::Base.default_timezone ValidatesTimeliness.default_timezone = ActiveRecord::Base.default_timezone
ValidatesTimeliness.extend_orms = [ :active_record ] ValidatesTimeliness.extend_orms << :active_record
ValidatesTimeliness.load_orms
end end
end end

View File

@@ -77,7 +77,7 @@ module ValidatesTimeliness
def attribute_raw_value(record, attr_name) def attribute_raw_value(record, attr_name)
record.respond_to?(:_timeliness_raw_value_for) && record.respond_to?(:_timeliness_raw_value_for) &&
record._timeliness_raw_value_for(attr_name) record._timeliness_raw_value_for(attr_name.to_s)
end end
def timezone_aware?(record, attr_name) def timezone_aware?(record, attr_name)

View File

@@ -1,3 +1,3 @@
module ValidatesTimeliness module ValidatesTimeliness
VERSION = '3.0.9' VERSION = '3.0.12'
end end

View File

@@ -14,6 +14,30 @@ describe ValidatesTimeliness, 'ActiveRecord' do
Employee.new.should respond_to(:validates_time) Employee.new.should respond_to(:validates_time)
Employee.new.should respond_to(:validates_datetime) Employee.new.should respond_to(:validates_datetime)
end end
it "should validate a valid value string" do
r = Employee.new
r.birth_date = '2012-01-01'
r.valid?
r.errors[:birth_date].should be_empty
end
it "should validate a invalid value string" do
r = Employee.new
r.birth_date = 'not a date'
r.valid?
r.errors[:birth_date].should_not be_empty
end
it "should validate a nil value" do
r = Employee.new
r.birth_date = nil
r.valid?
r.errors[:birth_date].should be_empty
end
end end
it 'should determine type for attribute' do it 'should determine type for attribute' do
@@ -23,13 +47,26 @@ describe ValidatesTimeliness, 'ActiveRecord' do
context "attribute write method" do context "attribute write method" do
class EmployeeWithCache < ActiveRecord::Base class EmployeeWithCache < ActiveRecord::Base
set_table_name 'employees' set_table_name 'employees'
validates_datetime :birth_datetime validates_date :birth_date, :allow_blank => true
validates_datetime :birth_datetime, :allow_blank => true
end end
it 'should cache attribute raw value' do context 'value cache' do
r = EmployeeWithCache.new context 'for datetime column' do
r.birth_datetime = date_string = '2010-01-01' it 'should store raw value' do
r._timeliness_raw_value_for('birth_datetime').should == date_string r = EmployeeWithCache.new
r.birth_datetime = date_string = '2010-01-01'
r._timeliness_raw_value_for('birth_datetime').should == date_string
end
end
context 'for date column' do
it 'should store raw value' do
r = EmployeeWithCache.new
r.birth_date = date_string = '2010-01-01'
r._timeliness_raw_value_for('birth_date').should == date_string
end
end
end end
context "with plugin parser" do context "with plugin parser" do
@@ -37,8 +74,8 @@ describe ValidatesTimeliness, 'ActiveRecord' do
class EmployeeWithParser < ActiveRecord::Base class EmployeeWithParser < ActiveRecord::Base
set_table_name 'employees' set_table_name 'employees'
validates_date :birth_date validates_date :birth_date, :allow_blank => true
validates_datetime :birth_datetime validates_datetime :birth_datetime, :allow_blank => true
end end
it 'should parse a string value' do it 'should parse a string value' do
@@ -47,7 +84,13 @@ describe ValidatesTimeliness, 'ActiveRecord' do
r.birth_date = '2010-01-01' r.birth_date = '2010-01-01'
end end
context "for a date column", :active_record => '3.0' do it 'should parse a invalid string value as nil' do
Timeliness::Parser.should_receive(:parse)
r = EmployeeWithParser.new
r.birth_date = 'not a date'
end
context "for a date column" do
it 'should store a date value after parsing string' do it 'should store a date value after parsing string' do
r = EmployeeWithParser.new r = EmployeeWithParser.new
r.birth_date = '2010-01-01' r.birth_date = '2010-01-01'
@@ -77,10 +120,11 @@ describe ValidatesTimeliness, 'ActiveRecord' do
end end
end end
context "cached value" do context "reload" do
it 'should be cleared on reload' do it 'should clear cache value' do
r = Employee.create! r = Employee.create!
r.birth_date = '2010-01-01' r.birth_date = '2010-01-01'
r.reload r.reload
r._timeliness_raw_value_for('birth_date').should be_nil r._timeliness_raw_value_for('birth_date').should be_nil

View File

@@ -38,6 +38,30 @@ describe ValidatesTimeliness, 'Mongoid' do
Article.new.should respond_to(:validates_time) Article.new.should respond_to(:validates_time)
Article.new.should respond_to(:validates_datetime) Article.new.should respond_to(:validates_datetime)
end end
it "should validate a valid value string" do
r = Article.new
r.publish_date = '2012-01-01'
r.valid?
r.errors[:publish_date].should be_empty
end
it "should validate a invalid value string" do
r = Article.new
r.publish_date = 'not a date'
r.valid?
r.errors[:publish_date].should_not be_empty
end
it "should validate a nil value" do
r = Article.new
r.publish_date = nil
r.valid?
r.errors[:publish_date].should be_empty
end
end end
it 'should determine type for attribute' do it 'should determine type for attribute' do
@@ -48,7 +72,7 @@ describe ValidatesTimeliness, 'Mongoid' do
it 'should cache attribute raw value' do it 'should cache attribute raw value' do
r = Article.new r = Article.new
r.publish_datetime = date_string = '2010-01-01' r.publish_datetime = date_string = '2010-01-01'
r._timeliness_raw_value_for(:publish_datetime).should == date_string r._timeliness_raw_value_for('publish_datetime').should == date_string
end end
context "with plugin parser" do context "with plugin parser" do
@@ -95,7 +119,7 @@ describe ValidatesTimeliness, 'Mongoid' do
r = Article.create! r = Article.create!
r.publish_date = '2010-01-01' r.publish_date = '2010-01-01'
r.reload r.reload
r._timeliness_raw_value_for(:publish_date).should be_nil r._timeliness_raw_value_for('publish_date').should be_nil
end end
end end

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.4"]) s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.6"])
end end