Skip to content

Commit

Permalink
Add specs for required project custom fields not bleeding through to …
Browse files Browse the repository at this point in the history
…other member projects without permission.
  • Loading branch information
dombesz committed Jul 31, 2024
1 parent c82e4ea commit fbbdc75
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
11 changes: 8 additions & 3 deletions spec/models/projects/customizable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@
.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" 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
Expand All @@ -93,6 +94,10 @@
end
end

let!(:required_cf) do
create(:string_project_custom_field, is_required: true)
end

let(:user) do
create(:user, member_with_permissions: {
project => [],
Expand All @@ -105,7 +110,7 @@
.to be_empty

expect(other_project.available_custom_fields)
.to contain_exactly(project_cf)
.to contain_exactly(project_cf, required_cf)
end
end
end
Expand Down
39 changes: 32 additions & 7 deletions spec/requests/api/v3/projects/index_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
end

let(: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]
end

let(:filters) do
Expand Down Expand Up @@ -427,7 +428,11 @@
create(:project_custom_field_project_mapping, project: public_wp_share_project)
.project_custom_field
end
let(:current_user) do
shared_let(:required_cf) do
create(:string_project_custom_field, is_required: true)
end

shared_let(:current_user) do
create(:user, member_with_permissions: {
project => [],
other_project => %i(view_project_attributes),
Expand Down Expand Up @@ -461,7 +466,8 @@
)
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" do
expect(subject)
.to be_json_eql(public_project.name.to_json)
.at_path("_embedded/elements/2/name")
Expand All @@ -471,8 +477,8 @@
)
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" do
expect(subject)
.to be_json_eql(project.name.to_json)
.at_path("_embedded/elements/3/name")
Expand All @@ -482,8 +488,8 @@
)
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" do
expect(subject)
.to be_json_eql(other_project.name.to_json)
.at_path("_embedded/elements/4/name")
Expand All @@ -492,6 +498,25 @@
"_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)}"
)
end
end
end
end
Expand Down

0 comments on commit fbbdc75

Please sign in to comment.