aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRich <jychen7@users.noreply.github.com>2018-08-20 01:18:28 +0800
committerRich <jychen7@users.noreply.github.com>2018-08-20 01:18:28 +0800
commitd510295b31dd6311f88e2eb2c76b12b1b0ab960a (patch)
tree0034ba687795625a7ca26892ac849848653ac227 /activerecord
parentfd1ec91c73ccfa1df71098a93cee76e9dd12a24b (diff)
downloadrails-d510295b31dd6311f88e2eb2c76b12b1b0ab960a.tar.gz
rails-d510295b31dd6311f88e2eb2c76b12b1b0ab960a.tar.bz2
rails-d510295b31dd6311f88e2eb2c76b12b1b0ab960a.zip
Improve test case to test enum correctly
without define the enum in class “SpecialBook”, any string status will be casted to integer 0. Then the test have no meaning. [Rich Chen]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index d7e898a1c0..9eea34d2b9 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -661,6 +661,8 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
self.table_name = "books"
belongs_to :author, class_name: "SpecialAuthor"
has_one :subscription, class_name: "SpecialSupscription", foreign_key: "subscriber_id"
+
+ enum status: [:proposed, :written, :published]
end
class SpecialAuthor < ActiveRecord::Base
@@ -678,6 +680,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
book = SpecialBook.create!(status: "published")
author.book = book
+ assert_equal "published", book.status
assert_not_equal 0, SpecialAuthor.joins(:book).where(books: { status: "published" }).count
end