From dad55456d5de5aee21357851df1378242a0bcfbe Mon Sep 17 00:00:00 2001 From: Adam Meehan Date: Fri, 5 Dec 2008 20:25:28 +1100 Subject: [PATCH] patched sqlite adapter in spec_helper to fix time attributes in rails 2.0.2 errorneously reporting time attributes as datetime column types --- .../multiparameter_attributes_spec.rb | 8 ++--- spec/spec_helper.rb | 29 ++++++++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/spec/active_record/multiparameter_attributes_spec.rb b/spec/active_record/multiparameter_attributes_spec.rb index 0c222d0..23b341b 100644 --- a/spec/active_record/multiparameter_attributes_spec.rb +++ b/spec/active_record/multiparameter_attributes_spec.rb @@ -39,11 +39,9 @@ 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 + 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 44c1f3e..57297aa 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,7 +16,11 @@ else require 'ginger' rescue LoadError end - gem 'rails' + 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'