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 default contract contexts
ulferts28deaaa9d9a6
diff --git a/spec/contracts/projects/create_contract_spec.rb b/spec/contracts/projects/create_contract_spec.rbindex fb96b3251b6..29a09192b78 100644--- a/spec/contracts/projects/create_contract_spec.rb+++ b/spec/contracts/projects/create_contract_spec.rb@@ -53,9 +53,7 @@ RSpec.describe Projects::CreateContract docontext "if the identifier is nil" dolet(:project_identifier) { nil }- it "is replaced for new project" do- expect_valid(true)- end+ it_behaves_like "contract is valid"enddescribe "permissions" dodiff --git a/spec/contracts/projects/shared_contract_examples.rb b/spec/contracts/projects/shared_contract_examples.rbindex 79bf902a03f..36055f4cd81 100644--- a/spec/contracts/projects/shared_contract_examples.rb+++ b/spec/contracts/projects/shared_contract_examples.rb@@ -29,8 +29,11 @@#++require "spec_helper"+require "contracts/shared/model_contract_shared_context"RSpec.shared_examples_for "project contract" do+ include_context "ModelContract shared context"+let(:current_user) { build_stubbed(:user) }before do@@ -89,68 +92,48 @@ RSpec.shared_examples_for "project contract" doassignable_parentsend- def expect_valid(valid, symbols = {})- expect(contract.validate).to eq(valid)-- symbols.each do |key, arr|- expect(contract.errors.symbols_for(key)).to match_array arr- end- end-- shared_examples "is valid" do- it "is valid" do- expect_valid(true)- end- end-- it_behaves_like "is valid"+ it_behaves_like "contract is valid"context "if the name is nil" dolet(:project_name) { nil }- it "is invalid" do- expect_valid(false, name: %i(blank))- end+ it_behaves_like "contract is invalid", name: %i(blank)endcontext "if the description is nil" dolet(:project_description) { nil }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "if the parent is nil" dolet(:project_parent) { nil }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "if the parent is not in the set of assignable_parents" dolet(:parent_assignable) { false }- it "is invalid" do- expect_valid(false, parent: %i(does_not_exist))- end+ it_behaves_like "contract is invalid", parent: %i(does_not_exist)endcontext "if active is nil" dolet(:project_active) { nil }- it "is invalid" do- expect_valid(false, active: %i(blank))- end+ it_behaves_like "contract is invalid", active: %i(blank)endcontext "if status code is nil" dolet(:project_status_code) { nil }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "if status explanation is nil" dolet(:project_status_explanation) { nil }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "if status code is invalid" do@@ -166,70 +149,62 @@ RSpec.shared_examples_for "project contract" docode_attributes.instance_variable_set(:@value, bogus_project_status_code)end- it "is invalid" do- expect_valid(false, status: %i(inclusion))- end+ it_behaves_like "contract is invalid", status: %i(inclusion)endcontext "when the identifier consists of only letters" dolet(:project_identifier) { "abc" }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "when the identifier consists of letters followed by numbers" dolet(:project_identifier) { "abc12" }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "when the identifier consists of letters followed by numbers with a hyphen in between" dolet(:project_identifier) { "abc-12" }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "when the identifier consists of letters followed by numbers with an underscore in between" dolet(:project_identifier) { "abc_12" }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "when the identifier consists of numbers followed by letters with a hyphen in between" dolet(:project_identifier) { "12-abc" }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "when the identifier consists of numbers followed by letters with an underscore in between" dolet(:project_identifier) { "12_abc" }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "when the identifier consists of only numbers" dolet(:project_identifier) { "12" }- it "is invalid" do- expect_valid(false, identifier: %i(invalid))- end+ it_behaves_like "contract is invalid", identifier: %i(invalid)endcontext "when the identifier consists of a reserved word" dolet(:project_identifier) { "new" }- it "is invalid" do- expect_valid(false, identifier: %i(exclusion))- end+ it_behaves_like "contract is invalid", identifier: %i(exclusion)endcontext "if the user lacks permission" dolet(:global_permissions) { [] }let(:project_permissions) { [] }- it "is invalid" do- expect_valid(false, base: %i(error_unauthorized))- end+ it_behaves_like "contract is invalid", base: %i(error_unauthorized)enddescribe "assignable_values" dodiff --git a/spec/contracts/projects/update_contract_spec.rb b/spec/contracts/projects/update_contract_spec.rbindex e61a8921c8b..31e36a4743a 100644--- a/spec/contracts/projects/update_contract_spec.rb+++ b/spec/contracts/projects/update_contract_spec.rb@@ -66,9 +66,7 @@ RSpec.describe Projects::UpdateContract docontext "if the identifier is nil" dolet(:project_identifier) { nil }- it "is replaced for new project" do- expect_valid(false, identifier: %i(blank))- end+ it_behaves_like "contract is invalid", identifier: %i(blank)enddescribe "permissions" do@@ -85,26 +83,23 @@ RSpec.describe Projects::UpdateContract docontext "and only project_custom_fields are changed" dolet(:project_changed) { false }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "and other project attributes are changed too" dolet(:project_changed) { true }- it "is invalid" do- expect_valid(false, { name: %i(error_readonly),- parent_id: %i(error_readonly),- identifier: %i(error_readonly) })- end+ it_behaves_like "contract is invalid",+ name: %i(error_readonly),+ parent_id: %i(error_readonly),+ identifier: %i(error_readonly)endendcontext "when project_attributes_only flag is false" dolet(:options) { { project_attributes_only: false } }- it "is invalid" do- expect_valid(false, base: %i(error_unauthorized))- end+ it_behaves_like "contract is invalid", name: %i(error_readonly)endend@@ -112,9 +107,7 @@ RSpec.describe Projects::UpdateContract docontext "when project_attributes_only flag is true" dolet(:options) { { project_attributes_only: true } }- it "is invalid" do- expect_valid(false, base: %i(error_unauthorized))- end+ it_behaves_like "contract user is unauthorized"endcontext "when project_attributes_only flag is false" do@@ -123,7 +116,7 @@ RSpec.describe Projects::UpdateContract docontext "and only project attributes are changed" dolet(:project_changed) { true }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "and project_custom_fields are changed too" do@@ -134,7 +127,7 @@ RSpec.describe Projects::UpdateContract doendit "is invalid" do- expect_valid(false, "custom_field_#{custom_field.id}": %i(error_readonly))+ expect_contract_invalid("custom_field_#{custom_field.id}": %i(error_readonly))endendend@@ -149,11 +142,10 @@ RSpec.describe Projects::UpdateContract docontext "and only project attributes are changed" dolet(:project_changed) { true }- it "is invalid" do- expect_valid(false, { name: %i(error_readonly),- parent_id: %i(error_readonly),- identifier: %i(error_readonly) })- end+ it_behaves_like "contract is invalid",+ name: %i(error_readonly),+ parent_id: %i(error_readonly),+ identifier: %i(error_readonly)endcontext "and only project_custom_fields are changed" do@@ -163,7 +155,7 @@ RSpec.describe Projects::UpdateContract doproject.custom_field_values = { custom_field.id => "1" }end- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "when both project attributes and project custom_fields are changed" do@@ -173,11 +165,10 @@ RSpec.describe Projects::UpdateContract doproject.custom_field_values = { custom_field.id => "1" }end- it "is invalid" do- expect_valid(false, { name: %i(error_readonly),- parent_id: %i(error_readonly),- identifier: %i(error_readonly) })- end+ it_behaves_like "contract is invalid",+ name: %i(error_readonly),+ parent_id: %i(error_readonly),+ identifier: %i(error_readonly)endend@@ -187,7 +178,7 @@ RSpec.describe Projects::UpdateContract docontext "and only project attributes are changed" dolet(:project_changed) { true }- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endcontext "and project_custom_fields are changed too" do@@ -197,7 +188,7 @@ RSpec.describe Projects::UpdateContract doproject.custom_field_values = { custom_field.id => "1" }end- it_behaves_like "is valid"+ it_behaves_like "contract is valid"endendend@@ -206,9 +197,7 @@ RSpec.describe Projects::UpdateContract dolet(:project_permissions) { [] }let(:options) { { project_attributes_only: true } }- it "is invalid" do- expect_valid(false, base: %i(error_unauthorized))- end+ it_behaves_like "contract user is unauthorized"endend