aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/enum_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafael@franca.dev>2019-07-25 17:18:41 -0400
committerRafael Mendonça França <rafael@franca.dev>2019-07-25 17:18:41 -0400
commit579864f79ce1e7b9e4cae0518ddb65b5dd456b8c (patch)
treee1ad99c96749c66ccb94799c70e307b404247fb5 /activerecord/test/cases/enum_test.rb
parent59c6d29ffac990ab16e162d79aba12e13232a896 (diff)
parent77daacf94d7d26c713d4412b68edb64260fc22d9 (diff)
downloadrails-579864f79ce1e7b9e4cae0518ddb65b5dd456b8c.tar.gz
rails-579864f79ce1e7b9e4cae0518ddb65b5dd456b8c.tar.bz2
rails-579864f79ce1e7b9e4cae0518ddb65b5dd456b8c.zip
Merge pull request #36380 from edudepetris/ed/36272-better-negative-scope-warning
Add a warning for enum elements with 'not_' prefix.
Diffstat (limited to 'activerecord/test/cases/enum_test.rb')
-rw-r--r--activerecord/test/cases/enum_test.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb
index ae0ce195b3..8673a99c45 100644
--- a/activerecord/test/cases/enum_test.rb
+++ b/activerecord/test/cases/enum_test.rb
@@ -3,6 +3,7 @@
require "cases/helper"
require "models/author"
require "models/book"
+require "active_support/log_subscriber/test_helper"
class EnumTest < ActiveRecord::TestCase
fixtures :books, :authors, :author_addresses
@@ -565,4 +566,25 @@ class EnumTest < ActiveRecord::TestCase
assert_raises(NoMethodError) { klass.proposed }
end
+
+ test "enums with a negative condition log a warning" do
+ old_logger = ActiveRecord::Base.logger
+ logger = ActiveSupport::LogSubscriber::TestHelper::MockLogger.new
+
+ ActiveRecord::Base.logger = logger
+
+ expected_message = "An enum element in Book uses the prefix 'not_'."\
+ " This will cause a conflict with auto generated negative scopes."
+
+ Class.new(ActiveRecord::Base) do
+ def self.name
+ "Book"
+ end
+ enum status: [:sent, :not_sent]
+ end
+
+ assert_match(expected_message, logger.logged(:warn).first)
+ ensure
+ ActiveRecord::Base.logger = old_logger
+ end
end