fix boolean casts
This commit is contained in:
parent
1dc3410a24
commit
46021b9351
|
@ -68,7 +68,11 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def type_cast_code(var_name)
|
||||
nil
|
||||
case type
|
||||
when :boolean then "#{self.class.name}.value_to_boolean(#{var_name})"
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -13,7 +13,7 @@ describe ActiveRecord::ConnectionAdapters::Mysql2Adapter do
|
|||
ActiveRecord::Base.establish_connection(:adapter => 'mysql2')
|
||||
}.should_not raise_error(Mysql2::Error)
|
||||
end
|
||||
|
||||
|
||||
context "once connected" do
|
||||
before(:each) do
|
||||
@connection = ActiveRecord::Base.connection
|
||||
|
@ -24,7 +24,7 @@ describe ActiveRecord::ConnectionAdapters::Mysql2Adapter do
|
|||
@connection.execute("SELECT NOW() as n").first['n'].class.should eql(Time)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "columns" do
|
||||
before(:all) do
|
||||
ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :database => 'test')
|
||||
|
@ -33,6 +33,7 @@ describe ActiveRecord::ConnectionAdapters::Mysql2Adapter do
|
|||
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
|
||||
`null_test` varchar(10) DEFAULT NULL,
|
||||
`bit_test` bit(64) NOT NULL DEFAULT b'1',
|
||||
`boolean_test` tinyint(1) DEFAULT 0,
|
||||
`tiny_int_test` tinyint(4) NOT NULL DEFAULT '1',
|
||||
`small_int_test` smallint(6) NOT NULL DEFAULT '1',
|
||||
`medium_int_test` mediumint(9) NOT NULL DEFAULT '1',
|
||||
|
@ -75,6 +76,7 @@ describe ActiveRecord::ConnectionAdapters::Mysql2Adapter do
|
|||
test = Mysql2Test2.new
|
||||
test.null_test.should be_nil
|
||||
test.bit_test.should eql("b'1'")
|
||||
test.boolean_test.should eql(false)
|
||||
test.tiny_int_test.should eql(1)
|
||||
test.small_int_test.should eql(1)
|
||||
test.medium_int_test.should eql(1)
|
||||
|
@ -103,6 +105,42 @@ describe ActiveRecord::ConnectionAdapters::Mysql2Adapter do
|
|||
test.long_blob_test.should be_nil
|
||||
test.enum_test.should eql('val1')
|
||||
test.set_test.should eql('val1,val2')
|
||||
test.save
|
||||
end
|
||||
|
||||
it "should have correct values when pulled from a db record" do
|
||||
test = Mysql2Test2.last
|
||||
test.null_test.should be_nil
|
||||
test.bit_test.class.should eql(String)
|
||||
test.boolean_test.should eql(false)
|
||||
test.tiny_int_test.should eql(1)
|
||||
test.small_int_test.should eql(1)
|
||||
test.medium_int_test.should eql(1)
|
||||
test.int_test.should eql(1)
|
||||
test.big_int_test.should eql(1)
|
||||
test.float_test.should eql('1.0000'.to_f)
|
||||
test.double_test.should eql('1.0000'.to_f)
|
||||
test.decimal_test.should eql(BigDecimal.new('1.0000'))
|
||||
test.date_test.should eql(Date.parse('2010-01-01'))
|
||||
test.date_time_test.should eql(Time.parse('2010-01-01 00:00:00'))
|
||||
test.timestamp_test.class.should eql(Time)
|
||||
test.time_test.class.should eql(Time)
|
||||
test.year_test.should eql(2010)
|
||||
test.char_test.should eql('abcdefghij')
|
||||
test.varchar_test.should eql('abcdefghij')
|
||||
test.binary_test.should eql('abcdefghij')
|
||||
test.varbinary_test.should eql('abcdefghij')
|
||||
test.tiny_blob_test.should eql("")
|
||||
test.tiny_text_test.should be_nil
|
||||
test.blob_test.should be_nil
|
||||
test.text_test.should be_nil
|
||||
test.medium_blob_test.should be_nil
|
||||
test.medium_text_test.should be_nil
|
||||
test.long_blob_test.should be_nil
|
||||
test.long_text_test.should be_nil
|
||||
test.long_blob_test.should be_nil
|
||||
test.enum_test.should eql('val1')
|
||||
test.set_test.should eql('val1,val2')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue