diff --git a/app/contracts/queries/projects/project_queries/base_contract.rb b/app/contracts/project_queries/base_contract.rb similarity index 98% rename from app/contracts/queries/projects/project_queries/base_contract.rb rename to app/contracts/project_queries/base_contract.rb index e4f0edd6f268..b68b54d91455 100644 --- a/app/contracts/queries/projects/project_queries/base_contract.rb +++ b/app/contracts/project_queries/base_contract.rb @@ -26,7 +26,7 @@ # See COPYRIGHT and LICENSE files for more details. # ++ -module Queries::Projects::ProjectQueries +module ProjectQueries class BaseContract < ::ModelContract attribute :name attribute :selects diff --git a/app/contracts/queries/projects/project_queries/create_contract.rb b/app/contracts/project_queries/create_contract.rb similarity index 96% rename from app/contracts/queries/projects/project_queries/create_contract.rb rename to app/contracts/project_queries/create_contract.rb index be862966c712..8a9b4a82027f 100644 --- a/app/contracts/queries/projects/project_queries/create_contract.rb +++ b/app/contracts/project_queries/create_contract.rb @@ -26,6 +26,6 @@ # See COPYRIGHT and LICENSE files for more details. # ++ -module Queries::Projects::ProjectQueries +module ProjectQueries class CreateContract < BaseContract; end end diff --git a/app/contracts/queries/projects/project_queries/delete_contract.rb b/app/contracts/project_queries/delete_contract.rb similarity index 96% rename from app/contracts/queries/projects/project_queries/delete_contract.rb rename to app/contracts/project_queries/delete_contract.rb index 2b149f6dce8d..d3a92e673bd9 100644 --- a/app/contracts/queries/projects/project_queries/delete_contract.rb +++ b/app/contracts/project_queries/delete_contract.rb @@ -26,7 +26,7 @@ # See COPYRIGHT and LICENSE files for more details. # ++ -module Queries::Projects::ProjectQueries +module ProjectQueries class DeleteContract < ::DeleteContract delete_permission -> { user == model.user } end diff --git a/app/contracts/queries/projects/project_queries/publish_contract.rb b/app/contracts/project_queries/publish_contract.rb similarity index 96% rename from app/contracts/queries/projects/project_queries/publish_contract.rb rename to app/contracts/project_queries/publish_contract.rb index 470b59089a84..02af4d7bc24a 100644 --- a/app/contracts/queries/projects/project_queries/publish_contract.rb +++ b/app/contracts/project_queries/publish_contract.rb @@ -26,7 +26,7 @@ # See COPYRIGHT and LICENSE files for more details. #++ -module Queries::Projects::ProjectQueries +module ProjectQueries class PublishContract < BaseContract attribute :public end diff --git a/app/contracts/queries/projects/project_queries/update_contract.rb b/app/contracts/project_queries/update_contract.rb similarity index 96% rename from app/contracts/queries/projects/project_queries/update_contract.rb rename to app/contracts/project_queries/update_contract.rb index ca0985f819bd..9d75a96a9bf5 100644 --- a/app/contracts/queries/projects/project_queries/update_contract.rb +++ b/app/contracts/project_queries/update_contract.rb @@ -26,6 +26,6 @@ # See COPYRIGHT and LICENSE files for more details. # ++ -module Queries::Projects::ProjectQueries +module ProjectQueries class UpdateContract < BaseContract; end end diff --git a/app/contracts/queries/projects/project_queries/loading_contract.rb b/app/contracts/queries/loading_contract.rb similarity index 97% rename from app/contracts/queries/projects/project_queries/loading_contract.rb rename to app/contracts/queries/loading_contract.rb index 5a46646e6844..d962561d4017 100644 --- a/app/contracts/queries/projects/project_queries/loading_contract.rb +++ b/app/contracts/queries/loading_contract.rb @@ -26,7 +26,7 @@ # See COPYRIGHT and LICENSE files for more details. # ++ -module Queries::Projects::ProjectQueries +module Queries class LoadingContract < ::ModelContract attribute :filters attribute :orders diff --git a/app/controllers/projects/queries_controller.rb b/app/controllers/projects/queries_controller.rb index 3b77ca9a3b20..f8fef33a06c0 100644 --- a/app/controllers/projects/queries_controller.rb +++ b/app/controllers/projects/queries_controller.rb @@ -27,7 +27,7 @@ # ++ class Projects::QueriesController < ApplicationController - include Projects::QueryLoading + include Queries::Loading include OpTurbo::ComponentStream include OpTurbo::DialogStreamHelper @@ -81,7 +81,7 @@ def rename end def create - call = Queries::Projects::ProjectQueries::CreateService + call = ProjectQueries::CreateService .new(from: @query, user: current_user) .call(permitted_query_params) @@ -89,7 +89,7 @@ def create end def update - call = Queries::Projects::ProjectQueries::UpdateService + call = ProjectQueries::UpdateService .new(user: current_user, model: @query) .call(permitted_query_params) @@ -100,7 +100,7 @@ def toggle_public # rubocop:disable Metrics/AbcSize to_be_public = ActiveRecord::Type::Boolean.new.cast(params["value"]) i18n_key = to_be_public ? "lists.publish" : "lists.unpublish" - call = Queries::Projects::ProjectQueries::PublishService + call = ProjectQueries::PublishService .new(user: current_user, model: @query) .call(public: to_be_public) @@ -119,8 +119,8 @@ def toggle_public # rubocop:disable Metrics/AbcSize end def destroy - Queries::Projects::ProjectQueries::DeleteService.new(user: current_user, model: @query) - .call + ProjectQueries::DeleteService.new(user: current_user, model: @query) + .call redirect_to projects_path end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index cca50ade55b8..2823f88bb3b9 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -44,7 +44,7 @@ class ProjectsController < ApplicationController include PaginationHelper include QueriesHelper include ProjectsHelper - include Projects::QueryLoading + include Queries::Loading include OpTurbo::DialogStreamHelper helper_method :has_managed_project_folders? diff --git a/app/controllers/projects/query_loading.rb b/app/controllers/queries/loading.rb similarity index 73% rename from app/controllers/projects/query_loading.rb rename to app/controllers/queries/loading.rb index 6555949a5a35..937f75da2b66 100644 --- a/app/controllers/projects/query_loading.rb +++ b/app/controllers/queries/loading.rb @@ -25,15 +25,16 @@ # # See COPYRIGHT and LICENSE files for more details. # ++ -module Projects - module QueryLoading +module Queries + module Loading private def load_query(duplicate:) - ::Queries::Projects::Factory.find(params[:query_id], - params: permitted_query_params, - user: current_user, - duplicate:) + ::Queries::Factory.find(params[:query_id], + query_class:, + params: permitted_query_params, + user: current_user, + duplicate:) end def load_query_or_deny_access @@ -59,5 +60,17 @@ def permitted_query_params query_params.with_indifferent_access end + + def query_class + controller_name = self.class.name.demodulize + + model_name = if controller_name == "QueriesController" + self.class.name.deconstantize + else + controller_name.chomp("Controller") + end + + "#{model_name.singularize}Query".constantize + end end end diff --git a/app/menus/projects/menu.rb b/app/menus/projects/menu.rb index 9617ccea87be..183b7194e01e 100644 --- a/app/menus/projects/menu.rb +++ b/app/menus/projects/menu.rb @@ -55,7 +55,7 @@ def selected?(query_params) # rubocop:disable Metrics/AbcSize when "projects" case params[:query_id] when nil - query_params[:query_id].to_s == Queries::Projects::Factory::DEFAULT_STATIC + query_params[:query_id].to_s == ProjectQueries::Static::DEFAULT when /\A\d+\z/ query_params[:query_id].to_s == params[:query_id] else @@ -78,24 +78,24 @@ def query_path(query_params) def main_static_filters static_filters [ - ::Queries::Projects::Factory::STATIC_ACTIVE, - ::Queries::Projects::Factory::STATIC_MY, - ::Queries::Projects::Factory::STATIC_FAVORED, - current_user.admin? ? ::Queries::Projects::Factory::STATIC_ARCHIVED : nil + ProjectQueries::Static::ACTIVE, + ProjectQueries::Static::MY, + ProjectQueries::Static::FAVORED, + current_user.admin? ? ProjectQueries::Static::ARCHIVED : nil ].compact end def status_static_filters static_filters [ - ::Queries::Projects::Factory::STATIC_ON_TRACK, - ::Queries::Projects::Factory::STATIC_OFF_TRACK, - ::Queries::Projects::Factory::STATIC_AT_RISK + ProjectQueries::Static::ON_TRACK, + ProjectQueries::Static::OFF_TRACK, + ProjectQueries::Static::AT_RISK ] end def static_filters(ids) ids.map do |id| - menu_item(title: ::Queries::Projects::Factory.static_query(id).name, query_params: { query_id: id }) + menu_item(title: ::ProjectQueries::Static.query(id).name, query_params: { query_id: id }) end end diff --git a/app/models/queries/projects/factory.rb b/app/models/project_queries/static.rb similarity index 63% rename from app/models/queries/projects/factory.rb rename to app/models/project_queries/static.rb index 854d8c049382..2b604e78fc68 100644 --- a/app/models/queries/projects/factory.rb +++ b/app/models/project_queries/static.rb @@ -26,42 +26,39 @@ # See COPYRIGHT and LICENSE files for more details. # ++ -class Queries::Projects::Factory - STATIC_ACTIVE = "active".freeze - STATIC_MY = "my".freeze - STATIC_FAVORED = "favored".freeze - STATIC_ARCHIVED = "archived".freeze - STATIC_ON_TRACK = "on_track".freeze - STATIC_OFF_TRACK = "off_track".freeze - STATIC_AT_RISK = "at_risk".freeze +class ProjectQueries::Static + ACTIVE = "active".freeze + MY = "my".freeze + FAVORED = "favored".freeze + ARCHIVED = "archived".freeze + ON_TRACK = "on_track".freeze + OFF_TRACK = "off_track".freeze + AT_RISK = "at_risk".freeze - DEFAULT_STATIC = STATIC_ACTIVE + DEFAULT = ACTIVE class << self - def find(id, params:, user:, duplicate: false) - find_static_query_and_set_attributes(id, params, user, duplicate:) || - find_persisted_query_and_set_attributes(id, params, user, duplicate:) - end - - def static_query(id) + def query(id) case id - when STATIC_ACTIVE, nil + when ACTIVE, nil static_query_active - when STATIC_MY + when MY static_query_my - when STATIC_FAVORED + when FAVORED static_query_favored - when STATIC_ARCHIVED + when ARCHIVED static_query_archived - when STATIC_ON_TRACK + when ON_TRACK static_query_status_on_track - when STATIC_OFF_TRACK + when OFF_TRACK static_query_status_off_track - when STATIC_AT_RISK + when AT_RISK static_query_status_at_risk end end + private + def static_query_active list_with(:"projects.lists.active") do |query| query.where("active", "=", OpenProject::Database::DB_VALUE_TRUE) @@ -117,49 +114,5 @@ def list_with(name) query.clear_changes_information end end - - def find_static_query_and_set_attributes(id, params, user, duplicate:) - query = static_query(id) - - return unless query - - query = duplicate_query(query) if duplicate || params.any? - - if params.any? - set_query_attributes(query, params, user) - else - query - end - end - - def find_persisted_query_and_set_attributes(id, params, user, duplicate:) - query = ProjectQuery.visible(user).find_by(id:) - - return unless query - - query.valid_subset! - query.clear_changes_information - - query = duplicate_query(query) if duplicate - - if params.any? - set_query_attributes(query, params, user) - else - query - end - end - - def duplicate_query(query) - ProjectQuery.new(query.attributes.slice("filters", "orders", "selects")) - end - - def set_query_attributes(query, params, user) - Queries::Projects::ProjectQueries::SetAttributesService - .new(user:, - model: query, - contract_class: Queries::Projects::ProjectQueries::LoadingContract) - .call(params) - .result - end end end diff --git a/app/models/queries/factory.rb b/app/models/queries/factory.rb new file mode 100644 index 000000000000..e15674f2436e --- /dev/null +++ b/app/models/queries/factory.rb @@ -0,0 +1,86 @@ +# -- 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. +# ++ + +class Queries::Factory + class << self + def find(id, query_class:, params:, user:, duplicate: false) + find_static_query_and_set_attributes(id, query_class, params, user, duplicate:) || + find_persisted_query_and_set_attributes(id, query_class, params, user, duplicate:) + end + + private + + def find_static_query_and_set_attributes(id, query_class, params, user, duplicate:) + query = query_namespace(query_class)::Static.query(id) + + return unless query + + query = duplicate_query(query) if duplicate || params.any? + + if params.any? + set_query_attributes(query, query_class, params, user) + else + query + end + end + + def find_persisted_query_and_set_attributes(id, query_class, params, user, duplicate:) + query = query_class.visible(user).find_by(id:) + + return unless query + + query.valid_subset! + query.clear_changes_information + + query = duplicate_query(query) if duplicate + + if params.any? + set_query_attributes(query, query_class, params, user) + else + query + end + end + + def duplicate_query(query) + query.class.new(query.attributes.slice("filters", "orders", "selects")) + end + + def set_query_attributes(query, query_class, params, user) + query_namespace(query_class)::SetAttributesService + .new(user:, + model: query, + contract_class: Queries::LoadingContract) + .call(params) + .result + end + + def query_namespace(query_class) + query_class.name.pluralize.constantize + end + end +end diff --git a/app/services/queries/projects/project_queries/create_service.rb b/app/services/project_queries/create_service.rb similarity index 94% rename from app/services/queries/projects/project_queries/create_service.rb rename to app/services/project_queries/create_service.rb index 7fff71fd0309..5f0cf86e862f 100644 --- a/app/services/queries/projects/project_queries/create_service.rb +++ b/app/services/project_queries/create_service.rb @@ -26,7 +26,7 @@ # See COPYRIGHT and LICENSE files for more details. # ++ -class Queries::Projects::ProjectQueries::CreateService < BaseServices::Create +class ProjectQueries::CreateService < BaseServices::Create def initialize(from: nil, **) @from = from super(**) diff --git a/app/services/queries/projects/project_queries/delete_service.rb b/app/services/project_queries/delete_service.rb similarity index 93% rename from app/services/queries/projects/project_queries/delete_service.rb rename to app/services/project_queries/delete_service.rb index 0300d92233d8..ee7f7a9e69d6 100644 --- a/app/services/queries/projects/project_queries/delete_service.rb +++ b/app/services/project_queries/delete_service.rb @@ -26,4 +26,4 @@ # See COPYRIGHT and LICENSE files for more details. #++ -class Queries::Projects::ProjectQueries::DeleteService < BaseServices::Delete; end +class ProjectQueries::DeleteService < BaseServices::Delete; end diff --git a/app/services/queries/projects/project_queries/publish_service.rb b/app/services/project_queries/publish_service.rb similarity index 93% rename from app/services/queries/projects/project_queries/publish_service.rb rename to app/services/project_queries/publish_service.rb index 244d1acf1e01..e291763f6ce3 100644 --- a/app/services/queries/projects/project_queries/publish_service.rb +++ b/app/services/project_queries/publish_service.rb @@ -26,7 +26,7 @@ # See COPYRIGHT and LICENSE files for more details. #++ -module Queries::Projects::ProjectQueries +module ProjectQueries class PublishService < BaseServices::Update private @@ -43,7 +43,7 @@ def persist(service_call) end def default_contract_class - Queries::Projects::ProjectQueries::PublishContract + ProjectQueries::PublishContract end end end diff --git a/app/services/queries/projects/project_queries/set_attributes_service.rb b/app/services/project_queries/set_attributes_service.rb similarity index 96% rename from app/services/queries/projects/project_queries/set_attributes_service.rb rename to app/services/project_queries/set_attributes_service.rb index d47e5f6012a2..88330ea5d046 100644 --- a/app/services/queries/projects/project_queries/set_attributes_service.rb +++ b/app/services/project_queries/set_attributes_service.rb @@ -26,7 +26,7 @@ # See COPYRIGHT and LICENSE files for more details. # ++ -class Queries::Projects::ProjectQueries::SetAttributesService < BaseServices::SetAttributes +class ProjectQueries::SetAttributesService < BaseServices::SetAttributes private def set_attributes(params) diff --git a/app/services/queries/projects/project_queries/update_service.rb b/app/services/project_queries/update_service.rb similarity index 93% rename from app/services/queries/projects/project_queries/update_service.rb rename to app/services/project_queries/update_service.rb index 16b6f00df60e..0fb9301b0a40 100644 --- a/app/services/queries/projects/project_queries/update_service.rb +++ b/app/services/project_queries/update_service.rb @@ -26,4 +26,4 @@ # See COPYRIGHT and LICENSE files for more details. # ++ -class Queries::Projects::ProjectQueries::UpdateService < BaseServices::Update; end +class ProjectQueries::UpdateService < BaseServices::Update; end diff --git a/spec/contracts/queries/projects/project_queries/create_contract_spec.rb b/spec/contracts/project_queries/create_contract_spec.rb similarity index 96% rename from spec/contracts/queries/projects/project_queries/create_contract_spec.rb rename to spec/contracts/project_queries/create_contract_spec.rb index 008a6a7de223..732375ea5f81 100644 --- a/spec/contracts/queries/projects/project_queries/create_contract_spec.rb +++ b/spec/contracts/project_queries/create_contract_spec.rb @@ -29,7 +29,7 @@ require "spec_helper" require_relative "shared_contract_examples" -RSpec.describe Queries::Projects::ProjectQueries::CreateContract do +RSpec.describe ProjectQueries::CreateContract do it_behaves_like "project queries contract" do let(:query) do ProjectQuery.new(name: query_name).tap do |query| diff --git a/spec/contracts/queries/projects/project_queries/delete_contract_spec.rb b/spec/contracts/project_queries/delete_contract_spec.rb similarity index 96% rename from spec/contracts/queries/projects/project_queries/delete_contract_spec.rb rename to spec/contracts/project_queries/delete_contract_spec.rb index 65a6dd212ca4..e5866cb3da91 100644 --- a/spec/contracts/queries/projects/project_queries/delete_contract_spec.rb +++ b/spec/contracts/project_queries/delete_contract_spec.rb @@ -31,7 +31,7 @@ require "spec_helper" require "contracts/shared/model_contract_shared_context" -RSpec.describe Queries::Projects::ProjectQueries::DeleteContract do +RSpec.describe ProjectQueries::DeleteContract do include_context "ModelContract shared context" let(:current_user) { build_stubbed(:user) } diff --git a/spec/contracts/queries/projects/project_queries/shared_contract_examples.rb b/spec/contracts/project_queries/shared_contract_examples.rb similarity index 100% rename from spec/contracts/queries/projects/project_queries/shared_contract_examples.rb rename to spec/contracts/project_queries/shared_contract_examples.rb diff --git a/spec/contracts/queries/projects/project_queries/update_contract_spec.rb b/spec/contracts/project_queries/update_contract_spec.rb similarity index 96% rename from spec/contracts/queries/projects/project_queries/update_contract_spec.rb rename to spec/contracts/project_queries/update_contract_spec.rb index 2795511e6e2d..ade688770084 100644 --- a/spec/contracts/queries/projects/project_queries/update_contract_spec.rb +++ b/spec/contracts/project_queries/update_contract_spec.rb @@ -29,7 +29,7 @@ require "spec_helper" require_relative "shared_contract_examples" -RSpec.describe Queries::Projects::ProjectQueries::UpdateContract do +RSpec.describe ProjectQueries::UpdateContract do it_behaves_like "project queries contract" do let(:query) do ProjectQuery.new(name: query_name).tap do |query| diff --git a/spec/contracts/queries/projects/project_queries/loading_contract_spec.rb b/spec/contracts/queries/loading_contract_spec.rb similarity index 96% rename from spec/contracts/queries/projects/project_queries/loading_contract_spec.rb rename to spec/contracts/queries/loading_contract_spec.rb index 167b0038f46a..f15181dcfd3a 100644 --- a/spec/contracts/queries/projects/project_queries/loading_contract_spec.rb +++ b/spec/contracts/queries/loading_contract_spec.rb @@ -29,7 +29,7 @@ require "spec_helper" require "contracts/shared/model_contract_shared_context" -RSpec.describe Queries::Projects::ProjectQueries::LoadingContract do +RSpec.describe Queries::LoadingContract do include_context "ModelContract shared context" let(:current_user) { build_stubbed(:user) } diff --git a/spec/controllers/projects/queries_controller_spec.rb b/spec/controllers/projects/queries_controller_spec.rb index e65855257cbe..217b6bfa8050 100644 --- a/spec/controllers/projects/queries_controller_spec.rb +++ b/spec/controllers/projects/queries_controller_spec.rb @@ -62,8 +62,9 @@ before do allow(controller).to receive(:permitted_query_params).and_return(query_params) - allow(Queries::Projects::Factory).to receive(:find) - .with(query_id, user:, params: query_params, duplicate: true).and_return(query) + allow(Queries::Factory).to receive(:find) + .with(query_id, query_class: ProjectQuery, user:, params: query_params, duplicate: true) + .and_return(query) login_as user end @@ -120,7 +121,7 @@ end describe "#create" do - let(:service_class) { Queries::Projects::ProjectQueries::CreateService } + let(:service_class) { ProjectQueries::CreateService } it "requires login" do post "create" @@ -137,8 +138,8 @@ before do allow(controller).to receive(:permitted_query_params).and_return(query_params) - allow(Queries::Projects::Factory).to receive(:find) - .with(nil, user:, params: query_params, duplicate: true).and_return(query) + allow(Queries::Factory).to receive(:find) + .with(nil, query_class: ProjectQuery, user:, params: query_params, duplicate: true).and_return(query) allow(service_class).to receive(:new).with(from: query, user:).and_return(service_instance) allow(service_instance).to receive(:call).with(query_params).and_return(service_result) @@ -191,7 +192,7 @@ end describe "#update" do - let(:service_class) { Queries::Projects::ProjectQueries::UpdateService } + let(:service_class) { ProjectQueries::UpdateService } it "requires login" do put "update", params: { id: 42 } @@ -264,7 +265,7 @@ end describe "#toggle_public" do - let(:service_class) { Queries::Projects::ProjectQueries::PublishService } + let(:service_class) { ProjectQueries::PublishService } it "requires login" do post "toggle_public", params: { id: "42", value: "1" } @@ -350,7 +351,7 @@ end describe "#destroy" do - let(:service_class) { Queries::Projects::ProjectQueries::DeleteService } + let(:service_class) { ProjectQueries::DeleteService } it "requires login" do delete "destroy", params: { id: 42 } diff --git a/spec/models/queries/projects/factory_spec.rb b/spec/models/queries/factory_project_query_spec.rb similarity index 82% rename from spec/models/queries/projects/factory_spec.rb rename to spec/models/queries/factory_project_query_spec.rb index 9e531ba3d677..00450479f92f 100644 --- a/spec/models/queries/projects/factory_spec.rb +++ b/spec/models/queries/factory_project_query_spec.rb @@ -29,7 +29,8 @@ require "spec_helper" require "services/base_services/behaves_like_create_service" -RSpec.describe Queries::Projects::Factory, +RSpec.describe Queries::Factory, + "ProjectQuery", with_settings: { enabled_projects_columns: %w[favored name project_status] } do before do scope = instance_double(ActiveRecord::Relation) @@ -80,7 +81,7 @@ current_user { build_stubbed(:user) } describe ".find" do - subject(:find) { described_class.find(id, params:, user: current_user, duplicate:) } + subject(:find) { described_class.find(id, query_class: ProjectQuery, params:, user: current_user, duplicate:) } let(:duplicate) { false } @@ -880,178 +881,4 @@ 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(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([%i[lft asc]]) - end - - it "has the enabled_project_columns columns as selects" do - expect(find.selects.map(&:attribute)) - .to eq(default_selects) - 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(ProjectQuery) - end - - it "has a name" do - expect(find.name) - .to eql(I18n.t("projects.lists.my")) - end - - it "has a filter for projects the user is a member of" 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([%i[lft asc]]) - end - - it "has the enabled_project_columns columns as selects" do - expect(find.selects.map(&:attribute)) - .to eq(default_selects) - 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(ProjectQuery) - end - - it "has a name" do - expect(find.name) - .to eql(I18n.t("projects.lists.archived")) - end - - it "has a filter for archived 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([%i[lft asc]]) - end - - it "has the enabled_project_columns columns as selects" do - expect(find.selects.map(&:attribute)) - .to eq(default_selects) - 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(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 project that are "on track"' 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([%i[lft asc]]) - end - - it "has the enabled_project_columns columns as selects" do - expect(find.selects.map(&:attribute)) - .to eq(default_selects) - 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(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 projects that are "off track"' 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([%i[lft asc]]) - end - - it "has the enabled_project_columns columns as selects" do - expect(find.selects.map(&:attribute)) - .to eq(default_selects) - 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(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 projects that are "at risk"' 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([%i[lft asc]]) - end - - it "has the enabled_project_columns columns as selects" do - expect(find.selects.map(&:attribute)) - .to eq(default_selects) - end - end end diff --git a/spec/services/queries/projects/project_queries/create_service_spec.rb b/spec/services/project_queries/create_service_spec.rb similarity index 97% rename from spec/services/queries/projects/project_queries/create_service_spec.rb rename to spec/services/project_queries/create_service_spec.rb index 7fb64b0c7fdf..a0a1652fe79a 100644 --- a/spec/services/queries/projects/project_queries/create_service_spec.rb +++ b/spec/services/project_queries/create_service_spec.rb @@ -29,7 +29,7 @@ require "spec_helper" require "services/base_services/behaves_like_create_service" -RSpec.describe Queries::Projects::ProjectQueries::CreateService, type: :model do +RSpec.describe ProjectQueries::CreateService, type: :model do it_behaves_like "BaseServices create service" do let(:model_class) { ProjectQuery } let(:factory) { :project_query } diff --git a/spec/services/queries/projects/project_queries/set_attributes_service_spec.rb b/spec/services/project_queries/set_attributes_service_spec.rb similarity index 96% rename from spec/services/queries/projects/project_queries/set_attributes_service_spec.rb rename to spec/services/project_queries/set_attributes_service_spec.rb index b40ba1b10bdf..537889fb99cd 100644 --- a/spec/services/queries/projects/project_queries/set_attributes_service_spec.rb +++ b/spec/services/project_queries/set_attributes_service_spec.rb @@ -28,10 +28,10 @@ require "spec_helper" -RSpec.describe Queries::Projects::ProjectQueries::SetAttributesService, type: :model do +RSpec.describe ProjectQueries::SetAttributesService, type: :model do let(:current_user) { build_stubbed(:user) } let(:contract_instance) do - contract = instance_double(Queries::Projects::ProjectQueries::CreateContract) + contract = instance_double(ProjectQueries::CreateContract) allow(contract) .to receive_messages(validate: contract_valid, errors: contract_errors) contract @@ -47,11 +47,11 @@ end let(:model_instance) { ProjectQuery.new } let(:contract_class) do - allow(Queries::Projects::ProjectQueries::CreateContract) + allow(ProjectQueries::CreateContract) .to receive(:new) .and_return(contract_instance) - Queries::Projects::ProjectQueries::CreateContract + ProjectQueries::CreateContract end let(:params) { {} } let!(:custom_field) do diff --git a/spec/services/queries/projects/project_queries/update_service_spec.rb b/spec/services/project_queries/update_service_spec.rb similarity index 94% rename from spec/services/queries/projects/project_queries/update_service_spec.rb rename to spec/services/project_queries/update_service_spec.rb index cdf95e2a44e0..d8b0e384db1b 100644 --- a/spec/services/queries/projects/project_queries/update_service_spec.rb +++ b/spec/services/project_queries/update_service_spec.rb @@ -29,7 +29,7 @@ require "spec_helper" require "services/base_services/behaves_like_update_service" -RSpec.describe Queries::Projects::ProjectQueries::UpdateService, type: :model do +RSpec.describe ProjectQueries::UpdateService, type: :model do it_behaves_like "BaseServices update service" do let(:factory) { :project_query } end