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
tests for the My::TimeTrackingController#calendar method
Klaus Zanders5c60d725f599
diff --git a/modules/costs/app/controllers/my/time_tracking_controller.rb b/modules/costs/app/controllers/my/time_tracking_controller.rbindex ae18f2fe518..2ed409eb2d7 100644--- a/modules/costs/app/controllers/my/time_tracking_controller.rb+++ b/modules/costs/app/controllers/my/time_tracking_controller.rb@@ -51,7 +51,7 @@ module Myhelper_method :current_day, :today?, :this_week?, :this_month?, :list_view_componentdef calendar- if browser.device.mobile?+ if mobile?redirect_to action: :day, view_mode: default_view_modeelseredirect_to action: :week, view_mode: default_view_mode@@ -132,5 +132,9 @@ module MyMy::TimeTracking::CalendarComponent.new(time_entries: @time_entries, mode: params[:action].to_sym, date: current_day)endend++ def mobile?+ browser.device.mobile?+ endendenddiff --git a/modules/costs/spec/controllers/my/time_tracking_controller_spec.rb b/modules/costs/spec/controllers/my/time_tracking_controller_spec.rbnew file mode 100644index 00000000000..81a144d372d--- /dev/null+++ b/modules/costs/spec/controllers/my/time_tracking_controller_spec.rb@@ -0,0 +1,97 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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_relative "../../spec_helper"++RSpec.describe My::TimeTrackingController do+ let(:user) { create(:user) }++ before do+ login_as user+ end++ describe "GET /my/time-tracking" do+ context "when requesting on a non mobile device" do+ before do+ allow(controller).to receive(:mobile?).and_return(false)+ end++ context "and tracking start and end times is enabled" do+ before do+ allow(TimeEntry).to receive(:can_track_start_and_end_time?).and_return(true)+ end++ it "redirects to the week calendar view" do+ get :calendar+ expect(response).to redirect_to(action: :week, view_mode: "calendar")+ end+ end++ context "and tracking start and end times is disabled" do+ before do+ allow(TimeEntry).to receive(:can_track_start_and_end_time?).and_return(false)+ end++ it "redirects to the week list view" do+ get :calendar+ expect(response).to redirect_to(action: :week, view_mode: "list")+ end+ end+ end++ context "when requesting on a mobile device" do+ before do+ allow(controller).to receive(:mobile?).and_return(true)+ end++ context "and tracking start and end times is enabled" do+ before do+ allow(TimeEntry).to receive(:can_track_start_and_end_time?).and_return(true)+ end++ it "redirects to the day calendar view" do+ get :calendar+ expect(response).to redirect_to(action: :day, view_mode: "calendar")+ end+ end++ context "and tracking start and end times is disabled" do+ before do+ allow(TimeEntry).to receive(:can_track_start_and_end_time?).and_return(false)+ end++ it "redirects to the day list view" do+ get :calendar+ expect(response).to redirect_to(action: :day, view_mode: "list")+ end+ end+ end+ end+end