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

Add Project.templated scope

Alexander Brandon Colese613e76899e9
diff --git a/app/models/project.rb b/app/models/project.rb
index e774b995fa2..3d9ec4fb049 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -204,6 +204,7 @@ class Project < ApplicationRecord
scope :archived, -> { where(active: false) }
scope :with_member, ->(user = User.current) { where(id: user.memberships.select(:project_id)) }
scope :without_member, ->(user = User.current) { where.not(id: user.memberships.select(:project_id)) }
+ scope :templated, -> { where(templated: true) }
scopes :activated_time_activity,
:visible_with_activated_time_activity
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 03f863800d5..1852d2bacd9 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -39,6 +39,15 @@ RSpec.describe Project do
let(:build_project) { build_stubbed(:project, active:) }
let(:user) { create(:user) }
+ describe ".templated" do
+ let!(:projects) { create_list(:project, 2) }
+ let!(:templated_projects) { create_list(:template_project, 1) }
+
+ it "returns templated projects only" do
+ expect(described_class.templated).to match_array(templated_projects)
+ end
+ end
+
describe "#active?" do
context "if active" do
it "is true" do