Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Rearrange ProjectLifeCycleStep::UpdateContracts specs.

Dombi Attila16418a08432b
diff --git a/spec/contracts/project_life_cycle_steps/update_contract_spec.rb b/spec/contracts/project_life_cycle_steps/update_contract_spec.rb
index b618dcbc9fc..e7a81838aac 100644
--- a/spec/contracts/project_life_cycle_steps/update_contract_spec.rb
+++ b/spec/contracts/project_life_cycle_steps/update_contract_spec.rb
@@ -49,156 +49,158 @@ RSpec.describe ProjectLifeCycleSteps::UpdateContract do
end
end
- it_behaves_like "contract is valid"
- it_behaves_like "contract reuses the model errors"
+ describe "contract validations" do
+ it_behaves_like "contract is valid"
+ it_behaves_like "contract reuses the model errors"
- context "when phase is invalid" do
- let(:phase) do
- build_stubbed(:project_phase, start_date: date + 1, finish_date: date - 1)
- end
-
- it_behaves_like "contract is invalid", start_date: :must_be_before_finish_date
- end
+ context "with an invalid start date" do
+ let(:phase) do
+ build_stubbed(:project_phase, start_date: date + 1, finish_date: date - 1)
+ end
- context "when trying to change extra attributes" do
- before do
- phase.duration = 42
+ it_behaves_like "contract is invalid", start_date: :must_be_before_finish_date
end
- it_behaves_like "contract is invalid", duration: :error_readonly
- end
-
- describe "#validate_start_after_preceeding_phases" do
- def create_phase(**) = create(:project_phase, project:, **)
-
- let(:project) { create(:project) }
- let(:phases) { [preceding, phase, following] }
- let(:phase) { create_phase(date_range:, active:) }
- let(:preceding) { create_phase(date_range: preceding_date_range) }
- let(:following) { create_phase(date_range: following_date_range) }
- let(:active) { true }
- let(:date_range) { date - 1..date + 1 }
- let(:preceding_date_range) { date - 6..date - 5 }
- let(:following_date_range) { date + 5..date + 6 }
-
- before do
- allow(project).to receive(:available_phases).and_return(phases)
- end
+ context "when trying to change extra attributes" do
+ before do
+ phase.duration = 42
+ end
- context "with successive non overlapping dates" do
- it_behaves_like "contract is valid"
+ it_behaves_like "contract is invalid", duration: :error_readonly
end
- context "without dates" do
- let(:date_range) { nil }
+ context "when the phase has preceeding phases" do
+ def create_phase(**) = create(:project_phase, project:, **)
- it_behaves_like "contract is valid"
- end
+ let(:project) { create(:project) }
+ let(:phases) { [preceding, phase, following] }
+ let(:phase) { create_phase(date_range:, active:) }
+ let(:preceding) { create_phase(date_range: preceding_date_range) }
+ let(:following) { create_phase(date_range: following_date_range) }
+ let(:active) { true }
+ let(:date_range) { date - 1..date + 1 }
+ let(:preceding_date_range) { date - 6..date - 5 }
+ let(:following_date_range) { date + 5..date + 6 }
- context "with preceding phase overlapping with start" do
- let(:preceding_date_range) { date - 6..date - 1 }
+ before do
+ allow(project).to receive(:available_phases).and_return(phases)
+ end
- it_behaves_like "contract is invalid", start_date: :non_continuous_dates
+ context "with successive non overlapping dates" do
+ it_behaves_like "contract is valid"
+ end
- context "when inactive" do
- let(:active) { false }
+ context "without dates" do
+ let(:date_range) { nil }
it_behaves_like "contract is valid"
end
- end
- context "with preceding phase following this" do
- let(:preceding_date_range) { date + 2..date + 4 }
+ context "with preceding phase overlapping with start" do
+ let(:preceding_date_range) { date - 6..date - 1 }
- it_behaves_like "contract is invalid", start_date: :non_continuous_dates
+ it_behaves_like "contract is invalid", start_date: :non_continuous_dates
- context "when inactive" do
- let(:active) { false }
+ context "when inactive" do
+ let(:active) { false }
- it_behaves_like "contract is valid"
+ it_behaves_like "contract is valid"
+ end
end
- end
- context "with preceding phase without dates" do
- let(:preceding_date_range) { nil }
+ context "with preceding phase following this" do
+ let(:preceding_date_range) { date + 2..date + 4 }
- it_behaves_like "contract is valid"
- end
+ it_behaves_like "contract is invalid", start_date: :non_continuous_dates
- context "with following phase overlapping with start" do
- let(:following_date_range) { date - 1..date + 6 }
+ context "when inactive" do
+ let(:active) { false }
- it_behaves_like "contract is valid"
- end
+ it_behaves_like "contract is valid"
+ end
+ end
- context "with following phase preceding this" do
- let(:following_date_range) { date - 4..date - 2 }
+ context "with preceding phase without dates" do
+ let(:preceding_date_range) { nil }
- it_behaves_like "contract is valid"
- end
- end
+ it_behaves_like "contract is valid"
+ end
- describe "#validate_dates_must_be_on_working_days" do
- let(:non_working_day) { Date.current }
- let(:phase) do
- build_stubbed(:project_phase, start_date:, finish_date:)
- end
+ context "with following phase overlapping with start" do
+ let(:following_date_range) { date - 1..date + 6 }
- before do
- set_non_working_days(non_working_day)
- end
+ it_behaves_like "contract is valid"
+ end
- context "when the start date is a non working day" do
- let(:start_date) { non_working_day }
- let(:finish_date) { non_working_day + 1.day }
+ context "with following phase preceding this" do
+ let(:following_date_range) { date - 4..date - 2 }
- it_behaves_like "contract is invalid", start_date: :cannot_be_a_non_working_day
+ it_behaves_like "contract is valid"
+ end
+ end
- context "and the finish date is nil" do
- let(:finish_date) { nil }
+ context "with non working days present" do
+ let(:non_working_day) { Date.current }
+ let(:phase) do
+ build_stubbed(:project_phase, start_date:, finish_date:)
+ end
- it_behaves_like "contract is invalid", start_date: :cannot_be_a_non_working_day
+ before do
+ set_non_working_days(non_working_day)
end
- end
- context "when the finish date is a non working day" do
- let(:start_date) { non_working_day - 1.day }
- let(:finish_date) { non_working_day }
+ context "when the start date is a non working day" do
+ let(:start_date) { non_working_day }
+ let(:finish_date) { non_working_day + 1.day }
- it_behaves_like "contract is invalid", finish_date: :cannot_be_a_non_working_day
+ it_behaves_like "contract is invalid", start_date: :cannot_be_a_non_working_day
- context "and the start date is nil" do
- let(:start_date) { nil }
+ context "and the finish date is nil" do
+ let(:finish_date) { nil }
- it_behaves_like "contract is invalid", finish_date: :cannot_be_a_non_working_day
+ it_behaves_like "contract is invalid", start_date: :cannot_be_a_non_working_day
+ end
end
- end
- context "when both dates are on non working day" do
- let(:start_date) { non_working_day }
- let(:finish_date) { non_working_day }
+ context "when the finish date is a non working day" do
+ let(:start_date) { non_working_day - 1.day }
+ let(:finish_date) { non_working_day }
- it_behaves_like "contract is invalid",
- start_date: :cannot_be_a_non_working_day,
- finish_date: :cannot_be_a_non_working_day
- end
+ it_behaves_like "contract is invalid", finish_date: :cannot_be_a_non_working_day
- context "when both dates are on a working day" do
- let(:start_date) { non_working_day - 1.day }
- let(:finish_date) { non_working_day + 1 }
+ context "and the start date is nil" do
+ let(:start_date) { nil }
- it_behaves_like "contract is valid"
+ it_behaves_like "contract is invalid", finish_date: :cannot_be_a_non_working_day
+ end
+ end
- context "and the start date is nil" do
- let(:start_date) { nil }
+ context "when both dates are on non working day" do
+ let(:start_date) { non_working_day }
+ let(:finish_date) { non_working_day }
- it_behaves_like "contract is valid"
+ it_behaves_like "contract is invalid",
+ start_date: :cannot_be_a_non_working_day,
+ finish_date: :cannot_be_a_non_working_day
end
- context "and the finish date is nil" do
- let(:finish_date) { nil }
+ context "when both dates are on a working day" do
+ let(:start_date) { non_working_day - 1.day }
+ let(:finish_date) { non_working_day + 1 }
it_behaves_like "contract is valid"
+
+ context "and the start date is nil" do
+ let(:start_date) { nil }
+
+ it_behaves_like "contract is valid"
+ end
+
+ context "and the finish date is nil" do
+ let(:finish_date) { nil }
+
+ it_behaves_like "contract is valid"
+ end
end
end
end