adds module for rails 2.0.x to add reader method for date checking

includes right module based on AR version
better vendored rails check in spec_helper
This commit is contained in:
Adam Meehan
2008-05-03 13:03:01 +10:00
parent 3cf6e64747
commit 8751eddac6
3 changed files with 86 additions and 83 deletions

View File

@@ -4,18 +4,8 @@ describe ValidatesTimeliness::AttributeMethods do
describe "for Time columns" do
before do
Person.define_read_method_for_time_zone_conversion(:birth_date_and_time)
Person.define_write_method_for_time_zone_conversion(:birth_date_and_time)
@person = Person.new
end
it "should define attribute read method for column" do
@person.respond_to?(:birth_date_and_time).should be_true
end
it "should define attribute write method for column" do
@person.respond_to?(:birth_date_and_time=).should be_true
end
it "should return string value for attribute_before_type_cast when written as string" do
@person.birth_date_and_time = "1980-12-25 01:02:03"
@@ -30,62 +20,20 @@ describe ValidatesTimeliness::AttributeMethods do
it "should return Time object using attribute read method when written with string" do
@person.birth_date_and_time = "1980-12-25 01:02:03"
@person.birth_date_and_time.should be_kind_of(Time)
end
if ActiveRecord::VERSION::STRING < '2.1'
it "should return stored time string as Time with correct timezone" do
@person.birth_date_and_time = "1980-12-25 01:02:03"
@person.birth_date_and_time.zone == 'EST'
ActiveRecord::Base.default_timezone = :utc
@person.birth_date_and_time.zone == 'UTC'
end
end
unless ActiveRecord::VERSION::STRING < '2.1'
it "should return stored time string as Time with correct timezone" do
Time.zone = TimeZone['Sydney'] # no I'm not from Sydney but there is no Melbourne timezone!
@person.birth_date_and_time = "1980-12-25 01:02:03"
@person.birth_date_and_time.zone == Time.zone
end
end
end
it "should return nil when time is invalid" do
@person.birth_date_and_time = "1980-02-30 01:02:03"
@person.birth_date_and_time.should be_nil
end
end
describe "for Date columns" do
before do
@person = Person.new
end
end
it "should define attribute read method for column" do
@person.respond_to?(:birth_date).should be_true
end
it "should define attribute write method for column" do
@person.respond_to?(:birth_date=).should be_true
end
it "should return string value for attribute_before_type_cast when written as string" do
@person.birth_date = "1980-12-25"
@person.birth_date_before_type_cast.should == "1980-12-25"
end
it "should return Date object for attribute_before_type_cast when written as Date" do
@person.birth_date = date = Date.new(1980, 12, 25)
@person.birth_date_before_type_cast.should be_kind_of(Date)
end
it "should return Date object using attribute read method when written with string" do
@person.birth_date = "1980-12-25"
@person.birth_date.should be_kind_of(Date)
end
it "should read stored time with correct timezone"
it "should return nil when date is invalid"
end
end
end

View File

@@ -3,11 +3,12 @@ $: << File.dirname(__FILE__) + '/../lib' << File.dirname(__FILE__)
require 'rubygems'
require 'spec'
if File.exists?(File.dirname(__FILE__) + '/../../../rails')
$: << File.dirname(__FILE__) + '/../../../rails'
require 'activerecord/lib/active_record'
require 'activerecord/lib/active_record/version'
puts "Using vendor ActiveRecord version #{ActiveRecord::VERSION::STRING}"
if File.exists?(File.dirname(__FILE__) + '/../../../../vendor/rails')
$: << File.dirname(__FILE__) + '/../../../../vendor/rails'
require 'activesupport/lib/active_support'
require 'activerecord/lib/active_record'
require 'activerecord/lib/active_record/version'
puts "Using vendored ActiveRecord version #{ActiveRecord::VERSION::STRING}"
else
require 'active_record'
require 'active_record/version'
@@ -16,12 +17,7 @@ end
require 'validates_timeliness'
conn = {
:adapter => 'sqlite3',
:database => ':memory:'
}
ActiveRecord::Base.establish_connection(conn)
ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'})
require 'resources/schema'
require 'resources/person'