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
fix time entry active scope
ulferts41d18b9a4f52
diff --git a/app/models/time_entry_activity/scopes/active_in_project.rb b/app/models/time_entry_activity/scopes/active_in_project.rbindex 916672c420f..35408c0f315 100644--- a/app/models/time_entry_activity/scopes/active_in_project.rb+++ b/app/models/time_entry_activity/scopes/active_in_project.rb@@ -30,13 +30,31 @@module TimeEntryActivity::Scopesclass ActiveInProject- def self.fetch(project)- scope = TimeEntryActivity.includes(time_entry_activities_projects: :activity)+ class << self+ def fetch(project)+ being_active_in_project(project)+ .or(being_not_inactive_in_project(project))+ end- 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 }))+ private++ # All activities, that have a specific setting for the project to be active.+ # The global active state has no effect in that case.+ def being_active_in_project(project)+ TimeEntryActivity+ .where(id: of_project(project).where(active: true))+ end++ # All activities that are active and do not have a project specific setting stating+ # the activity to be inactive. So there could either be no project specific setting (for that project) or+ # a project specific setting that is active.+ def being_not_inactive_in_project(project)+ TimeEntryActivity.where(active: true).where.not(id: of_project(project).where(active: false))+ end++ def of_project(project)+ TimeEntryActivitiesProject.where(project_id: project.id).select(:activity_id)+ endendendenddiff --git a/spec/models/time_entry_activity/scopes/active_in_project_spec.rb b/spec/models/time_entry_activity/scopes/active_in_project_spec.rbindex 1d19da76d3e..205e5a73c7a 100644--- a/spec/models/time_entry_activity/scopes/active_in_project_spec.rb+++ b/spec/models/time_entry_activity/scopes/active_in_project_spec.rb@@ -31,7 +31,8 @@require 'spec_helper'describe TimeEntryActivity::Scopes::ActiveInProject, type: :model do- let(:activity) { FactoryBot.create(:time_entry_activity) }+ let!(:activity) { FactoryBot.create(:time_entry_activity) }+ let!(:other_activity) { FactoryBot.create(:time_entry_activity) }let(:project) { FactoryBot.create(:project) }let(:other_project) { FactoryBot.create(:project) }@@ -42,7 +43,7 @@ describe TimeEntryActivity::Scopes::ActiveInProject, type: :model docontext 'with the activity being active' doit 'includes the activity' dois_expected- .to match_array [activity]+ .to match_array [activity, other_activity]endend@@ -53,7 +54,7 @@ describe TimeEntryActivity::Scopes::ActiveInProject, type: :model doit 'excludes the activity' dois_expected- .to be_empty+ .to match_array([other_activity])endendend@@ -65,7 +66,7 @@ describe TimeEntryActivity::Scopes::ActiveInProject, type: :model doit 'includes the activity' dois_expected- .to match_array [activity]+ .to match_array [activity, other_activity]endcontext 'with the activity being inactive' do@@ -75,7 +76,7 @@ describe TimeEntryActivity::Scopes::ActiveInProject, type: :model doit 'includes the activity' dois_expected- .to match_array [activity]+ .to match_array [activity, other_activity]endendend@@ -87,7 +88,7 @@ describe TimeEntryActivity::Scopes::ActiveInProject, type: :model doit 'includes the activity' dois_expected- .to match_array [activity]+ .to match_array [activity, other_activity]endend@@ -98,7 +99,18 @@ describe TimeEntryActivity::Scopes::ActiveInProject, type: :model doit 'excludes the activity' dois_expected- .to be_empty+ .to match_array [other_activity]+ end++ context 'with a project configuration configured to true but for a different project' do+ before do+ activity.time_entry_activities_projects.create(project: other_project, active: true)+ end++ it 'excludes the activity' do+ is_expected+ .to match_array [other_activity]+ endendendend