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 to the project customizable specs to ensure enabled custom fields are accessible only for the project they are enabled in.
Dombi Attilaf47fd4ff6806
diff --git a/spec/models/projects/customizable_spec.rb b/spec/models/projects/customizable_spec.rbindex b49e91ea23b..15f70332189 100644--- a/spec/models/projects/customizable_spec.rb+++ b/spec/models/projects/customizable_spec.rb@@ -39,9 +39,10 @@ RSpec.describe Project, "customizable" dolet!(:list_custom_field) docreate(:list_project_custom_field, project_custom_field_section: section)end+ let(:user) { build_stubbed(:admin) }before do- allow(User).to receive(:current).and_return build_stubbed(:admin)+ allow(User).to receive(:current).and_return userendcontext "when not persisted" do@@ -78,6 +79,35 @@ RSpec.describe Project, "customizable" doexpect(project.available_custom_fields).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+ let(: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+ # bleeding of enabled custom fields between 2 projects.+ create(:project_custom_field_project_mapping, project:).project_custom_field.tap do |pcf|+ create(:project_custom_field_project_mapping,+ project: other_project,+ project_custom_field: pcf)+ end+ end++ let(:user) do+ create(:user, member_with_permissions: {+ project => [],+ other_project => %i(view_project_attributes)+ })+ end++ it "returns available_custom_fields only for the other_project" do+ expect(project.available_custom_fields)+ .to be_empty++ expect(other_project.available_custom_fields)+ .to contain_exactly(project_cf)+ end+ endenddescribe "#custom_field_values and #custom_value_for" dodiff --git a/spec/requests/api/v3/projects/index_resource_spec.rb b/spec/requests/api/v3/projects/index_resource_spec.rbindex 78e71fb5f6b..6f14b88f43b 100644--- a/spec/requests/api/v3/projects/index_resource_spec.rb+++ b/spec/requests/api/v3/projects/index_resource_spec.rb@@ -410,11 +410,11 @@ RSpec.describe "API v3 Project resource index", content_type: :json doshared_let(:project_cf) do# This custom field is enabled in both project and other_project to test that there is no# bleeding of enabled custom fields between 2 projects.- pcf = create(:project_custom_field_project_mapping, project:).project_custom_field- create(:project_custom_field_project_mapping,- project: other_project,- project_custom_field: pcf)- pcf+ create(:project_custom_field_project_mapping, project:).project_custom_field.tap do |pcf|+ create(:project_custom_field_project_mapping,+ project: other_project,+ project_custom_field: pcf)+ endendshared_let(:public_cf) docreate(:project_custom_field_project_mapping, project: public_project).project_custom_field