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
refactor spec for Acts::Watchable::RouteConstraint and copy for Acts::Favorable::RouteConstraint
Ivan Kuchin83a2306fb7ba
diff --git a/spec/lib/acts_as_watchable/lib/open_project/acts/favorable/route_constraint_spec.rb b/spec/lib/acts_as_watchable/lib/open_project/acts/favorable/route_constraint_spec.rbnew file mode 100644index 00000000000..304608c76d9--- /dev/null+++ b/spec/lib/acts_as_watchable/lib/open_project/acts/favorable/route_constraint_spec.rb@@ -0,0 +1,69 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-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"++RSpec.describe OpenProject::Acts::Favorable::RouteConstraint do+ let(:request) { instance_double(ActionDispatch::Request, path_parameters:) }+ let(:path_parameters) { { object_id: id, object_type: type } }++ describe "matches?" do+ %w[+ projects+ ].each do |type|+ describe "routing #{type} watches" do+ let(:type) { type }++ describe "for a valid id string" do+ let(:id) { "1" }++ it "is true" do+ expect(described_class).to be_matches(request)+ end+ end++ describe "for an invalid id string" do+ let(:id) { "schmu" }++ it "is false" do+ expect(described_class).not_to be_matches(request)+ end+ end+ end+ end++ describe "for a non watched model" do+ let(:type) { "schmu" }+ let(:id) { "4" }++ it "is false" do+ expect(described_class).not_to be_matches(request)+ end+ end+ end+enddiff --git a/spec/lib/acts_as_watchable/lib/acts_as_watchable/route_constraint_spec.rb b/spec/lib/acts_as_watchable/lib/open_project/acts/watchable/route_constraint_spec.rbsimilarity index 71%rename from spec/lib/acts_as_watchable/lib/acts_as_watchable/route_constraint_spec.rbrename to spec/lib/acts_as_watchable/lib/open_project/acts/watchable/route_constraint_spec.rbindex 8d92881a7eb..d298079095e 100644--- a/spec/lib/acts_as_watchable/lib/acts_as_watchable/route_constraint_spec.rb+++ b/spec/lib/acts_as_watchable/lib/open_project/acts/watchable/route_constraint_spec.rb@@ -29,38 +29,37 @@require "spec_helper"RSpec.describe OpenProject::Acts::Watchable::RouteConstraint do- let(:request) do- Struct.new(:type, :id) do- def path_parameters- { object_id: id, object_type: type }- end- end.new(type, id)- end+ let(:request) { instance_double(ActionDispatch::Request, path_parameters:) }+ let(:path_parameters) { { object_id: id, object_type: type } }describe "matches?" do- shared_examples_for "watched model" do- describe "for a valid id string" do- let(:id) { "1" }-- it "is true" do- expect(described_class).to be_matches(request)- end- end+ %w[+ forums+ meetings+ messages+ news+ wiki_pages+ wikis+ work_packages+ ].each do |type|+ describe "routing #{type} watches" do+ let(:type) { type }- describe "for an invalid id string" do- let(:id) { "schmu" }+ describe "for a valid id string" do+ let(:id) { "1" }- it "is false" do- expect(described_class).not_to be_matches(request)+ it "is true" do+ expect(described_class).to be_matches(request)+ endend- end- end- ["work_packages", "news", "forums", "messages", "wikis", "wiki_pages"].each do |type|- describe "routing #{type} watches" do- let(:type) { type }+ describe "for an invalid id string" do+ let(:id) { "schmu" }- it_behaves_like "watched model"+ it "is false" do+ expect(described_class).not_to be_matches(request)+ end+ endendend