diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-29 11:23:07 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-29 11:23:07 -0300 |
commit | 4a3f71b6fb07f5bbf9e43b259a7429c96752e00b (patch) | |
tree | 0e9bbf31ebd8aa0e11a64d826bdc275291275010 /activerecord/test/cases/adapters | |
parent | 29f8eae3faf96cbe46e7eb949c7f674c5860c1cf (diff) | |
parent | 8eb536e7b487351d7485879d436e9d747520ed90 (diff) | |
download | rails-4a3f71b6fb07f5bbf9e43b259a7429c96752e00b.tar.gz rails-4a3f71b6fb07f5bbf9e43b259a7429c96752e00b.tar.bz2 rails-4a3f71b6fb07f5bbf9e43b259a7429c96752e00b.zip |
Merge pull request #15406 from sgrif/sg-column-type-override
Result sets never override a model's column type
Diffstat (limited to 'activerecord/test/cases/adapters')
-rw-r--r-- | activerecord/test/cases/adapters/mysql/consistency_test.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/mysql/consistency_test.rb b/activerecord/test/cases/adapters/mysql/consistency_test.rb new file mode 100644 index 0000000000..083d533bb2 --- /dev/null +++ b/activerecord/test/cases/adapters/mysql/consistency_test.rb @@ -0,0 +1,48 @@ +require "cases/helper" + +class MysqlConsistencyTest < ActiveRecord::TestCase + self.use_transactional_fixtures = false + + class Consistency < ActiveRecord::Base + self.table_name = "mysql_consistency" + end + + setup do + @old_emulate_booleans = ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans + ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = false + + @connection = ActiveRecord::Base.connection + @connection.create_table("mysql_consistency") do |t| + t.boolean "a_bool" + t.string "a_string" + end + Consistency.reset_column_information + Consistency.create! + end + + teardown do + ActiveRecord::ConnectionAdapters::MysqlAdapter.emulate_booleans = @old_emulate_booleans + @connection.drop_table "mysql_consistency" + end + + test "boolean columns with random value type cast to 0 when emulate_booleans is false" do + with_new = Consistency.new + with_last = Consistency.last + with_new.a_bool = 'wibble' + with_last.a_bool = 'wibble' + + assert_equal 0, with_new.a_bool + assert_equal 0, with_last.a_bool + end + + test "string columns call #to_s" do + with_new = Consistency.new + with_last = Consistency.last + thing = Object.new + with_new.a_string = thing + with_last.a_string = thing + + assert_equal thing.to_s, with_new.a_string + assert_equal thing.to_s, with_last.a_string + end +end |