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

Strengthen test suite around seeding

Christophe Bliardf4e6d0037fdd
diff --git a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb
index 046c7413e92..1f2755f52f5 100644
--- a/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb
+++ b/modules/bim/spec/seeders/root_seeder_bim_edition_spec.rb
@@ -27,15 +27,27 @@
#++
require 'spec_helper'
+require_relative '../../../../spec/seeders/root_seeder_shared_examples'
describe RootSeeder,
'BIM edition',
with_config: { edition: 'bim' },
with_settings: { journal_aggregation_time_minutes: 0 } do
- it 'creates the demo data' do
- expect { described_class.new.seed_data! }.not_to raise_error
+ before_all do
+ RSpec::Mocks.with_temporary_scope do
+ # the mocking of settings and configuration is duplicated here because
+ # it's executed outside of an example context
+ with_config(edition: 'bim')
+ with_settings(journal_aggregation_time_minutes: 0)
+ described_class.new.seed_data!
+ end
+ end
+ it 'creates an admin user' do
expect(User.not_builtin.where(admin: true).count).to eq 1
+ end
+
+ it 'creates the BIM demo data' do
expect(Project.count).to eq 4
expect(WorkPackage.count).to eq 76
expect(Wiki.count).to eq 3
@@ -48,10 +60,12 @@ describe RootSeeder,
expect(Bim::IfcModels::IfcModel.count).to eq 3
expect(Grids::Overview.count).to eq 4
expect(Boards::Grid.count).to eq 2
+ end
- perform_enqueued_jobs
-
- expect(ActionMailer::Base.deliveries)
- .to be_empty
+ it 'creates follows and parent-child relations' do
+ expect(Relation.follows.count).to eq 35
+ expect(WorkPackage.where.not(parent: nil).count).to eq 55
end
+
+ include_examples 'no email deliveries'
end
diff --git a/spec/seeders/root_seeder_shared_examples.rb b/spec/seeders/root_seeder_shared_examples.rb
new file mode 100644
index 00000000000..5c8c09c537d
--- /dev/null
+++ b/spec/seeders/root_seeder_shared_examples.rb
@@ -0,0 +1,38 @@
+# 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.
+#++
+
+RSpec.shared_examples 'no email deliveries' do
+ it 'does not perform any email deliveries' do
+ perform_enqueued_jobs
+
+ expect(ActionMailer::Base.deliveries)
+ .to be_empty
+ end
+end
diff --git a/spec/seeders/root_seeder_standard_edition_spec.rb b/spec/seeders/root_seeder_standard_edition_spec.rb
index 99e5b11aaec..979f1030d27 100644
--- a/spec/seeders/root_seeder_standard_edition_spec.rb
+++ b/spec/seeders/root_seeder_standard_edition_spec.rb
@@ -27,20 +27,12 @@
#++
require 'spec_helper'
+require_relative './root_seeder_shared_examples'
describe RootSeeder,
'standard edition',
with_config: { edition: 'standard' },
with_settings: { journal_aggregation_time_minutes: 0 } do
- shared_examples 'no email deliveries' do
- it 'does not perform any email deliveries' do
- perform_enqueued_jobs
-
- expect(ActionMailer::Base.deliveries)
- .to be_empty
- end
- end
-
describe 'demo data' do
before_all do
described_class.new.seed_data!
diff --git a/spec/support/shared/with_config.rb b/spec/support/shared/with_config.rb
index 0b47f6929ee..7d5ac3de92c 100644
--- a/spec/support/shared/with_config.rb
+++ b/spec/support/shared/with_config.rb
@@ -48,7 +48,12 @@ class WithConfig
#
# @config [Hash] Hash containing the configurations with keys as seen in `configuration.rb`.
def before(example, config)
- aggregate_mocked_configuration(example, config)
+ full_config = aggregate_mocked_configuration(example, config)
+ stub_config(full_config)
+ end
+
+ def stub_config(config)
+ config
.with_indifferent_access
.each { |k, v| stub_key(k, v) }
end
@@ -89,7 +94,17 @@ class WithConfig
end
end
+module WithConfigMixin
+ module_function
+
+ def with_config(config)
+ WithConfig.new(self).stub_config(config)
+ end
+end
+
RSpec.configure do |config|
+ config.include WithConfigMixin
+
config.before do |example|
with_config = example.metadata[:with_config]