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

extract version scopes

ulfertsf07bdc50785d
diff --git a/app/models/project.rb b/app/models/project.rb
index 8fa551314b4..3c8109cc810 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -233,18 +233,12 @@ class Project < ApplicationRecord
# Returns a scope of the Versions on subprojects
def rolled_up_versions
- shared_versions_base_scope
- .merge(Project.active)
- .where(projects: { id: self_and_descendants.select(:id) })
+ Version.rolled_up(self)
end
# Returns a scope of the Versions used by the project
def shared_versions
- if persisted?
- shared_versions_on_persisted
- else
- shared_versions_by_system
- end
+ Version.shared_with(self)
end
# Returns all versions a work package can be assigned to. Opposed to
@@ -257,7 +251,7 @@ class Project < ApplicationRecord
# reduce the number of db queries when performing operations including the
# project's versions.
def assignable_versions
- @all_shared_versions ||= shared_versions.with_status_open.order_by_semver_name.to_a
+ @assignable_versions ||= shared_versions.references(:project).with_status_open.order_by_semver_name.to_a
end
# Returns a hash of project users grouped by role
@@ -455,50 +449,6 @@ class Project < ApplicationRecord
.flatten
end
- protected
-
- def shared_versions_on_persisted
- shared_versions_base_scope
- .where(projects: { id: id })
- .or(shared_versions_by_system)
- .or(shared_versions_by_tree)
- .or(shared_versions_by_hierarchy_or_descendants)
- .or(shared_versions_by_hierarchy)
- end
-
- def shared_versions_by_tree
- r = root? ? self : root
-
- shared_versions_base_scope
- .merge(Project.active)
- .where(projects: { id: r.self_and_descendants.select(:id) })
- .where(sharing: 'tree')
- end
-
- def shared_versions_by_hierarchy_or_descendants
- shared_versions_base_scope
- .merge(Project.active)
- .where(projects: { id: ancestors.select(:id) })
- .where(sharing: %w(hierarchy descendants))
- end
-
- def shared_versions_by_hierarchy
- rolled_up_versions
- .where(sharing: 'hierarchy')
- end
-
- def shared_versions_by_system
- shared_versions_base_scope
- .merge(Project.active)
- .where(sharing: 'system')
- end
-
- def shared_versions_base_scope
- Version
- .includes(:project)
- .references(:projects)
- end
-
def remove_white_spaces_from_project_name
self.name = name.squish unless name.nil?
end
diff --git a/app/models/version.rb b/app/models/version.rb
index 368cf0fd610..348f5236472 100644
--- a/app/models/version.rb
+++ b/app/models/version.rb
@@ -48,7 +48,9 @@ class Version < ApplicationRecord
validates_inclusion_of :status, in: VERSION_STATUSES
validate :validate_start_date_before_effective_date
- scopes :order_by_semver_name
+ scopes :order_by_semver_name,
+ :rolled_up,
+ :shared_with
scope :visible, ->(*args) {
joins(:project)
diff --git a/app/models/versions/scopes/rolled_up.rb b/app/models/versions/scopes/rolled_up.rb
new file mode 100644
index 00000000000..f04a3bd24c4
--- /dev/null
+++ b/app/models/versions/scopes/rolled_up.rb
@@ -0,0 +1,45 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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 Versions::Scopes
+ module RolledUp
+ extend ActiveSupport::Concern
+
+ class_methods do
+ # Returns a scope of the Versions defined on the project
+ # itself or its descendants.
+ def rolled_up(project)
+ includes(:project)
+ .merge(Project.active)
+ .where(projects: { id: project.self_and_descendants.select(:id) })
+ end
+ end
+ end
+end
diff --git a/app/models/versions/scopes/shared_with.rb b/app/models/versions/scopes/shared_with.rb
new file mode 100644
index 00000000000..99eb8f64271
--- /dev/null
+++ b/app/models/versions/scopes/shared_with.rb
@@ -0,0 +1,86 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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 Versions::Scopes
+ module SharedWith
+ extend ActiveSupport::Concern
+
+ class_methods do
+ # Returns a scope of the Versions available
+ # in the project either because the project defined it itself
+ # or because it was shared with it
+ def shared_with(project)
+ if project.persisted?
+ shared_versions_on_persisted(project)
+ else
+ shared_versions_by_system
+ end
+ end
+
+ protected
+
+ def shared_versions_on_persisted(project)
+ includes(:project)
+ .where(projects: { id: project.id })
+ .or(shared_versions_by_system)
+ .or(shared_versions_by_tree(project))
+ .or(shared_versions_by_hierarchy_or_descendants(project))
+ .or(shared_versions_by_hierarchy(project))
+ end
+
+ def shared_versions_by_tree(project)
+ root = project.root? ? project : project.root
+
+ includes(:project)
+ .merge(Project.active)
+ .where(projects: { id: root.self_and_descendants.select(:id) })
+ .where(sharing: 'tree')
+ end
+
+ def shared_versions_by_hierarchy_or_descendants(project)
+ includes(:project)
+ .merge(Project.active)
+ .where(projects: { id: project.ancestors.select(:id) })
+ .where(sharing: %w(hierarchy descendants))
+ end
+
+ def shared_versions_by_hierarchy(project)
+ rolled_up(project)
+ .where(sharing: 'hierarchy')
+ end
+
+ def shared_versions_by_system
+ includes(:project)
+ .merge(Project.active)
+ .where(sharing: 'system')
+ end
+ end
+ end
+end
diff --git a/app/models/projects/scopes/activated_time_activity.rb b/modules/costs/app/models/projects/scopes/activated_time_activity.rb
similarity index 100%
rename from app/models/projects/scopes/activated_time_activity.rb
rename to modules/costs/app/models/projects/scopes/activated_time_activity.rb
diff --git a/app/models/projects/scopes/visible_with_activated_time_activity.rb b/modules/costs/app/models/projects/scopes/visible_with_activated_time_activity.rb
similarity index 100%
rename from app/models/projects/scopes/visible_with_activated_time_activity.rb
rename to modules/costs/app/models/projects/scopes/visible_with_activated_time_activity.rb
diff --git a/spec/models/projects/scopes/activated_time_activity_spec.rb b/modules/costs/spec/models/projects/scopes/activated_time_activity_spec.rb
similarity index 100%
rename from spec/models/projects/scopes/activated_time_activity_spec.rb
rename to modules/costs/spec/models/projects/scopes/activated_time_activity_spec.rb
diff --git a/spec/models/projects/scopes/visible_with_activated_time_activity_spec.rb b/modules/costs/spec/models/projects/scopes/visible_with_activated_time_activity_spec.rb
similarity index 100%
rename from spec/models/projects/scopes/visible_with_activated_time_activity_spec.rb
rename to modules/costs/spec/models/projects/scopes/visible_with_activated_time_activity_spec.rb
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 7b23cf0bb03..f02ddd343e4 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -141,14 +141,25 @@ describe Project, type: :model do
end
describe 'name' do
- let(:project) { FactoryBot.build_stubbed :project, name: ' Hello World ' }
+ let(:name) { ' Hello World ' }
+ let(:project) { described_class.new FactoryBot.attributes_for(:project, name: name) }
- before do
- project.valid?
+ context 'with white spaces in the name' do
+ it 'trims the name' do
+ project.save
+ expect(project.name).to eql('Hello World')
+ end
end
- it 'trims the name' do
- expect(project.name).to eql('Hello World')
+ context 'when updating the name' do
+ it 'persists the update' do
+ project.save
+ project.name = 'A new name'
+ project.save
+ project.reload
+
+ expect(project.name).to eql('A new name')
+ end
end
end
@@ -167,49 +178,4 @@ describe Project, type: :model do
expect(project.types_used_by_work_packages).to match_array [project_work_package.type]
end
end
-
- context '#rolled_up_versions' do
- let!(:project) { FactoryBot.create(:project) }
- let!(:parent_version1) { FactoryBot.create(:version, project: project) }
- let!(:parent_version2) { FactoryBot.create(:version, project: project) }
-
- it 'should include the versions for the current project' do
- expect(project.rolled_up_versions)
- .to match_array [parent_version1, parent_version2]
- end
-
- it 'should include versions for a subproject' do
- subproject = FactoryBot.create(:project, parent: project)
- subproject_version = FactoryBot.create(:version, project: subproject)
-
- project.reload
-
- expect(project.rolled_up_versions)
- .to match_array [parent_version1, parent_version2, subproject_version]
- end
-
- it 'should include versions for a sub-subproject' do
- subproject = FactoryBot.create(:project, parent: project)
- sub_subproject = FactoryBot.create(:project, parent: subproject)
- sub_subproject_version = FactoryBot.create(:version, project: sub_subproject)
-
- project.reload
-
- expect(project.rolled_up_versions)
- .to match_array [parent_version1, parent_version2, sub_subproject_version]
- end
-
- it 'should only check active projects' do
- subproject = FactoryBot.create(:project, parent: project)
- FactoryBot.create(:version, project: subproject)
- subproject.update(active: false)
-
- project.reload
-
- expect(subproject)
- .not_to be_active
- expect(project.rolled_up_versions)
- .to match_array [parent_version1, parent_version2]
- end
- end
end
diff --git a/spec/models/versions/scopes/rolled_up_spec.rb b/spec/models/versions/scopes/rolled_up_spec.rb
new file mode 100644
index 00000000000..b737d64666e
--- /dev/null
+++ b/spec/models/versions/scopes/rolled_up_spec.rb
@@ -0,0 +1,58 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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'
+
+describe Versions::Scopes::RolledUp, type: :model do
+ shared_let(:parent_project) { FactoryBot.create(:project) }
+ shared_let(:project) { FactoryBot.create(:project, parent: parent_project) }
+ shared_let(:sibling_project) { FactoryBot.create(:project, parent: parent_project) }
+ shared_let(:child_project) { FactoryBot.create(:project, parent: project) }
+ shared_let(:grand_child_project) { FactoryBot.create(:project, parent: child_project) }
+ shared_let(:version) { FactoryBot.create(:version, project: project) }
+ shared_let(:child_version) { FactoryBot.create(:version, project: child_project) }
+ shared_let(:grand_child_version) { FactoryBot.create(:version, project: grand_child_project) }
+ shared_let(:parent_version) { FactoryBot.create(:version, project: parent_project) }
+ shared_let(:sibling_version) { FactoryBot.create(:version, project: sibling_project) }
+
+ describe '.rolled_up' do
+ it 'includes versions of self and all descendants' do
+ expect(project.rolled_up_versions)
+ .to match_array [version, child_version, grand_child_version]
+ end
+
+ it 'excludes versions from inactive projects' do
+ grand_child_project.update(active: false)
+
+ expect(project.rolled_up_versions)
+ .to match_array [version, child_version]
+ end
+ end
+end
diff --git a/spec/models/versions/scopes/shared_with_spec.rb b/spec/models/versions/scopes/shared_with_spec.rb
new file mode 100644
index 00000000000..5f2e76f91cd
--- /dev/null
+++ b/spec/models/versions/scopes/shared_with_spec.rb
@@ -0,0 +1,216 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 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'
+
+describe Versions::Scopes::SharedWith, type: :model do
+ shared_let(:root_project) { FactoryBot.create(:project) }
+ shared_let(:parent_project) { FactoryBot.create(:project, parent: root_project) }
+ shared_let(:project) { FactoryBot.create(:project, parent: parent_project) }
+ shared_let(:other_root_project) { FactoryBot.create(:project) }
+ shared_let(:aunt_project) { FactoryBot.create(:project, parent: root_project) }
+ shared_let(:sibling_project) { FactoryBot.create(:project, parent: parent_project) }
+ shared_let(:child_project) { FactoryBot.create(:project, parent: project) }
+ shared_let(:grand_child_project) { FactoryBot.create(:project, parent: child_project) }
+
+ describe '.shared_with' do
+ context 'with the version not being shared' do
+ let!(:version) { FactoryBot.create(:version, project: project, sharing: 'none') }
+
+ it 'is visible within the original project' do
+ expect(Version.shared_with(project))
+ .to match_array [version]
+ end
+
+ it 'is not visible in any other project' do
+ [parent_project,
+ root_project,
+ other_root_project,
+ aunt_project,
+ sibling_project,
+ child_project,
+ grand_child_project].each do |p|
+ expect(Version.shared_with(p))
+ .to be_empty
+ end
+ end
+ end
+
+ context 'with the version being shared with descendants' do
+ let!(:version) { FactoryBot.create(:version, project: project, sharing: 'descendants') }
+
+ it 'is visible within the original project and it`s descendants' do
+ [project,
+ child_project,
+ grand_child_project].each do |p|
+ expect(Version.shared_with(p))
+ .to match_array [version]
+ end
+ end
+
+ it 'is not visible in any other project' do
+ [parent_project,
+ root_project,
+ other_root_project,
+ aunt_project,
+ sibling_project].each do |p|
+ expect(Version.shared_with(p))
+ .to be_empty
+ end
+ end
+
+ it 'is not visible in any other project if the project is inactive' do
+ project.update(active: false)
+
+ [parent_project,
+ root_project,
+ child_project,
+ grand_child_project,
+ aunt_project,
+ sibling_project,
+ other_root_project].each do |p|
+ expect(Version.shared_with(p))
+ .to be_empty
+ end
+ end
+ end
+
+ context 'with the version being shared with hierarchy' do
+ let!(:version) { FactoryBot.create(:version, project: project, sharing: 'hierarchy') }
+
+ it 'is visible within the original project and it`s descendants and ancestors' do
+ [project,
+ parent_project,
+ root_project,
+ child_project,
+ grand_child_project].each do |p|
+ expect(Version.shared_with(p))
+ .to match_array [version]
+ end
+ end
+
+ it 'is not visible in any other project' do
+ [other_root_project,
+ aunt_project,
+ sibling_project].each do |p|
+ expect(Version.shared_with(p))
+ .to be_empty
+ end
+ end
+
+ it 'is not visible in any other project if the project is inactive' do
+ project.update(active: false)
+
+ [parent_project,
+ root_project,
+ child_project,
+ grand_child_project,
+ aunt_project,
+ sibling_project,
+ other_root_project].each do |p|
+ expect(Version.shared_with(p))
+ .to be_empty
+ end
+ end
+ end
+
+ context 'with the version being shared with tree' do
+ let(:version) { FactoryBot.create(:version, project: project, sharing: 'tree') }
+
+ it 'is visible within the original project and every project within the same tree' do
+ [project,
+ parent_project,
+ root_project,
+ child_project,
+ grand_child_project,
+ aunt_project,
+ sibling_project].each do |p|
+ expect(Version.shared_with(p))
+ .to match_array [version]
+ end
+ end
+
+ it 'is not visible projects outside of the tree' do
+ [other_root_project].each do |p|
+ expect(Version.shared_with(p))
+ .to be_empty
+ end
+ end
+
+ it 'is not visible in any other project if the project is inactive' do
+ project.update(active: false)
+
+ [parent_project,
+ root_project,
+ child_project,
+ grand_child_project,
+ aunt_project,
+ sibling_project,
+ other_root_project].each do |p|
+ expect(Version.shared_with(p))
+ .to be_empty
+ end
+ end
+ end
+
+ context 'with the version being shared with system' do
+ let(:version) { FactoryBot.create(:version, project: project, sharing: 'system') }
+
+ it 'is visible in all projects' do
+ [project,
+ parent_project,
+ root_project,
+ child_project,
+ grand_child_project,
+ aunt_project,
+ sibling_project,
+ other_root_project].each do |p|
+ expect(Version.shared_with(p))
+ .to match_array [version]
+ end
+ end
+
+ it 'is not visible in any other project if the project is inactive' do
+ project.update(active: false)
+
+ [parent_project,
+ root_project,
+ child_project,
+ grand_child_project,
+ aunt_project,
+ sibling_project,
+ other_root_project].each do |p|
+ expect(Version.shared_with(p))
+ .to be_empty
+ end
+ end
+ end
+ end
+end
diff --git a/spec_legacy/unit/project_spec.rb b/spec_legacy/unit/project_spec.rb
index 980c0629ae3..74e2054c5bb 100644
--- a/spec_legacy/unit/project_spec.rb
+++ b/spec_legacy/unit/project_spec.rb
@@ -33,8 +33,6 @@ describe Project, type: :model do
fixtures :all
before do
- @ecookbook = Project.find(1)
- @ecookbook_sub1 = Project.find(3)
User.current = nil
end
@@ -63,19 +61,6 @@ describe Project, type: :model do
it { is_expected.to have_and_belong_to_many :work_package_custom_fields }
end
- it 'should truth' do
- assert_kind_of Project, @ecookbook
- assert_equal 'eCookbook', @ecookbook.name
- end
-
- it 'should update' do
- assert_equal 'eCookbook', @ecookbook.name
- @ecookbook.name = 'eCook'
- assert @ecookbook.save, @ecookbook.errors.full_messages.join('; ')
- @ecookbook.reload
- assert_equal 'eCook', @ecookbook.name
- end
-
it 'should members should be active users' do
Project.all.each do |project|
assert_nil project.members.detect { |m| !(m.principal.is_a?(User) && m.principal.active?) }
@@ -156,103 +141,6 @@ describe Project, type: :model do
assert_equal [1, 2], parent.rolled_up_types.map(&:id)
end
- it 'should shared versions none sharing' do
- p = Project.find(5)
- v = Version.create!(name: 'none_sharing', project: p, sharing: 'none')
- assert p.shared_versions.include?(v)
- assert !p.children.first.shared_versions.include?(v)
- assert !p.root.shared_versions.include?(v)
- assert !p.siblings.first.shared_versions.include?(v)
- assert !p.root.siblings.first.shared_versions.include?(v)
- end
-
- it 'should shared versions descendants sharing' do
- p = Project.find(5)
- v = Version.create!(name: 'descendants_sharing', project: p, sharing: 'descendants')
- assert p.shared_versions.include?(v)
- assert p.children.first.shared_versions.include?(v)
- assert !p.root.shared_versions.include?(v)
- assert !p.siblings.first.shared_versions.include?(v)
- assert !p.root.siblings.first.shared_versions.include?(v)
- end
-
- it 'should shared versions hierarchy sharing' do
- p = Project.find(5)
- v = Version.create!(name: 'hierarchy_sharing', project: p, sharing: 'hierarchy')
- assert p.shared_versions.include?(v)
- assert p.children.first.shared_versions.include?(v)
- assert p.root.shared_versions.include?(v)
- assert !p.siblings.first.shared_versions.include?(v)
- assert !p.root.siblings.first.shared_versions.include?(v)
- end
-
- it 'should shared versions tree sharing' do
- p = Project.find(5)
- v = Version.create!(name: 'tree_sharing', project: p, sharing: 'tree')
- assert p.shared_versions.include?(v)
- assert p.children.first.shared_versions.include?(v)
- assert p.root.shared_versions.include?(v)
- assert p.siblings.first.shared_versions.include?(v)
- assert !p.root.siblings.first.shared_versions.include?(v)
- end
-
- it 'should shared versions system sharing' do
- p = Project.find(5)
- v = Version.create!(name: 'system_sharing', project: p, sharing: 'system')
- assert p.shared_versions.include?(v)
- assert p.children.first.shared_versions.include?(v)
- assert p.root.shared_versions.include?(v)
- assert p.siblings.first.shared_versions.include?(v)
- assert p.root.siblings.first.shared_versions.include?(v)
- end
-
- it 'should shared versions' do
- parent = Project.find(1)
- child = parent.children.find(3)
- private_child = parent.children.find(5)
-
- assert_equal [1, 2, 3], parent.version_ids.sort
- assert_equal [4], child.version_ids
- assert_equal [6], private_child.version_ids
- assert_equal [7], Version.where(sharing: 'system').map(&:id)
-
- assert_equal 6, parent.shared_versions.size
- parent.shared_versions.each do |version|
- assert_kind_of Version, version
- end
-
- assert_equal [1, 2, 3, 4, 6, 7], parent.shared_versions.map(&:id).sort
- end
-
- it 'should shared versions should ignore archived subprojects' do
- parent = Project.find(1)
- child = parent.children.find(3)
- child.update(active: false)
- parent.reload
-
- assert_equal [1, 2, 3], parent.version_ids.sort
- assert_equal [4], child.version_ids
- assert !parent.shared_versions.map(&:id).include?(4)
- end
-
- it 'should shared versions visible to user' do
- user = User.find(3)
- parent = Project.find(1)
- child = parent.children.find(5)
-
- assert_equal [1, 2, 3], parent.version_ids.sort
- assert_equal [6], child.version_ids
-
- versions = parent.shared_versions.visible(user)
-
- assert_equal 4, versions.size
- versions.each do |version|
- assert_kind_of Version, version
- end
-
- assert !versions.map(&:id).include?(6)
- end
-
context 'with modules',
with_settings: { default_projects_modules: ['work_package_tracking', 'repository'] } do
it 'should enabled module names' do
@@ -286,9 +174,4 @@ describe Project, type: :model do
assert_nil project.versions.detect { |v| v.completed? && v.status != 'closed' }
refute_nil project.versions.detect { |v| !v.completed? && v.status == 'open' }
end
-
- it 'should export work packages is allowed' do
- project = Project.find(1)
- assert project.allows_to?(:export_work_packages)
- end
end