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
Reduce test nesting levels
Christophe Bliard425cf3b3bc4f
diff --git a/spec/services/work_packages/set_attributes_service/derive_progress_values_status_based_spec.rb b/spec/services/work_packages/set_attributes_service/derive_progress_values_status_based_spec.rbindex 3adc1607bdd..78042dc0370 100644--- a/spec/services/work_packages/set_attributes_service/derive_progress_values_status_based_spec.rb+++ b/spec/services/work_packages/set_attributes_service/derive_progress_values_status_based_spec.rb@@ -28,8 +28,10 @@require "spec_helper"+# Scenarios specified in https://community.openproject.org/wp/40749RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesStatusBased,- type: :model do+ type: :model,+ with_settings: { work_package_done_ratio: "status" } doshared_let(:status_0_pct_complete) { create(:status, default_done_ratio: 0, name: "0% complete") }shared_let(:status_50_pct_complete) { create(:status, default_done_ratio: 50, name: "50% complete") }shared_let(:status_70_pct_complete) { create(:status, default_done_ratio: 70, name: "70% complete") }@@ -72,120 +74,108 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesStatusBasendend- # Scenarios specified in https://community.openproject.org/wp/40749- describe "deriving remaining work attribute (remaining_hours)" do- context "in status-based mode",- with_settings: { work_package_done_ratio: "status" } do- context "given a work package with work, remaining work, and status with % complete being set" do- before do- work_package.status = status_50_pct_complete- work_package.done_ratio = work_package.status.default_done_ratio- work_package.estimated_hours = 10.0- work_package.remaining_hours = 5.0- work_package.send(:clear_changes_information)- end+ context "given a work package with work, remaining work, and status with % complete being set" do+ before do+ work_package.status = status_50_pct_complete+ work_package.done_ratio = work_package.status.default_done_ratio+ work_package.estimated_hours = 10.0+ work_package.remaining_hours = 5.0+ work_package.send(:clear_changes_information)+ end- context "when work is unset" do- let(:updated_attributes) { { estimated_hours: nil } }- let(:expected_attributes) { { remaining_hours: nil } }+ context "when work is unset" do+ let(:updated_attributes) { { estimated_hours: nil } }+ let(:expected_attributes) { { remaining_hours: nil } }- include_examples "update progress values", description: "unsets remaining work"- end+ include_examples "update progress values", description: "unsets remaining work"+ end- context "when work is changed" do- let(:updated_attributes) { { estimated_hours: 5.0 } }- let(:expected_attributes) { { remaining_hours: 2.5 } }+ context "when work is changed" do+ let(:updated_attributes) { { estimated_hours: 5.0 } }+ let(:expected_attributes) { { remaining_hours: 2.5 } }- include_examples "update progress values", description: "recomputes remaining work accordingly"- end+ include_examples "update progress values", description: "recomputes remaining work accordingly"+ end- context "when work is changed to a negative value" do- let(:updated_attributes) { { estimated_hours: -1.0 } }- let(:expected_kept_attributes) { %w[remaining_hours] }+ context "when work is changed to a negative value" do+ let(:updated_attributes) { { estimated_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[remaining_hours] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), and remaining work is kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), and remaining work is kept"+ end- context "when another status is set" do- let(:updated_attributes) { { status: status_70_pct_complete } }- let(:expected_attributes) { { remaining_hours: 3.0 } }+ context "when another status is set" do+ let(:updated_attributes) { { status: status_70_pct_complete } }+ let(:expected_attributes) { { remaining_hours: 3.0 } }- include_examples "update progress values",- description: "recomputes remaining work according to the % complete value of the new status"- end+ include_examples "update progress values",+ description: "recomputes remaining work according to the % complete value of the new status"+ end- context "when floating point operations are inaccurate (2.4000000000000004h)" do- let(:updated_attributes) { { estimated_hours: 8.0, status: status_70_pct_complete } }- let(:expected_attributes) { { remaining_hours: 2.4 } } # would be 2.4000000000000004 without rounding+ context "when floating point operations are inaccurate (2.4000000000000004h)" do+ let(:updated_attributes) { { estimated_hours: 8.0, status: status_70_pct_complete } }+ let(:expected_attributes) { { remaining_hours: 2.4 } } # would be 2.4000000000000004 without rounding- include_examples "update progress values", description: "remaining work is computed and rounded (2.4)"- end- end+ include_examples "update progress values", description: "remaining work is computed and rounded (2.4)"+ end+ end- context "given a work package with work and remaining work unset, and a status with 0% complete" do- before do- work_package.status = status_0_pct_complete- work_package.done_ratio = work_package.status.default_done_ratio- work_package.estimated_hours = nil- work_package.remaining_hours = nil- work_package.send(:clear_changes_information)- end+ context "given a work package with work and remaining work unset, and a status with 0% complete" do+ before do+ work_package.status = status_0_pct_complete+ work_package.done_ratio = work_package.status.default_done_ratio+ work_package.estimated_hours = nil+ work_package.remaining_hours = nil+ work_package.send(:clear_changes_information)+ end- context "when another status with another % complete value is set" do- let(:updated_attributes) { { status: status_70_pct_complete } }- let(:expected_attributes) { { remaining_hours: nil } }+ context "when another status with another % complete value is set" do+ let(:updated_attributes) { { status: status_70_pct_complete } }+ let(:expected_attributes) { { remaining_hours: nil } }- include_examples "update progress values",- description: "remaining work remains unset"- end+ include_examples "update progress values",+ description: "remaining work remains unset"+ end- context "when work is set" do- let(:updated_attributes) { { estimated_hours: 10.0 } }- let(:expected_attributes) { { remaining_hours: 10.0 } }+ context "when work is set" do+ let(:updated_attributes) { { estimated_hours: 10.0 } }+ let(:expected_attributes) { { remaining_hours: 10.0 } }- include_examples "update progress values",- description: "remaining work is updated accordingly from work and % complete value of the status"- end+ include_examples "update progress values",+ description: "remaining work is updated accordingly from work and % complete value of the status"+ end- context "when work is set to a negative value" do- let(:updated_attributes) { { estimated_hours: -1.0 } }- let(:expected_kept_attributes) { %w[remaining_hours] }+ context "when work is set to a negative value" do+ let(:updated_attributes) { { estimated_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[remaining_hours] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), and remaining work is kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), and remaining work is kept"+ end- context "when work is set with 2nd decimal rounding up" do- let(:updated_attributes) { { estimated_hours: 3.567 } }- let(:expected_attributes) { { estimated_hours: 3.57, remaining_hours: 3.57 } }+ context "when work is set with 2nd decimal rounding up" do+ let(:updated_attributes) { { estimated_hours: 3.567 } }+ let(:expected_attributes) { { estimated_hours: 3.57, remaining_hours: 3.57 } }- include_examples "update progress values",- description: "values are rounded up to 2 decimals and set to the same value"- end- end+ include_examples "update progress values",+ description: "values are rounded up to 2 decimals and set to the same value"endend- # Scenarios specified in https://community.openproject.org/wp/40749- describe "deriving % complete attribute (done_ratio)" do- context "in status-based mode",- with_settings: { work_package_done_ratio: "status" } do- context "given a work package with a status with 50% complete" do- before do- work_package.status = status_50_pct_complete- work_package.done_ratio = work_package.status.default_done_ratio- work_package.send(:clear_changes_information)- end+ context "given a work package with a status with 50% complete" do+ before do+ work_package.status = status_50_pct_complete+ work_package.done_ratio = work_package.status.default_done_ratio+ work_package.send(:clear_changes_information)+ end- context "when another status with another % complete value is set" do- let(:updated_attributes) { { status: status_70_pct_complete } }- let(:expected_attributes) { { done_ratio: 70 } }+ context "when another status with another % complete value is set" do+ let(:updated_attributes) { { status: status_70_pct_complete } }+ let(:expected_attributes) { { done_ratio: 70 } }- include_examples "update progress values",- description: "sets the % complete value to the status default % complete value"- end- end+ include_examples "update progress values",+ description: "sets the % complete value to the status default % complete value"endendenddiff --git a/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rb b/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rbindex 5c54d5d40c3..6c92c87869f 100644--- a/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rb+++ b/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rb@@ -28,8 +28,10 @@require "spec_helper"+# Scenarios specified in https://community.openproject.org/wp/40749RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBased,- type: :model do+ type: :model,+ with_settings: { work_package_done_ratio: "field" } dolet(:user) { build_stubbed(:user) }let(:project) { build_stubbed(:project) }let(:work_package) { build_stubbed(:work_package, project:) }@@ -68,429 +70,423 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedendend- # Scenarios specified in https://community.openproject.org/wp/40749- describe "deriving % complete attribute (done_ratio)" do- context "in work-based mode",- with_settings: { work_package_done_ratio: "field" } do- context "given a work package with work, remaining work, and % complete being set" do- before do- work_package.estimated_hours = 10.0- work_package.remaining_hours = 3.0- work_package.done_ratio = 70- work_package.send(:clear_changes_information)- end+ context "given a work package with work, remaining work, and % complete being set" do+ before do+ work_package.estimated_hours = 10.0+ work_package.remaining_hours = 3.0+ work_package.done_ratio = 70+ work_package.send(:clear_changes_information)+ end- context "when work is unset" do- let(:updated_attributes) { { estimated_hours: nil } }- let(:expected_attributes) { { remaining_hours: nil, done_ratio: nil } }+ context "when work is unset" do+ let(:updated_attributes) { { estimated_hours: nil } }+ let(:expected_attributes) { { remaining_hours: nil, done_ratio: nil } }- include_examples "update progress values", description: "unsets remaining work and % complete"- end+ include_examples "update progress values", description: "unsets remaining work and % complete"+ end- context "when remaining work is unset" do- let(:updated_attributes) { { remaining_hours: nil } }- let(:expected_attributes) { { estimated_hours: 10.0, done_ratio: nil } }+ context "when remaining work is unset" do+ let(:updated_attributes) { { remaining_hours: nil } }+ let(:expected_attributes) { { estimated_hours: 10.0, done_ratio: nil } }- include_examples "update progress values", description: "keeps work, and unsets % complete"- end+ include_examples "update progress values", description: "keeps work, and unsets % complete"+ end- context "when both work and remaining work are unset" do- let(:updated_attributes) { { estimated_hours: nil, remaining_hours: nil } }- let(:expected_attributes) { { done_ratio: nil } }+ context "when both work and remaining work are unset" do+ let(:updated_attributes) { { estimated_hours: nil, remaining_hours: nil } }+ let(:expected_attributes) { { done_ratio: nil } }- include_examples "update progress values", description: "unsets % complete"- end+ include_examples "update progress values", description: "unsets % complete"+ end- context "when work is increased" do- # work changed by +10h- let(:updated_attributes) { { estimated_hours: 10.0 + 10.0 } }- let(:expected_attributes) do- { remaining_hours: 3.0 + 10.0, done_ratio: 35 }- end+ context "when work is increased" do+ # work changed by +10h+ let(:updated_attributes) { { estimated_hours: 10.0 + 10.0 } }+ let(:expected_attributes) do+ { remaining_hours: 3.0 + 10.0, done_ratio: 35 }+ end- include_examples "update progress values",- description: "remaining work is increased by the same amount, and % complete is updated accordingly"- end+ include_examples "update progress values",+ description: "remaining work is increased by the same amount, and % complete is updated accordingly"+ end- context "when work is set to 0h" do- let(:updated_attributes) { { estimated_hours: 0 } }- let(:expected_attributes) do- { remaining_hours: 0, done_ratio: nil }- end+ context "when work is set to 0h" do+ let(:updated_attributes) { { estimated_hours: 0 } }+ let(:expected_attributes) do+ { remaining_hours: 0, done_ratio: nil }+ end- include_examples "update progress values",- description: "remaining work is set to 0h and % Complete is unset"- end+ include_examples "update progress values",+ description: "remaining work is set to 0h and % Complete is unset"+ end- context "when work is decreased" do- # work changed by -2h- let(:updated_attributes) { { estimated_hours: 10.0 - 2.0 } }- let(:expected_attributes) do- { remaining_hours: 3.0 - 2.0, done_ratio: 87 }- end+ context "when work is decreased" do+ # work changed by -2h+ let(:updated_attributes) { { estimated_hours: 10.0 - 2.0 } }+ let(:expected_attributes) do+ { remaining_hours: 3.0 - 2.0, done_ratio: 87 }+ end- include_examples "update progress values",- description: "remaining work is decreased by the same amount, and % complete is updated accordingly"- end+ include_examples "update progress values",+ description: "remaining work is decreased by the same amount, and % complete is updated accordingly"+ end- context "when work is decreased below remaining work value" do- # work changed by -8h- let(:updated_attributes) { { estimated_hours: 10.0 - 8.0 } }- let(:expected_attributes) do- { remaining_hours: 0, done_ratio: 100 }- end+ context "when work is decreased below remaining work value" do+ # work changed by -8h+ let(:updated_attributes) { { estimated_hours: 10.0 - 8.0 } }+ let(:expected_attributes) do+ { remaining_hours: 0, done_ratio: 100 }+ end- include_examples "update progress values",- description: "remaining work becomes 0h, and % complete becomes 100%"- end+ include_examples "update progress values",+ description: "remaining work becomes 0h, and % complete becomes 100%"+ end- context "when work is changed to a negative value" do- let(:updated_attributes) { { estimated_hours: -1.0 } }- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }+ context "when work is changed to a negative value" do+ let(:updated_attributes) { { estimated_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), " \- "and % complete and remaining work are kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), " \+ "and % complete and remaining work are kept"+ end- context "when remaining work is changed" do- let(:updated_attributes) { { remaining_hours: 2 } }- let(:expected_attributes) { { done_ratio: 80 } }- let(:expected_kept_attributes) { %w[estimated_hours] }+ context "when remaining work is changed" do+ let(:updated_attributes) { { remaining_hours: 2 } }+ let(:expected_attributes) { { done_ratio: 80 } }+ let(:expected_kept_attributes) { %w[estimated_hours] }- include_examples "update progress values", description: "updates % complete accordingly"- end+ include_examples "update progress values", description: "updates % complete accordingly"+ end- context "when work and remaining work are both changed to negative values" do- let(:updated_attributes) { { estimated_hours: -10, remaining_hours: -5 } }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when work and remaining work are both changed to negative values" do+ let(:updated_attributes) { { estimated_hours: -10, remaining_hours: -5 } }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), and % Complete is kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), and % Complete is kept"+ end- context "when work and remaining work are both changed to values with more than 2 decimals" do- let(:updated_attributes) { { estimated_hours: 10.123456, remaining_hours: 5.6789 } }- let(:expected_attributes) { { estimated_hours: 10.12, remaining_hours: 5.68, done_ratio: 43 } }+ context "when work and remaining work are both changed to values with more than 2 decimals" do+ let(:updated_attributes) { { estimated_hours: 10.123456, remaining_hours: 5.6789 } }+ let(:expected_attributes) { { estimated_hours: 10.12, remaining_hours: 5.68, done_ratio: 43 } }- include_examples "update progress values", description: "rounds work and remaining work to 2 decimals " \- "and updates % complete accordingly"- end+ include_examples "update progress values", description: "rounds work and remaining work to 2 decimals " \+ "and updates % complete accordingly"+ end- context "when remaining work is changed to a value greater than work" do- let(:updated_attributes) { { remaining_hours: 200.0 } }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when remaining work is changed to a value greater than work" do+ let(:updated_attributes) { { remaining_hours: 200.0 } }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), and % Complete is kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), and % Complete is kept"+ end- context "when remaining work is changed to a negative value" do- let(:updated_attributes) { { remaining_hours: -1.0 } }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when remaining work is changed to a negative value" do+ let(:updated_attributes) { { remaining_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), and % Complete is kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), and % Complete is kept"+ end- context "when both work and remaining work are changed" do- let(:updated_attributes) { { estimated_hours: 20, remaining_hours: 2 } }- let(:expected_attributes) { updated_attributes.merge(done_ratio: 90) }+ context "when both work and remaining work are changed" do+ let(:updated_attributes) { { estimated_hours: 20, remaining_hours: 2 } }+ let(:expected_attributes) { updated_attributes.merge(done_ratio: 90) }- include_examples "update progress values", description: "updates % complete accordingly"- end+ include_examples "update progress values", description: "updates % complete accordingly"+ end- context "when work is changed and remaining work is unset" do- let(:updated_attributes) { { estimated_hours: 8.0, remaining_hours: nil } }- let(:expected_attributes) { updated_attributes.dup }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when work is changed and remaining work is unset" do+ let(:updated_attributes) { { estimated_hours: 8.0, remaining_hours: nil } }+ let(:expected_attributes) { updated_attributes.dup }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values",- description: "% complete is kept and remaining work is kept unset and not recomputed" \- "(error state to be detected by contract)"- end+ include_examples "update progress values",+ description: "% complete is kept and remaining work is kept unset and not recomputed" \+ "(error state to be detected by contract)"+ end- context "when work is increased and remaining work is set to its current value (to prevent it from being increased)" do- # work changed by +10h- let(:updated_attributes) { { estimated_hours: 10.0 + 10.0, remaining_hours: 3 } }- let(:expected_attributes) { { remaining_hours: 3.0, done_ratio: 85 } }+ context "when work is increased and remaining work is set to its current value (to prevent it from being increased)" do+ # work changed by +10h+ let(:updated_attributes) { { estimated_hours: 10.0 + 10.0, remaining_hours: 3 } }+ let(:expected_attributes) { { remaining_hours: 3.0, done_ratio: 85 } }- include_examples "update progress values",- description: "remaining work is kept (not increased), and % complete is updated accordingly"- end- end+ include_examples "update progress values",+ description: "remaining work is kept (not increased), and % complete is updated accordingly"+ end+ end- context "given a work package with work and % complete being set, and remaining work being unset" do- before do- work_package.estimated_hours = 10- work_package.remaining_hours = nil- work_package.done_ratio = 30- work_package.send(:clear_changes_information)- end+ context "given a work package with work and % complete being set, and remaining work being unset" do+ before do+ work_package.estimated_hours = 10+ work_package.remaining_hours = nil+ work_package.done_ratio = 30+ work_package.send(:clear_changes_information)+ end- context "when work is changed" do- let(:updated_attributes) { { estimated_hours: 20.0 } }- let(:expected_attributes) { { remaining_hours: 14.0 } }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when work is changed" do+ let(:updated_attributes) { { estimated_hours: 20.0 } }+ let(:expected_attributes) { { remaining_hours: 14.0 } }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values", description: "% complete is kept and remaining work is updated accordingly"- end+ include_examples "update progress values", description: "% complete is kept and remaining work is updated accordingly"+ end- context "when work is changed to a negative value" do- let(:updated_attributes) { { estimated_hours: -1.0 } }- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }+ context "when work is changed to a negative value" do+ let(:updated_attributes) { { estimated_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), " \- "and % complete and remaining work are kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), " \+ "and % complete and remaining work are kept"+ end- context "when remaining work is set" do- let(:updated_attributes) { { remaining_hours: 1.0 } }- let(:expected_attributes) { updated_attributes.merge(done_ratio: 90.0) }- let(:expected_kept_attributes) { %w[estimated_hours] }+ context "when remaining work is set" do+ let(:updated_attributes) { { remaining_hours: 1.0 } }+ let(:expected_attributes) { updated_attributes.merge(done_ratio: 90.0) }+ let(:expected_kept_attributes) { %w[estimated_hours] }- include_examples "update progress values", description: "work is kept and % complete is updated accordingly"- end- end+ include_examples "update progress values", description: "work is kept and % complete is updated accordingly"+ end+ end- context "given a work package with remaining work and % complete being set, and work being unset" do- before do- work_package.estimated_hours = nil- work_package.remaining_hours = 2.0- work_package.done_ratio = 50- work_package.send(:clear_changes_information)- end+ context "given a work package with remaining work and % complete being set, and work being unset" do+ before do+ work_package.estimated_hours = nil+ work_package.remaining_hours = 2.0+ work_package.done_ratio = 50+ work_package.send(:clear_changes_information)+ end- context "when remaining work is changed" do- let(:updated_attributes) { { remaining_hours: 10.0 } }- let(:expected_attributes) { updated_attributes.merge(estimated_hours: 20.0) }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when remaining work is changed" do+ let(:updated_attributes) { { remaining_hours: 10.0 } }+ let(:expected_attributes) { updated_attributes.merge(estimated_hours: 20.0) }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values", description: "% complete is kept and work is updated accordingly"- end+ include_examples "update progress values", description: "% complete is kept and work is updated accordingly"+ end- context "when % complete is 0% and remaining work is changed to a decimal rounded up" do- let(:updated_attributes) { { remaining_hours: 5.679 } }- let(:expected_attributes) { { estimated_hours: 5.68, remaining_hours: 5.68 } }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when % complete is 0% and remaining work is changed to a decimal rounded up" do+ let(:updated_attributes) { { remaining_hours: 5.679 } }+ let(:expected_attributes) { { estimated_hours: 5.68, remaining_hours: 5.68 } }+ let(:expected_kept_attributes) { %w[done_ratio] }- before do- work_package.done_ratio = 0- work_package.send(:clear_changes_information)- end+ before do+ work_package.done_ratio = 0+ work_package.send(:clear_changes_information)+ end- include_examples "update progress values",- description: "% complete is kept, values are rounded, and work is updated accordingly"- end+ include_examples "update progress values",+ description: "% complete is kept, values are rounded, and work is updated accordingly"+ end- context "when work is set" do- let(:updated_attributes) { { estimated_hours: 10.0 } }- let(:expected_attributes) { updated_attributes.merge(done_ratio: 80.0) }- let(:expected_kept_attributes) { %w[remaining_hours] }+ context "when work is set" do+ let(:updated_attributes) { { estimated_hours: 10.0 } }+ let(:expected_attributes) { updated_attributes.merge(done_ratio: 80.0) }+ let(:expected_kept_attributes) { %w[remaining_hours] }- include_examples "update progress values", description: "remaining work is kept and % complete is updated accordingly"- end- end+ include_examples "update progress values", description: "remaining work is kept and % complete is updated accordingly"+ end+ end- context "given a work package with work being set, and remaining work and % complete being unset" do- before do- work_package.estimated_hours = 10- work_package.remaining_hours = nil- work_package.done_ratio = nil- work_package.send(:clear_changes_information)- end+ context "given a work package with work being set, and remaining work and % complete being unset" do+ before do+ work_package.estimated_hours = 10+ work_package.remaining_hours = nil+ work_package.done_ratio = nil+ work_package.send(:clear_changes_information)+ end- context "when work is changed" do- let(:updated_attributes) { { estimated_hours: 20.0 } }- let(:expected_attributes) { { remaining_hours: 20.0, done_ratio: 0 } }+ context "when work is changed" do+ let(:updated_attributes) { { estimated_hours: 20.0 } }+ let(:expected_attributes) { { remaining_hours: 20.0, done_ratio: 0 } }- include_examples "update progress values",- description: "remaining work is set to the same value and % complete is set to 0%"- end+ include_examples "update progress values",+ description: "remaining work is set to the same value and % complete is set to 0%"+ end- context "when work is changed and remaining work is unset" do- let(:updated_attributes) { { estimated_hours: 10.0, remaining_hours: nil } }- let(:expected_attributes) { updated_attributes.dup }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when work is changed and remaining work is unset" do+ let(:updated_attributes) { { estimated_hours: 10.0, remaining_hours: nil } }+ let(:expected_attributes) { updated_attributes.dup }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values",- description: "% complete is kept and remaining work is kept unset and not recomputed" \- "(error state to be detected by contract)"- end+ include_examples "update progress values",+ description: "% complete is kept and remaining work is kept unset and not recomputed" \+ "(error state to be detected by contract)"+ end- context "when work is changed to a negative value" do- let(:updated_attributes) { { estimated_hours: -1.0 } }- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }+ context "when work is changed to a negative value" do+ let(:updated_attributes) { { estimated_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), " \- "and % complete and remaining work are kept"- end- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), " \+ "and % complete and remaining work are kept"+ end+ end- context "given a work package with remaining work being set, and work and % complete being unset" do- before do- work_package.estimated_hours = nil- work_package.remaining_hours = 6.0- work_package.done_ratio = nil- work_package.send(:clear_changes_information)- end+ context "given a work package with remaining work being set, and work and % complete being unset" do+ before do+ work_package.estimated_hours = nil+ work_package.remaining_hours = 6.0+ work_package.done_ratio = nil+ work_package.send(:clear_changes_information)+ end- context "when work is set" do- let(:updated_attributes) { { estimated_hours: 10.0 } }- let(:expected_attributes) { { done_ratio: 40 } }- let(:expected_kept_attributes) { %w[remaining_hours] }+ context "when work is set" do+ let(:updated_attributes) { { estimated_hours: 10.0 } }+ let(:expected_attributes) { { done_ratio: 40 } }+ let(:expected_kept_attributes) { %w[remaining_hours] }- include_examples "update progress values",- description: "remaining work is kept to the same value and % complete is updated accordingly"- end+ include_examples "update progress values",+ description: "remaining work is kept to the same value and % complete is updated accordingly"+ end- context "when work is changed to a negative value" do- let(:updated_attributes) { { estimated_hours: -1.0 } }- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }+ context "when work is changed to a negative value" do+ let(:updated_attributes) { { estimated_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), " \- "and % complete and remaining work are kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), " \+ "and % complete and remaining work are kept"+ end- context "when remaining work is changed" do- let(:updated_attributes) { { remaining_hours: 12.0 } }- let(:expected_attributes) { { estimated_hours: 12.0, done_ratio: 0 } }+ context "when remaining work is changed" do+ let(:updated_attributes) { { remaining_hours: 12.0 } }+ let(:expected_attributes) { { estimated_hours: 12.0, done_ratio: 0 } }- include_examples "update progress values",- description: "work is set to the same value and % complete is set to 0%"- end+ include_examples "update progress values",+ description: "work is set to the same value and % complete is set to 0%"+ end- context "when remaining work is changed to a negative value" do- let(:updated_attributes) { { remaining_hours: -1.0 } }- let(:expected_kept_attributes) { %w[estimated_hours done_ratio] }+ context "when remaining work is changed to a negative value" do+ let(:updated_attributes) { { remaining_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[estimated_hours done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), " \- "and % complete and work are kept"- end- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), " \+ "and % complete and work are kept"+ end+ end- context "given a work package with work and remaining work unset, and % complete being set" do- before do- work_package.estimated_hours = nil- work_package.remaining_hours = nil- work_package.done_ratio = 60- work_package.send(:clear_changes_information)- end+ context "given a work package with work and remaining work unset, and % complete being set" do+ before do+ work_package.estimated_hours = nil+ work_package.remaining_hours = nil+ work_package.done_ratio = 60+ work_package.send(:clear_changes_information)+ end- context "when work is set" do- let(:updated_attributes) { { estimated_hours: 10.0 } }- let(:expected_attributes) { { remaining_hours: 4.0 } }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when work is set" do+ let(:updated_attributes) { { estimated_hours: 10.0 } }+ let(:expected_attributes) { { remaining_hours: 4.0 } }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values", description: "% complete is kept and remaining work is updated accordingly"- end+ include_examples "update progress values", description: "% complete is kept and remaining work is updated accordingly"+ end- context "when work is set to a number with with 4 decimals" do- let(:updated_attributes) { { estimated_hours: 2.5678 } }- let(:expected_attributes) { { estimated_hours: 2.57, remaining_hours: 1.03 } }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when work is set to a number with with 4 decimals" do+ let(:updated_attributes) { { estimated_hours: 2.5678 } }+ let(:expected_attributes) { { estimated_hours: 2.57, remaining_hours: 1.03 } }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values",- description: "% complete is kept, work is rounded to 2 decimals, " \- "and remaining work is updated and rounded to 2 decimals"- end+ include_examples "update progress values",+ description: "% complete is kept, work is rounded to 2 decimals, " \+ "and remaining work is updated and rounded to 2 decimals"+ end- context "when work is set to a string" do- let(:updated_attributes) { { estimated_hours: "I am a string" } }- let(:expected_attributes) { { estimated_hours: 0.0, remaining_hours: 0.0 } }+ context "when work is set to a string" do+ let(:updated_attributes) { { estimated_hours: "I am a string" } }+ let(:expected_attributes) { { estimated_hours: 0.0, remaining_hours: 0.0 } }- it "keeps the original string value in the _before_type_cast method " \- "so that validation can detect it is invalid" do- work_package.attributes = updated_attributes- instance.call+ it "keeps the original string value in the _before_type_cast method " \+ "so that validation can detect it is invalid" do+ work_package.attributes = updated_attributes+ instance.call- expect(work_package.estimated_hours_before_type_cast).to eq("I am a string")- end- end+ expect(work_package.estimated_hours_before_type_cast).to eq("I am a string")+ end+ end- context "when work and remaining work are set" do- let(:updated_attributes) { { estimated_hours: 10.0, remaining_hours: 0 } }- let(:expected_attributes) { updated_attributes.merge(done_ratio: 100) }+ context "when work and remaining work are set" do+ let(:updated_attributes) { { estimated_hours: 10.0, remaining_hours: 0 } }+ let(:expected_attributes) { updated_attributes.merge(done_ratio: 100) }- include_examples "update progress values", description: "% complete is updated accordingly"- end+ include_examples "update progress values", description: "% complete is updated accordingly"+ end- context "when work is set and remaining work is unset" do- let(:updated_attributes) { { estimated_hours: 10.0, remaining_hours: nil } }- let(:expected_attributes) { updated_attributes.dup }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when work is set and remaining work is unset" do+ let(:updated_attributes) { { estimated_hours: 10.0, remaining_hours: nil } }+ let(:expected_attributes) { updated_attributes.dup }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values",- description: "% complete is kept and remaining work is kept unset and not recomputed" \- "(error state to be detected by contract)"- end+ include_examples "update progress values",+ description: "% complete is kept and remaining work is kept unset and not recomputed" \+ "(error state to be detected by contract)"+ end- context "when work and remaining work are both set to negative values" do- let(:updated_attributes) { { estimated_hours: -10, remaining_hours: -5 } }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when work and remaining work are both set to negative values" do+ let(:updated_attributes) { { estimated_hours: -10, remaining_hours: -5 } }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), and % Complete is kept"- end- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), and % Complete is kept"+ end+ end- context "given a work package with work, remaining work, and % complete being unset" do- before do- work_package.estimated_hours = nil- work_package.remaining_hours = nil- work_package.done_ratio = nil- work_package.send(:clear_changes_information)- end+ context "given a work package with work, remaining work, and % complete being unset" do+ before do+ work_package.estimated_hours = nil+ work_package.remaining_hours = nil+ work_package.done_ratio = nil+ work_package.send(:clear_changes_information)+ end- context "when work is set" do- let(:updated_attributes) { { estimated_hours: 10.0 } }- let(:expected_attributes) do- { remaining_hours: 10.0, done_ratio: 0 }- end+ context "when work is set" do+ let(:updated_attributes) { { estimated_hours: 10.0 } }+ let(:expected_attributes) do+ { remaining_hours: 10.0, done_ratio: 0 }+ end- include_examples "update progress values",- description: "remaining work is set to the same value and % complete is set to 0%"- end+ include_examples "update progress values",+ description: "remaining work is set to the same value and % complete is set to 0%"+ end- context "when work is set to a negative value" do- let(:updated_attributes) { { estimated_hours: -1.0 } }- let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }+ context "when work is set to a negative value" do+ let(:updated_attributes) { { estimated_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), " \- "and % complete and remaining work are kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), " \+ "and % complete and remaining work are kept"+ end- context "when remaining work is set" do- let(:updated_attributes) { { remaining_hours: 10.0 } }- let(:expected_attributes) { { estimated_hours: 10.0, done_ratio: 0 } }+ context "when remaining work is set" do+ let(:updated_attributes) { { remaining_hours: 10.0 } }+ let(:expected_attributes) { { estimated_hours: 10.0, done_ratio: 0 } }- include_examples "update progress values", description: "work is set to the same value and % complete is set to 0%"- end+ include_examples "update progress values", description: "work is set to the same value and % complete is set to 0%"+ end- context "when remaining work is set to a negative value" do- let(:updated_attributes) { { remaining_hours: -1.0 } }- let(:expected_kept_attributes) { %w[estimated_hours done_ratio] }+ context "when remaining work is set to a negative value" do+ let(:updated_attributes) { { remaining_hours: -1.0 } }+ let(:expected_kept_attributes) { %w[estimated_hours done_ratio] }- include_examples "update progress values",- description: "is an error state (to be detected by contract), " \- "and % complete and work are kept"- end+ include_examples "update progress values",+ description: "is an error state (to be detected by contract), " \+ "and % complete and work are kept"+ end- context "when remaining work is set and work is unset" do- let(:updated_attributes) { { estimated_hours: nil, remaining_hours: 6.7 } }- let(:expected_attributes) { updated_attributes.dup }- let(:expected_kept_attributes) { %w[done_ratio] }+ context "when remaining work is set and work is unset" do+ let(:updated_attributes) { { estimated_hours: nil, remaining_hours: 6.7 } }+ let(:expected_attributes) { updated_attributes.dup }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values",- description: "% complete is kept and work is kept unset and not recomputed" \- "(error state to be detected by contract)"- end- end+ include_examples "update progress values",+ description: "% complete is kept and work is kept unset and not recomputed" \+ "(error state to be detected by contract)"endendend