aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorAlberto Almagro <albertoalmagro@gmail.com>2018-10-06 18:08:45 +0200
committerAlberto Almagro <albertoalmagro@gmail.com>2018-10-10 10:22:07 +0200
commit9b9640112e197e94e13940c0c0f990cc80ca5498 (patch)
treed8b0bc06af5ce347742d8c7beb2cef8f820c572f /activerecord/test
parenta52c6989a0aacc50b35891265a0b5631e1ec2370 (diff)
downloadrails-9b9640112e197e94e13940c0c0f990cc80ca5498.tar.gz
rails-9b9640112e197e94e13940c0c0f990cc80ca5498.tar.bz2
rails-9b9640112e197e94e13940c0c0f990cc80ca5498.zip
Raise on invalid definition values
When defining a Hash enum it can be easy to use [] instead of {}. This commit checks that only valid definition values are provided, those can be a Hash, an array of Symbols or an array of Strings. Otherwise it raises an ArgumentError. Fixes #33961
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/enum_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb
index d5a1d11e12..b4593ccdf2 100644
--- a/activerecord/test/cases/enum_test.rb
+++ b/activerecord/test/cases/enum_test.rb
@@ -265,6 +265,17 @@ class EnumTest < ActiveRecord::TestCase
assert_equal "published", @book.status
end
+ test "invalid definition values raise an ArgumentError" do
+ e = assert_raises(ArgumentError) do
+ Class.new(ActiveRecord::Base) do
+ self.table_name = "books"
+ enum status: [proposed: 1, written: 2, published: 3]
+ end
+ end
+
+ assert_match(/must be either a hash, an array of symbols, or an array of strings./, e.message)
+ end
+
test "reserved enum names" do
klass = Class.new(ActiveRecord::Base) do
self.table_name = "books"