mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
034aca557d
https://community.openproject.org/wp/64711 When seeding a second time in a different language, it was failing with the error "ArgumentError: Nothing registered with reference :default_color_blue (ArgumentError)". Here is why: the type seeder, as some types are already in the database, will try to look up existing types by their name attribute to store their reference in the seeder registry. To get the name attribute, it computes all types attributes, so it also computes the `color_id` attribute. To compute the `color_id` attribute, it will try to look up the color by its reference name in the seeder registry. As it's not there, it fails. So now, why is it not there? It's because the colors are already seeded, so it tries to look up existing ones to store them in the registry. To find them, it looks them up by their name attribute. But that name is different if current language is not the one used when the initial seeding was done. As the lookup returns nothing, it does not store the color in the registry. That's why looking the color up later fails. The fix is to look up the colors by their hexcode instead of their name. And if the colors hexcode has been changed, or if the colors were deleted, it would fail too. The fix in this case is to catch the lookup error and ignore it. It's not seeding, it's only looking up existing records so it's safe to ignore the error.
50 lines
1.7 KiB
Ruby
50 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
#-- copyright
|
|
# OpenProject is an open source project management software.
|
|
# Copyright (C) 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.
|
|
#++
|
|
|
|
module RootSeederTestHelpers
|
|
def with_edition(edition)
|
|
RSpec::Mocks.with_temporary_scope do
|
|
with_config(edition:)
|
|
yield
|
|
end
|
|
end
|
|
|
|
# The example needs to have the :settings_reset metadata to have
|
|
# `reset(:default_language)` working.
|
|
def with_locale_env(locale, env_var_name: "OPENPROJECT_SEED_LOCALE", &)
|
|
with_env(env_var_name => locale) do
|
|
reset(:default_language) # Settings are a pain to reset
|
|
yield
|
|
ensure
|
|
reset(:default_language)
|
|
end
|
|
end
|
|
end
|