aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/mysql2/boolean_test.rb
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2016-04-05 10:04:38 +0900
committeryui-knk <spiketeika@gmail.com>2016-04-05 10:04:38 +0900
commit72ecb9fc42fe0fe904b7c742036cdafa358c3cab (patch)
tree96f852a34d34324f8f9922a082aec9aa3a682c5c /activerecord/test/cases/adapters/mysql2/boolean_test.rb
parentbd49325e3ba9fba3bbea2d32b3e7a71ec1934c55 (diff)
downloadrails-72ecb9fc42fe0fe904b7c742036cdafa358c3cab.tar.gz
rails-72ecb9fc42fe0fe904b7c742036cdafa358c3cab.tar.bz2
rails-72ecb9fc42fe0fe904b7c742036cdafa358c3cab.zip
Use `QUOTED_TRUE` and `QUOTED_FALSE` instead of magic strings
Because we define `QUOTED_TRUE` as `"1"` and `QUOTED_FALSE` as `"0"`. And add test cases to ensure this commit does not break current behavior even if the value of `attributes_before_type_cast` is false.
Diffstat (limited to 'activerecord/test/cases/adapters/mysql2/boolean_test.rb')
-rw-r--r--activerecord/test/cases/adapters/mysql2/boolean_test.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/test/cases/adapters/mysql2/boolean_test.rb b/activerecord/test/cases/adapters/mysql2/boolean_test.rb
index 8575df9e43..739bb275ce 100644
--- a/activerecord/test/cases/adapters/mysql2/boolean_test.rb
+++ b/activerecord/test/cases/adapters/mysql2/boolean_test.rb
@@ -43,11 +43,16 @@ class Mysql2BooleanTest < ActiveRecord::Mysql2TestCase
boolean = BooleanType.create!(archived: true, published: true)
attributes = boolean.reload.attributes_before_type_cast
-
assert_equal 1, attributes["archived"]
assert_equal "1", attributes["published"]
+ boolean = BooleanType.create!(archived: false, published: false)
+ attributes = boolean.reload.attributes_before_type_cast
+ assert_equal 0, attributes["archived"]
+ assert_equal "0", attributes["published"]
+
assert_equal 1, @connection.type_cast(true)
+ assert_equal 0, @connection.type_cast(false)
end
test "test type casting without emulated booleans" do
@@ -55,11 +60,16 @@ class Mysql2BooleanTest < ActiveRecord::Mysql2TestCase
boolean = BooleanType.create!(archived: true, published: true)
attributes = boolean.reload.attributes_before_type_cast
-
assert_equal 1, attributes["archived"]
assert_equal "1", attributes["published"]
+ boolean = BooleanType.create!(archived: false, published: false)
+ attributes = boolean.reload.attributes_before_type_cast
+ assert_equal 0, attributes["archived"]
+ assert_equal "0", attributes["published"]
+
assert_equal 1, @connection.type_cast(true)
+ assert_equal 0, @connection.type_cast(false)
end
test "with booleans stored as 1 and 0" do