File obs-server-2.10-0107-Fix-validation-and-association-deprecations-for-rail.patch of Package obs-server

From eb459ed49125f46dc1e7d148b9ed79bb89dfc52c Mon Sep 17 00:00:00 2001
From: Lukas Krause <lkrause@suse.de>
Date: Wed, 12 Feb 2020 16:38:41 +0100
Subject: [PATCH] Fix validation and association deprecations for rails 6.0
 upgrade

A few things let to a broken development setup, since a
couple of the seeds couldn't sucessfully insert new entries to
the database

* the uniqueness validator will no longer enforce case sensitive comparison
  in Rails 6.1.
* since Rails 5 a belongs_to association requires to have the associated
  record to be present. This should be refactored in the future,but for
  now we can keep the old behaviour by setting 'belongs_to_required_by_default'
  to false in the application.rb.
---
 src/api/app/models/role.rb                            | 4 ++--
 src/api/config/application.rb                         | 2 ++
 src/api/config/initializers/new_framework_defaults.rb | 3 ---
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/api/app/models/role.rb b/src/api/app/models/role.rb
index 5d334a4f91..6bd7a64f98 100644
--- a/src/api/app/models/role.rb
+++ b/src/api/app/models/role.rb
@@ -22,8 +22,8 @@ class Role < ApplicationRecord
                       allow_nil: false }
 
   # We want to validate a role's title pretty thoroughly.
-  validates :title,
-            uniqueness: { message: 'is the name of an already existing role' }
+  validates :title, uniqueness: { case_sensitive: true,
+                                  message: 'is the name of an already existing role' }
 
   belongs_to :groups_roles
   belongs_to :attrib_type_modifiable_bies
diff --git a/src/api/config/application.rb b/src/api/config/application.rb
index 084a2811fd..113d07ea01 100644
--- a/src/api/config/application.rb
+++ b/src/api/config/application.rb
@@ -24,6 +24,8 @@ module OBSApi
     config.load_defaults(6.0)
     # For now, use the classic/oldway for code loading in rails instead of zeitwerk
     config.autoloader = :classic
+    # Require `belongs_to` associations by default. Previous versions had false.
+    config.active_record.belongs_to_required_by_default = false
 
     # Custom directories with classes and modules you want to be autoloadable.
     # config.autoload_paths += %W(#{config.root}/extras)
diff --git a/src/api/config/initializers/new_framework_defaults.rb b/src/api/config/initializers/new_framework_defaults.rb
index 2cb708e72a..8d8a6d4df8 100644
--- a/src/api/config/initializers/new_framework_defaults.rb
+++ b/src/api/config/initializers/new_framework_defaults.rb
@@ -15,6 +15,3 @@ Rails.application.config.action_controller.forgery_protection_origin_check = fal
 # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`.
 # Previous versions had false.
 ActiveSupport.to_time_preserves_timezone = false
-
-# Require `belongs_to` associations by default. Previous versions had false.
-Rails.application.config.active_record.belongs_to_required_by_default = false
-- 
2.31.1