From dcf69e509a9342f1c493303a8b0a4bee278e00b0 Mon Sep 17 00:00:00 2001 From: Marius Balteanu Date: Sun, 24 Oct 2021 09:57:56 +0000 Subject: Move custom DateValidator from @lib/redmine/core_ext/active_record.rb@ to @app/validators/date_validator.rb@ (#29914, #32938). git-svn-id: http://svn.redmine.org/redmine/trunk@21258 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .rubocop_todo.yml | 2 +- app/validators/date_validator.rb | 29 +++++++++++++++++++++++++++++ lib/redmine/core_ext/active_record.rb | 29 ----------------------------- 3 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 app/validators/date_validator.rb delete mode 100644 lib/redmine/core_ext/active_record.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 30009dcd6..5453038c1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1754,7 +1754,7 @@ Style/SoleNestedConditional: - 'app/models/watcher.rb' - 'app/models/wiki_page.rb' - 'app/models/wiki_annotate.rb' - - 'lib/redmine/core_ext/active_record.rb' + - 'app/validators/date_validator.rb' # Cop supports --auto-correct. # Configuration parameters: . diff --git a/app/validators/date_validator.rb b/app/validators/date_validator.rb new file mode 100644 index 000000000..df366b04f --- /dev/null +++ b/app/validators/date_validator.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2021 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 DateValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + before_type_cast = record.attributes_before_type_cast[attribute.to_s] + if before_type_cast.is_a?(String) && before_type_cast.present? + unless /\A\d{4}-\d{2}-\d{2}( 00:00:00)?\z/.match?(before_type_cast) && value + record.errors.add attribute, :not_a_date + end + end + end +end diff --git a/lib/redmine/core_ext/active_record.rb b/lib/redmine/core_ext/active_record.rb deleted file mode 100644 index df366b04f..000000000 --- a/lib/redmine/core_ext/active_record.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# Redmine - project management software -# Copyright (C) 2006-2021 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 DateValidator < ActiveModel::EachValidator - def validate_each(record, attribute, value) - before_type_cast = record.attributes_before_type_cast[attribute.to_s] - if before_type_cast.is_a?(String) && before_type_cast.present? - unless /\A\d{4}-\d{2}-\d{2}( 00:00:00)?\z/.match?(before_type_cast) && value - record.errors.add attribute, :not_a_date - end - end - end -end -- cgit v1.2.3