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
Add specs for required project custom fields not bleeding through to other member projects without permission.
Dombi Attilafbbdc7587ed8
diff --git a/spec/models/projects/customizable_spec.rb b/spec/models/projects/customizable_spec.rbindex 15f70332189..d3e0f76beff 100644--- a/spec/models/projects/customizable_spec.rb+++ b/spec/models/projects/customizable_spec.rb@@ -80,8 +80,9 @@ RSpec.describe Project, "customizable" do.to contain_exactly(bool_custom_field)end- context "when the same custom field is activated in multiple projects a user is member of " \- "and they only have view_project_attributes permission in one of the project" do+ context "with a custom field activated in different projects " \+ "and the user has view_project_attributes permission in one of the project " \+ "and with a required custom field" dolet(:other_project) { create(:project) }let!(:project_cf) do# This custom field is enabled in both project and other_project to test that there is no@@ -93,6 +94,10 @@ RSpec.describe Project, "customizable" doendend+ let!(:required_cf) do+ create(:string_project_custom_field, is_required: true)+ end+let(:user) docreate(:user, member_with_permissions: {project => [],@@ -105,7 +110,7 @@ RSpec.describe Project, "customizable" do.to be_emptyexpect(other_project.available_custom_fields)- .to contain_exactly(project_cf)+ .to contain_exactly(project_cf, required_cf)endendenddiff --git a/spec/requests/api/v3/projects/index_resource_spec.rb b/spec/requests/api/v3/projects/index_resource_spec.rbindex 6f14b88f43b..328d4e6d155 100644--- a/spec/requests/api/v3/projects/index_resource_spec.rb+++ b/spec/requests/api/v3/projects/index_resource_spec.rb@@ -148,7 +148,8 @@ RSpec.describe "API v3 Project resource index", content_type: :json doendlet(:valid_values) do- [project_custom_field_mapping1.custom_field_id.to_s, project_custom_field_mapping2.custom_field_id.to_s]+ [project_custom_field_mapping1.custom_field_id.to_s,+ project_custom_field_mapping2.custom_field_id.to_s]endlet(:filters) do@@ -427,7 +428,11 @@ RSpec.describe "API v3 Project resource index", content_type: :json docreate(:project_custom_field_project_mapping, project: public_wp_share_project).project_custom_fieldend- let(:current_user) do+ shared_let(:required_cf) do+ create(:string_project_custom_field, is_required: true)+ end++ shared_let(:current_user) docreate(:user, member_with_permissions: {project => [],other_project => %i(view_project_attributes),@@ -461,7 +466,8 @@ RSpec.describe "API v3 Project resource index", content_type: :json do)end- it "does not return the project attributes for a public project without view_project_attributes" do+ it "does not return the project attributes for a public project" \+ "as a member without view_project_attributes" doexpect(subject).to be_json_eql(public_project.name.to_json).at_path("_embedded/elements/2/name")@@ -471,8 +477,8 @@ RSpec.describe "API v3 Project resource index", content_type: :json do)end- it "does not return the project attributes for a private project without view_project_attributes " \- "even if the same custom field is active in other_project" do+ it "does not return the project attributes for a private project as a member without " \+ "view_project_attributes even if the same custom field is active in other_project" doexpect(subject).to be_json_eql(project.name.to_json).at_path("_embedded/elements/3/name")@@ -482,8 +488,8 @@ RSpec.describe "API v3 Project resource index", content_type: :json do)end- it "returns project attributes for other project with view_project_attributes for the same " \- "custom field enabled in the project too" do+ it "returns project attributes for other project as a member with view_project_attributes " \+ "for the same custom field enabled in a non-member project too" doexpect(subject).to be_json_eql(other_project.name.to_json).at_path("_embedded/elements/4/name")@@ -492,6 +498,25 @@ RSpec.describe "API v3 Project resource index", content_type: :json do"_embedded/elements/4/#{project_cf.attribute_name(:camel_case)}")end++ it "returns the required_cf only for the other_project as a member " \+ "with view_project_attributes" do+ expect(subject).not_to have_json_path(+ "_embedded/elements/0/#{required_cf.attribute_name(:camel_case)}"+ )+ expect(subject).not_to have_json_path(+ "_embedded/elements/1/#{required_cf.attribute_name(:camel_case)}"+ )+ expect(subject).not_to have_json_path(+ "_embedded/elements/2/#{required_cf.attribute_name(:camel_case)}"+ )+ expect(subject).not_to have_json_path(+ "_embedded/elements/3/#{required_cf.attribute_name(:camel_case)}"+ )+ expect(subject).to have_json_path(+ "_embedded/elements/4/#{required_cf.attribute_name(:camel_case)}"+ )+ endendendend