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
Re-enable deprecation notices and add tests
Klaus Zandersf9a5f822ba13
diff --git a/modules/costs/app/models/entry/deprecated_association.rb b/modules/costs/app/models/entry/deprecated_association.rbindex a63a34058a6..ba9e2c4e4f4 100644--- a/modules/costs/app/models/entry/deprecated_association.rb+++ b/modules/costs/app/models/entry/deprecated_association.rb@@ -36,7 +36,7 @@ module Entry::DeprecatedAssociationenddef work_package- # OpenProject::Deprecation.replaced(:work_package, :entity, caller_locations)+ OpenProject::Deprecation.replaced(:work_package, :entity, caller_locations)if entity_type == "WorkPackage"entity@@ -44,7 +44,7 @@ module Entry::DeprecatedAssociationenddef work_package_id- # OpenProject::Deprecation.replaced(:work_package_id, :entity_id, caller_locations)+ OpenProject::Deprecation.replaced(:work_package_id, :entity_id, caller_locations)if entity_type == "WorkPackage"entity_id@@ -52,12 +52,12 @@ module Entry::DeprecatedAssociationenddef work_package=(value)- # OpenProject::Deprecation.replaced(:work_package=, :entity=, caller_locations)+ OpenProject::Deprecation.replaced(:work_package=, :entity=, caller_locations)self.entity = valueenddef work_package_id=(value)- # OpenProject::Deprecation.replaced(:work_package_id=, :entity_id=, caller_locations)+ OpenProject::Deprecation.replaced(:work_package_id=, :entity_id=, caller_locations)self.entity_type = "WorkPackage"self.entity_id = valuediff --git a/modules/costs/spec/models/cost_entry_spec.rb b/modules/costs/spec/models/cost_entry_spec.rbindex c3879a169c4..e6b271a1ec7 100644--- a/modules/costs/spec/models/cost_entry_spec.rb+++ b/modules/costs/spec/models/cost_entry_spec.rb@@ -50,7 +50,7 @@ RSpec.describe CostEntry domemberbuild(:cost_entry, cost_type:,project:,- work_package:,+ entity: work_package,spent_on: date,units:,user:,@@ -60,7 +60,7 @@ RSpec.describe CostEntry dolet(:cost_entry2) dobuild(:cost_entry, cost_type:,project:,- work_package:,+ entity: work_package,spent_on: date,units:,user:,@@ -97,6 +97,14 @@ RSpec.describe CostEntry dolet(:units) { 5.0 }let(:date) { Date.today }+ describe "validations" do+ it "allows the correct entity types" do+ expect(described_class::ALLOWED_ENTITY_TYPES).to contain_exactly("WorkPackage")+ end++ it { is_expected.to validate_inclusion_of(:entity_type).in_array(described_class::ALLOWED_ENTITY_TYPES).allow_blank }+ end+describe "class" dodescribe "#visible" dodescribe "WHEN having the view_cost_entries permission " \@@ -286,20 +294,20 @@ RSpec.describe CostEntry docost_entry.project = nil# unfortunately the project get's set to the work_package's project if no project is provided# TODO: check if that is necessary- cost_entry.work_package = nil+ cost_entry.entity = nilendit { expect(cost_entry).not_to be_valid }end- describe "WHEN no work_package is provided" do- before { cost_entry.work_package = nil }+ describe "WHEN no entity is provided" do+ before { cost_entry.entity = nil }it { expect(cost_entry).not_to be_valid }end- describe "WHEN the work_package is not in the project" do- before { cost_entry.work_package = work_package2 }+ describe "WHEN the entity is not in the project" do+ before { cost_entry.entity = work_package2 }it { expect(cost_entry).not_to be_valid }end@@ -517,4 +525,55 @@ RSpec.describe CostEntry doendendend++ describe "deprecated work package association" do+ it "ignores the deprecated work package association" do+ expect(described_class.ignored_columns).to include("work_package_id")+ end++ it "allows access to the work package" do+ allow(OpenProject::Deprecation).to receive(:replaced)++ cost_entry.entity = work_package+ expect(cost_entry.work_package).to eq(work_package)++ cost_entry.entity = create(:meeting)+ expect(cost_entry.work_package).to be_nil++ expect(OpenProject::Deprecation).to have_received(:replaced).twice.with(:work_package, :entity, any_args)+ end++ it "allows access to the work package ID" do+ allow(OpenProject::Deprecation).to receive(:replaced)++ cost_entry.entity = work_package+ expect(cost_entry.work_package_id).to eq(work_package.id)++ cost_entry.entity = create(:meeting)+ expect(cost_entry.work_package_id).to be_nil++ expect(OpenProject::Deprecation).to have_received(:replaced).twice.with(:work_package_id, :entity_id, any_args)+ end++ it "allows setting the work package" do+ allow(OpenProject::Deprecation).to receive(:replaced)++ cost_entry.work_package = work_package+ expect(cost_entry.entity).to eq(work_package)++ expect(OpenProject::Deprecation).to have_received(:replaced).with(:work_package=, :entity=, any_args)+ end++ it "allows setting the work package ID" do+ allow(OpenProject::Deprecation).to receive(:replaced)++ cost_entry.entity_type = nil # to make sure that we properly set it+ cost_entry.work_package_id = work_package.id+ expect(cost_entry.entity).to eq(work_package)+ expect(cost_entry.entity_type).to eq("WorkPackage")+ expect(cost_entry.entity_id).to eq(work_package.id)++ expect(OpenProject::Deprecation).to have_received(:replaced).with(:work_package_id=, :entity_id=, any_args)+ end+ endenddiff --git a/modules/costs/spec/models/time_entry_spec.rb b/modules/costs/spec/models/time_entry_spec.rbindex b03088352b8..9b170376691 100644--- a/modules/costs/spec/models/time_entry_spec.rb+++ b/modules/costs/spec/models/time_entry_spec.rb@@ -58,7 +58,7 @@ RSpec.describe TimeEntry dolet(:time_entry) docreate(:time_entry,project:,- work_package:,+ entity: work_package,spent_on: date,hours:,start_time: start_time,@@ -71,7 +71,7 @@ RSpec.describe TimeEntry dolet(:time_entry2) docreate(:time_entry,project:,- work_package:,+ entity: work_package,spent_on: date,hours:,user:,@@ -424,6 +424,12 @@ RSpec.describe TimeEntry doenddescribe "validations" do+ it "allows the correct entity types" do+ expect(described_class::ALLOWED_ENTITY_TYPES).to contain_exactly("WorkPackage", "Meeting")+ end++ it { is_expected.to validate_inclusion_of(:entity_type).in_array(described_class::ALLOWED_ENTITY_TYPES).allow_blank }+describe "start_time" doit "allows blank values" dotime_entry.start_time = nil@@ -577,4 +583,55 @@ RSpec.describe TimeEntry doendendend++ describe "deprecated work package association" do+ it "ignores the deprecated work package association" do+ expect(described_class.ignored_columns).to include("work_package_id")+ end++ it "allows access to the work package" do+ allow(OpenProject::Deprecation).to receive(:replaced)++ time_entry.entity = work_package+ expect(time_entry.work_package).to eq(work_package)++ time_entry.entity = create(:meeting)+ expect(time_entry.work_package).to be_nil++ expect(OpenProject::Deprecation).to have_received(:replaced).twice.with(:work_package, :entity, any_args)+ end++ it "allows access to the work package ID" do+ allow(OpenProject::Deprecation).to receive(:replaced)++ time_entry.entity = work_package+ expect(time_entry.work_package_id).to eq(work_package.id)++ time_entry.entity = create(:meeting)+ expect(time_entry.work_package_id).to be_nil++ expect(OpenProject::Deprecation).to have_received(:replaced).twice.with(:work_package_id, :entity_id, any_args)+ end++ it "allows setting the work package" do+ allow(OpenProject::Deprecation).to receive(:replaced)++ time_entry.work_package = work_package+ expect(time_entry.entity).to eq(work_package)++ expect(OpenProject::Deprecation).to have_received(:replaced).with(:work_package=, :entity=, any_args)+ end++ it "allows setting the work package ID" do+ allow(OpenProject::Deprecation).to receive(:replaced)++ time_entry.entity_type = nil # to make sure that we properly set it+ time_entry.work_package_id = work_package.id+ expect(time_entry.entity).to eq(work_package)+ expect(time_entry.entity_type).to eq("WorkPackage")+ expect(time_entry.entity_id).to eq(work_package.id)++ expect(OpenProject::Deprecation).to have_received(:replaced).with(:work_package_id=, :entity_id=, any_args)+ end+ endend