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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
replace legacy spec
ulferts1d4dd5fed5d9
diff --git a/app/models/user.rb b/app/models/user.rbindex d401c9c2189..e6eef901c26 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -606,7 +606,7 @@ class User < Principalseparators = Regexp.escape(Setting.mail_suffix_separators)recipient, domain = mail.split('@').map { |part| Regexp.escape(part) }skip_suffix_check = recipient.nil? || Setting.mail_suffix_separators.empty? || recipient.match?(/.+[#{separators}].+/)- regexp = "#{recipient}([#{separators}][^@]+)*@#{domain}"+ regexp = "^#{recipient}([#{separators}][^@]+)*@#{domain}$"[skip_suffix_check, regexp]enddiff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rbindex 604c6be52d7..895418d77d2 100644--- a/spec/models/project_spec.rb+++ b/spec/models/project_spec.rb@@ -55,13 +55,13 @@ describe Project, type: :model doenddescribe '#archived?' do- context 'if active' do+ context 'if archived' doit 'is true' doexpect(project).not_to be_archivedendend- context 'if not active' do+ context 'if not archived' dolet(:active) { false }it 'is false' do@@ -321,4 +321,55 @@ describe Project, type: :model doendendend++ describe '#rolled_up_types' do+ let!(:parent) do+ create(:project, types: [parent_type]).tap do |p|+ project.update_attribute(:parent, p)+ end+ end+ let!(:child1) { create(:project, parent: project, types: [child1_type, shared_type]) }+ let!(:child2) { create(:project, parent: project, types: [child2_type], active: false) }++ let!(:unused_type) { create(:type) }+ let!(:parent_type) { create(:type) }+ let!(:child1_type) { create(:type) }+ let!(:child2_type) { create(:type) }+ let!(:shared_type) { create(:type) }++ let!(:project_type) do+ create(:type).tap do |t|+ project.types = [t, shared_type]+ end+ end++ it 'includes all types of active projects starting from receiver down to the leaves' do+ project.reload++ expect(project.rolled_up_types)+ .to eq [child1_type, project_type, shared_type].sort_by(&:position)+ end+ end++ describe '#enabled_module_names=', with_settings: { default_projects_modules: %w(work_package_tracking repository) } do+ context 'when assigning a new value' do+ let(:new_value) { %w(work_package_tracking news) }++ subject do+ project.enabled_module_names = new_value+ end++ it 'sets the value' do+ subject++ expect(project.reload.enabled_module_names.sort)+ .to eql new_value.sort+ end++ it 'keeps already assigned modules intact (same id)' do+ expect { subject }+ .not_to change { project.reload.enabled_modules.find { |em| em.name == 'work_package_tracking' }.id }+ end+ end+ endenddiff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex eeffb45d6a5..e9d42733f80 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -596,6 +596,106 @@ describe User, type: :model doendend+ describe '.try_to_login' do+ let(:password) { 'pwd123Password!' }+ let(:login) { 'the_login' }+ let(:status) { described_class.statuses[:active] }++ let!(:user) do+ create(:user,+ password:,+ password_confirmation: password,+ login:,+ status:)+ end++ context 'with good credentials' do+ it 'returns the user' do+ expect(described_class.try_to_login(login, password))+ .to eq user+ end+ end++ context 'with wrong password' do+ it 'returns the user' do+ expect(described_class.try_to_login(login, "#{password}!"))+ .to be_nil+ end+ end++ context 'with wrong case in login' do+ it 'returns the user' do+ expect(described_class.try_to_login('The_login', password))+ .to eq user+ end+ end++ context 'with wrong characters in login' do+ it 'returns nil' do+ expect(described_class.try_to_login(login[0..-2], password))+ .to be_nil+ end+ end++ context 'with the user being locked' do+ let(:status) { described_class.statuses[:locked] }++ it 'returns nil' do+ expect(described_class.try_to_login(login, "#{password}!"))+ .to be_nil+ end+ end++ context 'with the user\'s password being changed' do+ let(:new_password) { 'newPWD12%abc' }++ before do+ user.password = new_password+ user.save!+ end++ it 'returns the user' do+ expect(described_class.try_to_login(login, new_password))+ .to eq user+ end+ end+ end++ describe '.find_by_mail' do+ let(:mail) { '[email protected]' }+ let!(:user) { create :user, mail: }++ context 'with the exact mail' do+ it 'finds the user' do+ expect(described_class.find_by_mail(mail))+ .to eq user+ end+ end++ context 'with the mail address in uppercase' do+ it 'finds the user' do+ expect(described_class.find_by_mail(mail.upcase))+ .to eq user+ end+ end++ context 'with a different mail address' do+ it 'is nil' do+ expect(described_class.find_by_mail(mail[1..-2]))+ .to be_nil+ end+ end++ context 'with a mail suffix in the address' do+ let(:mail) { '[email protected]' }++ it 'finds the user' do+ expect(described_class.find_by_mail('[email protected]'))+ .to eq user+ end+ end+ end+include_examples 'creates an audit trail on destroy' dosubject { create(:attachment) }enddiff --git a/spec_legacy/unit/lib/redmine/i18n_spec.rb b/spec_legacy/unit/lib/redmine/i18n_spec.rbindex e291d5aa590..59b48d72e4e 100644--- a/spec_legacy/unit/lib/redmine/i18n_spec.rb+++ b/spec_legacy/unit/lib/redmine/i18n_spec.rb@@ -102,18 +102,4 @@ describe Redmine::I18n doend.not_to raise_errorendend-- it 'fallbacks' do- ::I18n.backend.store_translations(:en, untranslated: 'Untranslated string')- ::I18n.locale = 'en'- assert_equal 'Untranslated string', I18n.t(:untranslated)- ::I18n.locale = 'de'- assert_equal 'Untranslated string', I18n.t(:untranslated)-- ::I18n.backend.store_translations(:de, untranslated: 'Keine Übersetzung')- ::I18n.locale = 'en'- assert_equal 'Untranslated string', I18n.t(:untranslated)- ::I18n.locale = 'de'- assert_equal 'Keine Übersetzung', I18n.t(:untranslated)- endenddiff --git a/spec_legacy/unit/project_spec.rb b/spec_legacy/unit/project_spec.rbdeleted file mode 100644index da1c136e4f6..00000000000--- a/spec_legacy/unit/project_spec.rb+++ /dev/null@@ -1,88 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2022 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_relative '../legacy_spec_helper'--describe Project, type: :model do- fixtures :all-- before do- User.current = nil- end-- it 'rolleds up types' do- parent = Project.find(1)- parent.types = ::Type.find([1, 2])- child = parent.children.find(3)-- assert_equal [1, 2], parent.type_ids- assert_equal [2, 3], child.types.map(&:id)-- assert_kind_of ::Type, parent.rolled_up_types.first-- assert_equal [999, 1, 2, 3], parent.rolled_up_types.map(&:id)- assert_equal [2, 3], child.rolled_up_types.map(&:id)- end-- it 'rolleds up types should ignore archived subprojects' do- parent = Project.find(1)- parent.types = ::Type.find([1, 2])- child = parent.children.find(3)- child.types = ::Type.find([1, 3])- parent.children.each do |child|- child.update(active: false)- child.children.each do |grand_child|- grand_child.update(active: false)- end- end-- assert_equal [1, 2], parent.rolled_up_types.map(&:id)- end-- context 'with modules',- with_legacy_settings: { default_projects_modules: ['work_package_tracking', 'repository'] } do- it 'enableds module names' do- project = Project.new-- project.enabled_module_names = %w(work_package_tracking news)- assert_equal %w(news work_package_tracking), project.enabled_module_names.sort- end- end-- it 'enableds module names should not recreate enabled modules' do- project = Project.find(1)- # Remove one module- modules = project.enabled_modules.to_a.slice(0..-2)- assert modules.any?- assert_difference 'EnabledModule.count', -1 do- project.enabled_module_names = modules.map(&:name)- end- project.reload- # Ids should be preserved- assert_equal project.enabled_module_ids.sort, modules.map(&:id).sort- end-enddiff --git a/spec_legacy/unit/user_spec.rb b/spec_legacy/unit/user_spec.rbindex 0e57017042e..9063522ebd3 100644--- a/spec_legacy/unit/user_spec.rb+++ b/spec_legacy/unit/user_spec.rb@@ -98,37 +98,6 @@ describe User, type: :model doassert_equal 1, @admin.errors.countend- context 'User#try_to_login' do- it 'fall-backs to case-insensitive if user login is not found as-typed.' do- user = User.try_to_login('AdMin', 'adminADMIN!')- assert_kind_of User, user- assert_equal 'admin', user.login- end-- it 'selects the exact matching user first' do- case_sensitive_user = create(:user, login: 'changed', password: 'adminADMIN!',- password_confirmation: 'adminADMIN!')- # bypass validations to make it appear like existing data- case_sensitive_user.update_attribute(:login, 'ADMIN')-- user = User.try_to_login('ADMIN', 'adminADMIN!')- assert_kind_of User, user- assert_equal 'ADMIN', user.login- end- end-- it 'passwords' do- user = User.try_to_login('admin', 'adminADMIN!')- assert_kind_of User, user- assert_equal 'admin', user.login- user.password = 'newpassPASS!'- assert user.save-- user = User.try_to_login('admin', 'newpassPASS!')- assert_kind_of User, user- assert_equal 'admin', user.login- end-it 'names format' doassert_equal 'Smith, John', @jsmith.name(:lastname_coma_firstname)Setting.user_format = :firstname_lastname@@ -137,33 +106,6 @@ describe User, type: :model doassert_equal 'jsmith', @jsmith.reload.nameend- it 'locks' do- user = User.try_to_login('jsmith', 'jsmith')- assert_equal @jsmith, user-- @jsmith.status = User.statuses[:locked]- assert @jsmith.save-- user = User.try_to_login('jsmith', 'jsmith')- assert_equal nil, user- end-- describe '.try_to_login' do- context 'with good credentials' do- it 'returns the user' do- user = User.try_to_login('admin', 'adminADMIN!')- assert_kind_of User, user- assert_equal 'admin', user.login- end- end-- context 'with wrong credentials' do- it 'returns nil' do- assert_nil User.try_to_login('admin', 'foo')- end- end- end-it 'returns existing or new anonymous' doanon = User.anonymousassert !anon.new_record?@@ -224,10 +166,4 @@ describe User, type: :model do@jsmith.pref.comments_sorting = 'desc'assert @jsmith.wants_comments_in_reverse_order?end-- it 'finds by mail should be case insensitive' do- u = User.find_by_mail('[email protected]')- refute_nil u- assert_equal '[email protected]', u.mail- endend