SPEC: ensure never remap readonly columns

SPEC: ensure never remap readonly columns

Follow-up to bfcbfd78

diff --git a/lib/db_helper.rb b/lib/db_helper.rb
index fced634..32ce37a 100644
--- a/lib/db_helper.rb
+++ b/lib/db_helper.rb
@@ -1,3 +1,5 @@
+require_dependency "migration/base_dropper"
+
 class DbHelper
 
   REMAP_SQL ||= <<~SQL
@@ -23,7 +25,7 @@ class DbHelper
     text_columns = Hash.new { |h, k| h[k] = [] }
 
     DB.query(REMAP_SQL).each do |r|
-      unless triggers.include?("#{r.table_name}_#{r.column_name}_readonly")
+      unless triggers.include?(Migration::BaseDropper.readonly_trigger_name(r.table_name, r.column_name))
         text_columns[r.table_name] << r.column_name
       end
     end
@@ -55,7 +57,7 @@ class DbHelper
     text_columns = Hash.new { |h, k| h[k] = [] }
 
     DB.query(REMAP_SQL).each do |r|
-      unless triggers.include?("#{r.table_name}_#{r.column_name}_readonly")
+      unless triggers.include?(Migration::BaseDropper.readonly_trigger_name(r.table_name, r.column_name))
         text_columns[r.table_name] << r.column_name
       end
     end
diff --git a/spec/lib/db_helper_spec.rb b/spec/lib/db_helper_spec.rb
index 3f9d98e..af834dc 100644
--- a/spec/lib/db_helper_spec.rb
+++ b/spec/lib/db_helper_spec.rb
@@ -2,6 +2,7 @@
 
 require 'rails_helper'
 require_dependency 'db_helper'
+require_dependency 'migration/column_dropper'
 
 RSpec.describe DbHelper do
   describe '.remap' do
@@ -42,6 +43,21 @@ RSpec.describe DbHelper do
 
       expect(post.reload.cooked).to eq('test')
     end
+
+    it "does not remap readonly columns" do
+      post = Fabricate(:post, raw: "This is a test", cooked: "This is a test")
+
+      Migration::ColumnDropper.mark_readonly("posts", "cooked")
+
+      DbHelper.remap("test", "something else")
+
+      post.reload
+
+      expect(post.raw).to eq("This is a something else")
+      expect(post.cooked).to eq("This is a test")
+
+      DB.exec "DROP FUNCTION #{Migration::BaseDropper.readonly_function_name("posts", "cooked")} CASCADE"
+    end
   end
 
   describe ".regexp_replace" do

GitHub sha: b5c8f5f9