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

replace legacy specs

ulferts973ebd1fac70
diff --git a/spec/models/principal_spec.rb b/spec/models/principal_spec.rb
index 6281f9a5644..cfbbc1a787e 100644
--- a/spec/models/principal_spec.rb
+++ b/spec/models/principal_spec.rb
@@ -136,4 +136,51 @@ describe Principal, type: :model do
expect(subject).not_to include(deleted_user)
end
end
+
+ context '.like' do
+ let!(:login) do
+ FactoryBot.create(:principal, login: 'login')
+ end
+ let!(:login2) do
+ FactoryBot.create(:principal, login: 'login2')
+ end
+ let!(:firstname) do
+ FactoryBot.create(:principal, firstname: 'firstname')
+ end
+ let!(:firstname2) do
+ FactoryBot.create(:principal, firstname: 'firstname2')
+ end
+ let!(:lastname) do
+ FactoryBot.create(:principal, lastname: 'lastname')
+ end
+ let!(:lastname2) do
+ FactoryBot.create(:principal, lastname: 'lastname2')
+ end
+ let!(:mail) do
+ FactoryBot.create(:principal, mail: '[email protected]')
+ end
+ let!(:mail2) do
+ FactoryBot.create(:principal, mail: '[email protected]')
+ end
+
+ it 'finds by login' do
+ expect(Principal.like('login'))
+ .to match_array [login, login2]
+ end
+
+ it 'finds by firstname' do
+ expect(Principal.like('firstname'))
+ .to match_array [firstname, firstname2]
+ end
+
+ it 'finds by lastname' do
+ expect(Principal.like('lastname'))
+ .to match_array [lastname, lastname2]
+ end
+
+ it 'finds by mail' do
+ expect(Principal.like('mail'))
+ .to match_array [mail, mail2]
+ end
+ end
end
diff --git a/spec_legacy/unit/principal_spec.rb b/spec_legacy/unit/principal_spec.rb
deleted file mode 100644
index 0be0560810d..00000000000
--- a/spec_legacy/unit/principal_spec.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-#-- encoding: UTF-8
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.
-#++
-require 'legacy_spec_helper'
-
-describe Principal, type: :model do
- context '#like' do
- before do
- FactoryBot.create(:principal, login: 'login')
- FactoryBot.create(:principal, login: 'login2')
-
- FactoryBot.create(:principal, firstname: 'firstname')
- FactoryBot.create(:principal, firstname: 'firstname2')
-
- FactoryBot.create(:principal, lastname: 'lastname')
- FactoryBot.create(:principal, lastname: 'lastname2')
-
- FactoryBot.create(:principal, mail: '[email protected]')
- FactoryBot.create(:principal, mail: '[email protected]')
- end
-
- it 'should search login' do
- results = Principal.like('login')
-
- assert_equal 2, results.count
- assert results.all? { |u| u.login.match(/login/) }
- end
-
- it 'should search firstname' do
- results = Principal.like('firstname')
-
- assert_equal 2, results.count
- assert results.all? { |u| u.firstname.match(/firstname/) }
- end
-
- it 'should search lastname' do
- results = Principal.like('lastname')
-
- assert_equal 2, results.count
- assert results.all? { |u| u.lastname.match(/lastname/) }
- end
-
- it 'should search mail' do
- results = Principal.like('mail')
-
- assert_equal 2, results.count
- assert results.all? { |u| u.mail.match(/mail/) }
- end
- end
-end
diff --git a/spec_legacy/unit/user_spec.rb b/spec_legacy/unit/user_spec.rb
index 7aa711c4aa3..a9903451833 100644
--- a/spec_legacy/unit/user_spec.rb
+++ b/spec_legacy/unit/user_spec.rb
@@ -380,78 +380,4 @@ describe User, type: :model do
refute_nil u
assert_equal '[email protected]', u.mail
end
-
- context '#allowed_to?' do
- context 'with a unique project' do
- it 'should return false if project is archived' do
- project = Project.find(1)
- allow_any_instance_of(Project).to receive(:active?).and_return(false)
- assert ! @admin.allowed_to?(:view_work_packages, Project.find(1))
- end
-
- it 'should return false if related module is disabled' do
- project = Project.find(1)
- project.enabled_module_names = ['work_package_tracking']
- assert @admin.allowed_to?(:add_work_packages, project)
- assert ! @admin.allowed_to?(:view_wiki_pages, project)
- end
-
- it 'should authorize nearly everything for admin users' do
- project = Project.find(1)
- project.enabled_module_names = ['work_package_tracking', 'news', 'wiki', 'repository']
- assert @admin.member_of?(project)
- %w(edit_work_packages delete_work_packages manage_news manage_repository manage_wiki).each do |p|
- assert @admin.allowed_to?(p.to_sym, project)
- end
- end
-
- it 'should authorize normal users depending on their roles' do
- project = Project.find(1)
- project.enabled_module_names = ['forums']
- assert @jsmith.allowed_to?(:delete_messages, project) # Manager
- assert ! @dlopper.allowed_to?(:delete_messages, project) # Developper
- end
-
- it 'should only managers are allowed to export tickets' do
- project = Project.find(1)
- project.enabled_module_names = ['work_package_tracking']
- assert @jsmith.allowed_to?(:export_work_packages, project) # Manager
- assert ! @dlopper.allowed_to?(:export_work_packages, project) # Developper
- end
- end
-
- context 'with multiple projects' do
- it 'should return false if array is empty' do
- assert ! @admin.allowed_to?(:view_project, [])
- end
-
- it 'should return true only if user has permission on all these projects' do
- Project.all.each do |project|
- project.enabled_module_names = ['work_package_tracking']
- project.save!
- end
-
- assert @admin.allowed_to?(:view_project, Project.all)
- assert ! @dlopper.allowed_to?(:view_project, Project.all) # cannot see Project(2)
- assert @jsmith.allowed_to?(:edit_work_packages, @jsmith.projects) # Manager or Developer everywhere
- assert ! @jsmith.allowed_to?(:delete_work_package_watchers, @jsmith.projects) # Dev cannot delete_work_package_watchers
- end
-
- it 'should behave correctly with arrays of 1 project' do
- assert !User.anonymous.allowed_to?(:delete_work_packages, [Project.first])
- end
- end
-
- context 'with options[:global]' do
- it 'should authorize if user has at least one role that has this permission' do
- @dlopper2 = User.find(5) # only Developper on a project, not Manager anywhere
- @anonymous = User.find(6)
- assert @jsmith.allowed_to?(:delete_work_package_watchers, nil, global: true)
- assert ! @dlopper2.allowed_to?(:delete_work_package_watchers, nil, global: true)
- assert @dlopper2.allowed_to?(:add_work_packages, nil, global: true)
- assert ! @anonymous.allowed_to?(:add_work_packages, nil, global: true)
- assert @anonymous.allowed_to?(:view_work_packages, nil, global: true)
- end
- end
- end
end