patched sqlite adapter in spec_helper to fix time attributes in rails 2.0.2 errorneously reporting time attributes as datetime column types

This commit is contained in:
Adam Meehan 2008-12-05 20:25:28 +11:00
parent 87b0beef5a
commit dad55456d5
2 changed files with 31 additions and 6 deletions

View File

@ -39,12 +39,10 @@ describe ValidatesTimeliness::ActiveRecord::MultiparameterAttributes do
obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
end
unless RAILS_VER < '2.1' # sqlite doesn't support :time attribute in rails 2.0.x
it "should store time string for a time column" do
obj.should_receive(:birth_time=).once.with("09:10:11")
obj.send(:execute_callstack_for_multiparameter_attributes, @callstack)
end
end
end
end

View File

@ -16,8 +16,12 @@ else
require 'ginger'
rescue LoadError
end
if ENV['VERSION']
gem 'rails', ENV['VERSION']
else
gem 'rails'
end
end
RAILS_ROOT = File.dirname(__FILE__)
@ -41,8 +45,31 @@ if RAILS_VER >= '2.1'
ActiveRecord::Base.time_zone_aware_attributes = true
end
ActiveRecord::Migration.verbose = false
ActiveRecord::Base.establish_connection({:adapter => 'sqlite3', :database => ':memory:'})
# patches adapter in rails 2.0 which mistakenly made time attributes map to datetime column typs
if RAILS_VER < '2.1'
ActiveRecord::ConnectionAdapters::SQLiteAdapter.class_eval do
def native_database_types #:nodoc:
{
:primary_key => default_primary_key_type,
:string => { :name => "varchar", :limit => 255 },
:text => { :name => "text" },
:integer => { :name => "integer" },
:float => { :name => "float" },
:decimal => { :name => "decimal" },
:datetime => { :name => "datetime" },
:timestamp => { :name => "datetime" },
:time => { :name => "time" },
:date => { :name => "date" },
:binary => { :name => "blob" },
:boolean => { :name => "boolean" }
}
end
end
end
require 'schema'
require 'person'