aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-08-25 21:54:22 +0900
committerGitHub <noreply@github.com>2018-08-25 21:54:22 +0900
commit519d09cb99813c74d44d8cc7d97684a2fac386b1 (patch)
treed223153351cbc478e1f320e6d2bfd288f0bf0a1a /activerecord
parentb923beea6631df1d1f3fb0faeed0939d236b8afd (diff)
parenteed8b23318c03feb403498fcdea40edeee0532dc (diff)
downloadrails-519d09cb99813c74d44d8cc7d97684a2fac386b1.tar.gz
rails-519d09cb99813c74d44d8cc7d97684a2fac386b1.tar.bz2
rails-519d09cb99813c74d44d8cc7d97684a2fac386b1.zip
Merge pull request #33661 from jychen7/33428-test-has-many-association-enum
Add test case to test enum in has_many
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 5e6bea17ea..47b24a0b46 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -12,6 +12,7 @@ require "models/category"
require "models/image"
require "models/post"
require "models/author"
+require "models/book"
require "models/essay"
require "models/comment"
require "models/person"
@@ -377,6 +378,27 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal invoice.id, line_item.invoice_id
end
+ class SpecialAuthor < ActiveRecord::Base
+ self.table_name = "authors"
+ has_many :books, class_name: "SpecialBook", foreign_key: :author_id
+ end
+
+ class SpecialBook < ActiveRecord::Base
+ self.table_name = "books"
+
+ belongs_to :author
+ enum read_status: { unread: 0, reading: 2, read: 3, forgotten: nil }
+ end
+
+ def test_association_enum_works_properly
+ author = SpecialAuthor.create!(name: "Test")
+ book = SpecialBook.create!(read_status: "reading")
+ author.books << book
+
+ assert_equal "reading", book.read_status
+ assert_not_equal 0, SpecialAuthor.joins(:books).where(books: { read_status: "reading" }).count
+ end
+
# When creating objects on the association, we must not do it within a scope (even though it
# would be convenient), because this would cause that scope to be applied to any callbacks etc.
def test_build_and_create_should_not_happen_within_scope