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
#41816: add stubs of days representer
Christophe Bliard2471b069754d
diff --git a/app/models/day.rb b/app/models/day.rbnew file mode 100644index 00000000000..78807171cb6--- /dev/null+++ b/app/models/day.rb@@ -0,0 +1,33 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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 Day+ include ActiveModel::Model++ attr_accessor :date, :name, :working+enddiff --git a/lib/api/v3/days/day_collection_representer.rb b/lib/api/v3/days/day_collection_representer.rbnew file mode 100644index 00000000000..8cf31640f95--- /dev/null+++ b/lib/api/v3/days/day_collection_representer.rb@@ -0,0 +1,32 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#++++module API::V3::Days+ class DayCollectionRepresenter < ::API::Decorators::UnpaginatedCollection+ end+enddiff --git a/lib/api/v3/days/day_representer.rb b/lib/api/v3/days/day_representer.rbnew file mode 100644index 00000000000..03229601d18--- /dev/null+++ b/lib/api/v3/days/day_representer.rb@@ -0,0 +1,43 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#++++module API::V3::Days+ class DayRepresenter < ::API::Decorators::Single+ # include ::API::Caching::CachedRepresenter++ property :date+ property :name+ property :working++ self_link path: :day, id_attribute: :date++ def _type+ 'Day'+ end+ end+enddiff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex 18c3061c911..79176c373f7 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -192,8 +192,16 @@ module API"#{root}/custom_options/#{id}"end+ def self.day(date)+ "#{days}/#{date}"+ end++ def self.days+ "#{root}/days"+ end+def self.days_week- "#{root}/days/week"+ "#{days}/week"enddef self.days_week_day(day)diff --git a/spec/factories/day_factory.rb b/spec/factories/day_factory.rbnew file mode 100644index 00000000000..706056ba731--- /dev/null+++ b/spec/factories/day_factory.rb@@ -0,0 +1,37 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#++++FactoryBot.define do+ factory :day, class: 'Day' do+ sequence :date do |n|+ (1.year.ago + n.days).to_date+ end+ name { WeekDay.new(day: date.wday).name }+ working { date.wday < 6 }+ end+enddiff --git a/spec/factories/week_day_factory.rb b/spec/factories/week_day_factory.rbindex e8c7e45015c..10974857429 100644--- a/spec/factories/week_day_factory.rb+++ b/spec/factories/week_day_factory.rb@@ -1,3 +1,31 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#+++FactoryBot.define dofactory :week_day dosequence :day, [1, 2, 3, 4, 5, 6, 7].cyclediff --git a/spec/lib/api/v3/days/day_collection_representer_spec.rb b/spec/lib/api/v3/days/day_collection_representer_spec.rbnew file mode 100644index 00000000000..22773be52c4--- /dev/null+++ b/spec/lib/api/v3/days/day_collection_representer_spec.rb@@ -0,0 +1,51 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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'++describe ::API::V3::Days::DayCollectionRepresenter do+ let(:days) do+ [+ build(:day, date: Date.new(2022, 12, 27)),+ build(:day, date: Date.new(2022, 12, 28)),+ build(:day, date: Date.new(2022, 12, 29))+ ]+ end+ let(:current_user) { instance_double(User, name: 'current_user') }+ let(:representer) do+ described_class.new(days,+ self_link: '/api/v3/self_link_untested',+ current_user:)+ end++ describe '#to_json' do+ subject(:collection) { representer.to_json }++ it_behaves_like 'unpaginated APIv3 collection', 3, 'self_link_untested', 'Day'+ end+enddiff --git a/spec/lib/api/v3/days/day_representer_spec.rb b/spec/lib/api/v3/days/day_representer_spec.rbnew file mode 100644index 00000000000..cdce648808e--- /dev/null+++ b/spec/lib/api/v3/days/day_representer_spec.rb@@ -0,0 +1,76 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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'++describe ::API::V3::Days::DayRepresenter do+ let(:day) do+ build(:day, date: Date.new(2022, 12, 27), name: 'Tuesday', working: true)+ end+ let(:current_user) { instance_double(User, name: 'current_user') }+ let(:representer) { described_class.new(day, current_user:) }++ describe '#to_json' do+ subject(:generated) { representer.to_json }++ it 'has _type: Day' do+ expect(subject).to be_json_eql('Day'.to_json).at_path('_type')+ end++ it 'has date property' do+ expect(subject).to have_json_type(String).at_path('date')+ expect(subject).to be_json_eql('2022-12-27'.to_json).at_path('date')+ end++ it 'has name string property' do+ expect(subject).to have_json_type(String).at_path('name')+ expect(subject).to be_json_eql(day.name.to_json).at_path('name')+ end++ it 'has working boolean property' do+ expect(subject).to have_json_type(TrueClass).at_path('working')+ expect(subject).to be_json_eql(day.working.to_json).at_path('working')+ end++ describe '_links' do+ it 'is present' do+ expect(subject).to have_json_type(Object).at_path('_links')+ end++ describe 'self' do+ it 'links to this resource' do+ expected_json = {+ href: '/api/v3/days/2022-12-27',+ title: 'Tuesday'+ }.to_json+ expect(subject).to be_json_eql(expected_json).at_path('_links/self')+ end+ end+ end+ end+end