[openstreetmap/openstreetmap-website] Added a validation to the Redaction model for the title. (#2034)

Tom Hughes notifications at github.com
Tue Nov 20 18:55:20 UTC 2018


tomhughes requested changes on this pull request.

In addition to the above it needs a test as @gravitystorm explained.

> @@ -0,0 +1,19 @@
+class NameUnnamedRedactions < ActiveRecord::Migration[5.0]
+  def self.up
+    Redaction.find_each do |redaction|
+        if redaction.title.empty?

Indentation should be the standard two spaces please.

> @@ -0,0 +1,19 @@
+class NameUnnamedRedactions < ActiveRecord::Migration[5.0]
+  def self.up
+    Redaction.find_each do |redaction|
+        if redaction.title.empty?
+            redaction.title = redaction.id.to_s
+            redaction.save!
+        end
+    end

After you fixed any blank titles you need to use `change_column` to add a "not null" constraint to it.

> @@ -0,0 +1,19 @@
+class NameUnnamedRedactions < ActiveRecord::Migration[5.0]
+  def self.up
+    Redaction.find_each do |redaction|
+        if redaction.title.empty?
+            redaction.title = redaction.id.to_s
+            redaction.save!
+        end
+    end
+  end
+
+  def self.down
+    Redaction.find_each do |redaction|

There's no need to change the titles back here, but you do need to remove the constraint with `change_column` here.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/2034#pullrequestreview-176922418
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20181120/fc10bb35/attachment.html>


More information about the rails-dev mailing list