mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 14:56:43 +00:00
seperate attribute method specs into orm specific file
move ORM shims to orm folder
This commit is contained in:
parent
bf57efaaa6
commit
48b42da85e
@ -42,7 +42,7 @@ module ValidatesTimeliness
|
|||||||
# Setup method for plugin configuration
|
# Setup method for plugin configuration
|
||||||
def self.setup
|
def self.setup
|
||||||
yield self
|
yield self
|
||||||
extend_orms.each {|orm| require "validates_timeliness/orms/#{orm}" }
|
extend_orms.each {|orm| require "validates_timeliness/orm/#{orm}" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -6,21 +6,26 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "attribute write method" do
|
context "attribute write method" do
|
||||||
class EmployeeWithCache < ActiveRecord::Base
|
class PersonWithCache
|
||||||
set_table_name 'employees'
|
include TestModel
|
||||||
|
self.model_attributes = :birth_date, :birth_time, :birth_datetime
|
||||||
|
validates_date :birth_date
|
||||||
|
validates_time :birth_time
|
||||||
validates_datetime :birth_datetime
|
validates_datetime :birth_datetime
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should cache attribute raw value' do
|
it 'should cache attribute raw value' do
|
||||||
r = EmployeeWithCache.new
|
r = PersonWithCache.new
|
||||||
r.birth_datetime = date_string = '2010-01-01'
|
r.birth_datetime = date_string = '2010-01-01'
|
||||||
r._timeliness_raw_value_for(:birth_datetime).should == date_string
|
r._timeliness_raw_value_for(:birth_datetime).should == date_string
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with plugin parser" do
|
context "with plugin parser" do
|
||||||
class EmployeeWithParser < ActiveRecord::Base
|
class PersonWithParser
|
||||||
set_table_name 'employees'
|
include TestModel
|
||||||
|
self.model_attributes = :birth_date, :birth_time, :birth_datetime
|
||||||
validates_date :birth_date
|
validates_date :birth_date
|
||||||
|
validates_time :birth_time
|
||||||
validates_datetime :birth_datetime
|
validates_datetime :birth_datetime
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -30,12 +35,12 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
|
|
||||||
it 'should parse a string value' do
|
it 'should parse a string value' do
|
||||||
ValidatesTimeliness::Parser.should_receive(:parse)
|
ValidatesTimeliness::Parser.should_receive(:parse)
|
||||||
r = EmployeeWithParser.new
|
r = PersonWithParser.new
|
||||||
r.birth_date = '2010-01-01'
|
r.birth_date = '2010-01-01'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should parse string as current timezone' do
|
it 'should parse string as current timezone' do
|
||||||
r = EmployeeWithParser.new
|
r = PersonWithParser.new
|
||||||
r.birth_datetime = '2010-01-01 12:00'
|
r.birth_datetime = '2010-01-01 12:00'
|
||||||
r.birth_datetime.zone == Time.zone.name
|
r.birth_datetime.zone == Time.zone.name
|
||||||
end
|
end
|
||||||
@ -47,18 +52,8 @@ describe ValidatesTimeliness::AttributeMethods do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "before_type_cast method" do
|
context "before_type_cast method" do
|
||||||
it 'should be defined on class if ORM supports it' do
|
|
||||||
Employee.instance_methods(false).should include("birth_datetime_before_type_cast")
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not be defined if ORM does not support it' do
|
it 'should not be defined if ORM does not support it' do
|
||||||
Person.instance_methods(false).should_not include("birth_datetime_before_type_cast")
|
Person.instance_methods(false).should_not include("birth_datetime_before_type_cast")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return original value' do
|
|
||||||
r = Employee.new
|
|
||||||
r.birth_datetime = date_string = '2010-01-01'
|
|
||||||
r.birth_datetime_before_type_cast.should == date_string
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
60
spec/validates_timeliness/orm/active_record_spec.rb
Normal file
60
spec/validates_timeliness/orm/active_record_spec.rb
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe ValidatesTimeliness, 'ActiveRecord' do
|
||||||
|
it 'should define _timeliness_raw_value_for instance method' do
|
||||||
|
Employee.instance_methods.should include('_timeliness_raw_value_for')
|
||||||
|
end
|
||||||
|
|
||||||
|
context "attribute write method" do
|
||||||
|
class EmployeeWithCache < ActiveRecord::Base
|
||||||
|
set_table_name 'employees'
|
||||||
|
validates_datetime :birth_datetime
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should cache attribute raw value' do
|
||||||
|
r = EmployeeWithCache.new
|
||||||
|
r.birth_datetime = date_string = '2010-01-01'
|
||||||
|
r._timeliness_raw_value_for(:birth_datetime).should == date_string
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with plugin parser" do
|
||||||
|
class EmployeeWithParser < ActiveRecord::Base
|
||||||
|
set_table_name 'employees'
|
||||||
|
validates_date :birth_date
|
||||||
|
validates_datetime :birth_datetime
|
||||||
|
end
|
||||||
|
|
||||||
|
before :all do
|
||||||
|
ValidatesTimeliness.use_plugin_parser = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse a string value' do
|
||||||
|
ValidatesTimeliness::Parser.should_receive(:parse)
|
||||||
|
r = EmployeeWithParser.new
|
||||||
|
r.birth_date = '2010-01-01'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should parse string as current timezone' do
|
||||||
|
r = EmployeeWithParser.new
|
||||||
|
r.birth_datetime = '2010-01-01 12:00'
|
||||||
|
r.birth_datetime.zone == Time.zone.name
|
||||||
|
end
|
||||||
|
|
||||||
|
after :all do
|
||||||
|
ValidatesTimeliness.use_plugin_parser = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "before_type_cast method" do
|
||||||
|
it 'should be defined on class if ORM supports it' do
|
||||||
|
Employee.instance_methods(false).should include("birth_datetime_before_type_cast")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return original value' do
|
||||||
|
r = Employee.new
|
||||||
|
r.birth_datetime = date_string = '2010-01-01'
|
||||||
|
r.birth_datetime_before_type_cast.should == date_string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user