Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

refactor: Move method closer to where it's used

Christophe Bliard8ab45d704454
diff --git a/app/seeders/basic_data/model_seeder.rb b/app/seeders/basic_data/model_seeder.rb
index 7db7835b7e7..11fb06a8be4 100644
--- a/app/seeders/basic_data/model_seeder.rb
+++ b/app/seeders/basic_data/model_seeder.rb
@@ -61,6 +61,12 @@ module BasicData
seed_data_model_key.humanize(capitalize: false)
end
+ # Casts `'false'`, `'no'`, `''`, and `nil` into `false`, and return `true`
+ # for other values.
+ def true?(value)
+ ActiveRecord::Type::Boolean.new.cast(value) || false
+ end
+
protected
def color_id(name)
diff --git a/app/seeders/seeder.rb b/app/seeders/seeder.rb
index 91bf25e2ac9..25a3428f84b 100644
--- a/app/seeders/seeder.rb
+++ b/app/seeders/seeder.rb
@@ -83,10 +83,6 @@ class Seeder
@admin_user ||= User.not_builtin.admin.first
end
- def true?(value)
- ActiveRecord::Type::Boolean.new.cast(value) || false
- end
-
protected
def print_status(message)
diff --git a/spec/seeders/basic_data/model_seeder_spec.rb b/spec/seeders/basic_data/model_seeder_spec.rb
new file mode 100644
index 00000000000..3819eb100e5
--- /dev/null
+++ b/spec/seeders/basic_data/model_seeder_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# 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.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+require 'spec_helper'
+
+RSpec.describe BasicData::ModelSeeder do
+ subject(:seeder) { described_class.new }
+
+ describe '#true?' do
+ {
+ 'true' => true,
+ 'false' => false,
+ '' => false,
+ nil => false
+ }.each do |value, expected|
+ it "returns #{expected} when value is #{value.inspect}" do
+ expect(seeder.true?(value)).to eq(expected)
+ end
+ end
+ end
+end
diff --git a/spec/seeders/seeder_spec.rb b/spec/seeders/seeder_spec.rb
index 1e25d3fb6ca..230aa3a4dd3 100644
--- a/spec/seeders/seeder_spec.rb
+++ b/spec/seeders/seeder_spec.rb
@@ -47,17 +47,4 @@ RSpec.describe Seeder do
expect(seeder.admin_user).to be_nil
end
end
-
- describe '#true?' do
- {
- 'true' => true,
- 'false' => false,
- '' => false,
- nil => false
- }.each do |value, expected|
- it "returns #{expected} when value is #{value.inspect}" do
- expect(seeder.true?(value)).to eq(expected)
- end
- end
- end
end