OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
use join table for storing activites active in project
ulferts7d4a4a19e758
diff --git a/app/contracts/time_entries/base_contract.rb b/app/contracts/time_entries/base_contract.rbindex a0c0429bedc..ea5c968d9a9 100644--- a/app/contracts/time_entries/base_contract.rb+++ b/app/contracts/time_entries/base_contract.rb@@ -46,7 +46,9 @@ module TimeEntriesattribute :project_idattribute :work_package_id- attribute :activity_id+ attribute :activity_id do+ validate_activity_active+ endattribute :hoursattribute :commentsattribute :spent_on@@ -73,6 +75,10 @@ module TimeEntrieserrors.add :project_id, :invalid if model.project.nil?end+ def validate_activity_active+ errors.add :activity_id, :inclusion if model.activity && !model.activity.active_in_project?(model.project)+ end+def work_package_invisible?model.work_package.nil? || !model.work_package.visible?(user)enddiff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex b55292988a6..bd1400a46ab 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -316,7 +316,7 @@ class ApplicationController < ActionController::Baseis_authorized = AuthorizationService.new({ controller: ctrl, action: action }, context: context, global: global).callunless is_authorized- if @project && @project.archived?+ if @project&.archived?render_403 message: :notice_not_authorized_archived_projectelsedeny_accessdiff --git a/app/controllers/project_enumerations_controller.rb b/app/controllers/projects/time_entry_activities_controller.rbsimilarity index 74%rename from app/controllers/project_enumerations_controller.rbrename to app/controllers/projects/time_entry_activities_controller.rbindex 9a35834c477..2b5e1145140 100644--- a/app/controllers/project_enumerations_controller.rb+++ b/app/controllers/projects/time_entry_activities_controller.rb@@ -28,28 +28,22 @@# See doc/COPYRIGHT.rdoc for more details.#++-class ProjectEnumerationsController < ApplicationController+class Projects::TimeEntryActivitiesController < ApplicationControllerbefore_action :find_project_by_project_idbefore_action :authorizedef update- if permitted_params.enumerations.present?- Project.transaction do- permitted_params.enumerations.each do |id, activity|- @project.update_or_create_time_entry_activity(id, activity)- end- end- flash[:notice] = l(:notice_successful_update)- end+ TimeEntryActivitiesProject.upsert_all(update_params, unique_by: %i[project_id activity_id])+ flash[:notice] = l(:notice_successful_update)redirect_to settings_project_path(id: @project, tab: 'activities')end- def destroy- TimeEntryActivity.bulk_destroy(@project.time_entry_activities)-- flash[:notice] = l(:notice_successful_update)+ private- redirect_to settings_project_path(id: @project, tab: 'activities')+ def update_params+ permitted_params.time_entry_activities_project.map do |attributes|+ { project_id: @project.id, active: false }.with_indifferent_access.merge(attributes.to_h)+ endendenddiff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rbindex d0af82f7cae..075390e19e0 100644--- a/app/helpers/timelog_helper.rb+++ b/app/helpers/timelog_helper.rb@@ -37,9 +37,9 @@ module TimelogHelperproject ||= @projectactivities =if project.nil?- TimeEntryActivity.shared.active+ TimeEntryActivity.all.activeelse- project.activities+ TimeEntryActivity.in_project(project)endactivities.map do |a|diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rbindex b25500f4dd0..060a95f5849 100644--- a/app/models/permitted_params.rb+++ b/app/models/permitted_params.rb@@ -301,7 +301,8 @@ class PermittedParamsdef time_entrypermitted_params = params.fetch(:time_entry, {}).permit(- :hours, :comments, :work_package_id, :activity_id, :spent_on)+ :hours, :comments, :work_package_id, :activity_id, :spent_on+ )permitted_params.merge(custom_field_values(:time_entry, required: false))end@@ -379,6 +380,10 @@ class PermittedParamswhitelist.permit!end+ def time_entry_activities_project+ params.permit(time_entry_activities_project: %i[activity_id active]).require(:time_entry_activities_project)+ end+def watcherparams.require(:watcher).permit(:watchable, :user, :user_id)enddiff --git a/app/models/project.rb b/app/models/project.rbindex a7e45243f0b..eb537ed030c 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -42,8 +42,6 @@ class Project < ActiveRecord::Base# reserved identifiersRESERVED_IDENTIFIERS = %w(new).freeze- # Specific overridden Activities- has_many :time_entry_activitieshas_many :members, -> {includes(:principal, :roles).where(@@ -125,6 +123,7 @@ class Project < ActiveRecord::Baseorder("#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC")}, dependent: :destroyhas_many :time_entries, dependent: :delete_all+ has_many :time_entry_activities_projects, dependent: :delete_allhas_many :queries, dependent: :delete_allhas_many :news, -> { includes(:author) }, dependent: :destroyhas_many :categories, -> { order("#{Category.table_name}.name") }, dependent: :delete_all@@ -241,52 +240,6 @@ class Project < ActiveRecord::Basesuperend- # Returns the Systemwide and project specific activities- def activities(include_inactive = false)- if include_inactive- all_activities- else- active_activities- end- end-- # Will create a new Project specific Activity or update an existing one- #- # This will raise a ActiveRecord::Rollback if the TimeEntryActivity- # does not successfully save.- def update_or_create_time_entry_activity(id, activity_hash)- if activity_hash.respond_to?(:has_key?) && activity_hash.has_key?('parent_id')- create_time_entry_activity_if_needed(activity_hash)- else- activity = project.time_entry_activities.find_by(id: id.to_i)- activity&.update(activity_hash)- end- end-- # Create a new TimeEntryActivity if it overrides a system TimeEntryActivity- #- # This will raise a ActiveRecord::Rollback if the TimeEntryActivity- # does not successfully save.- def create_time_entry_activity_if_needed(activity)- if activity['parent_id']-- parent_activity = TimeEntryActivity.find(activity['parent_id'])- activity['name'] = parent_activity.name- activity['position'] = parent_activity.position-- if Enumeration.overridding_change?(activity, parent_activity)- project_activity = time_entry_activities.create(activity)-- if project_activity.new_record?- raise ActiveRecord::Rollback, 'Overridding TimeEntryActivity was not successfully saved'- else- time_entries.where(['activity_id = ?', parent_activity.id])- .update_all("activity_id = #{project_activity.id}")- end- end- end- end-# Returns a :conditions SQL string that can be used to find the issues associated with this project.## Examples:@@ -544,45 +497,6 @@ class Project < ActiveRecord::Base.flattenend- # Returns all the active Systemwide and project specific activities- def active_activities- overridden_activity_ids = time_entry_activities.map(&:parent_id)-- if overridden_activity_ids.empty?- TimeEntryActivity.shared.active- else- system_activities_and_project_overrides- end- end-- # Returns all the Systemwide and project specific activities- # (inactive and active)- def all_activities- overridden_activity_ids = time_entry_activities.map(&:parent_id)-- if overridden_activity_ids.empty?- TimeEntryActivity.shared- else- system_activities_and_project_overrides(true)- end- end-- # Returns the systemwide active activities merged with the project specific overrides- def system_activities_and_project_overrides(include_inactive = false)- if include_inactive- TimeEntryActivity- .shared- .where(['id NOT IN (?)', time_entry_activities.map(&:parent_id)]) +- time_entry_activities- else- TimeEntryActivity- .shared- .active- .where(['id NOT IN (?)', time_entry_activities.map(&:parent_id)]) +- time_entry_activities.active- end- end-def self.possible_principles_conditioncondition = if Setting.work_package_group_assignment?["(#{Principal.table_name}.type=? OR #{Principal.table_name}.type=?)", 'User', 'Group']diff --git a/app/models/time_entry_activities_project.rb b/app/models/time_entry_activities_project.rbnew file mode 100644index 00000000000..f8ade55d84c--- /dev/null+++ b/app/models/time_entry_activities_project.rb@@ -0,0 +1,34 @@+#-- 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.+#++++class TimeEntryActivitiesProject < ActiveRecord::Base+ belongs_to :project+ belongs_to :activity, class_name: 'TimeEntryActivity'+enddiff --git a/app/models/time_entry_activity.rb b/app/models/time_entry_activity.rbindex 7313a354b03..e2527e789c7 100644--- a/app/models/time_entry_activity.rb+++ b/app/models/time_entry_activity.rb@@ -30,6 +30,18 @@class TimeEntryActivity < Enumerationhas_many :time_entries, foreign_key: 'activity_id'+ has_many :time_entry_activities_projects, foreign_key: 'activity_id', dependent: :delete_all++ validates :parent, absence: true++ def self.in_project(project)+ scope = includes(time_entry_activities_projects: :activity)++ scope+ .where(time_entry_activities_projects: { project_id: project.id, active: true })+ .or(scope.where.not(time_entry_activities_projects: { project_id: project.id }).where(enumerations: { active: true }))+ .or(scope.where(time_entry_activities_projects: { project_id: nil }, enumerations: { active: true }))+ endOptionName = :enumeration_activities@@ -42,20 +54,30 @@ class TimeEntryActivity < Enumerationenddef transfer_relations(to)- time_entries.update_all("activity_id = #{to.id}")+ time_entries.update_all(activity_id: to.id)+ end++ def active_in_project?(project)+ teap = time_entry_activities_projects.detect { |t| t.project_id == project.id }+ !teap || teap.active?enddef activated_projects- scope = Project.all+ join_condition = <<-SQL+ LEFT OUTER JOIN time_entry_activities_projects+ ON projects.id = time_entry_activities_projects.project_id+ AND time_entry_activities_projects.activity_id = #{id}+ SQL++ join_scope = Project.joins(join_condition)- scope = if active?- scope- .where.not(id: children.select(:project_id))- else- scope- .where('1=0')- end+ result_scope = join_scope.where(time_entry_activities_projects: { active: true })- scope.or(Project.where(id: children.where(active: true).select(:project_id)))+ if active?+ result_scope+ .or(join_scope.where(time_entry_activities_projects: { project_id: nil }))+ else+ result_scope+ endendenddiff --git a/app/seeders/demo_data/work_package_seeder.rb b/app/seeders/demo_data/work_package_seeder.rbindex acc6440a8f0..8b237a84c5f 100644--- a/app/seeders/demo_data/work_package_seeder.rb+++ b/app/seeders/demo_data/work_package_seeder.rb@@ -28,7 +28,7 @@module DemoDataclass WorkPackageSeeder < Seederattr_accessor :project, :user, :statuses, :repository,- :time_entry_activities, :types, :key+ :types, :keyinclude ::DemoData::References@@ -38,7 +38,6 @@ module DemoDataself.user = User.admin.firstself.statuses = Status.allself.repository = Repository.first- self.time_entry_activities = TimeEntryActivity.allself.types = project.types.all.reject(&:is_milestone?)enddiff --git a/app/seeders/random_data/work_package_seeder.rb b/app/seeders/random_data/work_package_seeder.rbindex e40453c8611..73bf0dd81c2 100644--- a/app/seeders/random_data/work_package_seeder.rb+++ b/app/seeders/random_data/work_package_seeder.rb@@ -27,14 +27,13 @@# See doc/COPYRIGHT.rdoc for more details.module RandomDataclass WorkPackageSeeder- attr_accessor :project, :user, :statuses, :repository, :time_entry_activities, :types+ attr_accessor :project, :user, :statuses, :repository, :typesdef initialize(project)self.project = projectself.user = User.admin.firstself.statuses = Status.allself.repository = Repository.first- self.time_entry_activities = TimeEntryActivity.allself.types = project.types.all.reject(&:is_milestone?)enddiff --git a/app/services/time_entries/set_attributes_service.rb b/app/services/time_entries/set_attributes_service.rbindex 4fcf7f06c6a..170c55b9600 100644--- a/app/services/time_entries/set_attributes_service.rb+++ b/app/services/time_entries/set_attributes_service.rb@@ -40,8 +40,6 @@ module TimeEntriesif no_project_or_context_changed?model.project = model.work_package&.projectend-- use_project_activity(model)enddef set_default_attributes(*)@@ -62,15 +60,6 @@ module TimeEntriesmodel.hours = nil if model.hours&.zero?end- def use_project_activity(time_entry)- if time_entry.activity&.shared? && time_entry.project- project_activity = time_entry.project.time_entry_activities.find_by(parent_id: time_entry.activity_id) ||- time_entry.activity-- time_entry.activity = project_activity- end- end-def no_project_or_context_changed?!model.project ||(model.work_package && model.work_package_id_changed? && !model.project_id_changed?)diff --git a/app/views/project_settings/_activities.html.erb b/app/views/project_settings/_activities.html.erbindex aba31f31ac4..45c6c155f46 100644--- a/app/views/project_settings/_activities.html.erb+++ b/app/views/project_settings/_activities.html.erb@@ -26,8 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.See docs/COPYRIGHT.rdoc for more details.++#%>-<% if @project.activities(true).any? %>- <%= form_tag project_enumerations_path(@project),+<% if TimeEntryActivity.any? %>+ <%= form_tag project_time_entry_activities_path(@project),method: :put,class: "tabular" do %>diff --git a/app/views/projects/form/_activities.html.erb b/app/views/projects/form/_activities.html.erbindex 9754282adf4..349aaa267b0 100644--- a/app/views/projects/form/_activities.html.erb+++ b/app/views/projects/form/_activities.html.erb@@ -27,73 +27,29 @@ See docs/COPYRIGHT.rdoc for more details.++#%>-<fieldset class="form--fieldset" id="project_types">- <legend class="form--fieldset-legend"><%=l(:label_enabled_project_activities)%></legend>-- <div class="generic-table--container">- <div class="generic-table--results-container">- <table class="generic-table">- <colgroup>- <col highlight-col>- <col highlight-col>- <col highlight-col>- <% TimeEntryActivity.new.available_custom_fields.each do |value| %>- <col highlight-col>- <% end %>- </colgroup>- <thead>- <tr>- <th>- <div class="generic-table--sort-header-outer">- <div class="generic-table--sort-header">- <span>- <%= Enumeration.human_attribute_name(:active) %>- </span>- </div>- </div>- </th>- <th>- <div class="generic-table--sort-header-outer">- <div class="generic-table--sort-header">- <span>- <%= Enumeration.human_attribute_name(:name) %>- </span>- </div>- </div>- </th>- <th>- <div class="generic-table--sort-header-outer">- <div class="generic-table--sort-header">- <span>- <%= l(:enumeration_system_activity) %>- </span>- </div>- </div>- </th>- </tr>- </thead>- <% @project.activities(true).each do |enumeration| %>- <%= fields_for "enumerations[#{enumeration.id}]", enumeration do |ff| %>- <tr>- <td>- <%= label_tag "enumerations_#{enumeration.id}_active", "#{h(enumeration.name)} #{l(:description_active)}", class: "hidden-for-sighted" %>- <%= ff.check_box :active %>- </td>- <td>- <%= ff.hidden_field :parent_id, value: enumeration.id unless enumeration.project %>- <%= h(enumeration) %>- </td>- <td><%= checked_image !enumeration.project %></td>- </tr>- <% end %>- <% end %>- </table>-+<fieldset class="form--fieldset">+ <legend class="form--fieldset-legend"><%=t(:label_enabled_project_activities)%></legend>++ <% TimeEntryActivity+ .includes(:time_entry_activities_projects)+ .order(:name)+ .each do |activity| %>+ <div class="form--field">+ <%= styled_label_tag "time_entry_activities_project_#{activity.id}_active", activity.name %>+ <div class="form--field-container" >+ <%= hidden_field_tag "time_entry_activities_project[][activity_id]",+ activity.id %>+ <%= styled_check_box_tag "time_entry_activities_project[][active]",+ 1,+ activity.active_in_project?(@project),+ id: "time_entry_activities_project_#{activity.id}_active" %>+ </div></div>- </div>+ <% end %>+<% if withControlls == true %><div class="generic-table--action-buttons">- <%= styled_button_tag l(:button_save), class: '-highlight -with-icon icon-checkmark' %>+ <%= styled_button_tag t(:button_save), class: '-highlight -with-icon icon-checkmark' %></div><% end %></fieldset>diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 5439f715b1e..f24e59fb43d 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -194,7 +194,7 @@ OpenProject::AccessControl.map do |map|require: :loggedintime.permission :manage_project_activities,- { project_enumerations: %i[update destroy] },+ { 'projects/time_entry_activities': %i[update] },require: :memberenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 615901b2b1b..ac88b29d861 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1044,7 +1044,6 @@ en:enumeration_activities: "Activities (time tracking)"enumeration_work_package_priorities: "Work package priorities"- enumeration_system_activity: "System Activity"enumeration_reported_project_statuses: "Reported project status"error_auth_source_sso_failed: "Single Sign-On (SSO) for user '%{value}' failed"diff --git a/config/routes.rb b/config/routes.rbindex 5e2635eeb21..2bf99f52717 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -196,7 +196,7 @@ OpenProject::Application.routes.draw doget :level_listend- resource :enumerations, controller: 'project_enumerations', only: %i[update destroy]+ resource :time_entry_activities, controller: 'projects/time_entry_activities', only: %i[update]resources :versions, only: %i[new create] docollection dodiff --git a/db/migrate/20191216135213_join_table_for_active_activities.rb b/db/migrate/20191216135213_join_table_for_active_activities.rbnew file mode 100644index 00000000000..9777d23ce33--- /dev/null+++ b/db/migrate/20191216135213_join_table_for_active_activities.rb@@ -0,0 +1,92 @@+class JoinTableForActiveActivities < ActiveRecord::Migration[6.0]+ class ActivitiesJoinTable < ActiveRecord::Base+ self.table_name = :time_entry_activities_projects+ end++ class TimeEntryActivity < ActiveRecord::Base+ self.table_name = :enumerations+ end++ def up+ create_join_table+ link_time_entries_to_root_activities+ fill_new_join_table+ delete_inherited_activities+ end++ def down+ create_project_specific_activities+ link_time_entries_to_project_activities++ drop_table :time_entry_activities_projects+ end++ def create_join_table+ create_table :time_entry_activities_projects do |t|+ t.references :activity, null: false, foreign_key: { to_table: :enumerations }, index: true+ t.references :project, null: false, foreign_key: true, index: true+ t.boolean :active, default: true, index: true+ end+ add_index :time_entry_activities_projects,+ %i[project_id activity_id],+ unique: true,+ name: 'index_teap_on_project_id_and_activity_id'+ end++ def link_time_entries_to_root_activities+ ActiveRecord::Base.connection.exec_query(+ <<-SQL+ UPDATE time_entries SET activity_id = enumerations.parent_id+ FROM+ time_entries te+ INNER JOIN enumerations ON te.activity_id = enumerations.id AND enumerations.parent_id IS NOT NULL AND enumerations.type = 'TimeEntryActivity'+ SQL+ )+ end++ def link_time_entries_to_project_activities+ ActiveRecord::Base.connection.exec_query(+ <<-SQL+ UPDATE time_entries SET activity_id = COALESCE(child.id, root.id)+ FROM+ time_entries te+ INNER JOIN enumerations root ON te.activity_id = root.id AND root.type = 'TimeEntryActivity'+ LEFT OUTER JOIN enumerations child ON child.parent_id = root.id+ SQL+ )+ end++ def fill_new_join_table+ values = TimeEntryActivity+ .where+ .not(parent_id: nil)+ .pluck(:project_id, :parent_id, :active)+ .map { |project_id, parent_id, active| { project_id: project_id, activity_id: parent_id, active: active } }++ ActivitiesJoinTable.insert_all(values) if values.present?+ end++ def delete_inherited_activities+ TimeEntryActivity.where.not(parent_id: nil).delete_all+ end++ def create_project_specific_activities+ ActiveRecord::Base.connection.exec_query(+ <<-SQL+ INSERT INTO enumerations (name, is_default, type, position, parent_id, project_id, active, created_at, updated_at)+ SELECT+ tea.name,+ false,+ tea.type,+ tea.position,+ teap.activity_id,+ teap.project_id,+ teap.active,+ NOW(),+ NOW()+ FROM time_entry_activities_projects teap+ JOIN enumerations tea ON tea.id = teap.activity_id AND tea.type = 'TimeEntryActivity'+ SQL+ )+ end+enddiff --git a/lib/api/v3/time_entries/time_entries_activity_representer.rb b/lib/api/v3/time_entries/time_entries_activity_representer.rbindex 907c6dfe035..2cebbd8c912 100644--- a/lib/api/v3/time_entries/time_entries_activity_representer.rb+++ b/lib/api/v3/time_entries/time_entries_activity_representer.rb@@ -65,9 +65,10 @@ module APIenddef active_projects- represented- .activated_projects- .visible+ # TODO: Move into contract+ Project+ .allowed_to(current_user, :view_time_entries)+ .where(id: represented.activated_projects.select(:id))endendenddiff --git a/spec/contracts/time_entries/shared_contract_examples.rb b/spec/contracts/time_entries/shared_contract_examples.rbindex 64765e24598..f60292d9dbc 100644--- a/spec/contracts/time_entries/shared_contract_examples.rb+++ b/spec/contracts/time_entries/shared_contract_examples.rb@@ -46,7 +46,15 @@ shared_examples_for 'time entry contract' doendlet(:time_entry_project) { FactoryBot.build_stubbed(:project) }let(:time_entry_user) { current_user }- let(:time_entry_activity) { FactoryBot.build_stubbed(:time_entry_activity) }+ let(:time_entry_activity) do+ FactoryBot.build_stubbed(:time_entry_activity).tap do |activity|+ allow(activity)+ .to receive(:active_in_project?)+ .with(time_entry_project)+ .and_return(time_entry_activity_active)+ end+ end+ let(:time_entry_activity_active) { true }let(:time_entry_spent_on) { Date.today }let(:time_entry_hours) { 5 }let(:time_entry_comments) { "A comment" }@@ -99,6 +107,14 @@ shared_examples_for 'time entry contract' doendend+ context 'if the activity is disabled in the project' do+ let(:time_entry_activity_active) { false }++ it 'is invalid' do+ expect_valid(false, activity_id: %i(inclusion))+ end+ end+context 'when spent_on is nil' dolet(:time_entry_spent_on) { nil }diff --git a/spec/lib/api/v3/time_entries/time_entries_activity_representer_rendering_spec.rb b/spec/lib/api/v3/time_entries/time_entries_activity_representer_rendering_spec.rbindex 347aa7fb482..cc399c61ffc 100644--- a/spec/lib/api/v3/time_entries/time_entries_activity_representer_rendering_spec.rb+++ b/spec/lib/api/v3/time_entries/time_entries_activity_representer_rendering_spec.rb@@ -54,8 +54,15 @@ describe ::API::V3::TimeEntries::TimeEntriesActivityRepresenter, 'rendering' dolet(:project2) { FactoryBot.build_stubbed(:project) }before do+ scope = double('scope')+allow(activity)- .to receive_message_chain(:activated_projects, :visible)+ .to receive(:activated_projects)+ .and_return(scope)++ allow(scope)+ .to receive(:allowed_to)+ .with(user, :view_time_entries).and_return([project1,project2])enddiff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rbindex 95be056b30f..7c1bac59223 100644--- a/spec/models/permitted_params_spec.rb+++ b/spec/models/permitted_params_spec.rb@@ -525,6 +525,23 @@ describe PermittedParams, type: :model doendend+ describe '#time_entry_activities_project' do+ let(:attribute) { :time_entry_activities_project }+ let(:hash) do+ [+ { "activity_id" => "5", "active" => "0" },+ { "activity_id" => "6", "active" => "1" }+ ]+ end+ let(:allowed_params) do+ [{ "activity_id" => "5", "active" => "0" }, { "activity_id" => "6", "active" => "1" }]+ end++ it_behaves_like 'allows params' do+ subject { PermittedParams.new(params, user).send(attribute) }+ end+ end+describe '#user' doinclude_context 'prepare params comparison'diff --git a/spec/models/time_entry_activity_spec.rb b/spec/models/time_entry_activity_spec.rbnew file mode 100644index 00000000000..0e2b61e4ede--- /dev/null+++ b/spec/models/time_entry_activity_spec.rb@@ -0,0 +1,154 @@+#-- 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 TimeEntryActivity, type: :model do+ let(:activity) { FactoryBot.create(:time_entry_activity) }+ let(:project) { FactoryBot.create(:project) }+ let(:other_project) { FactoryBot.create(:project) }++ describe '.in_project' do+ context 'without a project configuration' do+ context 'with the activity being active' do+ it 'includes the activity' do+ expect(TimeEntryActivity.in_project(project))+ .to match_array [activity]+ end+ end++ context 'with the activity being inactive' do+ before do+ activity.update_attribute(:active, false)+ end++ it 'excludes the activity' do+ expect(TimeEntryActivity.in_project(project))+ .to be_empty+ end+ end+ end++ context 'with a project configuration configured to true' do+ before do+ activity.time_entry_activities_projects.create(project: project, active: true)+ end++ it 'includes the activity' do+ expect(TimeEntryActivity.in_project(project))+ .to match_array [activity]+ end++ context 'with the activity being inactive' do+ before do+ activity.update_attribute(:active, false)+ end++ it 'includes the activity' do+ expect(TimeEntryActivity.in_project(project))+ .to match_array [activity]+ end+ end+ end++ context 'with a project configuration configured to false but for a different project' do+ before do+ activity.time_entry_activities_projects.create(project: other_project, active: false)+ end++ it 'includes the activity' do+ expect(TimeEntryActivity.in_project(project))+ .to match_array [activity]+ end+ end++ context 'with a project configuration configured to false' do+ before do+ activity.time_entry_activities_projects.create(project: project, active: false)+ end++ it 'excludes the activity' do+ expect(TimeEntryActivity.in_project(project))+ .to be_empty+ end+ end+ end++ describe '#activated_projects' do+ before do+ project+ other_project+ end++ context 'without project specific overrides' do+ context 'and being active' do+ it 'returns all projects' do+ expect(activity.activated_projects)+ .to match_array [project, other_project]+ end+ end++ context 'and not being active' do+ before do+ activity.update_attribute(:active, false)+ end++ it 'returns no projects' do+ expect(activity.activated_projects)+ .to be_empty+ end+ end+ end++ context 'with project specific overrides' do+ before do+ TimeEntryActivitiesProject.insert(activity_id: activity.id, project_id: project.id, active: true)+ TimeEntryActivitiesProject.insert(activity_id: activity.id, project_id: other_project.id, active: false)+ end++ context 'and being active' do+ it 'returns the project the activity is activated in' do+ expect(activity.activated_projects)+ .to match_array [project]+ end+ end++ context 'and not being active' do+ before do+ activity.update_attribute(:active, false)+ end++ it 'returns only the projects the activity is activated in' do+ expect(activity.activated_projects)+ .to match_array [project]+ end+ end+ end+ end+enddiff --git a/spec/models/time_entry_spec.rb b/spec/models/time_entry_spec.rbindex bfd5af12660..1b9f9b91586 100644--- a/spec/models/time_entry_spec.rb+++ b/spec/models/time_entry_spec.rb@@ -31,83 +31,4 @@require 'spec_helper'describe TimeEntry, type: :model do- let(:activity) do- FactoryBot.build(:time_entry_activity)- end-- describe '#activated_projects' do- let(:project1) { FactoryBot.create(:project) }-- context 'project specific activity' do- before do- activity.project = project1- activity.save!- end-- context 'when the activity is active' do- it 'returns the project if the activity is active' do- expect(activity.activated_projects)- .to match_array [project1]- end- end-- context 'when the activity is inactive' do- before do- activity.update_attribute(:active, false)- end-- it 'is empty if the activity is inactive' do- expect(activity.activated_projects)- .to be_empty- end- end- end-- context 'system activity' do- let(:project2) { FactoryBot.create(:project) }- let(:project3) { FactoryBot.create(:project) }-- let(:child_activity_active) do- FactoryBot.create(:time_entry_activity,- parent: activity,- project: project1)- end- let(:child_activity_inactive) do- FactoryBot.create(:time_entry_activity,- parent: activity,- project: project2,- active: false)- end-- before do- child_activity_active- child_activity_inactive- project3- end-- context 'when the activity is active' do- before do- activity.active = true- activity.save!- end-- it 'returns all projects except for those that have inactive child activities' do- expect(activity.activated_projects)- .to match_array([project1, project3])- end- end-- context 'when the activity is inactive' do- before do- activity.active = false- activity.save!- end-- it 'returns only those projects, that have active child activities' do- expect(activity.activated_projects)- .to match_array([project1])- end- end- end- endenddiff --git a/spec/requests/api/v3/time_entry_resource_spec.rb b/spec/requests/api/v3/time_entry_resource_spec.rbindex c969987781a..8b41ce59a40 100644--- a/spec/requests/api/v3/time_entry_resource_spec.rb+++ b/spec/requests/api/v3/time_entry_resource_spec.rb@@ -245,52 +245,32 @@ describe 'API v3 time_entry resource', type: :request doendcontext 'filtering by global activity' do- let(:project_activity) do- FactoryBot.create(:time_entry_activity,- parent: activity,- project: project)+ let(:activity) do+ FactoryBot.create(:time_entry_activity)end- let(:other_project_activity) do- FactoryBot.create(:time_entry_activity,- parent: activity,- project: other_project)- end- let(:another_project_activity) do- FactoryBot.create(:time_entry_activity,- parent: FactoryBot.create(:time_entry_activity),- project: project)- end- let(:shared_activity) do- FactoryBot.create(:time_entry_activity,- parent: nil)+ let(:another_activity) do+ FactoryBot.create(:time_entry_activity)endlet!(:time_entry) doFactoryBot.create(:time_entry,project: project,work_package: work_package,user: current_user,- activity: project_activity)+ activity: activity)endlet!(:other_time_entry) doFactoryBot.create(:time_entry,project: other_project,work_package: other_work_package,user: current_user,- activity: other_project_activity)+ activity: activity)endlet!(:another_time_entry) doFactoryBot.create(:time_entry,project: project,work_package: work_package,user: current_user,- activity: another_project_activity)- end- let!(:shared_time_entry) do- FactoryBot.create(:time_entry,- project: project,- work_package: work_package,- user: current_user,- activity: shared_activity)+ activity: another_activity)endbefore do@@ -306,17 +286,17 @@ describe 'API v3 time_entry resource', type: :request do{'activity_id' => {'operator' => '=',- 'values' => [activity.id, shared_activity.id]+ 'values' => [activity.id]}}]- "#{api_v3_paths.time_entries}?#{{ filters: filter.to_json }.to_query}&sortBy=#{[%w(id asc)].to_json}"+ api_v3_paths.path_for(:time_entries, filters: filter, sort_by: [%w(id asc)])endit 'contains only the filtered time entries in the response' doexpect(subject.body)- .to be_json_eql('3')+ .to be_json_eql('2').at_path('total')expect(subject.body)@@ -326,10 +306,6 @@ describe 'API v3 time_entry resource', type: :request doexpect(subject.body).to be_json_eql(other_time_entry.id.to_json).at_path('_embedded/elements/1/id')-- expect(subject.body)- .to be_json_eql(shared_time_entry.id.to_json)- .at_path('_embedded/elements/2/id')endend@@ -478,21 +454,20 @@ describe 'API v3 time_entry resource', type: :request doendend- context 'when sending an activity the project overrides' do- let(:project_activity) do- params = activity.attributes.except('id')- params['parent_id'] = activity.id- project.create_time_entry_activity_if_needed(params)-- project.time_entry_activities.first+ context 'if sending an activity the project disables' do+ let(:disable_activity) do+ TimeEntryActivitiesProject.insert activity_id: activity.id, project_id: project.id, active: falseend- let(:additional_setup) { -> { project_activity } }- it 'creates the time entry with the project activity' do- new_entry = TimeEntry.first+ let(:additional_setup) { -> { disable_activity } }- expect(new_entry.activity)- .to eql project_activity+ it 'returns 422 and complains about the activity' do+ expect(subject.status)+ .to eql(422)++ expect(subject.body)+ .to be_json_eql("Activity is not set to one of the allowed values.".to_json)+ .at_path("message")endend@@ -572,22 +547,20 @@ describe 'API v3 time_entry resource', type: :request doendend- context 'when sending an activity the project overrides' do- let(:project_activity) do- params = activity.attributes.except('id')- params['parent_id'] = activity.id- project.create_time_entry_activity_if_needed(params)-- project.time_entry_activities.first+ context 'if sending an activity the project disables' do+ let(:disable_activity) do+ TimeEntryActivitiesProject.insert activity_id: activity.id, project_id: project.id, active: falseend- let(:additional_setup) { -> { project_activity } }+ let(:additional_setup) { -> { disable_activity } }- it 'creates the time entry with the project activity' do- time_entry.reload+ it 'returns 422 and complains about the activity' do+ expect(subject.status)+ .to eql(422)- expect(time_entry.activity)- .to eql project_activity+ expect(subject.body)+ .to be_json_eql("Activity is not set to one of the allowed values.".to_json)+ .at_path("message")endenddiff --git a/spec/routing/project_enumerations_spec.rb b/spec/routing/projects/time_entry_activities_spec.rbsimilarity index 73%rename from spec/routing/project_enumerations_spec.rbrename to spec/routing/projects/time_entry_activities_spec.rbindex 823a85cc750..835d9a28944 100644--- a/spec/routing/project_enumerations_spec.rb+++ b/spec/routing/projects/time_entry_activities_spec.rb@@ -28,18 +28,11 @@require 'spec_helper'-describe 'project_enumerations routes', type: :routing do+describe 'project/time_entry_activities routes', type: :routing dodescribe 'update' do- it 'links PUT /projects/:project_id/enumerations' do- expect(put('/projects/64/enumerations'))- .to route_to('project_enumerations#update', project_id: '64')- end- end-- describe 'delete' do- it 'links DELETE /projects/:project_id/enumerations' do- expect(delete('/projects/64/enumerations'))- .to route_to('project_enumerations#destroy', project_id: '64')+ it 'links PUT /projects/:project_id/time_entry_activities' do+ expect(put('/projects/64/time_entry_activities'))+ .to route_to('projects/time_entry_activities#update', project_id: '64')endendenddiff --git a/spec/services/time_entries/set_attributes_service_spec.rb b/spec/services/time_entries/set_attributes_service_spec.rbindex 2eb059de543..05890c69ccd 100644--- a/spec/services/time_entries/set_attributes_service_spec.rb+++ b/spec/services/time_entries/set_attributes_service_spec.rb@@ -190,47 +190,4 @@ describe TimeEntries::SetAttributesService, type: :model do.to eql(contract_errors)endend-- context 'with a system activity' do- let!(:system_activity) { FactoryBot.build_stubbed(:time_entry_activity) }- let(:params) do- {- project: project,- activity: system_activity- }- end-- context 'with no project activity existing' do- it 'sets the system activity' do- subject-- expect(time_entry_instance.activity)- .to eql(system_activity)- end- end-- context 'with a project activity existing' do- let!(:project_activity) { FactoryBot.build_stubbed(:time_entry_activity, parent: system_activity, project: project) }-- before do- project_activities = [project_activity]-- allow(project)- .to receive(:time_entry_activities)- .and_return(project_activities)-- allow(project_activities)- .to receive(:find_by)- .with(parent_id: system_activity.id)- .and_return(project_activity)- end-- it 'uses the project activity instead' do- subject-- expect(time_entry_instance.activity)- .to eql(project_activity)- end- end- endenddiff --git a/spec_legacy/functional/project_enumerations_controller_spec.rb b/spec_legacy/functional/project_enumerations_controller_spec.rbdeleted file mode 100644index 97230e26b80..00000000000--- a/spec_legacy/functional/project_enumerations_controller_spec.rb+++ /dev/null@@ -1,263 +0,0 @@-#-- 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.-#++--require_relative '../legacy_spec_helper'--describe ProjectEnumerationsController, type: :controller do- fixtures :all-- before do- session[:user_id] = nil- Setting.default_language = 'en'- end-- it 'update to override system activities' do- session[:user_id] = 2 # manager- billable_field = TimeEntryActivityCustomField.find_by(name: 'Billable')-- params = {- project_id: 1,- enumerations: {- # Design, De-activate- '9' => { 'parent_id' => '9', 'custom_field_values' => { '7' => '1' }, 'active' => '0' },- # Development, Change custom value- '10' => { 'parent_id' => '10', 'custom_field_values' => { '7' => '0' }, 'active' => '1' },- # Inactive Activity, Activate with custom value- '14' => { 'parent_id' => '14', 'custom_field_values' => { '7' => '1' }, 'active' => '1' },- '11' => { 'parent_id' => '11', 'custom_field_values' => { '7' => '1' }, 'active' => '1' } # QA, no changes- }- }-- put :update, params: params-- assert_response :redirect- assert_redirected_to '/projects/ecookbook/settings/activities'-- # Created project specific activities...- project = Project.find('ecookbook')-- # ... Design- design = project.time_entry_activities.find_by(name: 'Design')- assert design, 'Project activity not found'-- assert_equal 9, design.parent_id # Relate to the system activity- refute_equal design.parent.id, design.id # Different records- assert_equal design.parent.name, design.name # Same name- assert !design.active?-- # ... Development- development = project.time_entry_activities.find_by(name: 'Development')- assert development, 'Project activity not found'-- assert_equal 10, development.parent_id # Relate to the system activity- refute_equal development.parent.id, development.id # Different records- assert_equal development.parent.name, development.name # Same name- assert development.active?- assert_equal 'f', development.custom_value_for(billable_field).value-- # ... Inactive Activity- previously_inactive = project.time_entry_activities.find_by(name: 'Inactive Activity')- assert previously_inactive, 'Project activity not found'-- assert_equal 14, previously_inactive.parent_id # Relate to the system activity- refute_equal previously_inactive.parent.id, previously_inactive.id # Different records- assert_equal previously_inactive.parent.name, previously_inactive.name # Same name- assert previously_inactive.active?- assert_equal 't', previously_inactive.custom_value_for(billable_field).value-- # ... QA- assert_equal nil, project.time_entry_activities.find_by(name: 'QA'), "Custom QA activity created when it wasn't modified"- end-- it 'update will update project specific activities' do- session[:user_id] = 2 # manager-- project_activity = TimeEntryActivity.new(- name: 'Project Specific',- parent: TimeEntryActivity.first,- project: Project.find(1),- active: true- )- assert project_activity.save- project_activity_two = TimeEntryActivity.new(- name: 'Project Specific Two',- parent: TimeEntryActivity.last,- project: Project.find(1),- active: true- )- assert project_activity_two.save-- params = {- project_id: 1,- enumerations: {- project_activity.id => { 'custom_field_values' => { '7' => '1' }, 'active' => '0' }, # De-activate- project_activity_two.id => { 'custom_field_values' => { '7' => '1' }, 'active' => '0' } # De-activate- }- }-- put :update, params: params-- assert_response :redirect- assert_redirected_to '/projects/ecookbook/settings/activities'-- # Created project specific activities...- project = Project.find('ecookbook')- assert_equal 2, project.time_entry_activities.count-- activity_one = project.time_entry_activities.find_by(name: project_activity.name)- assert activity_one, 'Project activity not found'- assert_equal project_activity.id, activity_one.id- assert !activity_one.active?-- activity_two = project.time_entry_activities.find_by(name: project_activity_two.name)- assert activity_two, 'Project activity not found'- assert_equal project_activity_two.id, activity_two.id- assert !activity_two.active?- end-- it 'update when creating new activities will convert existing data' do- assert_equal 3, TimeEntry.where(activity_id: 9, project_id: 1).size-- session[:user_id] = 2 # manager-- params = {- project_id: 1,- enumerations: {- '9' => { 'parent_id' => '9', 'custom_field_values' => { '7' => '1' }, 'active' => '0' } # Design, De-activate- }- }- put :update, params: params-- assert_response :redirect-- # No more TimeEntries using the system activity- assert_equal 0, TimeEntry.where(activity_id: 9, project_id: 1).size, 'Time Entries still assigned to system activities'- # All TimeEntries using project activity- project_specific_activity = TimeEntryActivity.find_by(parent_id: 9, project_id: 1)- assert_equal 3,- TimeEntry.where(activity_id: project_specific_activity.id, project_id: 1).size,- 'No Time Entries assigned to the project activity'- end-- it 'update when creating new activities will not convert existing data if an exception is raised' do- # TODO: Need to cause an exception on create but these tests- # aren't setup for mocking. Just create a record now so the- # second one is a duplicate- # parent = TimeEntryActivity.find(9)- parent = TimeEntryActivity.new- parent.attributes = { name: parent.name, project_id: 1, position: parent.position, active: true }- parent.save(validate: false)-- project = Project.find(1)- project.time_entries.create!(hours: 1.0,- user: User.find(1),- work_package_id: 3,- activity_id: 10,- spent_on: '2009-01-01')-- assert_equal 3, TimeEntry.where(activity_id: 9, project_id: 1).size- assert_equal 1, TimeEntry.where(activity_id: 10, project_id: 1).size-- session[:user_id] = 2 # manager-- params = {- project_id: 1,- enumerations: {- '9' => { 'parent_id' => parent.id,- 'custom_field_values' => { '7' => '1' },- 'active' => '0' }- }- }-- put :update, params: params-- assert_response :redirect-- # TimeEntries shouldn't have been reassigned on the failed record- assert_equal 3,- TimeEntry.where(activity_id: 9, project_id: 1).size,- 'Time Entries are not assigned to system activities'- # TimeEntries shouldn't have been reassigned on the saved record either- assert_equal 1,- TimeEntry.where(activity_id: 10, project_id: 1).size,- 'Time Entries are not assigned to system activities'- end-- it 'destroy' do- session[:user_id] = 2 # manager- project_activity = TimeEntryActivity.new(- name: 'Project Specific',- parent: TimeEntryActivity.first,- project: Project.find(1),- active: true- )- assert project_activity.save- project_activity_two = TimeEntryActivity.new(- name: 'Project Specific Two',- parent: TimeEntryActivity.last,- project: Project.find(1),- active: true- )- assert project_activity_two.save-- delete :destroy, params: { project_id: 1 }- assert_response :redirect- assert_redirected_to '/projects/ecookbook/settings/activities'-- assert_nil TimeEntryActivity.find_by(id: project_activity.id)- assert_nil TimeEntryActivity.find_by(id: project_activity_two.id)- end-- it 'destroy should reassign time entries back to the system activity' do- session[:user_id] = 2 # manager- project_activity = TimeEntryActivity.new(- name: 'Project Specific Design',- parent: TimeEntryActivity.find(9),- project: Project.find(1),- active: true- )- assert project_activity.save- assert TimeEntry.where(['project_id = ? AND activity_id = ?', 1, 9])- .update_all("activity_id = '#{project_activity.id}'")- assert_equal 3, TimeEntry.where(activity_id: project_activity.id, project_id: 1).size-- delete :destroy, params: { project_id: 1 }- assert_response :redirect- assert_redirected_to '/projects/ecookbook/settings/activities'-- assert_nil TimeEntryActivity.find_by(id: project_activity.id)- assert_equal 0,- TimeEntry.where(activity_id: project_activity.id, project_id: 1).size,- 'TimeEntries still assigned to project specific activity'- assert_equal 3,- TimeEntry.where(activity_id: 9, project_id: 1).size,- 'TimeEntries still assigned to project specific activity'- end-enddiff --git a/spec_legacy/unit/helpers/timelog_helper_spec.rb b/spec_legacy/unit/helpers/timelog_helper_spec.rbdeleted file mode 100644index eb73d48b185..00000000000--- a/spec_legacy/unit/helpers/timelog_helper_spec.rb+++ /dev/null@@ -1,59 +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_relative '../../legacy_spec_helper'--describe TimelogHelper, type: :helper do- include TimelogHelper- include ActionView::Helpers::TextHelper- include ActionView::Helpers::DateHelper-- it 'should activities collection for select options should return array of activity names and ids' do- design = TimeEntryActivity.find_by(name: 'My Design') || FactoryBot.create(:activity, name: 'My Design')- development = TimeEntryActivity.find_by(name: 'My Development') || FactoryBot.create(:activity, name: 'My Development')- activities = activity_collection_for_select_options- assert activities.include?(['My Design', design.id])- assert activities.include?(['My Development', development.id])- end-- it 'should activities collection for select options should not include inactive activities' do- inactive = TimeEntryActivity.find_by(name: 'Inactive Activity') || FactoryBot.create(:inactive_activity, name: 'Inactive Activity')- activities = activity_collection_for_select_options- assert !activities.include?(['Inactive Activity', inactive.id])- end-- it 'should activities collection for select options should use the projects override' do- project = FactoryBot.create :valid_project- design = TimeEntryActivity.find_by(name: 'Design') || FactoryBot.create(:activity, name: 'Design')- override_activity = TimeEntryActivity.create!(name: 'Design override', parent: TimeEntryActivity.find_by(name: 'Design'), project: project)-- activities = activity_collection_for_select_options(nil, project)- assert !activities.include?(['Design', design.id]), 'System activity found in: ' + activities.inspect- assert activities.include?(['Design override', override_activity.id]), 'Override activity not found in: ' + activities.inspect- end-enddiff --git a/spec_legacy/unit/project_spec.rb b/spec_legacy/unit/project_spec.rbindex aac6013882d..e51fd689bc4 100644--- a/spec_legacy/unit/project_spec.rb+++ b/spec_legacy/unit/project_spec.rb@@ -326,78 +326,6 @@ describe Project, type: :model doassert copied_project.activeend- it 'should activities should use the system activities' do- project = Project.find(1)- assert_equal project.activities, TimeEntryActivity.where(active: true).to_a- end-- it 'should activities should use the project specific activities' do- project = Project.find(1)- overridden_activity = TimeEntryActivity.new(name: 'Project', project: project)- assert overridden_activity.save!-- assert project.activities.include?(overridden_activity), 'Project specific Activity not found'- end-- it 'should activities should not include the inactive project specific activities' do- project = Project.find(1)- overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: TimeEntryActivity.first, active: false)- assert overridden_activity.save!-- assert !project.activities.include?(overridden_activity), 'Inactive Project specific Activity found'- end-- it 'should activities should not include project specific activities from other projects' do- project = Project.find(1)- overridden_activity = TimeEntryActivity.new(name: 'Project', project: Project.find(2))- assert overridden_activity.save!-- assert !project.activities.include?(overridden_activity), 'Project specific Activity found on a different project'- end-- it 'should activities should handle nils' do- overridden_activity = TimeEntryActivity.new(name: 'Project', project: Project.find(1), parent: TimeEntryActivity.first)- TimeEntryActivity.delete_all-- # No activities- project = Project.find(1)- assert project.activities.empty?-- # No system, one overridden- assert overridden_activity.save!- project.reload- assert_equal [overridden_activity], project.activities- end-- it 'should activities should override system activities with project activities' do- project = Project.find(1)- parent_activity = TimeEntryActivity.first- overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: parent_activity)- assert overridden_activity.save!-- assert project.activities.include?(overridden_activity), 'Project specific Activity not found'- assert !project.activities.include?(parent_activity), 'System Activity found when it should have been overridden'- end-- it 'should activities should include inactive activities if specified' do- project = Project.find(1)- overridden_activity = TimeEntryActivity.new(name: 'Project', project: project, parent: TimeEntryActivity.first, active: false)- assert overridden_activity.save!-- assert project.activities(true).include?(overridden_activity), 'Inactive Project specific Activity not found'- end-- specify 'activities should not include active System activities if the project has an override that is inactive' do- project = Project.find(1)- system_activity = TimeEntryActivity.find_by(name: 'Design')- assert system_activity.active?- overridden_activity = FactoryBot.create(:time_entry_activity, project: project, parent: system_activity, active: false)- assert overridden_activity.save!-- assert !project.activities.include?(overridden_activity), 'Inactive Project specific Activity not found'- assert !project.activities.include?(system_activity), 'System activity found when the project has an inactive override'- end-it 'should close completed versions' doVersion.update_all("status = 'open'")project = Project.find(1)diff --git a/spec_legacy/unit/time_entry_activity_spec.rb b/spec_legacy/unit/time_entry_activity_spec.rbindex b263049ca97..5754201f6f4 100644--- a/spec_legacy/unit/time_entry_activity_spec.rb+++ b/spec_legacy/unit/time_entry_activity_spec.rb@@ -26,7 +26,7 @@## See docs/COPYRIGHT.rdoc for more details.#++-require 'legacy_spec_helper'+require_relative '../legacy_spec_helper'describe TimeEntryActivity, type: :model doinclude MiniTest::Assertions # refute