From 10bb12e09f81dcc56f7a11342b841b9b7cf8d53e Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Tue, 28 Jan 2020 09:49:14 +0000 Subject: [PATCH] Fix 'DEPRECATION WARNING: Uniqueness validator will no longer enforce case sensitive comparison in Rails 6.1.' (#32897). Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@19478 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/auth_source.rb | 2 +- app/models/changeset.rb | 4 ++-- app/models/custom_field.rb | 2 +- app/models/enabled_module.rb | 2 +- app/models/enumeration.rb | 2 +- app/models/issue_category.rb | 2 +- app/models/issue_relation.rb | 2 +- app/models/issue_status.rb | 2 +- app/models/member.rb | 2 +- app/models/project.rb | 2 +- app/models/repository.rb | 2 +- app/models/role.rb | 2 +- app/models/setting.rb | 2 +- app/models/token.rb | 2 +- app/models/tracker.rb | 2 +- app/models/version.rb | 2 +- app/models/watcher.rb | 2 +- 17 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/models/auth_source.rb b/app/models/auth_source.rb index c8ec1f92f..e0368aed8 100644 --- a/app/models/auth_source.rb +++ b/app/models/auth_source.rb @@ -30,7 +30,7 @@ class AuthSource < ActiveRecord::Base has_many :users validates_presence_of :name - validates_uniqueness_of :name + validates_uniqueness_of :name, :case_sensitive => false validates_length_of :name, :maximum => 60 safe_attributes( diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 6a0b42df8..7e7615b4a 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -46,8 +46,8 @@ class Changeset < ActiveRecord::Base :scope => preload(:user, {:repository => :project}) validates_presence_of :repository_id, :revision, :committed_on, :commit_date - validates_uniqueness_of :revision, :scope => :repository_id - validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true + validates_uniqueness_of :revision, :scope => :repository_id, :case_sensitive => false + validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true, :case_sensitive => false scope :visible, lambda {|*args| joins(:repository => :project). diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb index 1802702bd..5fee33bdd 100644 --- a/app/models/custom_field.rb +++ b/app/models/custom_field.rb @@ -32,7 +32,7 @@ class CustomField < ActiveRecord::Base store :format_store validates_presence_of :name, :field_format - validates_uniqueness_of :name, :scope => :type + validates_uniqueness_of :name, :scope => :type, :case_sensitive => false validates_length_of :name, :maximum => 30 validates_length_of :regexp, maximum: 255 validates_inclusion_of :field_format, :in => Proc.new { Redmine::FieldFormat.available_formats } diff --git a/app/models/enabled_module.rb b/app/models/enabled_module.rb index c66377682..f2cfa60d8 100644 --- a/app/models/enabled_module.rb +++ b/app/models/enabled_module.rb @@ -22,7 +22,7 @@ class EnabledModule < ActiveRecord::Base acts_as_watchable validates_presence_of :name - validates_uniqueness_of :name, :scope => :project_id + validates_uniqueness_of :name, :scope => :project_id, :case_sensitive => false after_create :module_enabled diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb index 70dda077b..6a3f16a02 100644 --- a/app/models/enumeration.rb +++ b/app/models/enumeration.rb @@ -32,7 +32,7 @@ class Enumeration < ActiveRecord::Base before_save :check_default validates_presence_of :name - validates_uniqueness_of :name, :scope => [:type, :project_id] + validates_uniqueness_of :name, :scope => [:type, :project_id], :case_sensitive => false validates_length_of :name, :maximum => 30 scope :shared, lambda { where(:project_id => nil) } diff --git a/app/models/issue_category.rb b/app/models/issue_category.rb index c6ac0aea2..e117222ed 100644 --- a/app/models/issue_category.rb +++ b/app/models/issue_category.rb @@ -24,7 +24,7 @@ class IssueCategory < ActiveRecord::Base has_many :issues, :foreign_key => 'category_id', :dependent => :nullify validates_presence_of :name - validates_uniqueness_of :name, :scope => [:project_id] + validates_uniqueness_of :name, :scope => [:project_id], :case_sensitive => false validates_length_of :name, :maximum => 60 safe_attributes 'name', 'assigned_to_id' diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb index 284f0052a..07354680b 100644 --- a/app/models/issue_relation.rb +++ b/app/models/issue_relation.rb @@ -72,7 +72,7 @@ class IssueRelation < ActiveRecord::Base validates_presence_of :issue_from, :issue_to, :relation_type validates_inclusion_of :relation_type, :in => TYPES.keys validates_numericality_of :delay, :allow_nil => true - validates_uniqueness_of :issue_to_id, :scope => :issue_from_id + validates_uniqueness_of :issue_to_id, :scope => :issue_from_id, :case_sensitive => false validate :validate_issue_relation before_save :handle_issue_order diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index c94f1006f..f07c13cf2 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -29,7 +29,7 @@ class IssueStatus < ActiveRecord::Base before_destroy :delete_workflow_rules validates_presence_of :name - validates_uniqueness_of :name + validates_uniqueness_of :name, :case_sensitive => false validates_length_of :name, :maximum => 30 validates_inclusion_of :default_done_ratio, :in => 0..100, :allow_nil => true diff --git a/app/models/member.rb b/app/models/member.rb index ad049a7d4..f03ede2d1 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -25,7 +25,7 @@ class Member < ActiveRecord::Base belongs_to :project validates_presence_of :principal, :project - validates_uniqueness_of :user_id, :scope => :project_id + validates_uniqueness_of :user_id, :scope => :project_id, :case_sensitive => false validate :validate_role before_destroy :set_issue_category_nil, :remove_from_project_default_assigned_to diff --git a/app/models/project.rb b/app/models/project.rb index baeeb8e3e..79d230f6b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -70,7 +70,7 @@ class Project < ActiveRecord::Base :author => nil validates_presence_of :name, :identifier - validates_uniqueness_of :identifier, :if => Proc.new {|p| p.identifier_changed?} + validates_uniqueness_of :identifier, :if => Proc.new {|p| p.identifier_changed?}, :case_sensitive => false validates_length_of :name, :maximum => 255 validates_length_of :homepage, :maximum => 255 validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH diff --git a/app/models/repository.rb b/app/models/repository.rb index 089027c9d..f20eacc20 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -43,7 +43,7 @@ class Repository < ActiveRecord::Base validates_length_of :password, :maximum => 255, :allow_nil => true validates_length_of :root_url, :url, maximum: 255 validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true - validates_uniqueness_of :identifier, :scope => :project_id + validates_uniqueness_of :identifier, :scope => :project_id, :case_sensitive => false validates_exclusion_of :identifier, :in => %w(browse show entry raw changes annotate diff statistics graph revisions revision) # donwcase letters, digits, dashes, underscores but not digits only validates_format_of :identifier, :with => /\A(?!\d+$)[a-z0-9\-_]*\z/, :allow_blank => true diff --git a/app/models/role.rb b/app/models/role.rb index 5c4795c42..f49a3e337 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -76,7 +76,7 @@ class Role < ActiveRecord::Base store :settings, :accessors => [:permissions_all_trackers, :permissions_tracker_ids] validates_presence_of :name - validates_uniqueness_of :name + validates_uniqueness_of :name, :case_sensitive => false validates_length_of :name, :maximum => 255 validates_inclusion_of( :issues_visibility, diff --git a/app/models/setting.rb b/app/models/setting.rb index 503ee1d3f..03fcb8ef0 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -85,7 +85,7 @@ class Setting < ActiveRecord::Base cattr_accessor :available_settings self.available_settings ||= {} - validates_uniqueness_of :name, :if => Proc.new {|setting| setting.new_record? || setting.name_changed?} + validates_uniqueness_of :name, :case_sensitive => false, :if => Proc.new {|setting| setting.new_record? || setting.name_changed?} validates_inclusion_of :name, :in => Proc.new {available_settings.keys} validates_numericality_of :value, :only_integer => true, :if => Proc.new { |setting| (s = available_settings[setting.name]) && s['format'] == 'int' diff --git a/app/models/token.rb b/app/models/token.rb index 8e93918ec..91806f609 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -19,7 +19,7 @@ class Token < ActiveRecord::Base belongs_to :user - validates_uniqueness_of :value + validates_uniqueness_of :value, :case_sensitive => false before_create :delete_previous_tokens, :generate_new_token diff --git a/app/models/tracker.rb b/app/models/tracker.rb index a3357866d..5785f47bd 100644 --- a/app/models/tracker.rb +++ b/app/models/tracker.rb @@ -36,7 +36,7 @@ class Tracker < ActiveRecord::Base validates_presence_of :default_status validates_presence_of :name - validates_uniqueness_of :name + validates_uniqueness_of :name, :case_sensitive => false validates_length_of :name, :maximum => 30 validates_length_of :description, :maximum => 255 diff --git a/app/models/version.rb b/app/models/version.rb index ef8d1dc59..e97d1484d 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -127,7 +127,7 @@ class Version < ActiveRecord::Base VERSION_SHARINGS = %w(none descendants hierarchy tree system) validates_presence_of :name - validates_uniqueness_of :name, :scope => [:project_id] + validates_uniqueness_of :name, :scope => [:project_id], :case_sensitive => false validates_length_of :name, :maximum => 60 validates_length_of :description, :wiki_page_title, :maximum => 255 validates :effective_date, :date => true diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 8ea457060..c17ceae7b 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -22,7 +22,7 @@ class Watcher < ActiveRecord::Base belongs_to :user validates_presence_of :user - validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id] + validates_uniqueness_of :user_id, :scope => [:watchable_type, :watchable_id], :case_sensitive => false validate :validate_user # Returns true if at least one object among objects is watched by user -- 2.39.5