summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Balteanu <marius.balteanu@zitec.com>2024-01-23 11:52:38 +0000
committerMarius Balteanu <marius.balteanu@zitec.com>2024-01-23 11:52:38 +0000
commit13aeb797cfaa5a70bd8903d8350ea8ce3e0bb151 (patch)
tree51ae69c0c3837e531b8cef6fac455e06eea04d88
parent28061fbcdb2cabbef698db2ca3a80cc428388456 (diff)
downloadredmine-13aeb797cfaa5a70bd8903d8350ea8ce3e0bb151.tar.gz
redmine-13aeb797cfaa5a70bd8903d8350ea8ce3e0bb151.zip
Use ApplicationRecord instead of ActiveRecord::Base (#38975).
Patch by Minoru Maeda (@maeda-m). git-svn-id: https://svn.redmine.org/redmine/trunk@22619 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--.rubocop.yml4
-rw-r--r--.rubocop_todo.yml4
-rw-r--r--app/controllers/watchers_controller.rb2
-rw-r--r--app/models/application_record.rb32
-rw-r--r--app/models/attachment.rb2
-rw-r--r--app/models/auth_source.rb2
-rw-r--r--app/models/board.rb2
-rw-r--r--app/models/change.rb2
-rw-r--r--app/models/changeset.rb2
-rw-r--r--app/models/comment.rb2
-rw-r--r--app/models/custom_field.rb2
-rw-r--r--app/models/custom_field_enumeration.rb2
-rw-r--r--app/models/custom_value.rb2
-rw-r--r--app/models/document.rb2
-rw-r--r--app/models/email_address.rb2
-rw-r--r--app/models/enabled_module.rb2
-rw-r--r--app/models/enumeration.rb2
-rw-r--r--app/models/import.rb2
-rw-r--r--app/models/import_item.rb2
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/models/issue_category.rb2
-rw-r--r--app/models/issue_relation.rb2
-rw-r--r--app/models/issue_status.rb2
-rw-r--r--app/models/journal.rb2
-rw-r--r--app/models/journal_detail.rb2
-rw-r--r--app/models/member.rb2
-rw-r--r--app/models/member_role.rb2
-rw-r--r--app/models/message.rb2
-rw-r--r--app/models/news.rb2
-rw-r--r--app/models/principal.rb2
-rw-r--r--app/models/project.rb2
-rw-r--r--app/models/query.rb2
-rw-r--r--app/models/repository.rb2
-rw-r--r--app/models/role.rb2
-rw-r--r--app/models/setting.rb2
-rw-r--r--app/models/time_entry.rb2
-rw-r--r--app/models/token.rb2
-rw-r--r--app/models/tracker.rb2
-rw-r--r--app/models/user_preference.rb2
-rw-r--r--app/models/version.rb2
-rw-r--r--app/models/watcher.rb2
-rw-r--r--app/models/wiki.rb2
-rw-r--r--app/models/wiki_content.rb2
-rw-r--r--app/models/wiki_content_version.rb2
-rw-r--r--app/models/wiki_page.rb2
-rw-r--r--app/models/wiki_redirect.rb2
-rw-r--r--app/models/workflow_rule.rb2
-rw-r--r--config/initializers/10-patches.rb16
-rw-r--r--extra/sample_plugin/app/models/meeting.rb2
-rw-r--r--lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb2
-rw-r--r--lib/plugins/acts_as_activity_provider/init.rb4
-rw-r--r--lib/plugins/acts_as_attachable/init.rb4
-rw-r--r--lib/plugins/acts_as_customizable/init.rb4
-rw-r--r--lib/plugins/acts_as_event/init.rb4
-rw-r--r--lib/plugins/acts_as_searchable/init.rb4
-rw-r--r--lib/plugins/acts_as_tree/README2
-rw-r--r--lib/plugins/acts_as_tree/init.rb4
-rw-r--r--lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb2
-rw-r--r--lib/plugins/acts_as_tree/test/acts_as_tree_test.rb2
-rw-r--r--lib/plugins/acts_as_watchable/init.rb4
-rw-r--r--lib/plugins/gravatar/init.rb4
-rw-r--r--lib/redmine/preparation.rb6
-rw-r--r--test/unit/initializers/patches_test.rb12
63 files changed, 118 insertions, 86 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 4fae950f0..4dc78a911 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -129,6 +129,10 @@ Rails/ActiveSupportOnLoad:
# TODO: Need to check the impact on plugins. Disable for now.
- 'lib/redmine/preparation.rb'
+Rails/ApplicationRecord:
+ Exclude:
+ - 'db/migrate/0*.rb'
+
Rails/BulkChangeTable:
Exclude:
- 'db/migrate/20120714122200_add_workflows_rule_fields.rb'
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 93b0bbd21..1d45121c2 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -497,10 +497,6 @@ Rails/ApplicationMailer:
- 'app/models/mail_handler.rb'
- 'app/models/mailer.rb'
-# This cop supports unsafe autocorrection (--autocorrect-all).
-Rails/ApplicationRecord:
- Enabled: false
-
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Include.
# Include: **/test/**/*
diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb
index dbacb5c76..ae7d09e95 100644
--- a/app/controllers/watchers_controller.rb
+++ b/app/controllers/watchers_controller.rb
@@ -209,7 +209,7 @@ class WatchersController < ApplicationController
nil
end
return unless klass && Class === klass # rubocop:disable Style/CaseEquality
- return unless klass < ActiveRecord::Base
+ return unless klass < ApplicationRecord
return unless klass < Redmine::Acts::Watchable::InstanceMethods
scope = klass.where(:id => Array.wrap(params[:object_id]))
diff --git a/app/models/application_record.rb b/app/models/application_record.rb
new file mode 100644
index 000000000..3c89dc683
--- /dev/null
+++ b/app/models/application_record.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+# Redmine - project management software
+# Copyright (C) 2006-2023 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+class ApplicationRecord < ActiveRecord::Base
+ self.abstract_class = true
+
+ # Translate attribute names for validation errors display
+ def self.human_attribute_name(attr, options = {})
+ prepared_attr = attr.to_s.sub(/_id$/, '').sub(/^.+\./, '')
+ class_prefix = name.underscore.tr('/', '_')
+ redmine_default = [
+ :"field_#{class_prefix}_#{prepared_attr}",
+ :"field_#{prepared_attr}"
+ ]
+ options[:default] = redmine_default + Array(options[:default])
+ super
+ end
+end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 97dea32bd..b168f0729 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -21,7 +21,7 @@ require "digest"
require "fileutils"
require "zip"
-class Attachment < ActiveRecord::Base
+class Attachment < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :container, :polymorphic => true
belongs_to :author, :class_name => "User"
diff --git a/app/models/auth_source.rb b/app/models/auth_source.rb
index c871e30c6..9f444bb5a 100644
--- a/app/models/auth_source.rb
+++ b/app/models/auth_source.rb
@@ -22,7 +22,7 @@
class AuthSourceException < StandardError; end
class AuthSourceTimeoutException < AuthSourceException; end
-class AuthSource < ActiveRecord::Base
+class AuthSource < ApplicationRecord
include Redmine::SafeAttributes
include Redmine::SubclassFactory
include Redmine::Ciphering
diff --git a/app/models/board.rb b/app/models/board.rb
index 8cf16f559..e9cbf60eb 100644
--- a/app/models/board.rb
+++ b/app/models/board.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Board < ActiveRecord::Base
+class Board < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :project
has_many :messages, lambda {order("#{Message.table_name}.created_on DESC")}, :dependent => :destroy
diff --git a/app/models/change.rb b/app/models/change.rb
index f2eff4ea1..62d41e261 100644
--- a/app/models/change.rb
+++ b/app/models/change.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Change < ActiveRecord::Base
+class Change < ApplicationRecord
belongs_to :changeset
validates_presence_of :changeset_id, :action, :path
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 535335ef8..833d09d45 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Changeset < ActiveRecord::Base
+class Changeset < ApplicationRecord
belongs_to :repository
belongs_to :user
has_many :filechanges, :class_name => 'Change', :dependent => :delete_all
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 525a3a4ab..71856035d 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Comment < ActiveRecord::Base
+class Comment < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :commented, :polymorphic => true, :counter_cache => true
belongs_to :author, :class_name => 'User'
diff --git a/app/models/custom_field.rb b/app/models/custom_field.rb
index be9cf550f..fa9d5ab73 100644
--- a/app/models/custom_field.rb
+++ b/app/models/custom_field.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class CustomField < ActiveRecord::Base
+class CustomField < ApplicationRecord
include Redmine::SafeAttributes
include Redmine::SubclassFactory
diff --git a/app/models/custom_field_enumeration.rb b/app/models/custom_field_enumeration.rb
index 547d6a359..81c5fbe79 100644
--- a/app/models/custom_field_enumeration.rb
+++ b/app/models/custom_field_enumeration.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class CustomFieldEnumeration < ActiveRecord::Base
+class CustomFieldEnumeration < ApplicationRecord
belongs_to :custom_field
validates_presence_of :name, :position, :custom_field_id
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 9cfac3079..b90a05549 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class CustomValue < ActiveRecord::Base
+class CustomValue < ApplicationRecord
belongs_to :custom_field
belongs_to :customized, :polymorphic => true
diff --git a/app/models/document.rb b/app/models/document.rb
index 51cc8d837..c2fc75c66 100644
--- a/app/models/document.rb
+++ b/app/models/document.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Document < ActiveRecord::Base
+class Document < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :project
belongs_to :category, :class_name => "DocumentCategory"
diff --git a/app/models/email_address.rb b/app/models/email_address.rb
index cc9064e04..a62ac9cf9 100644
--- a/app/models/email_address.rb
+++ b/app/models/email_address.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class EmailAddress < ActiveRecord::Base
+class EmailAddress < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :user
diff --git a/app/models/enabled_module.rb b/app/models/enabled_module.rb
index 1b97903fb..17ca8a9f4 100644
--- a/app/models/enabled_module.rb
+++ b/app/models/enabled_module.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class EnabledModule < ActiveRecord::Base
+class EnabledModule < ApplicationRecord
belongs_to :project
acts_as_watchable
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index f2f63372a..b61711644 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Enumeration < ActiveRecord::Base
+class Enumeration < ApplicationRecord
include Redmine::SubclassFactory
default_scope lambda {order(:position)}
diff --git a/app/models/import.rb b/app/models/import.rb
index 8fcb769d3..91cc8cb0f 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -19,7 +19,7 @@
require 'csv'
-class Import < ActiveRecord::Base
+class Import < ApplicationRecord
has_many :items, :class_name => 'ImportItem', :dependent => :delete_all
belongs_to :user
serialize :settings
diff --git a/app/models/import_item.rb b/app/models/import_item.rb
index 5f0432e9b..2885cacd0 100644
--- a/app/models/import_item.rb
+++ b/app/models/import_item.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class ImportItem < ActiveRecord::Base
+class ImportItem < ApplicationRecord
belongs_to :import
validates_presence_of :import_id, :position
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 17802d227..670921eb0 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Issue < ActiveRecord::Base
+class Issue < ApplicationRecord
include Redmine::SafeAttributes
include Redmine::Utils::DateCalculation
include Redmine::I18n
diff --git a/app/models/issue_category.rb b/app/models/issue_category.rb
index eadb44891..d30af1705 100644
--- a/app/models/issue_category.rb
+++ b/app/models/issue_category.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class IssueCategory < ActiveRecord::Base
+class IssueCategory < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :project
belongs_to :assigned_to, :class_name => 'Principal'
diff --git a/app/models/issue_relation.rb b/app/models/issue_relation.rb
index 2caaca9ba..defd254fd 100644
--- a/app/models/issue_relation.rb
+++ b/app/models/issue_relation.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class IssueRelation < ActiveRecord::Base
+class IssueRelation < ApplicationRecord
# Class used to represent the relations of an issue
class Relations < Array
include Redmine::I18n
diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb
index a93bd5ddc..c8c8c14b1 100644
--- a/app/models/issue_status.rb
+++ b/app/models/issue_status.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class IssueStatus < ActiveRecord::Base
+class IssueStatus < ApplicationRecord
include Redmine::SafeAttributes
before_destroy :check_integrity
diff --git a/app/models/journal.rb b/app/models/journal.rb
index c19a63816..9bf12735e 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Journal < ActiveRecord::Base
+class Journal < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :journalized, :polymorphic => true
diff --git a/app/models/journal_detail.rb b/app/models/journal_detail.rb
index 08a38e026..5c4fb1dd2 100644
--- a/app/models/journal_detail.rb
+++ b/app/models/journal_detail.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class JournalDetail < ActiveRecord::Base
+class JournalDetail < ApplicationRecord
belongs_to :journal
def custom_field
diff --git a/app/models/member.rb b/app/models/member.rb
index 9e623d5f3..0ab9f564f 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Member < ActiveRecord::Base
+class Member < ApplicationRecord
belongs_to :user
belongs_to :principal, :foreign_key => 'user_id'
has_many :member_roles, :dependent => :destroy
diff --git a/app/models/member_role.rb b/app/models/member_role.rb
index a20531f94..cb228d05a 100644
--- a/app/models/member_role.rb
+++ b/app/models/member_role.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class MemberRole < ActiveRecord::Base
+class MemberRole < ApplicationRecord
belongs_to :member
belongs_to :role
diff --git a/app/models/message.rb b/app/models/message.rb
index 3f7ed285c..28aa6fe88 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Message < ActiveRecord::Base
+class Message < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :board
belongs_to :author, :class_name => 'User'
diff --git a/app/models/news.rb b/app/models/news.rb
index 8860d6c97..cbd7023ba 100644
--- a/app/models/news.rb
+++ b/app/models/news.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class News < ActiveRecord::Base
+class News < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :project
belongs_to :author, :class_name => 'User'
diff --git a/app/models/principal.rb b/app/models/principal.rb
index 25a79d768..1ef191796 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Principal < ActiveRecord::Base
+class Principal < ApplicationRecord
self.table_name = "#{table_name_prefix}users#{table_name_suffix}"
# Account statuses
diff --git a/app/models/project.rb b/app/models/project.rb
index 58346d373..d101bedd4 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Project < ActiveRecord::Base
+class Project < ApplicationRecord
include Redmine::SafeAttributes
include Redmine::NestedSet::ProjectNestedSet
diff --git a/app/models/query.rb b/app/models/query.rb
index 1826bd509..558cee23e 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -239,7 +239,7 @@ class QueryFilter
end
end
-class Query < ActiveRecord::Base
+class Query < ApplicationRecord
class StatementInvalid < ::ActiveRecord::StatementInvalid
end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 80142739d..9fb8206f6 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -19,7 +19,7 @@
class ScmFetchError < StandardError; end
-class Repository < ActiveRecord::Base
+class Repository < ApplicationRecord
include Redmine::Ciphering
include Redmine::SafeAttributes
diff --git a/app/models/role.rb b/app/models/role.rb
index 13ebb3324..e67a64554 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Role < ActiveRecord::Base
+class Role < ApplicationRecord
include Redmine::SafeAttributes
# Custom coder for the permissions attribute that should be an
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 8ee5b1f50..e649f2dea 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Setting < ActiveRecord::Base
+class Setting < ApplicationRecord
PASSWORD_CHAR_CLASSES = {
'uppercase' => /[A-Z]/,
'lowercase' => /[a-z]/,
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb
index 38504b774..66f5c5031 100644
--- a/app/models/time_entry.rb
+++ b/app/models/time_entry.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class TimeEntry < ActiveRecord::Base
+class TimeEntry < ApplicationRecord
include Redmine::SafeAttributes
# could have used polymorphic association
# project association here allows easy loading of time entries at project level with one database trip
diff --git a/app/models/token.rb b/app/models/token.rb
index 29340edba..efa8764f2 100644
--- a/app/models/token.rb
+++ b/app/models/token.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Token < ActiveRecord::Base
+class Token < ApplicationRecord
belongs_to :user
validates_uniqueness_of :value, :case_sensitive => true
diff --git a/app/models/tracker.rb b/app/models/tracker.rb
index ef2f48b04..df3d4814e 100644
--- a/app/models/tracker.rb
+++ b/app/models/tracker.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Tracker < ActiveRecord::Base
+class Tracker < ApplicationRecord
include Redmine::SafeAttributes
CORE_FIELDS_UNDISABLABLE = %w(project_id tracker_id subject is_private).freeze
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 21992f945..17eec682d 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -19,7 +19,7 @@
require 'redmine/my_page'
-class UserPreference < ActiveRecord::Base
+class UserPreference < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :user
diff --git a/app/models/version.rb b/app/models/version.rb
index 77228826c..1968cff42 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -108,7 +108,7 @@ module FixedIssuesExtension
end
end
-class Version < ActiveRecord::Base
+class Version < ApplicationRecord
include Redmine::SafeAttributes
after_update :update_issues_from_sharing_change
diff --git a/app/models/watcher.rb b/app/models/watcher.rb
index 9f1a09cf0..78a63f81c 100644
--- a/app/models/watcher.rb
+++ b/app/models/watcher.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Watcher < ActiveRecord::Base
+class Watcher < ApplicationRecord
belongs_to :watchable, :polymorphic => true
belongs_to :user, :class_name => 'Principal'
diff --git a/app/models/wiki.rb b/app/models/wiki.rb
index 0fddeb3a9..4d1770508 100644
--- a/app/models/wiki.rb
+++ b/app/models/wiki.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class Wiki < ActiveRecord::Base
+class Wiki < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :project
has_many :pages, lambda {order(Arel.sql('LOWER(title)').asc)}, :class_name => 'WikiPage', :dependent => :destroy
diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb
index d6a317a32..4ec4bb438 100644
--- a/app/models/wiki_content.rb
+++ b/app/models/wiki_content.rb
@@ -19,7 +19,7 @@
require 'zlib'
-class WikiContent < ActiveRecord::Base
+class WikiContent < ApplicationRecord
self.locking_column = 'version'
belongs_to :page, :class_name => 'WikiPage'
belongs_to :author, :class_name => 'User'
diff --git a/app/models/wiki_content_version.rb b/app/models/wiki_content_version.rb
index 85bd84fe7..bb7570806 100644
--- a/app/models/wiki_content_version.rb
+++ b/app/models/wiki_content_version.rb
@@ -19,7 +19,7 @@
require 'zlib'
-class WikiContentVersion < ActiveRecord::Base
+class WikiContentVersion < ApplicationRecord
belongs_to :page, :class_name => 'WikiPage'
belongs_to :author, :class_name => 'User'
diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb
index ea9d079e8..290ee7798 100644
--- a/app/models/wiki_page.rb
+++ b/app/models/wiki_page.rb
@@ -19,7 +19,7 @@
require 'redmine/string_array_diff/diff'
-class WikiPage < ActiveRecord::Base
+class WikiPage < ApplicationRecord
include Redmine::SafeAttributes
belongs_to :wiki
diff --git a/app/models/wiki_redirect.rb b/app/models/wiki_redirect.rb
index f338e20b0..564be06f2 100644
--- a/app/models/wiki_redirect.rb
+++ b/app/models/wiki_redirect.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class WikiRedirect < ActiveRecord::Base
+class WikiRedirect < ApplicationRecord
belongs_to :wiki
validates_presence_of :wiki_id, :title, :redirects_to
diff --git a/app/models/workflow_rule.rb b/app/models/workflow_rule.rb
index ec4e506c8..dd0a824d6 100644
--- a/app/models/workflow_rule.rb
+++ b/app/models/workflow_rule.rb
@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-class WorkflowRule < ActiveRecord::Base
+class WorkflowRule < ApplicationRecord
self.table_name = "#{table_name_prefix}workflows#{table_name_suffix}"
belongs_to :role
diff --git a/config/initializers/10-patches.rb b/config/initializers/10-patches.rb
index e9d15cae5..c298b9609 100644
--- a/config/initializers/10-patches.rb
+++ b/config/initializers/10-patches.rb
@@ -1,22 +1,6 @@
# frozen_string_literal: true
module ActiveRecord
- class Base
- # Translate attribute names for validation errors display
- def self.human_attribute_name(attr, options = {})
- prepared_attr = attr.to_s.delete_suffix('_id').sub(/^.+\./, '')
- class_prefix = name.underscore.tr('/', '_')
-
- redmine_default = [
- :"field_#{class_prefix}_#{prepared_attr}",
- :"field_#{prepared_attr}"
- ]
-
- options[:default] = redmine_default + Array(options[:default])
-
- super
- end
- end
# Undefines private Kernel#open method to allow using `open` scopes in models.
# See Defect #11545 (http://www.redmine.org/issues/11545) for details.
diff --git a/extra/sample_plugin/app/models/meeting.rb b/extra/sample_plugin/app/models/meeting.rb
index 78d801304..34310647c 100644
--- a/extra/sample_plugin/app/models/meeting.rb
+++ b/extra/sample_plugin/app/models/meeting.rb
@@ -1,4 +1,4 @@
-class Meeting < ActiveRecord::Base
+class Meeting < ApplicationRecord
belongs_to :project
acts_as_event :title => Proc.new {|o| "#{o.scheduled_on} Meeting"},
diff --git a/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb b/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
index 2715a7bbe..9fafbec77 100644
--- a/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
+++ b/lib/generators/redmine_plugin_model/redmine_plugin_model_generator.rb
@@ -63,6 +63,6 @@ class RedminePluginModelGenerator < Rails::Generators::NamedBase
end
def parent_class_name
- options[:parent] || "ActiveRecord::Base"
+ options[:parent] || "ApplicationRecord"
end
end
diff --git a/lib/plugins/acts_as_activity_provider/init.rb b/lib/plugins/acts_as_activity_provider/init.rb
index eaf15886d..47f23c5f1 100644
--- a/lib/plugins/acts_as_activity_provider/init.rb
+++ b/lib/plugins/acts_as_activity_provider/init.rb
@@ -18,4 +18,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_relative 'lib/acts_as_activity_provider'
-ActiveRecord::Base.send(:include, Redmine::Acts::ActivityProvider)
+Rails.application.reloader.to_prepare do
+ ApplicationRecord.send(:include, Redmine::Acts::ActivityProvider)
+end
diff --git a/lib/plugins/acts_as_attachable/init.rb b/lib/plugins/acts_as_attachable/init.rb
index e621b10ab..a19ae0595 100644
--- a/lib/plugins/acts_as_attachable/init.rb
+++ b/lib/plugins/acts_as_attachable/init.rb
@@ -18,4 +18,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_relative 'lib/acts_as_attachable'
-ActiveRecord::Base.send(:include, Redmine::Acts::Attachable)
+Rails.application.reloader.to_prepare do
+ ApplicationRecord.send(:include, Redmine::Acts::Attachable)
+end
diff --git a/lib/plugins/acts_as_customizable/init.rb b/lib/plugins/acts_as_customizable/init.rb
index 7a85ef160..27bdb2f84 100644
--- a/lib/plugins/acts_as_customizable/init.rb
+++ b/lib/plugins/acts_as_customizable/init.rb
@@ -18,4 +18,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_relative 'lib/acts_as_customizable'
-ActiveRecord::Base.send(:include, Redmine::Acts::Customizable)
+Rails.application.reloader.to_prepare do
+ ApplicationRecord.send(:include, Redmine::Acts::Customizable)
+end \ No newline at end of file
diff --git a/lib/plugins/acts_as_event/init.rb b/lib/plugins/acts_as_event/init.rb
index 2669f1cf1..2b4feb607 100644
--- a/lib/plugins/acts_as_event/init.rb
+++ b/lib/plugins/acts_as_event/init.rb
@@ -18,4 +18,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_relative 'lib/acts_as_event'
-ActiveRecord::Base.send(:include, Redmine::Acts::Event)
+Rails.application.reloader.to_prepare do
+ ApplicationRecord.send(:include, Redmine::Acts::Event)
+end \ No newline at end of file
diff --git a/lib/plugins/acts_as_searchable/init.rb b/lib/plugins/acts_as_searchable/init.rb
index a268122d8..18598688b 100644
--- a/lib/plugins/acts_as_searchable/init.rb
+++ b/lib/plugins/acts_as_searchable/init.rb
@@ -18,4 +18,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_relative 'lib/acts_as_searchable'
-ActiveRecord::Base.send(:include, Redmine::Acts::Searchable)
+Rails.application.reloader.to_prepare do
+ ApplicationRecord.send(:include, Redmine::Acts::Searchable)
+end
diff --git a/lib/plugins/acts_as_tree/README b/lib/plugins/acts_as_tree/README
index a6cc6a904..a10826ff5 100644
--- a/lib/plugins/acts_as_tree/README
+++ b/lib/plugins/acts_as_tree/README
@@ -4,7 +4,7 @@ acts_as_tree
Specify this +acts_as+ extension if you want to model a tree structure by providing a parent association and a children
association. This requires that you have a foreign key column, which by default is called +parent_id+.
- class Category < ActiveRecord::Base
+ class Category < ApplicationRecord
acts_as_tree :order => "name"
end
diff --git a/lib/plugins/acts_as_tree/init.rb b/lib/plugins/acts_as_tree/init.rb
index 36d1193d0..e7f63c70a 100644
--- a/lib/plugins/acts_as_tree/init.rb
+++ b/lib/plugins/acts_as_tree/init.rb
@@ -1,4 +1,6 @@
# frozen_string_literal: true
require_relative 'lib/active_record/acts/tree'
-ActiveRecord::Base.send :include, ActiveRecord::Acts::Tree
+Rails.application.reloader.to_prepare do
+ ApplicationRecord.send :include, ActiveRecord::Acts::Tree
+end
diff --git a/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb b/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb
index 14dce355a..831056d59 100644
--- a/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb
+++ b/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb
@@ -10,7 +10,7 @@ module ActiveRecord
# Specify this +acts_as+ extension if you want to model a tree structure by providing a parent association and a children
# association. This requires that you have a foreign key column, which by default is called +parent_id+.
#
- # class Category < ActiveRecord::Base
+ # class Category < ApplicationRecord
# acts_as_tree :order => "name"
# end
#
diff --git a/lib/plugins/acts_as_tree/test/acts_as_tree_test.rb b/lib/plugins/acts_as_tree/test/acts_as_tree_test.rb
index 94899f940..337411151 100644
--- a/lib/plugins/acts_as_tree/test/acts_as_tree_test.rb
+++ b/lib/plugins/acts_as_tree/test/acts_as_tree_test.rb
@@ -42,7 +42,7 @@ def teardown_db
end
end
-class Mixin < ActiveRecord::Base
+class Mixin < ApplicationRecord
end
class TreeMixin < Mixin
diff --git a/lib/plugins/acts_as_watchable/init.rb b/lib/plugins/acts_as_watchable/init.rb
index 6056987c7..565e27e1d 100644
--- a/lib/plugins/acts_as_watchable/init.rb
+++ b/lib/plugins/acts_as_watchable/init.rb
@@ -19,4 +19,6 @@
# Include hook code here
require_relative 'lib/acts_as_watchable'
-ActiveRecord::Base.send(:include, Redmine::Acts::Watchable)
+Rails.application.reloader.to_prepare do
+ ApplicationRecord.send(:include, Redmine::Acts::Watchable)
+end
diff --git a/lib/plugins/gravatar/init.rb b/lib/plugins/gravatar/init.rb
index a312000f5..648eeb282 100644
--- a/lib/plugins/gravatar/init.rb
+++ b/lib/plugins/gravatar/init.rb
@@ -1,4 +1,6 @@
# frozen_string_literal: true
require_relative 'lib/gravatar'
-ActionView::Base.send :include, GravatarHelper::PublicMethods
+Rails.application.reloader.to_prepare do
+ ApplicationRecord.send :include, GravatarHelper::PublicMethods
+end
diff --git a/lib/redmine/preparation.rb b/lib/redmine/preparation.rb
index 64333672a..3042eaa94 100644
--- a/lib/redmine/preparation.rb
+++ b/lib/redmine/preparation.rb
@@ -20,9 +20,9 @@
module Redmine
module Preparation
def self.prepare
- ActiveRecord::Base.include Redmine::Acts::Positioned
- ActiveRecord::Base.include Redmine::Acts::Mentionable
- ActiveRecord::Base.include Redmine::I18n
+ ApplicationRecord.include Redmine::Acts::Positioned
+ ApplicationRecord.include Redmine::Acts::Mentionable
+ ApplicationRecord.include Redmine::I18n
Scm::Base.add "Subversion"
Scm::Base.add "Mercurial"
diff --git a/test/unit/initializers/patches_test.rb b/test/unit/initializers/patches_test.rb
index 57eff0662..db1b60ca3 100644
--- a/test/unit/initializers/patches_test.rb
+++ b/test/unit/initializers/patches_test.rb
@@ -27,16 +27,16 @@ class PatchesTest < ActiveSupport::TestCase
Setting.default_language = 'en'
end
- test "ActiveRecord::Base.human_attribute_name should transform name to field_name" do
- assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on')
+ test "ApplicationRecord.human_attribute_name should transform name to field_name" do
+ assert_equal l('field_last_login_on'), ApplicationRecord.human_attribute_name('last_login_on')
end
- test "ActiveRecord::Base.human_attribute_name should cut extra _id suffix for better validation" do
- assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on_id')
+ test "ApplicationRecord.human_attribute_name should cut extra _id suffix for better validation" do
+ assert_equal l('field_last_login_on'), ApplicationRecord.human_attribute_name('last_login_on_id')
end
- test "ActiveRecord::Base.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do
- assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name')
+ test "ApplicationRecord.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do
+ assert_equal 'Patch name', ApplicationRecord.human_attribute_name('Patch name')
end
test 'ActionView::Helpers::FormHelper.date_field should add max=9999-12-31 to limit year value to 4 digits by default' do