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
prevent access to another user`s queries
ulferts793d240606c0
diff --git a/app/controllers/projects/menus_controller.rb b/app/controllers/projects/menus_controller.rbindex e80b17129be..4e9aaf66f0b 100644--- a/app/controllers/projects/menus_controller.rb+++ b/app/controllers/projects/menus_controller.rb@@ -51,16 +51,21 @@ module Projectsdef static_filters[query_menu_item(::Queries::Projects::Factory.static_query_active, selected: no_query_props_or_all?),- query_menu_item(::Queries::Projects::Factory.static_query_my, id: 'my'),- query_menu_item(::Queries::Projects::Factory.static_query_archived, id: 'archived')+ query_menu_item(::Queries::Projects::Factory.static_query_my,+ id: ::Queries::Projects::Factory::STATIC_MY),+ query_menu_item(::Queries::Projects::Factory.static_query_archived,+ id: ::Queries::Projects::Factory::STATIC_ARCHIVED)]enddef static_status_filters[- query_menu_item(::Queries::Projects::Factory.static_query_status_on_track, id: 'on_track'),- query_menu_item(::Queries::Projects::Factory.static_query_status_off_track, id: 'off_track'),- query_menu_item(::Queries::Projects::Factory.static_query_status_at_risk, id: 'at_risk')+ query_menu_item(::Queries::Projects::Factory.static_query_status_on_track,+ id: ::Queries::Projects::Factory::STATIC_ON_TRACK),+ query_menu_item(::Queries::Projects::Factory.static_query_status_off_track,+ id: ::Queries::Projects::Factory::STATIC_OFF_TRACK),+ query_menu_item(::Queries::Projects::Factory.static_query_status_at_risk,+ id: ::Queries::Projects::Factory::STATIC_AT_RISK)]end@@ -90,8 +95,7 @@ module Projectsenddef no_query_props_or_all?- (params[:query_id].nil? && params[:filters].nil?) ||- params[:query_id] == 'all'+ params[:query_id].nil? && params[:filters].nil? && params[:sortBy].nil?endendenddiff --git a/app/controllers/projects/queries_controller.rb b/app/controllers/projects/queries_controller.rbindex 68a1b9d2840..35d87f7c922 100644--- a/app/controllers/projects/queries_controller.rb+++ b/app/controllers/projects/queries_controller.rb@@ -32,17 +32,16 @@ class Projects::QueriesController < ApplicationController# No need for a more specific authorization check. That is carried out in the contracts.before_action :require_loginbefore_action :find_query, only: :destroy+ before_action :load_query_or_deny_access, only: %i[new]current_menu_item [:new, :create] do:projectsenddef new- call = load_query(existing: false)-render template: '/projects/index',layout: 'global',- locals: { query: call.result, state: :edit }+ locals: { query: @query, state: :edit }enddef creatediff --git a/app/controllers/projects/query_loading.rb b/app/controllers/projects/query_loading.rbindex e03e04650c5..071f41318b5 100644--- a/app/controllers/projects/query_loading.rb+++ b/app/controllers/projects/query_loading.rb@@ -27,32 +27,16 @@# ++module Projectsmodule QueryLoading- def load_query(existing: true)- query = if existing- Queries::Projects::Factory.find(params[:query_id])- else- Queries::Projects::ProjectQuery.new- end+ private- contract_class = if existing- # This one allows to change the name of the query.- # Semantically, it would be better to use the UpdateContract- # but there wasn't the need to create that yet and for now it- # would be the same as the CreateContract anyway.- Queries::Projects::ProjectQueries::CreateContract- else- Queries::Projects::ProjectQueries::LoadingContract- end+ def load_query_or_deny_access+ @query = Queries::Projects::Factory.find(params[:query_id],+ params: permitted_query_params,+ user: current_user)- Queries::Projects::ProjectQueries::SetAttributesService- .new(user: current_user,- model: query,- contract_class:)- .call(permitted_query_params)+ render_403 unless @queryend- private-def permitted_query_paramsquery_params = if params[:query]paramsdiff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rbindex 5168aaaf29e..de4617468a0 100644--- a/app/controllers/projects_controller.rb+++ b/app/controllers/projects_controller.rb@@ -31,6 +31,7 @@ class ProjectsController < ApplicationControllermenu_item :roadmap, only: :roadmapbefore_action :find_project, except: %i[index new]+ before_action :load_query_or_deny_access, only: %i[index]before_action :authorize, only: %i[copy]before_action :authorize_global, only: %i[new]before_action :require_admin, only: %i[destroy destroy_info]@@ -48,17 +49,15 @@ class ProjectsController < ApplicationControllerenddef index- call = load_query(existing: params[:filters].blank?)-respond_to do |format|format.html do- flash.now[:error] = call.errors.full_messages unless call.success?+ flash.now[:error] = @query.errors.full_messages if @query.errors.any?- render layout: 'global', locals: { query: call.result, state: :show }+ render layout: 'global', locals: { query: @query, state: :show }endformat.any(*supported_export_formats) do- export_list(call.result, request.format.symbol)+ export_list(@query, request.format.symbol)endendenddiff --git a/app/models/queries/projects/factory.rb b/app/models/queries/projects/factory.rbindex c3b3da439d5..54a89a81b5a 100644--- a/app/models/queries/projects/factory.rb+++ b/app/models/queries/projects/factory.rb@@ -27,27 +27,32 @@# ++class Queries::Projects::Factory+ STATIC_ACTIVE = 'active'.freeze+ STATIC_MY = 'my'.freeze+ STATIC_ARCHIVED = 'archived'.freeze+ STATIC_ON_TRACK = 'on_track'.freeze+ STATIC_OFF_TRACK = 'off_track'.freeze+ STATIC_AT_RISK = 'at_risk'.freeze+class << self- def find(id)- static_query(id) || Queries::Projects::ProjectQuery.find(id)+ def find(id, params:, user:)+ find_and_update_static_query(id, params, user) || find_and_update_persisted_query(id, params, user)enddef static_query(id)case id- when 'active'+ when STATIC_ACTIVE, nilstatic_query_active- when 'my'+ when STATIC_MYstatic_query_my- when 'archived'+ when STATIC_ARCHIVEDstatic_query_archived- when 'on_track'+ when STATIC_ON_TRACKstatic_query_status_on_track- when 'off_track'+ when STATIC_OFF_TRACKstatic_query_status_off_track- when 'at_risk'+ when STATIC_AT_RISKstatic_query_status_at_risk- when nil- list_with(:'projects.lists.active')endend@@ -91,8 +96,49 @@ class Queries::Projects::Factorydef list_with(name)Queries::Projects::ProjectQuery.new(name: I18n.t(name)) do |query|- yield query if block_given?+ query.order('lft' => 'asc')++ yield query+ end+ end++ def find_and_update_static_query(id, params, user)+ query = static_query(id)++ return unless query++ if params.any?+ new_query(query, params, user)+ else+ query+ end+ end++ def find_and_update_persisted_query(id, params, user)+ query = Queries::Projects::ProjectQuery.where(user:).find_by(id:)++ return unless query++ if params.any?+ update_query(query, params, user)+ else+ queryendend++ def new_query(source_query, params, user)+ update_query(Queries::Projects::ProjectQuery.new(source_query.attributes.slice('filters', 'orders')),+ params,+ user)+ end++ def update_query(query, params, user)+ Queries::Projects::ProjectQueries::SetAttributesService+ .new(user:,+ model: query,+ contract_class: Queries::Projects::ProjectQueries::LoadingContract)+ .call(params)+ .result+ endendenddiff --git a/app/views/projects/menus/_menu.html.erb b/app/views/projects/menus/_menu.html.erbindex 1c9d182f872..d856f3e617a 100644--- a/app/views/projects/menus/_menu.html.erb+++ b/app/views/projects/menus/_menu.html.erb@@ -1,5 +1,5 @@<%= turbo_frame_tag "projects_sidemenu",- src: projects_menu_path(params.permit(:filters, :query_id)),+ src: projects_menu_path(params.permit(:filters, :sortBy, :query_id)),target: '_top',data: { turbo: false },loading: :lazy %>diff --git a/spec/features/projects/persisted_lists_spec.rb b/spec/features/projects/persisted_lists_spec.rbindex 5a631521f1b..c7513f9fd19 100644--- a/spec/features/projects/persisted_lists_spec.rb+++ b/spec/features/projects/persisted_lists_spec.rb@@ -354,5 +354,14 @@ RSpec.describe 'Persisted lists on projects index page',projects_page.expect_projects_not_listed(another_project, # Because it is on the second pagedevelopment_project) # Because it is on the second pageend++ it 'cannot access another user`s list' do+ visit projects_path(query_id: another_users_projects_list.id)++ expect(page)+ .to have_no_text(another_users_projects_list.name)+ expect(page)+ .to have_text('You are not authorized to access this page.')+ endendenddiff --git a/spec/models/queries/projects/factory_spec.rb b/spec/models/queries/projects/factory_spec.rbnew file mode 100644index 00000000000..9c3430e2e0d--- /dev/null+++ b/spec/models/queries/projects/factory_spec.rb@@ -0,0 +1,631 @@+# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+# ++++require 'spec_helper'+require 'services/base_services/behaves_like_create_service'++RSpec.describe Queries::Projects::Factory do+ let(:current_user) { build_stubbed(:user) }+ let!(:query_finder) do+ scope = instance_double(ActiveRecord::Relation)++ allow(Queries::Projects::ProjectQuery)+ .to receive(:where)+ .with(user: current_user)+ .and_return(scope)++ allow(scope)+ .to receive(:find_by)+ .with(id:)+ .and_return(persisted_query)+ end+ let(:persisted_query) do+ build_stubbed(:project_query) do |query|+ query.order(id: :asc)+ query.where(:project_status, '=', [Project.status_codes[:on_track].to_s])+ end+ end++ let(:id) { nil }+ let(:params) { {} }++ describe '.find' do+ subject(:find) { described_class.find(id, params:, user: current_user) }++ context 'without id' do+ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('projects.lists.active'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:active, '=', ['t']]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ context 'with the \'active\' id' do+ let(:id) { 'active' }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('projects.lists.active'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:active, '=', ['t']]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ context 'with the \'my\' id' do+ let(:id) { 'my' }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('projects.lists.my'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:member_of, '=', ['t']]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ context 'with the \'archived\' id' do+ let(:id) { 'archived' }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('projects.lists.archived'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:active, '=', ['f']]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ context 'with the \'on_track\' id' do+ let(:id) { 'on_track' }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('activerecord.attributes.project.status_codes.on_track'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:project_status_code, '=', [Project.status_codes[:on_track].to_s]]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ context 'with the \'off_track\' id' do+ let(:id) { 'off_track' }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('activerecord.attributes.project.status_codes.off_track'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:project_status_code, '=', [Project.status_codes[:off_track].to_s]]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ context 'with the \'at_risk\' id' do+ let(:id) { 'at_risk' }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('activerecord.attributes.project.status_codes.at_risk'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:project_status_code, '=', [Project.status_codes[:at_risk].to_s]]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ context 'with an integer id for which the user has a query' do+ let(:id) { 42 }++ it 'returns the persisted query' do+ expect(find)+ .to eql(persisted_query)+ end+ end++ context 'with an integer id for which the user does not have a persisted query' do+ let(:id) { 42 }+ let(:persisted_query) { nil }++ it 'returns nil' do+ expect(find)+ .to be_nil+ end+ end++ context 'without an id and with params' do+ let(:id) { nil }+ let(:params) do+ {+ filters: [+ {+ attribute: 'active',+ operator: '=',+ values: ['f']+ },+ {+ attribute: 'member_of',+ operator: '=',+ values: ['t']+ }+ ],+ orders: [+ {+ attribute: 'id',+ direction: 'asc'+ },+ {+ attribute: 'name',+ direction: 'desc'+ }+ ]+ }+ end++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has no name' do+ expect(find.name)+ .to be_nil+ end++ it 'has the filters applied' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:active, '=', ['f']], [:member_of, '=', ['t']]])+ end++ it 'has the orders applied' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['id', :asc], ['name', :desc]])+ end+ end++ context 'with the \'active\' id and with order params' do+ let(:id) { 'active' }+ let(:params) do+ {+ orders: [+ {+ attribute: 'id',+ direction: 'asc'+ },+ {+ attribute: 'name',+ direction: 'desc'+ }+ ]+ }+ end++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has no name' do+ expect(find.name)+ .to be_nil+ end++ it 'has the filters of the default \'active\' query applied' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:active, '=', ['t']]])+ end++ it 'has the orders overwritten' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['id', :asc], ['name', :desc]])+ end+ end++ context 'with the \'active\' id and with filter params' do+ let(:id) { nil }+ let(:params) do+ {+ filters: [+ {+ attribute: 'active',+ operator: '=',+ values: ['f']+ },+ {+ attribute: 'member_of',+ operator: '=',+ values: ['t']+ }+ ]+ }+ end++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has no name' do+ expect(find.name)+ .to be_nil+ end++ it 'has the filters overwritten' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:active, '=', ['f']], [:member_of, '=', ['t']]])+ end++ it 'has the orders of the default \'active\' query applied' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([%i[lft asc]])+ end+ end++ context 'with an integer id for which the user has a query and with filter params' do+ let(:id) { 42 }+ let(:params) do+ {+ filters: [+ {+ attribute: 'active',+ operator: '=',+ values: ['f']+ },+ {+ attribute: 'member_of',+ operator: '=',+ values: ['t']+ }+ ]+ }+ end++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'keeps the name' do+ expect(find.name)+ .to eql(persisted_query.name)+ end++ it 'has the filters overwritten' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:active, '=', ['f']], [:member_of, '=', ['t']]])+ end++ it 'has the orders of the persisted query' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq(persisted_query.orders.map { |order| [order.attribute, order.direction] })+ end+ end++ context 'with an integer id for which the user has a query and with order params' do+ let(:id) { 42 }+ let(:params) do+ {+ orders: [+ {+ attribute: 'id',+ direction: 'asc'+ },+ {+ attribute: 'name',+ direction: 'desc'+ }+ ]+ }+ end++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'keeps the name' do+ expect(find.name)+ .to eql(persisted_query.name)+ end++ it 'has the filters of the persisted query' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq(persisted_query.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ end++ it 'has the orders overwritten' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq [["id", :asc], ["name", :desc]]+ end+ end++ context 'with an integer id for which the user does not have a query and with params' do+ let(:id) { 42 }+ let(:persisted_query) { nil }+ let(:params) do+ {+ filters: [+ {+ attribute: 'active',+ operator: '=',+ values: ['f']+ },+ {+ attribute: 'member_of',+ operator: '=',+ values: ['t']+ }+ ],+ orders: [+ {+ attribute: 'id',+ direction: 'asc'+ },+ {+ attribute: 'name',+ direction: 'desc'+ }+ ]+ }+ end++ it 'returns nil' do+ expect(find)+ .to be_nil+ end+ end+ end++ describe '.static_query_active' do+ subject(:find) { described_class.static_query_active }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('projects.lists.active'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:active, '=', ['t']]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ describe '.static_query_my' do+ subject(:find) { described_class.static_query_my }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('projects.lists.my'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:member_of, '=', ['t']]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ describe '.static_query_archived' do+ subject(:find) { described_class.static_query_archived }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('projects.lists.archived'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:active, '=', ['f']]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ describe '.static_query_status_on_track' do+ subject(:find) { described_class.static_query_status_on_track }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('activerecord.attributes.project.status_codes.on_track'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:project_status_code, '=', [Project.status_codes[:on_track].to_s]]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ describe '.static_query_status_off_track' do+ subject(:find) { described_class.static_query_status_off_track }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('activerecord.attributes.project.status_codes.off_track'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:project_status_code, '=', [Project.status_codes[:off_track].to_s]]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end++ describe '.static_query_status_at_risk' do+ subject(:find) { described_class.static_query_status_at_risk }++ it 'returns a project query' do+ expect(find)+ .to be_a(Queries::Projects::ProjectQuery)+ end++ it 'has a name' do+ expect(find.name)+ .to eql(I18n.t('activerecord.attributes.project.status_codes.at_risk'))+ end++ it 'has a filter for active projects' do+ expect(find.filters.map { |filter| [filter.field, filter.operator, filter.values] })+ .to eq([[:project_status_code, '=', [Project.status_codes[:at_risk].to_s]]])+ end++ it 'is ordered by lft asc' do+ expect(find.orders.map { |order| [order.attribute, order.direction] })+ .to eq([['lft', :asc]])+ end+ end+end