mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-23 22:36:45 +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
|
||||
def self.setup
|
||||
yield self
|
||||
extend_orms.each {|orm| require "validates_timeliness/orms/#{orm}" }
|
||||
extend_orms.each {|orm| require "validates_timeliness/orm/#{orm}" }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -6,21 +6,26 @@ describe ValidatesTimeliness::AttributeMethods do
|
||||
end
|
||||
|
||||
context "attribute write method" do
|
||||
class EmployeeWithCache < ActiveRecord::Base
|
||||
set_table_name 'employees'
|
||||
class PersonWithCache
|
||||
include TestModel
|
||||
self.model_attributes = :birth_date, :birth_time, :birth_datetime
|
||||
validates_date :birth_date
|
||||
validates_time :birth_time
|
||||
validates_datetime :birth_datetime
|
||||
end
|
||||
|
||||
it 'should cache attribute raw value' do
|
||||
r = EmployeeWithCache.new
|
||||
r = PersonWithCache.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'
|
||||
class PersonWithParser
|
||||
include TestModel
|
||||
self.model_attributes = :birth_date, :birth_time, :birth_datetime
|
||||
validates_date :birth_date
|
||||
validates_time :birth_time
|
||||
validates_datetime :birth_datetime
|
||||
end
|
||||
|
||||
@ -30,12 +35,12 @@ describe ValidatesTimeliness::AttributeMethods do
|
||||
|
||||
it 'should parse a string value' do
|
||||
ValidatesTimeliness::Parser.should_receive(:parse)
|
||||
r = EmployeeWithParser.new
|
||||
r = PersonWithParser.new
|
||||
r.birth_date = '2010-01-01'
|
||||
end
|
||||
|
||||
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.zone == Time.zone.name
|
||||
end
|
||||
@ -47,18 +52,8 @@ describe ValidatesTimeliness::AttributeMethods do
|
||||
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 not be defined if ORM does not support it' do
|
||||
Person.instance_methods(false).should_not 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
|
||||
|
||||
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