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

[#36559] add more test cases to custom_field_select_spec

Tobias Dillmannb9c3700069b8
diff --git a/spec/models/queries/work_packages/selects/custom_field_select_spec.rb b/spec/models/queries/work_packages/selects/custom_field_select_spec.rb
index 004001de025..a39c433468f 100644
--- a/spec/models/queries/work_packages/selects/custom_field_select_spec.rb
+++ b/spec/models/queries/work_packages/selects/custom_field_select_spec.rb
@@ -46,12 +46,6 @@ RSpec.describe Queries::WorkPackages::Selects::CustomFieldSelect do
current_user { user }
- before do
- allow(wp_relation).to receive(:visible_by_user)
- .with(user)
- .and_return([text_custom_field, list_custom_field])
- end
-
context "within project" do
before do
allow(project)
@@ -59,12 +53,32 @@ RSpec.describe Queries::WorkPackages::Selects::CustomFieldSelect do
.and_return(wp_relation)
end
- it "contains only non text cf columns" do
- expect(described_class.instances(project).length)
- .to eq 1
+ context "with a user that can see the custom field" do
+ before do
+ allow(wp_relation).to receive(:visible_by_user)
+ .with(user)
+ .and_return([text_custom_field, list_custom_field])
+ end
+
+ it "contains only non text cf columns" do
+ expect(described_class.instances(project).length)
+ .to eq 1
+
+ expect(described_class.instances(project)[0].custom_field)
+ .to eq list_custom_field
+ end
+ end
+
+ context "with a user that cannot see custom fields" do
+ before do
+ allow(wp_relation).to receive(:visible_by_user)
+ .with(user)
+ .and_return([])
+ end
- expect(described_class.instances(project)[0].custom_field)
- .to eq list_custom_field
+ it "is empty" do
+ expect(described_class.instances).to be_empty
+ end
end
end
@@ -75,12 +89,32 @@ RSpec.describe Queries::WorkPackages::Selects::CustomFieldSelect do
.and_return(wp_relation)
end
- it "contains only non text cf columns" do
- expect(described_class.instances.length)
- .to eq 1
+ context "with a user that can see the custom field" do
+ before do
+ allow(wp_relation).to receive(:visible_by_user)
+ .with(user)
+ .and_return([text_custom_field, list_custom_field])
+ end
+
+ it "contains only non text cf columns" do
+ expect(described_class.instances.length)
+ .to eq 1
+
+ expect(described_class.instances[0].custom_field)
+ .to eq list_custom_field
+ end
+ end
+
+ context "with a user that cannot see custom fields" do
+ before do
+ allow(wp_relation).to receive(:visible_by_user)
+ .with(user)
+ .and_return([])
+ end
- expect(described_class.instances[0].custom_field)
- .to eq list_custom_field
+ it "is empty" do
+ expect(described_class.instances).to be_empty
+ end
end
end
end