]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/relation.rb
Rubocop fixes for ruby 2.5
[rails.git] / app / models / relation.rb
index b17a3b604674abe85e166aeb8da09d34e9fecfc9..f55711a69bb75b060ae7a0ec61a120afbf852657 100644 (file)
@@ -260,7 +260,7 @@ class Relation < ActiveRecord::Base
       element = model.lock("for share").find_by(:id => m[1])
 
       # and check that it is OK to use.
       element = model.lock("for share").find_by(:id => m[1])
 
       # and check that it is OK to use.
-      raise OSM::APIPreconditionFailedError, "Relation with id #{id} cannot be saved due to #{m[0]} with id #{m[1]}" unless element && element.visible? && element.preconditions_ok?
+      raise OSM::APIPreconditionFailedError, "Relation with id #{id} cannot be saved due to #{m[0]} with id #{m[1]}" unless element&.visible? && element&.preconditions_ok?
 
       hash[m[1]] = true
     end
 
       hash[m[1]] = true
     end
@@ -275,7 +275,7 @@ class Relation < ActiveRecord::Base
   def fix_placeholders!(id_map, placeholder_id = nil)
     members.map! do |type, id, role|
       old_id = id.to_i
   def fix_placeholders!(id_map, placeholder_id = nil)
     members.map! do |type, id, role|
       old_id = id.to_i
-      if old_id < 0
+      if old_id.negative?
         new_id = id_map[type.downcase.to_sym][old_id]
         raise OSM::APIBadUserInput, "Placeholder #{type} not found for reference #{old_id} in relation #{self.id.nil? ? placeholder_id : self.id}." if new_id.nil?
 
         new_id = id_map[type.downcase.to_sym][old_id]
         raise OSM::APIBadUserInput, "Placeholder #{type} not found for reference #{old_id} in relation #{self.id.nil? ? placeholder_id : self.id}." if new_id.nil?
 
@@ -381,10 +381,12 @@ class Relation < ActiveRecord::Base
       # reasonable on the assumption that adding or removing members doesn't
       # materially change the rest of the relation.
       any_relations =
       # reasonable on the assumption that adding or removing members doesn't
       # materially change the rest of the relation.
       any_relations =
-        changed_members.collect { |_id, type| type == "relation" }
+        changed_members.collect { |type, _id, _role| type == "Relation" }
                        .inject(false) { |acc, elem| acc || elem }
 
                        .inject(false) { |acc, elem| acc || elem }
 
-      update_members = if tags_changed || any_relations
+      # if the relation is being deleted tags_changed will be true and members empty
+      # so we need to use changed_members to create a correct bounding box
+      update_members = if visible && (tags_changed || any_relations)
                          # add all non-relation bounding boxes to the changeset
                          # FIXME: check for tag changes along with element deletions and
                          # make sure that the deleted element's bounding box is hit.
                          # add all non-relation bounding boxes to the changeset
                          # FIXME: check for tag changes along with element deletions and
                          # make sure that the deleted element's bounding box is hit.