From b63701e272f3dc932ba7a20127f6dc82b567cfb4 Mon Sep 17 00:00:00 2001
From: Sean Griffin <sean@seantheprogrammer.com>
Date: Tue, 30 Oct 2018 12:52:23 -0600
Subject: `update_columns` raises if the column is unknown

Previosly, `update_columns` would just take whatever keys you gave it
and tried to run the update query. Most likely this would result in an
error from the database. However, if the column actually did exist, but
was in `ignored_columns`, this would result in the method returning
successfully when it should have raised, and an attribute that should
not exist written to `@attributes`.
---
 activerecord/test/cases/attribute_methods_test.rb | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'activerecord/test')

diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 0bfd46a522..6c2e256447 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -310,6 +310,12 @@ class AttributeMethodsTest < ActiveRecord::TestCase
     assert_equal "New topic", topic.title
   end
 
+  test "write_attribute raises ActiveModel::MissingAttributeError when the attribute does not exist" do
+    topic = Topic.first
+    assert_raises(ActiveModel::MissingAttributeError) { topic.update_columns(no_column_exists: "Hello!") }
+    assert_raises(ActiveModel::UnknownAttributeError) { topic.update(no_column_exists: "Hello!") }
+  end
+
   test "read_attribute" do
     topic = Topic.new
     topic.title = "Don't change the topic"
-- 
cgit v1.2.3