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

reuse project services in controller

ulferts57f7da4f392a
diff --git a/app/contracts/empty_contract.rb b/app/contracts/empty_contract.rb
new file mode 100644
index 00000000000..853d4f8c88f
--- /dev/null
+++ b/app/contracts/empty_contract.rb
@@ -0,0 +1,37 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is a project management system.
+# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
+#
+# 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 doc/COPYRIGHT.rdoc for more details.
+#++
+
+class EmptyContract
+ def initialize(*); end
+
+ def validate
+ true
+ end
+end
diff --git a/app/contracts/projects/create_contract.rb b/app/contracts/projects/create_contract.rb
index d671bdf0338..3dd0d13007c 100644
--- a/app/contracts/projects/create_contract.rb
+++ b/app/contracts/projects/create_contract.rb
@@ -31,7 +31,11 @@ module Projects
private
def validate_user_allowed_to_manage
- errors.add :base, :error_unauthorized unless user.allowed_to_globally?(:add_project)
+ unless user.allowed_to_globally?(:add_project) ||
+ model.parent && user.allowed_to?(:add_subprojects, model.parent)
+
+ errors.add :base, :error_unauthorized
+ end
end
end
end
diff --git a/app/controllers/copy_projects_controller.rb b/app/controllers/copy_projects_controller.rb
index ffa4bda8e77..2e984d5c3fb 100644
--- a/app/controllers/copy_projects_controller.rb
+++ b/app/controllers/copy_projects_controller.rb
@@ -32,24 +32,25 @@ class CopyProjectsController < ApplicationController
before_action :authorize
def copy
- @copy_project = project_copy
+ @copy_project = Project.new
+ call = project_copy(@copy_project)
- if @copy_project.valid?
+ if call.success?
enqueue_copy_job
- flash[:notice] = I18n.t('copy_project.started',
- source_project_name: @project.name,
- target_project_name: permitted_params.project[:name])
+ copy_started_notice
redirect_to origin
else
+ @errors = call.errors
render action: copy_action
end
end
def copy_project
@copy_project = Project.copy_attributes(@project)
+
if @copy_project
- @copy_project.identifier = Project.next_identifier if Setting.sequential_project_identifiers?
+ @errors = project_copy(@copy_project).errors
render action: copy_action
else
@@ -67,16 +68,12 @@ class CopyProjectsController < ApplicationController
"copy_from_#{from}"
end
- def project_copy
- copy_project = Project.new
- copy_project.attributes = permitted_params.project
-
- # cannot use set_allowed_parent! as it requires a persisted project
- if copy_project.allowed_parent?(params['project']['parent_id'])
- copy_project.parent_id = params['project']['parent_id']
- end
-
- copy_project
+ def project_copy(nucleous)
+ Projects::SetAttributesService
+ .new(user: current_user,
+ model: nucleous,
+ contract_class: Projects::CreateContract)
+ .call(params[:project] ? permitted_params.project : {})
end
def origin
@@ -100,4 +97,10 @@ class CopyProjectsController < ApplicationController
.with_indifferent_access
.merge(custom_field_values: @copy_project.custom_value_attributes)
end
+
+ def copy_started_notice
+ flash[:notice] = I18n.t('copy_project.started',
+ source_project_name: @project.name,
+ target_project_name: permitted_params.project[:name])
+ end
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 0fad12bf73a..c3b332c6126 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -56,11 +56,7 @@ class ProjectsController < ApplicationController
@projects = load_projects query
@custom_fields = ProjectCustomField.visible(User.current)
- respond_to do |format|
- format.html do
- render layout: 'no_menu'
- end
- end
+ render layout: 'no_menu'
end
current_menu_item :index do
@@ -69,8 +65,13 @@ class ProjectsController < ApplicationController
def new
assign_default_create_variables
+
@project = Project.new
+ Projects::SetAttributesService
+ .new(user: current_user, model: @project, contract_class: EmptyContract)
+ .call({})
+
render layout: 'no_menu'
end
@@ -79,41 +80,34 @@ class ProjectsController < ApplicationController
end
def create
- assign_default_create_variables
+ call_result = Projects::CreateService
+ .new(user: current_user)
+ .call(permitted_params.project)
- if validate_parent_id && @project.save
- @project.set_allowed_parent!(params['project']['parent_id']) if params['project'].has_key?('parent_id')
- add_current_user_to_project_if_not_admin(@project)
- respond_to do |format|
- format.html do
- flash[:notice] = l(:notice_successful_create)
- redirect_work_packages_or_overview
- end
- end
+ @project = call_result.result
+
+ if call_result.success?
+ flash[:notice] = t(:notice_successful_create)
+ redirect_work_packages_or_overview
else
- respond_to do |format|
- format.html { render action: 'new', layout: 'no_menu' }
- end
+ @errors = call_result.errors
+ assign_default_create_variables
+
+ render action: 'new', layout: 'no_menu'
end
end
def update
@altered_project = Project.find(@project.id)
- # TODO: move the validation into the contract
- # move setting the allowed parents to the service
- service = Projects::UpdateService
- .new(user: current_user,
- model: @altered_project)
+ service_call = Projects::UpdateService
+ .new(user: current_user,
+ model: @altered_project)
+ .call(permitted_params.project)
- if validate_parent_id && service.call(permitted_params.project).success?
- if params['project'].has_key?('parent_id')
- @altered_project.set_allowed_parent!(params['project']['parent_id'])
- end
- flash[:notice] = l(:notice_successful_update)
- OpenProject::Notifications.send('project_updated', project: @altered_project)
- end
+ @errors = service_call.errors
+ flash[:notice] = l(:notice_successful_update) if service_call.success?
redirect_to settings_project_path(@altered_project)
end
@@ -231,17 +225,6 @@ class ProjectsController < ApplicationController
@project = nil
end
- def add_current_user_to_project_if_not_admin(project)
- unless User.current.admin?
- r = Role.givable.find_by(id: Setting.new_project_user_role_id.to_i) || Role.givable.first
- m = Member.new do |member|
- member.principal = User.current
- member.role_ids = [r].map(&:id) # member.roles = [r] fails, this works
- end
- project.members << m
- end
- end
-
def load_query
@query = ParamsToQueryService.new(Project, current_user).call(params)
@@ -271,9 +254,6 @@ class ProjectsController < ApplicationController
def assign_default_create_variables
@wp_custom_fields = WorkPackageCustomField.order("#{CustomField.table_name}.position")
@types = ::Type.all
-
- @project.parent = Project.find(params[:parent_id]) if params[:parent_id]
- @project.attributes = permitted_params.project if params[:project].present?
end
protected
@@ -298,21 +278,6 @@ class ProjectsController < ApplicationController
filter_projects_by_permission projects
end
- # Validates parent_id param according to user's permissions
- # TODO: move it to Project model in a validation that depends on User.current
- def validate_parent_id
- return true if User.current.admin?
- parent_id = permitted_params.project && params[:project][:parent_id]
- if parent_id || @project.new_record?
- parent = parent_id.blank? ? nil : Project.find_by(id: parent_id.to_i)
- unless @project.allowed_parents.include?(parent)
- @project.errors.add :parent_id, :invalid
- return false
- end
- end
- true
- end
-
def update_demo_project_settings(project, value)
# e.g. when one of the demo projects gets deleted or a archived
if project.identifier == 'your-scrum-project' || project.identifier == 'demo-project'
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index b5557a966b8..2cb5d8df28e 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -287,4 +287,21 @@ module ProjectsHelper
def sorted_by_lft?
@sort_criteria.first_key == 'lft'
end
+
+ def allowed_parent_projects(project)
+ if project.persisted?
+ Projects::UpdateContract
+ else
+ Projects::CreateContract
+ end.new(project, current_user)
+ .assignable_parents
+ end
+
+ def short_project_description(project, length = 255)
+ unless project.description.present?
+ return ''
+ end
+
+ project.description.gsub(/\A(.{#{length}}[^\n\r]*).*\z/m, '\1...').strip
+ end
end
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index 2e87d54ba95..4dfaaa3886a 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -298,6 +298,7 @@ class PermittedParams
:responsible_id,
:identifier,
:project_type_id,
+ :parent_id,
custom_fields: [],
work_package_custom_field_ids: [],
type_ids: [],
diff --git a/app/models/project.rb b/app/models/project.rb
index 0d4399f1714..ee819cab06d 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1,4 +1,5 @@
#-- encoding: UTF-8
+
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
@@ -198,25 +199,6 @@ class Project < ActiveRecord::Base
visible.like(query)
end
- # TODO: move into SetAttributesService
- def initialize(attributes = nil)
- super
-
- initialized = (attributes || {}).stringify_keys
- if !initialized.key?('identifier') && Setting.sequential_project_identifiers?
- self.identifier = Project.next_identifier
- end
- if !initialized.key?('is_public')
- self.is_public = Setting.default_projects_public?
- end
- if !initialized.key?('enabled_module_names')
- self.enabled_module_names = Setting.default_projects_modules
- end
- if !initialized.key?('types') && !initialized.key?('type_ids')
- self.types = ::Type.default
- end
- end
-
def possible_members(criteria, limit)
Principal.active_or_registered.like(criteria).not_in_project(self).limit(limit)
end
@@ -273,7 +255,7 @@ class Project < ActiveRecord::Base
create_time_entry_activity_if_needed(activity_hash)
else
activity = project.time_entry_activities.find_by(id: id.to_i)
- activity.update_attributes(activity_hash) if activity
+ activity&.update(activity_hash)
end
end
@@ -342,71 +324,6 @@ class Project < ActiveRecord::Base
update_attribute :status, STATUS_ACTIVE
end
- # TODO: Move into contract
- # Returns an array of projects the project can be moved to
- # by the current user
- def allowed_parents
- return @allowed_parents if @allowed_parents
-
- @allowed_parents = Project.allowed_to(User.current, :add_subprojects)
- @allowed_parents = @allowed_parents - self_and_descendants
- if User.current.allowed_to?(:add_project, nil, global: true) || (!new_record? && parent.nil?)
- @allowed_parents << nil
- end
- unless parent.nil? || @allowed_parents.empty? || @allowed_parents.include?(parent)
- @allowed_parents << parent
- end
- @allowed_parents
- end
-
- # TODO: Move into contract
- def allowed_parent?(p)
- p = guarantee_project_or_nil_or_false(p)
- return false if p == false # have to explicitly check for false
-
- !((p.nil? && persisted? && allowed_parents.empty?) ||
- (p.present? && allowed_parents.exclude?(p)))
- end
-
- # Sets the parent of the project with authorization check
- def set_allowed_parent!(p)
- set_parent!(p) if allowed_parent?(p)
- end
-
- # Sets the parent of the project
- # Argument can be either a Project, a String, a Fixnum or nil
- def set_parent!(p)
- p = guarantee_project_or_nil_or_false(p)
- return false if p == false # have to explicitly check for false
-
- if p == parent && !p.nil?
- # Nothing to do
- true
- elsif p.nil? || (p.active? && move_possible?(p))
- # Insert the project so that target's children or root projects stay alphabetically sorted
- sibs = (p.nil? ? self.class.roots : p.children)
- to_be_inserted_before = sibs.detect { |c| c.name.to_s.downcase > name.to_s.downcase }
- if to_be_inserted_before
- move_to_left_of(to_be_inserted_before)
- elsif p.nil?
- if sibs.empty?
- # move_to_root adds the project in first (ie. left) position
- move_to_root
- else
- move_to_right_of(sibs.last) unless self == sibs.last
- end
- else
- # move_to_child_of adds the project in last (ie.right) position
- move_to_child_of(p)
- end
- WorkPackage.update_versions_from_hierarchy_change(self)
- true
- else
- # Can not move to the given target
- false
- end
- end
-
def types_used_by_work_packages
::Type.where(id: WorkPackage.where(project_id: project.id)
.select(:type_id)
@@ -541,57 +458,6 @@ class Project < ActiveRecord::Base
name
end
- # TODO: Move into helper
- # Returns a short description of the projects (first lines)
- def short_description(length = 255)
- unless description.present?
- return ''
- end
-
- description.gsub(/\A(.{#{length}}[^\n\r]*).*\z/m, '\1...').strip
- end
-
- # The earliest start date of a project, based on it's issues and versions
- def start_date
- [
- work_packages.minimum('start_date'),
- shared_versions.map(&:effective_date),
- shared_versions.map(&:start_date)
- ].flatten.compact.min
- end
-
- # The latest finish date of an issue or version
- def due_date
- [
- work_packages.maximum('due_date'),
- shared_versions.map(&:effective_date),
- shared_versions.map { |v| v.fixed_issues.maximum('due_date') }
- ].flatten.compact.max
- end
-
- def overdue?
- active? && !due_date.nil? && (due_date < Date.today)
- end
-
- # TODO: Can be deleted?
- # Returns the percent completed for this project, based on the
- # progress on it's versions.
- def completed_percent(options = { include_subprojects: false })
- if options.delete(:include_subprojects)
- total = self_and_descendants.map(&:completed_percent).sum
-
- total / self_and_descendants.count
- else
- if versions.count > 0
- total = versions.map(&:completed_percent).sum
-
- total / versions.count
- else
- 100
- end
- end
- end
-
# Return true if this project is allowed to do the specified action.
# action can be:
# * a parameter-like Hash (eg. controller: '/projects', action: 'edit')
@@ -610,7 +476,7 @@ class Project < ActiveRecord::Base
end
def enabled_module_names=(module_names)
- if module_names && module_names.is_a?(Array)
+ if module_names&.is_a?(Array)
module_names = module_names.map(&:to_s).reject(&:blank?)
self.enabled_modules = module_names.map { |name| enabled_modules.detect { |mod| mod.name == name } || EnabledModule.new(name: name) }
else
@@ -674,7 +540,7 @@ class Project < ActiveRecord::Base
end
# at the end the root level must be sorted as well
- result.sort_by { |h| h[:project].name.downcase if h[:project].name }
+ result.sort_by { |h| h[:project].name&.downcase }
end
def self.project_tree_from_hierarchy(projects_hierarchy, level, &block)
diff --git a/app/models/role.rb b/app/models/role.rb
index 9a3cd6b9f0e..8f064f01f63 100644
--- a/app/models/role.rb
+++ b/app/models/role.rb
@@ -170,6 +170,13 @@ class Role < ActiveRecord::Base
paginate_scope! givable.like(search), options
end
+ def self.in_new_project
+ givable
+ .except(:order)
+ .order(Arel.sql("COALESCE(#{Setting.new_project_user_role_id.to_i} = id, false) DESC, position"))
+ .first
+ end
+
private
def allowed_permissions
diff --git a/app/services/base_services/create.rb b/app/services/base_services/create.rb
index 01d19485203..92b48088776 100644
--- a/app/services/base_services/create.rb
+++ b/app/services/base_services/create.rb
@@ -29,69 +29,15 @@
#++
module BaseServices
- class Create
- include Concerns::Contracted
- include Shared::ServiceContext
-
- attr_reader :user
-
- def initialize(user:, contract_class: nil)
- @user = user
- self.contract_class = contract_class || default_contract_class
- end
-
- def call(params)
- in_context(false) do
- create(params)
- end
- end
-
+ class Create < Write
private
- def create(params)
- attributes_call = set_attributes(params)
-
- if attributes_call.success? &&
- !attributes_call.result.save
- attributes_call.errors = attributes_call.result.errors
- attributes_call.success = false
- else
- after_save(attributes_call)
- end
-
- attributes_call
- end
-
- def set_attributes(params)
- attributes_service_class
- .new(user: user,
- model: new_instance(params),
- contract_class: contract_class)
- .call(params)
- end
-
- def after_save(_attributes_call)
- # nothing for now but subclasses can override
- end
-
- def new_instance(_params)
+ def instance(_params)
instance_class.new
end
def default_contract_class
"#{namespace}::CreateContract".constantize
end
-
- def attributes_service_class
- "#{namespace}::SetAttributesService".constantize
- end
-
- def instance_class
- namespace.singularize.constantize
- end
-
- def namespace
- self.class.name.deconstantize
- end
end
end
diff --git a/app/services/base_services/set_attributes.rb b/app/services/base_services/set_attributes.rb
index 47c81330a05..4ee9a14d6e3 100644
--- a/app/services/base_services/set_attributes.rb
+++ b/app/services/base_services/set_attributes.rb
@@ -60,10 +60,10 @@ module BaseServices
def set_attributes(params)
model.attributes = params
- set_default_attributes if model.new_record?
+ set_default_attributes(params) if model.new_record?
end
- def set_default_attributes
+ def set_default_attributes(_params)
# nothing to do for now but a subclass may
end
diff --git a/app/services/base_services/update.rb b/app/services/base_services/update.rb
index 0c9975a6c8f..3859dbc4643 100644
--- a/app/services/base_services/update.rb
+++ b/app/services/base_services/update.rb
@@ -29,68 +29,22 @@
#++
module BaseServices
- class Update
- include Concerns::Contracted
- include Shared::ServiceContext
-
- attr_reader :user,
- :model
+ class Update < Write
+ attr_reader :model
def initialize(user:, model:, contract_class: nil)
- @user = user
@model = model
- self.contract_class = contract_class || default_contract_class
- end
-
- def call(params)
- in_context(false) do
- update(params)
- end
+ super(user: user, contract_class: contract_class)
end
private
- def update(params)
- attributes_call = set_attributes(params)
-
- if attributes_call.failure?
- # nothing to do
- elsif !attributes_call.result.save
- attributes_call.errors = attributes_call.result.errors
- attributes_call.success = false
- else
- after_save
- end
-
- attributes_call
- end
-
- def set_attributes(params)
- attributes_service_class
- .new(user: user,
- model: model,
- contract_class: contract_class)
- .call(params)
- end
-
- def after_save
- # nothing for now
+ def instance(_params)
+ model
end
def default_contract_class
"#{namespace}::UpdateContract".constantize
end
-
- def attributes_service_class
- "#{namespace}::SetAttributesService".constantize
- end
-
- def instance_class
- namespace.singularize.constantize
- end
-
- def namespace
- self.class.name.deconstantize
- end
end
end
diff --git a/app/services/base_services/write.rb b/app/services/base_services/write.rb
new file mode 100644
index 00000000000..4bca6c37758
--- /dev/null
+++ b/app/services/base_services/write.rb
@@ -0,0 +1,98 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is a project management system.
+# Copyright (C) 2012-2019 the OpenProject Foundation (OPF)
+#
+# 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 doc/COPYRIGHT.rdoc for more details.
+#++
+
+module BaseServices
+ class Write
+ include Concerns::Contracted
+ include Shared::ServiceContext
+
+ attr_reader :user
+
+ def initialize(user:, contract_class: nil)
+ @user = user
+ self.contract_class = contract_class || default_contract_class
+ end
+
+ def call(params)
+ in_context(false) do
+ write(params)
+ end
+ end
+
+ private
+
+ def write(params)
+ attributes_call = set_attributes(params)
+
+ if attributes_call.failure?
+ # nothing to do
+ elsif !attributes_call.result.save
+ attributes_call.errors = attributes_call.result.errors
+ attributes_call.success = false
+ else
+ after_save(attributes_call)
+ end
+
+ attributes_call
+ end
+
+ def set_attributes(params)
+ attributes_service_class
+ .new(user: user,
+ model: instance(params),
+ contract_class: contract_class)
+ .call(params)
+ end
+
+ def after_save(_attributes_call)
+ # nothing for now but subclasses can override
+ end
+
+ def instance(_params)
+ raise NotImplementedError
+ end
+
+ def default_contract_class
+ raise NotImplementedError
+ end
+
+ def attributes_service_class
+ "#{namespace}::SetAttributesService".constantize
+ end
+
+ def instance_class
+ namespace.singularize.constantize
+ end
+
+ def namespace
+ self.class.name.deconstantize
+ end
+ end
+end
diff --git a/app/services/concerns/contracted.rb b/app/services/concerns/contracted.rb
index 8aeee08aecb..0a297d26edf 100644
--- a/app/services/concerns/contracted.rb
+++ b/app/services/concerns/contracted.rb
@@ -71,7 +71,9 @@ module Concerns::Contracted
def validate(object, user)
validate_and_yield(object, user) do
- object.valid?
+ # No object validation is necessary at this point
+ # as object.valid? is already called in the contract
+ true
end
end
end
diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb
index aa2ce74a14d..d174945104e 100644
--- a/app/services/projects/create_service.rb
+++ b/app/services/projects/create_service.rb
@@ -30,5 +30,8 @@
module Projects
class CreateService < ::BaseServices::Create
+ def after_save(attributes_call)
+ attributes_call.result.add_member!(user, Role.in_new_project) unless user.admin?
+ end
end
end
diff --git a/app/services/projects/set_attributes_service.rb b/app/services/projects/set_attributes_service.rb
index e4303df5e20..38ea1fd2418 100644
--- a/app/services/projects/set_attributes_service.rb
+++ b/app/services/projects/set_attributes_service.rb
@@ -30,5 +30,33 @@
module Projects
class SetAttributesService < ::BaseServices::SetAttributes
+ private
+
+ def set_default_attributes(attributes)
+ attribute_keys = attributes.keys.map(&:to_s)
+
+ set_default_identifier(attribute_keys.include?('identifier'))
+ set_default_is_public(attribute_keys.include?('is_public'))
+ set_default_module_names(attribute_keys.include?('enabled_module_names'))
+ set_default_types(attribute_keys.include?('types') || attribute_keys.include?('type_ids'))
+ end
+
+ def set_default_identifier(provided)
+ if !provided && Setting.sequential_project_identifiers?
+ model.identifier = Project.next_identifier
+ end
+ end
+
+ def set_default_is_public(provided)
+ model.is_public = Setting.default_projects_public? unless provided
+ end
+
+ def set_default_module_names(provided)
+ model.enabled_module_names = Setting.default_projects_modules if !provided && model.enabled_module_names.empty?
+ end
+
+ def set_default_types(provided)
+ model.types = ::Type.default if !provided && model.types.empty?
+ end
end
end
diff --git a/app/services/projects/update_service.rb b/app/services/projects/update_service.rb
index f48ffab1c38..67b05ca63c7 100644
--- a/app/services/projects/update_service.rb
+++ b/app/services/projects/update_service.rb
@@ -32,9 +32,23 @@ module Projects
class UpdateService < ::BaseServices::Update
private
- def after_save
+ attr_accessor :memoized_changes
+
+ def set_attributes(params)
+ ret = super
+
+ # Because awesome_nested_set reloads the model after saving, we cannot rely
+ # on saved_changes.
+ self.memoized_changes = model.changes
+
+ ret
+ end
+
+ def after_save(*)
touch_on_custom_values_update
notify_on_identifier_renamed
+ send_update_notification
+ update_wp_versions_on_parent_change
end
def touch_on_custom_values_update
@@ -42,13 +56,23 @@ module Projects
end
def notify_on_identifier_renamed
- return unless model.saved_change_to_identifier?
+ return unless memoized_changes['identifier']
OpenProject::Notifications.send('project_renamed', project: model)
end
+ def send_update_notification
+ OpenProject::Notifications.send('project_updated', project: model)
+ end
+
def only_custom_values_updated?
!model.saved_changes? && model.custom_values.any?(&:saved_changes?)
end
+
+ def update_wp_versions_on_parent_change
+ return unless memoized_changes['parent_id']
+
+ WorkPackage.update_versions_from_hierarchy_change(model)
+ end
end
end
diff --git a/app/services/roles/create_service.rb b/app/services/roles/create_service.rb
index b54f2fcba67..b26ee135825 100644
--- a/app/services/roles/create_service.rb
+++ b/app/services/roles/create_service.rb
@@ -33,7 +33,7 @@ class Roles::CreateService < ::BaseServices::Create
private
- def create(params)
+ def write(params)
copy_workflow_id = params.delete(:copy_workflow_from)
super_call = super
@@ -47,7 +47,7 @@ class Roles::CreateService < ::BaseServices::Create
super_call
end
- def new_instance(params)
+ def instance(params)
if params.delete(:global_role)
GlobalRole.new
else
diff --git a/app/services/roles/set_attributes_service.rb b/app/services/roles/set_attributes_service.rb
index 3d7f9973207..2f60a34e4f5 100644
--- a/app/services/roles/set_attributes_service.rb
+++ b/app/services/roles/set_attributes_service.rb
@@ -30,7 +30,7 @@
module Roles
class SetAttributesService < ::BaseServices::SetAttributes
- def set_default_attributes
+ def set_default_attributes(*)
model.permissions = Role.non_member.permissions if model.permissions.nil? || model.permissions.empty?
end
end
diff --git a/app/services/time_entries/set_attributes_service.rb b/app/services/time_entries/set_attributes_service.rb
index adb4a29048d..4fcf7f06c6a 100644
--- a/app/services/time_entries/set_attributes_service.rb
+++ b/app/services/time_entries/set_attributes_service.rb
@@ -44,7 +44,7 @@ module TimeEntries
use_project_activity(model)
end
- def set_default_attributes
+ def set_default_attributes(*)
set_default_user
set_default_activity
set_default_hours
diff --git a/app/services/versions/set_attributes_service.rb b/app/services/versions/set_attributes_service.rb
index 9afc49bdefa..669ec26cb2a 100644
--- a/app/services/versions/set_attributes_service.rb
+++ b/app/services/versions/set_attributes_service.rb
@@ -32,7 +32,7 @@ module Versions
class SetAttributesService < ::BaseServices::SetAttributes
private
- def set_default_attributes
+ def set_default_attributes(*)
return unless model.new_record?
model.sharing ||= 'none'
diff --git a/app/services/versions/update_service.rb b/app/services/versions/update_service.rb
index c64d494090f..81be79cfcc4 100644
--- a/app/services/versions/update_service.rb
+++ b/app/services/versions/update_service.rb
@@ -32,7 +32,7 @@ module Versions
class UpdateService < ::BaseServices::Update
private
- def after_save
+ def after_save(*)
model.touch if only_custom_values_updated?
update_wps_from_sharing_change if model.saved_change_to_sharing?
end
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rb
index 706f0c0dd68..1d15ae076d9 100644
--- a/app/services/work_packages/set_attributes_service.rb
+++ b/app/services/work_packages/set_attributes_service.rb
@@ -38,7 +38,7 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributes
set_static_attributes(attributes)
work_package.change_by_system do
- set_default_attributes
+ set_default_attributes(attributes)
update_project_dependent_attributes
end
@@ -59,7 +59,7 @@ class WorkPackages::SetAttributesService < ::BaseServices::SetAttributes
work_package.attributes = assignable_attributes
end
- def set_default_attributes
+ def set_default_attributes(*)
return unless work_package.new_record?
work_package.priority ||= IssuePriority.active.default
diff --git a/app/views/copy_projects/copy_from_admin.html.erb b/app/views/copy_projects/copy_from_admin.html.erb
index b7e9a83b0ac..5e0cc6c7692 100644
--- a/app/views/copy_projects/copy_from_admin.html.erb
+++ b/app/views/copy_projects/copy_from_admin.html.erb
@@ -36,6 +36,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= render partial: 'projects/form', locals: { f: f,
project: @copy_project,
+ errors: @errors,
render_advanced: true,
render_types: false,
render_modules: false,
diff --git a/app/views/copy_projects/copy_from_settings.html.erb b/app/views/copy_projects/copy_from_settings.html.erb
index b0ba7f2f5ba..e7b12cb540c 100644
--- a/app/views/copy_projects/copy_from_settings.html.erb
+++ b/app/views/copy_projects/copy_from_settings.html.erb
@@ -35,6 +35,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= render partial: 'projects/form', locals: { f: f,
project: @copy_project,
+ errors: @errors,
render_advanced: true,
render_types: false,
render_modules: false,
diff --git a/app/views/homescreen/blocks/_projects.html.erb b/app/views/homescreen/blocks/_projects.html.erb
index ee4e4482743..43798e42a7b 100644
--- a/app/views/homescreen/blocks/_projects.html.erb
+++ b/app/views/homescreen/blocks/_projects.html.erb
@@ -9,7 +9,7 @@
<ul class="widget-box--arrow-links">
<% @newest_projects.each do |project| %>
<li>
- <%= link_to project, project_path(project), title: project.short_description %>
+ <%= link_to project, project_path(project), title: short_project_description(project) %>
<small>(<%= format_date(project.created_on) %>)</small>
</li>
<% end %>
diff --git a/app/views/projects/_edit.html.erb b/app/views/projects/_edit.html.erb
index b345c4e598c..b4ad2ab272d 100644
--- a/app/views/projects/_edit.html.erb
+++ b/app/views/projects/_edit.html.erb
@@ -27,14 +27,16 @@ See docs/COPYRIGHT.rdoc for more details.
++#%>
<%= labelled_tabular_form_for @altered_project, url: project_path(@project) do |f| %>
- <%= render partial: '/projects/form', locals: {
- f: f,
- project: @altered_project,
- render_advanced: false,
- render_types: false,
- render_modules: false,
- render_custom_fields: false
- } %>
+ <%= render partial: '/projects/form',
+ locals: {
+ f: f,
+ project: @altered_project,
+ errors: @errors,
+ render_advanced: false,
+ render_types: false,
+ render_modules: false,
+ render_custom_fields: false
+ } %>
<%= f.button l(:button_save), class: 'button -highlight -with-icon icon-checkmark' %>
<% end %>
diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb
index 262e4cf980a..4aefcc51fdf 100644
--- a/app/views/projects/_form.html.erb
+++ b/app/views/projects/_form.html.erb
@@ -27,7 +27,7 @@ See docs/COPYRIGHT.rdoc for more details.
++#%>
-<%= error_messages_for(project, classes: '-inline') unless local_assigns[:no_error_messages] %>
+<%= error_messages_for_contract(project, errors) unless local_assigns[:no_error_messages] %>
<!--[form:project]-->
diff --git a/app/views/projects/form/attributes/_parent_id.html.erb b/app/views/projects/form/attributes/_parent_id.html.erb
index 8be6bdc76f3..9ed80389db9 100644
--- a/app/views/projects/form/attributes/_parent_id.html.erb
+++ b/app/views/projects/form/attributes/_parent_id.html.erb
@@ -27,14 +27,17 @@ See docs/COPYRIGHT.rdoc for more details.
++#%>
-<% project = form.object %>
+<%
+ project = form.object
+ allowed_parents = allowed_parent_projects(project).to_a
+%>
-<% unless project.allowed_parents.compact.empty? %>
+<% unless allowed_parents.empty? %>
<div class="form--field">
<%= form.select :parent_id,
- project_tree_options_for_select(project.allowed_parents.compact,
+ project_tree_options_for_select(allowed_parents,
selected: project.parent),
- include_blank: project.allowed_parents.include?(nil),
+ include_blank: true,
container_class: '-wide' %>
</div>
<% end %>
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index 32509a0962a..c5ebe6248ee 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -91,7 +91,7 @@ See docs/COPYRIGHT.rdoc for more details.
</thead>
<tbody>
<% projects_with_levels_order_sensitive(@projects) do |project, level| %>
- <tr class="basics context-menu--reveal <%= project_css_classes(project) %> <%= level > 0 ? "idnt idnt-#{level}" : nil %> <%= params[:expand] == 'all' && project.short_description.present? ? '-no-highlighting -expanded' : '' %>">
+ <tr class="basics context-menu--reveal <%= project_css_classes(project) %> <%= level > 0 ? "idnt idnt-#{level}" : nil %> <%= params[:expand] == 'all' && short_project_description(project).present? ? '-no-highlighting -expanded' : '' %>">
<td></td>
<td class="name project--hierarchy <%= project.archived? ? 'archived' : '' %>">
<i class="projects-table--hierarchy-icon"></i>
@@ -146,7 +146,7 @@ See docs/COPYRIGHT.rdoc for more details.
<td></td>
<td colspan="<%= @custom_fields.size + (User.current.admin? ? 6 : 3) %>" class="project--hierarchy">
<div class="description-container">
- <span class="wiki"><%= format_text(project.short_description(255), project: project) %></span>
+ <span class="wiki"><%= format_text(short_project_description(project), project: project) %></span>
</div>
</td>
</tr>
diff --git a/app/views/projects/new.html.erb b/app/views/projects/new.html.erb
index 864ec197dfd..a412b7ef956 100644
--- a/app/views/projects/new.html.erb
+++ b/app/views/projects/new.html.erb
@@ -29,12 +29,15 @@ See docs/COPYRIGHT.rdoc for more details.
<% html_title l("label_project_new") %>
<%= toolbar title: l(:label_project_new) %>
<%= labelled_tabular_form_for @project do |f| %>
- <%= render partial: 'form', locals: { f: f,
- project: @project,
- render_advanced: true,
- render_types: false,
- render_modules: false,
- render_custom_fields: false
- } %>
+ <%= render partial: 'form',
+ locals: {
+ f: f,
+ project: @project,
+ errors: @errors,
+ render_advanced: true,
+ render_types: false,
+ render_modules: false,
+ render_custom_fields: false
+ } %>
<%= styled_button_tag l(:button_create), class: '-highlight -with-icon icon-checkmark' %>
<% end %>
diff --git a/app/workers/copy_project_job.rb b/app/workers/copy_project_job.rb
index df240408e18..2243c9405e9 100644
--- a/app/workers/copy_project_job.rb
+++ b/app/workers/copy_project_job.rb
@@ -49,19 +49,18 @@ class CopyProjectJob < ApplicationJob
User.current = user
target_project_name = target_project_params[:name]
- target_project, errors = with_locale_for(user) {
+ target_project, errors = with_locale_for(user) do
create_project_copy(source_project,
target_project_params,
associations_to_copy,
send_mails)
- }
+ end
if target_project
ProjectMailer.copy_project_succeeded(user, source_project, target_project, errors).deliver_now
else
ProjectMailer.copy_project_failed(user, source_project, target_project_name, errors).deliver_now
end
-
rescue StandardError => e
logger.error { "Failed to finish copy project job: #{e} #{e.message}" }
errors = [I18n.t('copy_project.failed_internal')]
@@ -86,14 +85,15 @@ class CopyProjectJob < ApplicationJob
errors = []
ProjectMailer.with_deliveries(send_mails) do
- parent_id = target_project_params[:parent_id]
-
target_project = Project.copy_attributes(source_project)
- target_project.attributes = target_project_params
- if validate_parent_id(target_project, parent_id) && target_project.save
- target_project.set_allowed_parent!(parent_id) if parent_id
+ service_call = Projects::SetAttributesService
+ .new(user: user,
+ model: target_project,
+ contract_class: Projects::CreateContract)
+ .call(target_project_params)
+ if service_call.success? && target_project.save
target_project.copy_associations(source_project, only: associations_to_copy)
# Project was created
@@ -108,7 +108,7 @@ class CopyProjectJob < ApplicationJob
end
end
else
- errors = target_project.errors.full_messages
+ errors = service_call.errors.merge(target_project.errors).full_messages
target_project = nil
logger.error("Copying project fails with validation errors: #{errors.join("\n")}")
end
@@ -127,24 +127,6 @@ class CopyProjectJob < ApplicationJob
return target_project, errors
end
- # Validates parent_id param according to user's permissions
- # TODO: move it to Project model in a validation that depends on User.current
- def validate_parent_id(project, parent_id)
- return true if User.current.admin?
-
- if parent_id || project.new_record?
- parent = parent_id.blank? ? nil : Project.find_by(id: parent_id.to_i)
-
- unless project.allowed_parents.include?(parent)
- project.errors.add :parent_id, :invalid
-
- return false
- end
- end
-
- true
- end
-
def logger
Delayed::Worker.logger
end
diff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rb
index 4ea6a3f8ba4..c30365065c2 100644
--- a/lib/api/v3/utilities/custom_field_injector.rb
+++ b/lib/api/v3/utilities/custom_field_injector.rb
@@ -294,8 +294,8 @@ module API
end
def allowed_users_href_callback
- # for now we ASSUME that every customized that has a
- # user custom field, will also define a project...
+ static_filters = allowed_users_static_filters
+
->(*) {
project_id_value = if represented.respond_to?(:model) && represented.model.is_a?(Project)
represented.id
@@ -303,15 +303,9 @@ module API
represented.project_id.to_s
end
- params = [{ status: { operator: '!',
- values: [Principal::STATUSES[:builtin].to_s,
- Principal::STATUSES[:locked].to_s] } },
- { type: { operator: '=', values: ['User'] } },
- { member: { operator: '=', values: [project_id_value.to_s] } }]
-
- query = CGI.escape(::JSON.dump(params))
+ filters = static_filters << { member: { operator: '=', values: [project_id_value.to_s] } }
- "#{api_v3_paths.principals}?filters=#{query}&pageSize=0"
+ api_v3_paths.path_for(:principals, filters: filters, page_size: 0)
}
end
@@ -355,6 +349,13 @@ module API
end
end
+ def allowed_users_static_filters
+ [{ status: { operator: '!',
+ values: [Principal::STATUSES[:builtin].to_s,
+ Principal::STATUSES[:locked].to_s] } },
+ { type: { operator: '=', values: ['User'] } }]
+ end
+
module RepresenterClass
def custom_field_injector(config)
@custom_field_injector_config = config.reverse_merge custom_field_injector_config
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index 9db82753535..b584027f38b 100644
--- a/lib/api/v3/utilities/path_helper.rb
+++ b/lib/api/v3/utilities/path_helper.rb
@@ -423,10 +423,11 @@ module API
"#{project(project_id)}/work_packages"
end
- def self.path_for(path, filters: nil, sort_by: nil)
+ def self.path_for(path, filters: nil, sort_by: nil, page_size: nil)
query_params = {
filters: filters&.to_json,
- sortBy: sort_by&.to_json
+ sortBy: sort_by&.to_json,
+ pageSize: page_size
}.reject { |_, v| v.blank? }
if query_params.any?
diff --git a/modules/backlogs/spec/models/sprint_spec.rb b/modules/backlogs/spec/models/sprint_spec.rb
index 7a0426d9ed3..ba4e6e639fe 100644
--- a/modules/backlogs/spec/models/sprint_spec.rb
+++ b/modules/backlogs/spec/models/sprint_spec.rb
@@ -229,7 +229,8 @@ describe Sprint, type: :model do
describe 'WITH the version beeing shared from a parent project' do
before(:each) do
- project.set_parent!(@other_project)
+ project.update(parent: @other_project)
+ project.reload
@version = FactoryBot.create(:sprint, name: 'descended', project: @other_project, sharing: 'descendants')
end
@@ -240,9 +241,9 @@ describe Sprint, type: :model do
describe 'WITH the version beeing shared within the tree' do
before(:each) do
@parent_project = FactoryBot.create(:project)
- # Setting the parent has to be in this order, don't know why yet
- @other_project.set_parent!(@parent_project)
- project.set_parent!(@parent_project)
+ @other_project.update(parent: @parent_project)
+ project.update(parent: @parent_project)
+ project.reload
@version = FactoryBot.create(:sprint, name: 'treed', project: @other_project, sharing: 'tree')
end
@@ -252,8 +253,8 @@ describe Sprint, type: :model do
describe 'WITH the version beeing shared within the tree' do
before(:each) do
- @descendant_project = FactoryBot.create(:project)
- @descendant_project.set_parent!(project)
+ @descendant_project = FactoryBot.create(:project, parent: project)
+ project.reload
@version = FactoryBot.create(:sprint, name: 'hierar', project: @descendant_project, sharing: 'hierarchy')
end
diff --git a/modules/grids/app/services/grids/set_attributes_service.rb b/modules/grids/app/services/grids/set_attributes_service.rb
index 87396b20614..4be29f0fa1c 100644
--- a/modules/grids/app/services/grids/set_attributes_service.rb
+++ b/modules/grids/app/services/grids/set_attributes_service.rb
@@ -36,7 +36,7 @@ class Grids::SetAttributesService < ::BaseServices::SetAttributes
def set_attributes(attributes)
widget_attributes = attributes.delete(:widgets)
- ret = super
+ ret = super(attributes)
update_widgets(widget_attributes)
diff --git a/modules/grids/app/services/grids/update_service.rb b/modules/grids/app/services/grids/update_service.rb
index c0988bbda3e..b82d256c3f6 100644
--- a/modules/grids/app/services/grids/update_service.rb
+++ b/modules/grids/app/services/grids/update_service.rb
@@ -31,13 +31,13 @@
class Grids::UpdateService < ::BaseServices::Update
protected
- def update(attributes)
+ def write(attributes)
set_type_for_error_message(attributes.delete(:scope))
super
end
- def after_save
+ def after_save(*)
model.touch if only_widgets_updated?
end
diff --git a/modules/reporting/spec/models/cost_query/operator_spec.rb b/modules/reporting/spec/models/cost_query/operator_spec.rb
index 6dd653537fc..72920760c43 100644
--- a/modules/reporting/spec/models/cost_query/operator_spec.rb
+++ b/modules/reporting/spec/models/cost_query/operator_spec.rb
@@ -40,10 +40,7 @@ describe CostQuery, type: :model, reporting_query_helper: true do
end
def create_project(options = {})
- parent = options.delete :parent
- p = FactoryBot.create(:project, options)
- p.set_parent! parent if parent
- p
+ FactoryBot.create(:project, options)
end
it "does =" do
diff --git a/spec/factories/project_factory.rb b/spec/factories/project_factory.rb
index 0a9489a0c0c..13fcfbf7481 100644
--- a/spec/factories/project_factory.rb
+++ b/spec/factories/project_factory.rb
@@ -39,16 +39,14 @@ FactoryBot.define do
created_on { Time.now }
updated_on { Time.now }
enabled_module_names { OpenProject::AccessControl.available_project_modules }
+ is_public { false }
callback(:after_build) do |project, evaluator|
disabled_modules = Array(evaluator.disable_modules)
project.enabled_module_names = project.enabled_module_names - disabled_modules
- end
- callback(:before_create) do |project, evaluator|
- unless evaluator.no_types ||
- ::Type.where(is_standard: true).count > 0
- project.types << FactoryBot.build(:type_standard)
+ if !evaluator.no_types && project.types.empty?
+ project.types << (::Type.where(is_standard: true).first || FactoryBot.build(:type_standard))
end
end
diff --git a/spec/factories/type_factory.rb b/spec/factories/type_factory.rb
index 49ffbcd8796..5025e6cad07 100644
--- a/spec/factories/type_factory.rb
+++ b/spec/factories/type_factory.rb
@@ -58,19 +58,19 @@ FactoryBot.define do
name { 'None' }
is_standard { true }
is_default { true }
- created_at do Time.now end
+ created_at { Time.now }
updated_at { Time.now }
end
factory :type_bug, class: ::Type do
name { 'Bug' }
position { 1 }
- created_at do Time.now end
- updated_at do Time.now end
+ created_at { Time.now }
+ updated_at { Time.now }
# reuse existing type with the given name
# this prevents a validation error (name has to be unique)
- initialize_with do ::Type.find_or_initialize_by(name: name) end
+ initialize_with { ::Type.find_or_initialize_by(name: name) }
factory :type_feature do
name { 'Feature' }
diff --git a/spec/factories/work_package_factory.rb b/spec/factories/work_package_factory.rb
index a52dd86fbb5..8b5073c96e2 100644
--- a/spec/factories/work_package_factory.rb
+++ b/spec/factories/work_package_factory.rb
@@ -35,8 +35,8 @@ FactoryBot.define do
priority
project factory: :project_with_types
status factory: :status
- sequence(:subject) do |n| "WorkPackage No. #{n}" end
- description do |i| "Description for '#{i.subject}'" end
+ sequence(:subject) { |n| "WorkPackage No. #{n}" }
+ description { |i| "Description for '#{i.subject}'" }
author factory: :user
created_at { Time.now }
updated_at { Time.now }
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index 9534a1295b2..e6808286007 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -32,7 +32,6 @@ describe 'Projects index page',
type: :feature,
js: true,
with_settings: { login_required?: false } do
-
let!(:admin) { FactoryBot.create :admin }
let!(:manager) { FactoryBot.create :role, name: 'Manager' }
@@ -619,7 +618,7 @@ describe 'Projects index page',
member_in_project: parent_project,
member_through_role: can_add_subprojects_role)
end
- let!(:simple_member) do
+ let(:simple_member) do
FactoryBot.create(:user,
member_in_project: parent_project,
member_through_role: developer)
diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb
index e298f00ad0b..eef4af49cd0 100644
--- a/spec/helpers/projects_helper_spec.rb
+++ b/spec/helpers/projects_helper_spec.rb
@@ -211,4 +211,13 @@ describe ProjectsHelper, type: :helper do
end
end
end
+
+ context '#short_project_description' do
+ let(:project) { FactoryBot.build_stubbed(:project, description: ('Abcd ' * 5 + "\n") * 11) }
+
+ it 'returns shortened description' do
+ expect(helper.short_project_description(project))
+ .to eql((('Abcd ' * 5 + "\n") * 10)[0..-2] + '...')
+ end
+ end
end
diff --git a/spec/lib/api/v3/work_packages/work_package_payload_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_payload_representer_spec.rb
index 3e88bd93e1f..20e2b0722db 100644
--- a/spec/lib/api/v3/work_packages/work_package_payload_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_payload_representer_spec.rb
@@ -421,6 +421,8 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter do
describe 'caching' do
it 'does not cache' do
+ representer.to_json
+
expect(Rails.cache)
.not_to receive(:fetch)
diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
index dff3919f398..de5745a2b29 100644
--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
@@ -1054,7 +1054,7 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
it 'is based on the representer\'s cache_key' do
allow(OpenProject::Cache)
.to receive(:fetch)
- .and_return("{}")
+ .and_return({_links: {}}.to_json)
expect(OpenProject::Cache)
.to receive(:fetch)
.with(representer.json_cache_key)
diff --git a/spec/models/changeset_spec.rb b/spec/models/changeset_spec.rb
index a0f28d6bfde..1c20318b906 100644
--- a/spec/models/changeset_spec.rb
+++ b/spec/models/changeset_spec.rb
@@ -32,13 +32,13 @@ describe Changeset, type: :model do
let(:email) { '[email protected]' }
with_virtual_subversion_repository do
- let(:changeset) {
+ let(:changeset) do
FactoryBot.build(:changeset,
repository: repository,
revision: '1',
committer: email,
comments: 'Initial commit')
- }
+ end
end
shared_examples_for 'valid changeset' do
@@ -82,13 +82,13 @@ describe Changeset, type: :model do
describe 'stripping commit' do
let(:comment) { 'This is a looooooooooooooong comment' + (' ' * 80 + "\n") * 5 }
with_virtual_subversion_repository do
- let(:changeset) {
+ let(:changeset) do
FactoryBot.build(:changeset,
repository: repository,
revision: '1',
committer: email,
comments: comment)
- }
+ end
end
it 'should for changeset comments strip' do
@@ -157,14 +157,18 @@ describe Changeset, type: :model do
let(:comments) { "Some fix made, fixes ##{work_package.id} and fixes ##{other_work_package.id}" }
with_virtual_subversion_repository do
- let!(:work_package) { FactoryBot.create :work_package, project: repository.project, status: open_status }
- let(:changeset) {
+ let!(:work_package) do
+ FactoryBot.create :work_package,
+ project: repository.project,
+ status: open_status
+ end
+ let(:changeset) do
FactoryBot.create(:changeset,
repository: repository,
revision: '123',
committer: user.login,
comments: comments)
- }
+ end
end
before do
diff --git a/spec/models/copy_project_job_spec.rb b/spec/models/copy_project_job_spec.rb
index 7910d23b577..f192f727b27 100644
--- a/spec/models/copy_project_job_spec.rb
+++ b/spec/models/copy_project_job_spec.rb
@@ -44,12 +44,12 @@ describe CopyProjectJob, type: :model do
let(:source_project) { FactoryBot.create(:project) }
let(:target_project) { FactoryBot.create(:project) }
- let(:copy_job) {
+ let(:copy_job) do
CopyProjectJob.new user_id: user_de.id,
source_project_id: source_project.id,
target_project_params: {},
associations_to_copy: []
- }
+ end
before do
# 'Delayed Job' uses a work around to get Rails 3 mailers working with it
@@ -74,19 +74,19 @@ describe CopyProjectJob, type: :model do
let(:source_project) { FactoryBot.create(:project, types: [type]) }
let!(:work_package) { FactoryBot.create(:work_package, project: source_project, type: type) }
let(:type) { FactoryBot.create(:type_bug) }
- let (:custom_field) {
+ let(:custom_field) do
FactoryBot.create(:work_package_custom_field,
- name: 'required_field',
- field_format: 'text',
- is_required: true,
- is_for_all: true)
- }
- let(:copy_job) {
+ name: 'required_field',
+ field_format: 'text',
+ is_required: true,
+ is_for_all: true)
+ end
+ let(:copy_job) do
CopyProjectJob.new user_id: admin.id,
source_project_id: source_project.id,
target_project_params: params,
associations_to_copy: [:work_packages]
- } # send mails
+ end # send mails
let(:params) { { name: 'Copy', identifier: 'copy', type_ids: [type.id], work_package_custom_field_ids: [custom_field.id] } }
let(:expected_error_message) { "#{WorkPackage.model_name.human} '#{work_package.type.name} #: #{work_package.subject}': #{custom_field.name} #{I18n.t('errors.messages.blank')}." }
@@ -121,12 +121,12 @@ describe CopyProjectJob, type: :model do
describe 'copy project fails with internal error' do
let(:admin) { FactoryBot.create(:admin) }
let(:source_project) { FactoryBot.create(:project) }
- let(:copy_job) {
+ let(:copy_job) do
CopyProjectJob.new user_id: admin.id,
source_project_id: source_project.id,
target_project_params: params,
associations_to_copy: [:work_packages]
- } # send mails
+ end # send mails
let(:params) { { name: 'Copy', identifier: 'copy' } }
before do
@@ -184,12 +184,12 @@ describe CopyProjectJob, type: :model do
describe 'valid parent' do
let(:role_add_subproject) { FactoryBot.create(:role, permissions: [:add_subprojects]) }
- let(:member_add_subproject) {
+ let(:member_add_subproject) do
FactoryBot.create(:member,
- user: user,
- project: project,
- roles: [role_add_subproject])
- }
+ user: user,
+ project: project,
+ roles: [role_add_subproject])
+ end
before do
member_add_subproject
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index f8419ae23e2..8cd441d754a 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -157,9 +157,9 @@ describe Project, type: :model do
describe '#types_used_by_work_packages' do
let(:project) { FactoryBot.create(:project_with_types) }
let(:type) { project.types.first }
- let(:other_type) { project.types.second }
+ let(:other_type) { FactoryBot.create(:type) }
let(:project_work_package) { FactoryBot.create(:work_package, type: type, project: project) }
- let(:other_project) { FactoryBot.create(:project, no_types: true, types: [other_type, type]) }
+ let(:other_project) { FactoryBot.create(:project, types: [other_type, type]) }
let(:other_project_work_package) { FactoryBot.create(:work_package, type: other_type, project: other_project) }
it 'returns the type used by a work package of the project' do
@@ -170,113 +170,129 @@ describe Project, type: :model do
end
end
- describe '#allowed_parent?' do
- let(:project) { FactoryBot.build_stubbed(:project) }
- let(:other_project) { FactoryBot.build_stubbed(:project) }
- let(:another_project) { FactoryBot.build_stubbed(:project) }
+ 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 'is false for nil on a persisted project with no allowed parents' do
- allow(project)
- .to receive(:allowed_parents)
- .and_return([])
-
- expect(project.allowed_parent?(nil)).to be_falsey
+ it 'should include the versions for the current project' do
+ expect(project.rolled_up_versions)
+ .to match_array [parent_version1, parent_version2]
end
- it 'is true for nil on a persisted project with allowed parents' do
- allow(project)
- .to receive(:allowed_parents)
- .and_return(['something'])
+ 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.allowed_parent?(nil)).to be_truthy
+ expect(project.rolled_up_versions)
+ .to match_array [parent_version1, parent_version2, subproject_version]
end
- it 'is true for nil on an unpersisted project with no allowed parents' do
- project = FactoryBot.build(:project)
+ 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)
- allow(project)
- .to receive(:allowed_parents)
- .and_return([])
+ project.reload
- expect(project.allowed_parent?(nil)).to be_truthy
+ expect(project.rolled_up_versions)
+ .to match_array [parent_version1, parent_version2, sub_subproject_version]
end
- it 'is false for blank on a persisted project with no allowed parents' do
- allow(project)
- .to receive(:allowed_parents)
- .and_return([])
+ it 'should only check active projects' do
+ subproject = FactoryBot.create(:project, parent: project)
+ FactoryBot.create(:version, project: subproject)
+ subproject.archive
+
+ project.reload
- expect(project.allowed_parent?('')).to be_falsey
+ expect(subproject)
+ .not_to be_active
+ expect(project.rolled_up_versions)
+ .to match_array [parent_version1, parent_version2]
end
+ end
+
+ context '#notified_users' do
+ let(:project) { FactoryBot.create(:project) }
+ let(:role) { FactoryBot.create(:role) }
- it 'is true for blank on a persisted project with allowed parents' do
- allow(project)
- .to receive(:allowed_parents)
- .and_return(['something'])
+ let(:principal) { raise NotImplementedError }
+ let(:mail_notification) { false }
- expect(project.allowed_parent?('')).to be_truthy
+ before do
+ FactoryBot.create(:member,
+ project: project,
+ principal: principal,
+ roles: [role],
+ mail_notification: mail_notification)
end
- it 'is true for blank on an unpersisted project with no allowed parents' do
- project = FactoryBot.build(:project)
+ context 'members with selected mail notification' do
+ let(:principal) { FactoryBot.create(:user, mail_notification: 'selected') }
+ let(:mail_notification) { true }
- allow(project)
- .to receive(:allowed_parents)
- .and_return([])
+ it 'are included' do
+ expect(project.notified_users)
+ .to include(principal)
+ end
+ end
- expect(project.allowed_parent?('')).to be_truthy
+ context 'members with unselected mail notification' do
+ let(:principal) { FactoryBot.create(:user, mail_notification: 'selected') }
+ let(:mail_notification) { false }
+
+ it 'are not included' do
+ expect(project.notified_users)
+ .to be_empty
+ end
end
- it 'is true for an id pointing to a project in allowed_parents' do
- allow(Project)
- .to receive(:find_by)
- .with(id: 1)
- .and_return(other_project)
- allow(project)
- .to receive(:allowed_parents)
- .and_return([other_project])
+ context 'members with `all` notification' do
+ let(:principal) { FactoryBot.create(:user, mail_notification: 'all') }
- expect(project.allowed_parent?(1)).to be_truthy
+ it 'are included' do
+ expect(project.notified_users)
+ .to include(principal)
+ end
end
- it 'is false for an id pointing to a project in allowed_parents' do
- allow(Project)
- .to receive(:find_by)
- .with(id: 1)
- .and_return(other_project)
- allow(project)
- .to receive(:allowed_parents)
- .and_return([another_project])
+ context 'members with `none` mail notification' do
+ let(:principal) { FactoryBot.create(:user, mail_notification: 'none') }
- expect(project.allowed_parent?(1)).to be_falsey
+ it 'are not included' do
+ expect(project.notified_users)
+ .to be_empty
+ end
end
- it 'is false for a non existing project id' do
- allow(Project)
- .to receive(:find_by)
- .with(id: 1)
- .and_return(nil)
- allow(project)
- .to receive(:allowed_parents)
- .and_return([other_project])
+ context 'members with `only_my_events` mail notification' do
+ let(:principal) { FactoryBot.create(:user, mail_notification: 'only_my_events') }
- expect(project.allowed_parent?(1)).to be_falsey
+ it 'are not included' do
+ expect(project.notified_users)
+ .to be_empty
+ end
end
- it 'is true for a project in allowed_projects' do
- allow(project)
- .to receive(:allowed_parents)
- .and_return([other_project])
+ context 'members with `only_assigned` mail notification' do
+ let(:principal) { FactoryBot.create(:user, mail_notification: 'only_assigned') }
- expect(project.allowed_parent?(other_project)).to be_truthy
+ it 'are not included' do
+ expect(project.notified_users)
+ .to be_empty
+ end
end
- it 'is false for a project not in allowed_projects' do
- allow(project)
- .to receive(:allowed_parents)
- .and_return([another_project])
+ context 'members with `only_owner` mail notification' do
+ let(:principal) { FactoryBot.create(:user, mail_notification: 'only_owner') }
- expect(project.allowed_parent?(other_project)).to be_falsey
+ it 'are not included' do
+ expect(project.notified_users)
+ .to be_empty
+ end
end
end
end
diff --git a/spec/models/role_spec.rb b/spec/models/role_spec.rb
index ea13827c473..14a4e4c3ca9 100644
--- a/spec/models/role_spec.rb
+++ b/spec/models/role_spec.rb
@@ -134,7 +134,7 @@ describe Role, type: :model do
end
end
- describe '#givable' do
+ describe '.givable' do
before do
# this should not be necessary once Role (in a membership) and GlobalRole have
# a common ancestor class, e.g. Role (a new one)
@@ -148,4 +148,51 @@ describe Role, type: :model do
it { expect(Role.givable.size).to eq(1) }
it { expect(Role.givable[0]).to eql @mem_role1 }
end
+
+ describe '.in_new_project' do
+ let!(:ungivable_role) { FactoryBot.create(:role, builtin: Role::BUILTIN_NON_MEMBER) }
+ let!(:second_role) do
+ FactoryBot.create(:role).tap do |r|
+ r.update_column(:position, 100)
+ end
+ end
+ let!(:first_role) do
+ FactoryBot.create(:role).tap do |r|
+ r.update_column(:position, 1)
+ end
+ end
+
+ context 'without a specified role' do
+ it 'returns the first role (by position)' do
+ expect(Role.in_new_project)
+ .to eql first_role
+ end
+ end
+
+ context 'with a specified role' do
+ before do
+ allow(Setting)
+ .to receive(:new_project_user_role_id)
+ .and_return(second_role.id.to_s)
+ end
+
+ it 'returns that role' do
+ expect(Role.in_new_project)
+ .to eql second_role
+ end
+ end
+
+ context 'with a specified role but that one is faulty (e.g. does not exist any more)' do
+ before do
+ allow(Setting)
+ .to receive(:new_project_user_role_id)
+ .and_return("-1")
+ end
+
+ it 'returns the first role (by position)' do
+ expect(Role.in_new_project)
+ .to eql first_role
+ end
+ end
+ end
end
diff --git a/spec/models/type_spec.rb b/spec/models/type_spec.rb
index 0e6fc108214..3433a129a4b 100644
--- a/spec/models/type_spec.rb
+++ b/spec/models/type_spec.rb
@@ -32,7 +32,7 @@ require 'spec_helper'
describe ::Type, type: :model do
let(:type) { FactoryBot.build(:type) }
let(:type2) { FactoryBot.build(:type) }
- let(:project) { FactoryBot.build(:project) }
+ let(:project) { FactoryBot.build(:project, no_types: true) }
describe '.enabled_in(project)' do
before do
diff --git a/spec/requests/api/v3/work_packages/create_form_resource_spec.rb b/spec/requests/api/v3/work_packages/create_form_resource_spec.rb
index 7eed2b7927b..aebe1ad96b6 100644
--- a/spec/requests/api/v3/work_packages/create_form_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/create_form_resource_spec.rb
@@ -82,7 +82,7 @@ describe ::API::V3::WorkPackages::CreateProjectFormAPI do
end
describe 'with all minimum parameters' do
- let(:type) { project.types.default.first }
+ let(:type) { project.types.first }
let(:parameters) do
{
_links: {
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index a85370c557f..34f881437bc 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -79,6 +79,7 @@ describe Projects::CreateService, type: :model do
.to receive(:call)
.and_return(set_attributes_result)
end
+ let(:new_project_role) { FactoryBot.build_stubbed(:role) }
describe 'call' do
subject { instance.call(call_attributes) }
@@ -105,7 +106,32 @@ describe Projects::CreateService, type: :model do
.to eql created_project
end
- context 'when the SetAttributeService is unsuccessful' do
+ it 'adds the current user to the project' do
+ allow(Role)
+ .to receive(:in_new_project)
+ .and_return(new_project_role)
+
+ expect(created_project)
+ .to receive(:add_member!)
+ .with(user, new_project_role)
+
+ subject
+ end
+
+ context 'current user is admin' do
+ it 'does not add the user to the project' do
+ allow(user)
+ .to receive(:admin?)
+ .and_return(true)
+
+ expect(created_project)
+ .not_to receive(:add_member!)
+
+ subject
+ end
+ end
+
+ context 'if the SetAttributeService is unsuccessful' do
let(:set_attributes_success) { false }
it 'is unsuccessful' do
diff --git a/spec/services/projects/set_attributes_service_spec.rb b/spec/services/projects/set_attributes_service_spec.rb
new file mode 100644
index 00000000000..8adc19ee46a
--- /dev/null
+++ b/spec/services/projects/set_attributes_service_spec.rb
@@ -0,0 +1,259 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is a project management system.
+# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
+#
+# 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 'spec_helper'
+
+describe Projects::SetAttributesService, type: :model do
+ let(:user) { FactoryBot.build_stubbed(:user) }
+ let(:contract_class) do
+ contract = double('contract_class')
+
+ allow(contract)
+ .to receive(:new)
+ .with(project, user)
+ .and_return(contract_instance)
+
+ contract
+ end
+ let(:contract_instance) do
+ double('contract_instance', validate: contract_valid, errors: contract_errors)
+ end
+ let(:contract_valid) { true }
+ let(:contract_errors) do
+ double('contract_errors')
+ end
+ let(:project_valid) { true }
+ let(:instance) do
+ described_class.new(user: user,
+ model: project,
+ contract_class: contract_class)
+ end
+ let(:call_attributes) { {} }
+ let(:project) do
+ FactoryBot.build_stubbed(:project)
+ end
+
+ describe 'call' do
+ let(:call_attributes) do
+ {
+ }
+ end
+
+ before do
+ allow(project)
+ .to receive(:valid?)
+ .and_return(project_valid)
+
+ expect(contract_instance)
+ .to receive(:validate)
+ .and_return(contract_valid)
+ end
+
+ subject { instance.call(call_attributes) }
+
+ it 'is successful' do
+ expect(subject.success?).to be_truthy
+ end
+
+ it 'sets the attributes' do
+ subject
+
+ expect(project.attributes.slice(*project.changed).symbolize_keys)
+ .to eql call_attributes
+ end
+
+ it 'does not persist the project' do
+ expect(project)
+ .not_to receive(:save)
+
+ subject
+ end
+
+ context 'for a new record' do
+ let(:project) do
+ Project.new
+ end
+
+ context 'identifier default value' do
+ context 'with a default identifier configured', with_settings: { sequential_project_identifiers: true } do
+ context 'with an identifier provided' do
+ let(:call_attributes) do
+ {
+ identifier: 'lorem'
+ }
+ end
+
+ it 'does not alter the identifier' do
+ expect(subject.result.identifier)
+ .to eql 'lorem'
+ end
+ end
+
+ context 'with no identifier provided' do
+ it 'sets a default identifier' do
+ allow(Project)
+ .to receive(:next_identifier)
+ .and_return('ipsum')
+
+ expect(subject.result.identifier)
+ .to eql 'ipsum'
+ end
+ end
+ end
+
+ context 'without a default identifier configured', with_settings: { sequential_project_identifiers: false } do
+ context 'with an identifier provided' do
+ let(:call_attributes) do
+ {
+ identifier: 'lorem'
+ }
+ end
+
+ it 'does not alter the identifier' do
+ expect(subject.result.identifier)
+ .to eql 'lorem'
+ end
+ end
+
+ context 'with no identifier provided' do
+ it 'stays nil' do
+ allow(Project)
+ .to receive(:next_identifier)
+ .and_return('ipsum')
+
+ expect(subject.result.identifier)
+ .to be_nil
+ end
+ end
+ end
+ end
+
+ context 'is_public default value', with_settings: { default_projects_public: true } do
+ context 'with a value for is_public provided' do
+ let(:call_attributes) do
+ {
+ is_public: false
+ }
+ end
+
+ it 'does not alter the is_public value' do
+ expect(subject.result.is_public)
+ .to be_falsey
+ end
+ end
+
+ context 'with no value for is_public provided' do
+ it 'sets uses the default value' do
+ expect(subject.result.is_public)
+ .to be_truthy
+ end
+ end
+ end
+
+ context 'enabled_module_names default value', with_settings: { default_projects_modules: ['lorem', 'ipsum'] } do
+ context 'with a value for enabled_module_names provided' do
+ let(:call_attributes) do
+ {
+ enabled_module_names: %w(some other)
+ }
+ end
+
+ it 'does not alter the enabled modules' do
+ expect(subject.result.enabled_module_names)
+ .to match_array %w(some other)
+ end
+ end
+
+ context 'with no value for enabled_module_names provided' do
+ it 'sets a default enabled modules' do
+ expect(subject.result.enabled_module_names)
+ .to match_array %w(lorem ipsum)
+ end
+ end
+
+ context 'with the enabled modules being set before' do
+ before do
+ project.enabled_module_names = %w(some other)
+ end
+
+ it 'does not alter the enabled modules' do
+ expect(subject.result.enabled_module_names)
+ .to match_array %w(some other)
+ end
+ end
+ end
+
+ context 'types default value' do
+ let(:other_types) do
+ [FactoryBot.build_stubbed(:type)]
+ end
+ let(:default_types) do
+ [FactoryBot.build_stubbed(:type)]
+ end
+ before do
+ allow(Type)
+ .to receive(:default)
+ .and_return default_types
+ end
+
+ context 'with a value for types provided' do
+ let(:call_attributes) do
+ {
+ types: other_types
+ }
+ end
+
+ it 'does not alter the types' do
+ expect(subject.result.types)
+ .to match_array other_types
+ end
+ end
+
+ context 'with no value for types provided' do
+ it 'sets the default types' do
+ expect(subject.result.types)
+ .to match_array default_types
+ end
+ end
+
+ context 'with the types being set before' do
+ before do
+ project.types.build(name: 'lorem')
+ end
+
+ it 'does not alter the types modules' do
+ expect(subject.result.types.map(&:name))
+ .to match_array %w(lorem)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb
index b1694e32f05..c5e97a89a97 100644
--- a/spec/services/projects/update_service_spec.rb
+++ b/spec/services/projects/update_service_spec.rb
@@ -100,16 +100,27 @@ describe Projects::UpdateService, type: :model do
.to eql project
end
+ it 'sends an update notification' do
+ expect(OpenProject::Notifications)
+ .to receive(:send)
+ .with('project_updated', project: project)
+
+ subject
+ end
+
context 'if the identifier is altered' do
let(:call_attributes) { { identifier: 'Some identifier' } }
before do
allow(project)
- .to receive(:saved_change_to_identifier?)
- .and_return(true)
+ .to receive(:changes)
+ .and_return('identifier' => %w(lorem ipsum))
end
it 'sends the notification' do
+ expect(OpenProject::Notifications)
+ .to receive(:send)
+ .with('project_updated', project: project)
expect(OpenProject::Notifications)
.to receive(:send)
.with('project_renamed', project: project)
@@ -118,6 +129,22 @@ describe Projects::UpdateService, type: :model do
end
end
+ context 'if the parent is altered' do
+ before do
+ allow(project)
+ .to receive(:changes)
+ .and_return('parent_id' => [nil, 5])
+ end
+
+ it 'updates the versions associated with the work packages' do
+ expect(WorkPackage)
+ .to receive(:update_versions_from_hierarchy_change)
+ .with(project)
+
+ subject
+ end
+ end
+
context 'if the SetAttributeService is unsuccessful' do
let(:set_attributes_success) { false }
diff --git a/spec/services/time_entries/set_attributes_service_spec.rb b/spec/services/time_entries/set_attributes_service_spec.rb
index 2b8bae3d01a..597bf1e8a93 100644
--- a/spec/services/time_entries/set_attributes_service_spec.rb
+++ b/spec/services/time_entries/set_attributes_service_spec.rb
@@ -191,20 +191,6 @@ describe TimeEntries::SetAttributesService, type: :model do
end
end
- context 'with an invalid time_entry' do
- let(:time_entry_valid) { false }
-
- it 'returns failure' do
- is_expected
- .not_to be_success
- end
-
- it "returns the time_entry's errors" do
- expect(subject.errors)
- .to eql(time_entry_instance.errors)
- end
- end
-
context 'with a system activity' do
let!(:system_activity) { FactoryBot.build_stubbed(:time_entry_activity) }
let(:params) do
diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rb
index 92a0d05d8b7..9200e380285 100644
--- a/spec/services/work_packages/set_attributes_service_spec.rb
+++ b/spec/services/work_packages/set_attributes_service_spec.rb
@@ -43,20 +43,10 @@ describe WorkPackages::SetAttributesService, type: :model do
wp.type = FactoryBot.build_stubbed(:type)
wp.send(:clear_changes_information)
- allow(wp)
- .to receive(:valid?)
- .and_return(work_package_valid)
-
wp
end
let(:new_work_package) do
- wp = WorkPackage.new
-
- allow(wp)
- .to receive(:valid?)
- .and_return(work_package_valid)
-
- wp
+ WorkPackage.new
end
let(:contract_class) { WorkPackages::UpdateContract }
let(:mock_contract) do
@@ -72,7 +62,6 @@ describe WorkPackages::SetAttributesService, type: :model do
mock
end
let(:contract_valid) { true }
- let(:work_package_valid) { true }
let(:instance) do
described_class.new(user: user,
model: work_package,
@@ -125,26 +114,6 @@ describe WorkPackages::SetAttributesService, type: :model do
expect(subject.errors).to eql mock_contract_instance.errors
end
end
-
- context 'when the work package is invalid' do
- let(:work_package_valid) { false }
-
- it 'is unsuccessful' do
- expect(subject.success?).to be_falsey
- end
-
- it 'leaves the value unchanged' do
- subject
-
- expect(work_package.changed?).to be_truthy
- end
-
- it "exposes the work_packages's errors" do
- subject
-
- expect(subject.errors).to eql work_package.errors
- end
- end
end
context 'update subject before calling the service' do
@@ -318,7 +287,6 @@ describe WorkPackages::SetAttributesService, type: :model do
let(:call_attributes) { attributes }
let(:attributes) { { start_date: Date.today - 5.days } }
let(:contract_valid) { true }
- let(:work_package_valid) { true }
subject { instance.call(call_attributes) }
it 'is successful' do
diff --git a/spec_legacy/functional/projects_controller_spec.rb b/spec_legacy/functional/projects_controller_spec.rb
index 4dc37a379f6..9003a940cf1 100644
--- a/spec_legacy/functional/projects_controller_spec.rb
+++ b/spec_legacy/functional/projects_controller_spec.rb
@@ -239,7 +239,8 @@ describe ProjectsController, type: :controller do
assert_response :success
project = assigns(:project)
assert_kind_of Project, project
- refute_empty project.errors[:parent_id]
+ errors = assigns(:errors)
+ refute_empty errors[:parent]
end
end
@@ -281,7 +282,9 @@ describe ProjectsController, type: :controller do
assert_response :success
project = assigns(:project)
assert_kind_of Project, project
- refute_empty project.errors[:parent_id]
+ errors = assigns(:errors)
+ expect(errors.symbols_for(:base))
+ .to match_array [:error_unauthorized]
end
it 'should fail with unauthorized parent_id' do
@@ -302,7 +305,8 @@ describe ProjectsController, type: :controller do
assert_response :success
project = assigns(:project)
assert_kind_of Project, project
- refute_empty project.errors[:parent_id]
+ errors = assigns(:errors)
+ refute_empty errors[:parent]
end
end
end
diff --git a/spec_legacy/unit/project_nested_set_spec.rb b/spec_legacy/unit/project_nested_set_spec.rb
deleted file mode 100644
index 1198d10fc3a..00000000000
--- a/spec_legacy/unit/project_nested_set_spec.rb
+++ /dev/null
@@ -1,129 +0,0 @@
-#-- encoding: UTF-8
-#-- copyright
-# OpenProject is a project management system.
-# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
-#
-# 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 'ProjectNestedSet', type: :model do
- context 'nested set' do
- before do
- FactoryBot.create(:type_standard)
- Project.delete_all
-
- @a = Project.create!(name: 'Project A', identifier: 'projecta')
- @a1 = Project.create!(name: 'Project A1', identifier: 'projecta1')
- @a1.set_parent!(@a)
- @a2 = Project.create!(name: 'Project A2', identifier: 'projecta2')
- @a2.set_parent!(@a)
-
- @b = Project.create!(name: 'Project B', identifier: 'projectb')
- @b1 = Project.create!(name: 'Project B1', identifier: 'projectb1')
- @b1.set_parent!(@b)
- @b11 = Project.create!(name: 'Project B11', identifier: 'projectb11')
- @b11.set_parent!(@b1)
- @b2 = Project.create!(name: 'Project B2', identifier: 'projectb2')
- @b2.set_parent!(@b)
-
- @c = Project.create!(name: 'Project C', identifier: 'projectc')
- @c1 = Project.create!(name: 'Project C1', identifier: 'projectc1')
- @c1.set_parent!(@c)
-
- [@a, @a1, @a2, @b, @b1, @b11, @b2, @c, @c1].each(&:reload)
- end
-
- context '#create' do
- it 'should build valid tree' do
- assert_nested_set_values(
- @a => [nil, 1, 6],
- @a1 => [@a.id, 2, 3],
- @a2 => [@a.id, 4, 5],
- @b => [nil, 7, 14],
- @b1 => [@b.id, 8, 11],
- @b11 => [@b1.id, 9, 10],
- @b2 => [@b.id, 12, 13],
- @c => [nil, 15, 18],
- @c1 => [@c.id, 16, 17]
- )
- end
- end
-
- context '#set_parent!' do
- it 'should keep valid tree' do
- assert_no_difference 'Project.count' do
- Project.find_by(name: 'Project B1').set_parent!(Project.find_by(name: 'Project A2'))
- end
- assert_nested_set_values(
- @a => [nil, 1, 10],
- @a2 => [@a.id, 4, 9],
- @b1 => [@a2.id, 5, 8],
- @b11 => [@b1.id, 6, 7],
- @b => [nil, 11, 14],
- @c => [nil, 15, 18]
- )
- end
- end
-
- context '#destroy' do
- context 'a root with children' do
- it 'should not mess up the tree' do
- assert_difference 'Project.count', -4 do
- Project.find_by(name: 'Project B').destroy
- end
- assert_nested_set_values(
- @a => [nil, 1, 6],
- @a1 => [@a.id, 2, 3],
- @a2 => [@a.id, 4, 5],
- @c => [nil, 7, 10],
- @c1 => [@c.id, 8, 9]
- )
- end
- end
-
- context 'a child with children' do
- it 'should not mess up the tree' do
- assert_difference 'Project.count', -2 do
- Project.find_by(name: 'Project B1').destroy
- end
- assert_nested_set_values(
- @a => [nil, 1, 6],
- @b => [nil, 7, 10],
- @b2 => [@b.id, 8, 9],
- @c => [nil, 11, 14]
- )
- end
- end
- end
- end
-
- def assert_nested_set_values(h)
- assert Project.valid?
- h.each do |project, expected|
- project.reload
- assert_equal expected, [project.parent_id, project.lft, project.rgt], "Unexpected nested set values for #{project.name}"
- end
- end
-end
diff --git a/spec_legacy/unit/project_spec.rb b/spec_legacy/unit/project_spec.rb
index 7a96b6f2359..4b9f4ddbfb8 100644
--- a/spec_legacy/unit/project_spec.rb
+++ b/spec_legacy/unit/project_spec.rb
@@ -72,39 +72,6 @@ describe Project, type: :model do
assert_equal 'eCookbook', @ecookbook.name
end
- context 'when default public', with_settings: { default_projects_public?: true } do
- it 'should default attributes' do
- assert_equal true, Project.new.is_public
- assert_equal false, Project.new(is_public: false).is_public
-
- assert_equal ::Type.all, Project.new.types
- assert_equal ::Type.find(1, 3), Project.new(type_ids: [1, 3]).types
- end
- end
-
- context 'when default private', with_settings: { default_projects_public?: false } do
- it 'should default attributes' do
- assert_equal false, Project.new.is_public
- assert_equal true, Project.new(is_public: true).is_public
- end
- end
-
- context 'with sequential identifiers',
- with_settings: { sequential_project_identifiers?: true } do
- it 'should default attributes' do
- assert !Project.new.identifier.blank?
- assert Project.new(identifier: '').identifier.blank?
- end
- end
-
- context 'with no sequential identifiers',
- with_settings: { sequential_project_identifiers?: false } do
- it 'should default attributes' do
- assert Project.new.identifier.blank?
- assert !Project.new(identifier: 'test').blank?
- end
- end
-
it 'should update' do
assert_equal 'eCookbook', @ecookbook.name
@ecookbook.name = 'eCook'
@@ -233,101 +200,6 @@ describe Project, type: :model do
assert_equal 0, CustomValue.where(customized_type: ['Project', 'Issue', 'TimeEntry', 'Version']).count
end
- it 'should move an orphan project to a root project' do
- sub = Project.find(2)
- sub.set_parent! @ecookbook
- assert_equal @ecookbook.id, sub.parent.id
- @ecookbook.reload
- assert_equal 4, @ecookbook.children.size
- end
-
- it 'should move an orphan project to a subproject' do
- sub = Project.find(2)
- assert sub.set_parent!(@ecookbook_sub1)
- end
-
- it 'should move a root project to a project' do
- sub = @ecookbook
- assert sub.set_parent!(Project.find(2))
- end
-
- it 'should not move a project to its children' do
- sub = @ecookbook
- assert !(sub.set_parent!(Project.find(3)))
- end
-
- it 'should set parent should add roots in alphabetical order' do
- ProjectCustomField.destroy_all
- Project.delete_all
- Project.create!(name: 'Project C', identifier: 'project-c').set_parent!(nil)
- Project.create!(name: 'Project B', identifier: 'project-b').set_parent!(nil)
- Project.create!(name: 'Project D', identifier: 'project-d').set_parent!(nil)
- Project.create!(name: 'Project A', identifier: 'project-a').set_parent!(nil)
-
- assert_equal 4, Project.count
- assert_equal Project.all.sort_by(&:name), Project.all.sort_by(&:lft)
- end
-
- it 'should set parent should add children in alphabetical order' do
- ProjectCustomField.destroy_all
- parent = Project.create!(name: 'Parent', identifier: 'parent')
- Project.create!(name: 'Project C', identifier: 'project-c').set_parent!(parent)
- Project.create!(name: 'Project B', identifier: 'project-b').set_parent!(parent)
- Project.create!(name: 'Project D', identifier: 'project-d').set_parent!(parent)
- Project.create!(name: 'Project A', identifier: 'project-a').set_parent!(parent)
-
- parent.reload
- assert_equal 4, parent.children.size
- assert_equal parent.children.sort_by(&:name), parent.children
- end
-
- it 'should rebuild should sort children alphabetically' do
- ProjectCustomField.destroy_all
- parent = Project.create!(name: 'Parent', identifier: 'parent')
- Project.create!(name: 'Project C', identifier: 'project-c').move_to_child_of(parent)
- Project.create!(name: 'Project B', identifier: 'project-b').move_to_child_of(parent)
- Project.create!(name: 'Project D', identifier: 'project-d').move_to_child_of(parent)
- Project.create!(name: 'Project A', identifier: 'project-a').move_to_child_of(parent)
-
- Project.update_all('lft = NULL, rgt = NULL')
- Project.rebuild!
-
- parent.reload
- assert_equal 4, parent.children.size
- assert_equal parent.children.sort_by(&:name), parent.children
- end
-
- it 'should set parent should update issue fixed version associations when a fixed version is moved out of the hierarchy' do
- # Parent issue with a hierarchy project's fixed version
- parent_issue = WorkPackage.find(1)
- parent_issue.update_attribute(:fixed_version_id, 4)
- parent_issue.reload
- assert_equal 4, parent_issue.fixed_version_id
-
- # Should keep fixed versions for the issues
- issue_with_local_fixed_version = WorkPackage.find(5)
- issue_with_local_fixed_version.update_attribute(:fixed_version_id, 4)
- issue_with_local_fixed_version.reload
- assert_equal 4, issue_with_local_fixed_version.fixed_version_id
-
- # Local issue with hierarchy fixed_version
- issue_with_hierarchy_fixed_version = WorkPackage.find(13)
- issue_with_hierarchy_fixed_version.update_attribute(:fixed_version_id, 6)
- issue_with_hierarchy_fixed_version.reload
- assert_equal 6, issue_with_hierarchy_fixed_version.fixed_version_id
-
- # Move project out of the issue's hierarchy
- moved_project = Project.find(3)
- moved_project.set_parent!(Project.find(2))
- parent_issue.reload
- issue_with_local_fixed_version.reload
- issue_with_hierarchy_fixed_version.reload
-
- assert_equal 4, issue_with_local_fixed_version.fixed_version_id, 'Fixed version was not keep on an issue local to the moved project'
- assert_nil issue_with_hierarchy_fixed_version.fixed_version_id, 'Fixed version is still set after moving the Project out of the hierarchy where the version is defined in'
- assert_nil parent_issue.fixed_version_id, 'Fixed version is still set after moving the Version out of the hierarchy for the issue.'
- end
-
it 'should parent' do
p = Project.find(6).parent
assert p.is_a?(Project)
@@ -359,56 +231,6 @@ describe Project, type: :model do
assert_equal [3,4,5,6], d.sort
end
- it 'should allowed parents should be empty for non member user' do
- Role.non_member.add_permission!(:add_project)
- user = User.find(9)
- assert user.memberships.empty?
- User.current = user
- assert Project.new.allowed_parents.compact.empty?
- end
-
- it 'should allowed parents with add subprojects permission' do
- Role.find(1).remove_permission!(:add_project)
- Role.find(1).add_permission!(:add_subprojects)
- User.current = User.find(2)
- # new project
- assert !Project.new.allowed_parents.include?(nil)
- assert Project.new.allowed_parents.include?(Project.find(1))
- # existing root project
- assert Project.find(1).allowed_parents.include?(nil)
- # existing child
- assert Project.find(3).allowed_parents.include?(Project.find(1))
- assert !Project.find(3).allowed_parents.include?(nil)
- end
-
- it 'should allowed parents with add project permission' do
- Role.find(1).add_permission!(:add_project)
- Role.find(1).remove_permission!(:add_subprojects)
- User.current = User.find(2)
- # new project
- assert Project.new.allowed_parents.include?(nil)
- assert !Project.new.allowed_parents.include?(Project.find(1))
- # existing root project
- assert Project.find(1).allowed_parents.include?(nil)
- # existing child
- assert Project.find(3).allowed_parents.include?(Project.find(1))
- assert Project.find(3).allowed_parents.include?(nil)
- end
-
- it 'should allowed parents with add project and subprojects permission' do
- Role.find(1).add_permission!(:add_project)
- Role.find(1).add_permission!(:add_subprojects)
- User.current = User.find(2)
- # new project
- assert Project.new.allowed_parents.include?(nil)
- assert Project.new.allowed_parents.include?(Project.find(1))
- # existing root project
- assert Project.find(1).allowed_parents.include?(nil)
- # existing child
- assert Project.find(3).allowed_parents.include?(Project.find(1))
- assert Project.find(3).allowed_parents.include?(nil)
- end
-
it 'should users by role' do
users_by_role = Project.find(1).users_by_role
assert_kind_of Hash, users_by_role
@@ -441,72 +263,6 @@ describe Project, type: :model do
assert_equal [1, 2], parent.rolled_up_types.map(&:id)
end
- context 'description' do
- before do
- # this block unfortunately isn't run
- # move first two lines of next to specs up here
- # when you know that it will work
- end
-
- it 'should short description returns shortened description' do
- @project = FactoryBot.create(:project)
- @project.description = ('Abcd ' * 5 + "\n") * 11
- assert_equal (('Abcd ' * 5 + "\n") * 10)[0..-2] + '...', @project.short_description
- end
- end
-
- context '#rolled_up_versions' do
- before do
- @project = FactoryBot.create(:project)
- @parent_version_1 = FactoryBot.create(:version, project: @project)
- @parent_version_2 = FactoryBot.create(:version, project: @project)
- end
-
- it 'should include the versions for the current project' do
- assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions
- end
-
- it 'should include versions for a subproject' do
- @subproject = FactoryBot.create(:project)
- @subproject.set_parent!(@project)
- @subproject_version = FactoryBot.create(:version, project: @subproject)
-
- assert_same_elements [
- @parent_version_1,
- @parent_version_2,
- @subproject_version
- ], @project.rolled_up_versions
- end
-
- it 'should include versions for a sub-subproject' do
- @subproject = FactoryBot.create(:project)
- @subproject.set_parent!(@project)
- @sub_subproject = FactoryBot.create(:project)
- @sub_subproject.set_parent!(@subproject)
- @sub_subproject_version = FactoryBot.create(:version, project: @sub_subproject)
-
- @project.reload
-
- assert_same_elements [
- @parent_version_1,
- @parent_version_2,
- @sub_subproject_version
- ], @project.rolled_up_versions
- end
-
- it 'should only check active projects' do
- @subproject = FactoryBot.create(:project)
- @subproject.set_parent!(@project)
- @subproject_version = FactoryBot.create(:version, project: @subproject)
- assert @subproject.archive
-
- @project.reload
-
- assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions
- end
- end
-
it 'should shared versions none sharing' do
p = Project.find(5)
v = Version.create!(name: 'none_sharing', project: p, sharing: 'none')
@@ -995,163 +751,4 @@ describe Project, type: :model do
assert @project.work_packages.empty?
end
end
-
- context '#start_date' do
- before do
- ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
- @project = FactoryBot.create(:project, identifier: 'test0')
- @project.types << FactoryBot.create(:type)
- end
-
- it 'should be nil if there are no issues on the project' do
- assert_nil @project.start_date
- end
-
- it "should be the earliest start date of it's issues" do
- early = 7.days.ago.to_date
- FactoryBot.create(:work_package, project: @project, start_date: Date.today)
- FactoryBot.create(:work_package, project: @project, start_date: early)
-
- assert_equal early, @project.start_date
- end
- end
-
- context '#due_date' do
- before do
- ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
- @project = FactoryBot.create(:project, identifier: 'test0')
- @project.types << FactoryBot.create(:type)
- end
-
- it 'should be nil if there are no issues on the project' do
- assert_nil @project.due_date
- end
-
- it "should be the latest finish date of it's issues" do
- future = 7.days.from_now.to_date
- FactoryBot.create(:work_package, project: @project, due_date: future)
- FactoryBot.create(:work_package, project: @project, due_date: Date.today)
-
- assert_equal future, @project.due_date
- end
-
- it "should be the latest finish date of it's versions" do
- future = 7.days.from_now.to_date
- @project.versions << FactoryBot.create(:version, effective_date: future)
- @project.versions << FactoryBot.create(:version, effective_date: Date.today)
-
- assert_equal future, @project.due_date
- end
-
- it "should pick the latest date from it's issues and versions" do
- future = 7.days.from_now.to_date
- far_future = 14.days.from_now.to_date
- FactoryBot.create(:work_package, project: @project, due_date: far_future)
- @project.versions << FactoryBot.create(:version, effective_date: future)
-
- assert_equal far_future, @project.due_date
- end
- end
-
- context 'Project#completed_percent' do
- before do
- ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
- @project = FactoryBot.create(:project, identifier: 'test0')
- @project.types << FactoryBot.create(:type)
- end
-
- context 'no versions' do
- it 'should be 100' do
- assert_equal 100, @project.completed_percent
- end
- end
-
- context 'with versions' do
- it 'should return 0 if the versions have no issues' do
- FactoryBot.create(:version, project: @project)
- FactoryBot.create(:version, project: @project)
-
- assert_equal 0, @project.completed_percent
- end
-
- it 'should return 100 if the version has only closed issues' do
- v1 = FactoryBot.create(:version, project: @project)
- v2 = FactoryBot.create(:version, project: @project)
- FactoryBot.create(:work_package, project: @project, status: Status.find_by_name('Closed'), fixed_version: v1)
- FactoryBot.create(:work_package, project: @project, status: Status.find_by_name('Closed'), fixed_version: v2)
-
- assert_equal 100, @project.completed_percent
- end
-
- it 'should return the averaged completed percent of the versions (not weighted)' do
- v1 = FactoryBot.create(:version, project: @project)
- v2 = FactoryBot.create(:version, project: @project)
- FactoryBot.create(:work_package, project: @project, status: Status.find_by_name('New'), estimated_hours: 10, done_ratio: 50, fixed_version: v1)
- FactoryBot.create(:work_package, project: @project, status: Status.find_by_name('New'), estimated_hours: 10, done_ratio: 50, fixed_version: v2)
-
- assert_equal 50, @project.completed_percent
- end
- end
- end
-
- context '#notified_users' do
- before do
- @project = FactoryBot.create(:project)
- @role = FactoryBot.create(:role)
-
- @user_with_membership_notification = FactoryBot.create(:user, mail_notification: 'selected')
- Member.create!(project: @project, principal: @user_with_membership_notification, mail_notification: true) do |member|
- member.role_ids = [@role.id]
- end
-
- @all_events_user = FactoryBot.create(:user, mail_notification: 'all')
- Member.create!(project: @project, principal: @all_events_user) do |member|
- member.role_ids = [@role.id]
- end
-
- @no_events_user = FactoryBot.create(:user, mail_notification: 'none')
- Member.create!(project: @project, principal: @no_events_user) do |member|
- member.role_ids = [@role.id]
- end
-
- @only_my_events_user = FactoryBot.create(:user, mail_notification: 'only_my_events')
- Member.create!(project: @project, principal: @only_my_events_user) do |member|
- member.role_ids = [@role.id]
- end
-
- @only_assigned_user = FactoryBot.create(:user, mail_notification: 'only_assigned')
- Member.create!(project: @project, principal: @only_assigned_user) do |member|
- member.role_ids = [@role.id]
- end
-
- @only_owned_user = FactoryBot.create(:user, mail_notification: 'only_owner')
- Member.create!(project: @project, principal: @only_owned_user) do |member|
- member.role_ids = [@role.id]
- end
- end
-
- it 'should include members with a mail notification' do
- assert @project.notified_users.include?(@user_with_membership_notification)
- end
-
- it "should include users with the 'all' notification option" do
- assert @project.notified_users.include?(@all_events_user)
- end
-
- it "should not include users with the 'none' notification option" do
- assert [email protected]_users.include?(@no_events_user)
- end
-
- it "should not include users with the 'only_my_events' notification option" do
- assert [email protected]_users.include?(@only_my_events_user)
- end
-
- it "should not include users with the 'only_assigned' notification option" do
- assert [email protected]_users.include?(@only_assigned_user)
- end
-
- it "should not include users with the 'only_owner' notification option" do
- assert [email protected]_users.include?(@only_owned_user)
- end
- end
end
diff --git a/spec_legacy/unit/watcher_spec.rb b/spec_legacy/unit/watcher_spec.rb
index 775b32af910..2e3b8145ee9 100644
--- a/spec_legacy/unit/watcher_spec.rb
+++ b/spec_legacy/unit/watcher_spec.rb
@@ -26,7 +26,7 @@
#
# See docs/COPYRIGHT.rdoc for more details.
#++
-require 'legacy_spec_helper'
+require_relative '../legacy_spec_helper'
describe Watcher do
before do