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
[#36559] fix query_spec
Tobias Dillmann0384156eac22
diff --git a/spec/models/query_spec.rb b/spec/models/query_spec.rbindex 4204eaad9ce..f5b844e390f 100644--- a/spec/models/query_spec.rb+++ b/spec/models/query_spec.rb@@ -34,6 +34,8 @@ RSpec.describe Query,with_ee: %i[baseline_comparison conditional_highlighting work_package_query_relation_columns] dolet(:query) { build(:query) }let(:project) { create(:project) }+ let(:user_cf) { create(:user, member_with_permissions: { project => [:select_custom_fields] }) }+ let(:user_restricted) { create(:user) }describe ".new_default" doit "set the default sortation" do@@ -325,7 +327,7 @@ RSpec.describe Query,expect(query.displayable_columns.map(&:name)).to include :done_ratioend- context "results caching" do+ context "with results caching" dolet(:project2) { create(:project) }it "does not call the db twice" do@@ -349,13 +351,9 @@ RSpec.describe Query,query.project = project2- expect(project2)- .to receive(:all_work_package_custom_fields)- .and_return []-- expect(project2)- .to receive(:types)- .and_return []+ allow(project2)+ .to receive_messages(all_work_package_custom_fields: WorkPackageCustomField.none,+ types: Type.none)query.displayable_columnsend@@ -367,19 +365,24 @@ RSpec.describe Query,query.project = nil- expect(WorkPackageCustomField)+ empty_wp_relation = double(visible_by_user: []) # rubocop:disable RSpec/VerifiedDoubles+ # We cannot simply return `WorkPackageCustomField.none` here, as that aliases to `all` and would trigger+ # its own expectation again. Hence, we must set up a double.+ allow(WorkPackageCustomField).to receive(:all)- .and_return []+ .and_return empty_wp_relation- expect(Type)+ allow(Type).to receive(:all).and_return []query.displayable_columns++ expect(WorkPackageCustomField).to have_received(:all).onceendend- context "relation_to_type columns" do+ context "with relation_to_type columns" dolet(:type_in_project) dotype = create(:type)project.types << type@@ -484,6 +487,8 @@ RSpec.describe Query,endcontext "with the enterprise token allowing relation columns" do+ current_user { user_cf }+it "has all static columns, cf columns and relation columns" doexpected_columns = %i(id project assigned_to authorcategory created_at due_date estimated_hours@@ -496,9 +501,25 @@ RSpec.describe Query,expect(described_class.available_columns.map(&:name)).to include *expected_columnsend++ context "when the user does not have the necessary custom field permissions" do+ current_user { user_restricted }++ it "does not list custom field columns" do+ columns = described_class.available_columns.map(&:name)++ # We do not really care about column details here, but let's see if we have some amount of them:+ expect(columns.count).to be > 5++ # This is the important assertion:+ expect(columns).not_to include custom_field.column_name.to_sym+ end+ endendcontext "with the enterprise token disallowing relation columns", with_ee: false do+ current_user { user_cf }+it "has all static columns, cf columns but no relation columns" doexpected_columns = %i(id project assigned_to authorcategory created_at due_date estimated_hours@@ -569,13 +590,9 @@ RSpec.describe Query,context "with filters" dobefore do- allow(Status)- .to receive(:all)- .and_return([valid_status])allow(Status)- .to receive(:exists?)- .and_return(true)+ .to receive_messages(all: [valid_status], exists?: true)query.filters.clearquery.add_filter("status_id", "=", values)