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
fixed rubocop warnings
Jonas Jabaricc3c923ae932
diff --git a/modules/calendar/app/controllers/calendar/ical_controller.rb b/modules/calendar/app/controllers/calendar/ical_controller.rbindex 4a3ef20450d..c3357458d6b 100644--- a/modules/calendar/app/controllers/calendar/ical_controller.rb+++ b/modules/calendar/app/controllers/calendar/ical_controller.rb@@ -28,10 +28,9 @@module ::Calendarclass IcalController < ApplicationController-def icalbegin- call = ::Calendar::IcalResponseService.new().call(+ call = ::Calendar::IcalResponseService.new.call(ical_token: params[:ical_token],query_id: params[:id])@@ -47,6 +46,5 @@ module ::Calendarrender_404endend-endenddiff --git a/modules/calendar/app/services/calendar/create_ical_service.rb b/modules/calendar/app/services/calendar/create_ical_service.rbindex 4f0757ee506..35aaaba09b6 100644--- a/modules/calendar/app/services/calendar/create_ical_service.rb+++ b/modules/calendar/app/services/calendar/create_ical_service.rb@@ -31,10 +31,10 @@ require 'icalendar'module Calendarclass CreateIcalService < ::BaseServices::BaseCallableinclude OpenProject::StaticRouting::UrlHelpers-+def perform(work_packages:, calendar_name: "OpenProject Calendar")ical_string = create_ical_string(work_packages, calendar_name)-+ServiceResult.success(result: ical_string)end@@ -50,6 +50,7 @@ module Calendarnext if work_package.start_date.nil? && work_package.due_date.nil?event = create_event(work_package)+ event = add_attendee_value(event, work_package)calendar.add_event(event)end@@ -59,27 +60,45 @@ module Calendardef create_event(work_package)event = Icalendar::Event.new- event.uid = "#{work_package.id}@#{host}"- # event.attendee = [work_package.assigned_to&.name] # causing thunderbird error "id is null"- event.attendee = [work_package.assigned_to&.name] if work_package.assigned_to.present?- event.organizer = work_package.author&.name- event.summary = work_package.name- event.dtstart = Icalendar::Values::Date.new(start_date(work_package))- event.dtend = Icalendar::Values::Date.new(due_date(work_package))- event.location = work_package_url(work_package)+ event.uid = event_uid_value(work_package)+ event.organizer = organizer_value(work_package)+ event.summary = summary_value(work_package)+ event.dtstart = dtstart_value(work_package)+ event.dtend = dtend_value(work_package)+ event.location = location_value(work_package)event.description = description_value(work_package)eventend-++ def event_uid_value(work_package)+ "#{work_package.id}@#{host}"+ end++ def attendee_value(work_package)+ [work_package.assigned_to&.name]+ end++ def organizer_value(work_package)+ work_package.author&.name+ end++ def summary_value(work_package)+ work_package.name+ end++ def dtstart_value(work_package)+ Icalendar::Values::Date.new(start_date(work_package))+ end+def start_date(work_package)- if work_package.start_date.present?- work_package.start_date- else- work_package.due_date- end+ (work_package.start_date.presence || work_package.due_date)+ end++ def dtend_value(work_package)+ Icalendar::Values::Date.new(due_date(work_package))end-+def due_date(work_package)if work_package.due_date.present?work_package.due_date + 1.day@@ -88,14 +107,14 @@ module Calendarendend- def work_package_url(work_package)+ def location_value(work_package)url_for(controller: :work_packages,action: :show,id: work_package.id,only_path: false,- protocol: protocol,- host: host+ protocol:,+ host:)end@@ -126,9 +145,7 @@ module Calendarstatus = "Status: #{work_package.status&.name}"assignee = "Assignee: #{work_package.assigned_to&.name}"priority = "Priority: #{priority_emoji(work_package)}#{work_package.priority&.name}"- unless work_package.description.blank?- description = "\nDescription:\n #{work_package.description&.truncate(250)}"- end+ description = truncated_work_package_description_value(work_package)[project, type, status, assignee, priority, description@@ -139,11 +156,23 @@ module Calendar# TODO: Differentiate emoji based on type# "🟩"end-+def priority_emoji(work_package)# TODO: Differentiate emoji based on priority# "🟢"end+ def truncated_work_package_description_value(work_package)+ if work_package.description.present?+ "\nDescription:\n #{work_package.description&.truncate(250)}"+ end+ end++ def add_attendee_value(event, work_package)+ # event.attendee = [work_package.assigned_to&.name] # causing thunderbird error "id is null"+ event.attendee = attendee_value(work_package) if work_package.assigned_to.present?++ event+ endendenddiff --git a/modules/calendar/app/services/calendar/generate_ical_url.rb b/modules/calendar/app/services/calendar/generate_ical_url.rbindex 6e15947623f..8e4d7e86adf 100644--- a/modules/calendar/app/services/calendar/generate_ical_url.rb+++ b/modules/calendar/app/services/calendar/generate_ical_url.rb@@ -29,11 +29,11 @@module Calendarclass GenerateIcalUrl < ::BaseServices::BaseCallableinclude OpenProject::StaticRouting::UrlHelpers-+def perform(user:, query_id:, project_id:)new_ical_token = create_ical_token(user)new_ical_url = create_ical_url(query_id, project_id, new_ical_token)-+ServiceResult.success(result: new_ical_url)end@@ -48,13 +48,14 @@ module Calendarcontroller: "calendar/ical",action: :ical,id: query_id,- project_id: project_id,- ical_token: ical_token,+ project_id:,+ ical_token:,only_path: false,- protocol: protocol,- host: host+ protocol:,+ host:)end+# implementation taken from application_mailerdef hostif OpenProject::Configuration.rails_relative_url_root.blank?@@ -74,6 +75,5 @@ module Calendar# def controller# nil# end-endenddiff --git a/modules/calendar/app/services/calendar/ical_response_service.rb b/modules/calendar/app/services/calendar/ical_response_service.rbindex 4bf1867541d..ddbbb1e7703 100644--- a/modules/calendar/app/services/calendar/ical_response_service.rb+++ b/modules/calendar/app/services/calendar/ical_response_service.rb@@ -26,11 +26,9 @@# See COPYRIGHT and LICENSE files for more details.#++-module Calendarclass IcalResponseService < ::BaseServices::BaseCallable-- ICAL_CACHE_EXPIRES_IN = 0.minute # cache disabled for now by setting to 0.minute+ ICAL_CACHE_EXPIRES_IN = 0.minutes # cache disabled for now by setting to 0.minutedef perform(ical_token:, query_id:)ical_string = resolve_from_cache_or_regenerate(ical_token, query_id)@@ -50,7 +48,7 @@ module Calendardef resolve_from_cache_or_regenerate(ical_token, query_id)OpenProject::Cache.fetch(- cache_key(ical_token, query_id),+ cache_key(ical_token, query_id),expires_in: ICAL_CACHE_EXPIRES_IN) doregenerate_ical_string(ical_token, query_id)@@ -61,14 +59,12 @@ module Calendaruser = resolve_user_by_token(ical_token)query = resolve_and_authorize_query(user, query_id)work_packages = resolve_work_packages(query)- ical_string = create_ical_string(work_packages, query.name)-- ical_string+ create_ical_string(work_packages, query.name)enddef resolve_user_by_token(ical_token)- call = ::Calendar::ResolveIcalUserService.new().call(- ical_token: ical_token+ call = ::Calendar::ResolveIcalUserService.new.call(+ ical_token:)user = call.result if call.success?@@ -76,9 +72,9 @@ module Calendarenddef resolve_and_authorize_query(user, query_id)- call = ::Calendar::ResolveAndAuthorizeQueryService.new().call(- user: user,- query_id: query_id+ call = ::Calendar::ResolveAndAuthorizeQueryService.new.call(+ user:,+ query_id:)query = call.result if call.success?@@ -86,8 +82,8 @@ module Calendarenddef resolve_work_packages(query)- call = ::Calendar::ResolveWorkPackagesService.new().call(- query: query+ call = ::Calendar::ResolveWorkPackagesService.new.call(+ query:)work_packages = call.result if call.success?@@ -95,13 +91,12 @@ module Calendarenddef create_ical_string(work_packages, calendar_name)- call = ::Calendar::CreateIcalService.new().call(- work_packages: work_packages, calendar_name: calendar_name+ call = ::Calendar::CreateIcalService.new.call(+ work_packages:, calendar_name:)ical_string = call.result if call.success?ical_stringend-endenddiff --git a/modules/calendar/app/services/calendar/resolve_and_authorize_query_service.rb b/modules/calendar/app/services/calendar/resolve_and_authorize_query_service.rbindex 862053f80c4..d7256d74803 100644--- a/modules/calendar/app/services/calendar/resolve_and_authorize_query_service.rb+++ b/modules/calendar/app/services/calendar/resolve_and_authorize_query_service.rb@@ -28,17 +28,16 @@module Calendarclass ResolveAndAuthorizeQueryService < ::BaseServices::BaseCallable-def perform(user:, query_id:)query = Query.visible(user) # authorization.find(query_id)- # TODO:+ # TODO:# Is this the correct way of unscoping the calendar view state# in order to get all workpackages from the query?query.filters = query.filters- .reject { |filter| filter.name == :dates_interval }+ .reject { |filter| filter.name == :dates_interval }sharing_permitted = QueryPolicy.new(user).allowed?(query, :share_via_ical@@ -51,6 +50,5 @@ module Calendarraise ActiveRecord::RecordNotFoundendend-endenddiff --git a/modules/calendar/app/services/calendar/resolve_ical_user_service.rb b/modules/calendar/app/services/calendar/resolve_ical_user_service.rbindex 7adf64ee7b9..154fc905b0d 100644--- a/modules/calendar/app/services/calendar/resolve_ical_user_service.rb+++ b/modules/calendar/app/services/calendar/resolve_ical_user_service.rb@@ -28,13 +28,14 @@module Calendarclass ResolveIcalUserService < ::BaseServices::BaseCallable-def perform(ical_token:)if ical_token.blank?raise ActiveRecord::RecordNotFoundend-++ # rubocop:disable Rails/DynamicFindBytoken = Token::Ical.find_by_plaintext_value(ical_token)+ # rubocop:enable Rails/DynamicFindByif token.present?user = token.user@@ -42,12 +43,11 @@ module Calendar# TODO: required for internal query scoping?# TODO: does that have any security implications?User.current = user-+ServiceResult.success(result: user)elseraise ActiveRecord::RecordNotFoundendend-endenddiff --git a/modules/calendar/app/services/calendar/resolve_work_packages_service.rb b/modules/calendar/app/services/calendar/resolve_work_packages_service.rbindex 32c59f63971..83bf0cda88c 100644--- a/modules/calendar/app/services/calendar/resolve_work_packages_service.rb+++ b/modules/calendar/app/services/calendar/resolve_work_packages_service.rb@@ -28,25 +28,23 @@module Calendarclass ResolveWorkPackagesService < ::BaseServices::BaseCallable-def perform(query:)- unless(- query.nil? ||+ unless+ query.nil? ||query.results.nil?- )+# TODO: check if the includes makes sense here in order to avoid n+1 querieswork_packages = query.results.work_packages.includes(:project, :assigned_to, :author, :priority, :status)end- unless work_packages.nil?- ServiceResult.success(result: work_packages)+ if work_packages.nil?+ # TODO: raise specific error+ raise ActiveRecord::RecordNotFoundelse- # TODO: raise specific error- raise ActiveRecord::RecordNotFound+ ServiceResult.success(result: work_packages)endend-endenddiff --git a/modules/calendar/config/routes.rb b/modules/calendar/config/routes.rbindex f8197a07426..df7feeff726 100644--- a/modules/calendar/config/routes.rb+++ b/modules/calendar/config/routes.rb@@ -11,4 +11,4 @@ OpenProject::Application.routes.draw doget '(/*state)' => 'calendar/calendars#show', on: :member, as: ''endend-end\ No newline at end of file+enddiff --git a/modules/calendar/spec/controllers/ical_controller_spec.rb b/modules/calendar/spec/controllers/ical_controller_spec.rbindex 6e54705ee16..807dfcbbc3d 100644--- a/modules/calendar/spec/controllers/ical_controller_spec.rb+++ b/modules/calendar/spec/controllers/ical_controller_spec.rb@@ -30,17 +30,17 @@ require 'spec_helper'describe Calendar::IcalController dolet(:project) { create(:project) }- let(:user) do+ let(:user) docreate(:user,- member_in_project: project,- member_with_permissions: sufficient_permissions)+ member_in_project: project,+ member_with_permissions: sufficient_permissions)endlet(:sufficient_permissions) { %i[view_work_packages share_calendars] }let(:valid_ical_token_value) { Token::Ical.create_and_return_value user }let(:query) docreate(:query,- project: project,- user: user,+ project:,+ user:,public: false)end@@ -57,29 +57,26 @@ describe Calendar::IcalController doif expected == :failureit { is_expected.not_to be_successful }end-endcontext 'with valid params' do-before do- get :ical, params: {- project_id: project.id,- id: query.id,- ical_token: valid_ical_token_value }-+ get :ical, params: {+ project_id: project.id,+ id: query.id,+ ical_token: valid_ical_token_value+ }endit_behaves_like 'ical#ical', :successendcontext 'with invalid token' do-before do- get :ical, params: {- project_id: project.id,- id: query.id,- ical_token: SecureRandom.hex+ get :ical, params: {+ project_id: project.id,+ id: query.id,+ ical_token: SecureRandom.hex}end@@ -87,25 +84,23 @@ describe Calendar::IcalController doendcontext 'with invalid query' do-before do- get :ical, params: {- project_id: project.id,- id: SecureRandom.hex,- ical_token: valid_ical_token_value+ get :ical, params: {+ project_id: project.id,+ id: SecureRandom.hex,+ ical_token: valid_ical_token_value}endit_behaves_like 'ical#ical', :failureend-+context 'with invalid project' do-before do- get :ical, params: {- project_id: SecureRandom.hex,- id: query.id,- ical_token: valid_ical_token_value+ get :ical, params: {+ project_id: SecureRandom.hex,+ id: query.id,+ ical_token: valid_ical_token_value}enddiff --git a/modules/calendar/spec/features/calendar_sharing_spec.rb b/modules/calendar/spec/features/calendar_sharing_spec.rbindex d0af561911a..0482fc1520d 100644--- a/modules/calendar/spec/features/calendar_sharing_spec.rb+++ b/modules/calendar/spec/features/calendar_sharing_spec.rb@@ -33,7 +33,7 @@ describe 'Calendar sharing via ical', js: true doinclude_context 'with calendar full access'let!(:user_with_sharing_permission) do- create :user,+ create(:user,firstname: 'Bernd',member_in_project: project,member_with_permissions: %w[@@ -44,11 +44,11 @@ describe 'Calendar sharing via ical', js: true doview_calendarmanage_calendarsshare_calendars- ]+ ])endlet!(:user_without_sharing_permission) do- create :user,+ create(:user,firstname: 'Bernd',member_in_project: project,member_with_permissions: %w[@@ -58,7 +58,7 @@ describe 'Calendar sharing via ical', js: true dosave_public_queriesview_calendarmanage_calendars- ]+ ])endlet(:saved_query) do@@ -68,8 +68,7 @@ describe 'Calendar sharing via ical', js: true dopublic: false)end- context 'user with sufficient permissions' do-+ context 'with sufficient permissions' do# TODO: save_queries permission is mandatory to see settings button used for sharing option# does that make sense? the sharing feature therefore has an implicit dependency on this permission@@ -79,7 +78,6 @@ describe 'Calendar sharing via ical', js: true doendcontext 'on not persisted calendar query' do-it 'shows disabled sharing menu item' dovisit project_calendars_path(project)@@ -89,23 +87,21 @@ describe 'Calendar sharing via ical', js: true doexpect(page).to have_selector("#work-packages-settings-button")# click on settings button- page.find("#work-packages-settings-button").click+ page.find_by_id('work-packages-settings-button').click# expect disabled sharing menu itemwithin "#settingsDropdown" do- # expect(page).to have_button("Share iCalendar ...", disabled: true) # disabled selector not working- expect(page).to have_selector(".menu-item.inactive", text: "Share iCalendar ...")- page.click_button("Share iCalendar ...")+ # expect(page).to have_button("Share iCalendar", disabled: true) # disabled selector not working+ expect(page).to have_selector(".menu-item.inactive", text: "Share iCalendar")+ page.click_button("Share iCalendar")# modal should not be shown- expect(page).not_to have_selector('.spot-modal--header', text: "Share calendar")+ expect(page).not_to have_selector('.spot-modal--header', text: "Share iCalendar")end-endendcontext 'on persisted calendar query' do-it 'shows sharing menu item and sharing modal if clicked' dosaved_query@@ -121,14 +117,13 @@ describe 'Calendar sharing via ical', js: true doexpect(page).to have_selector("#work-packages-settings-button")# click on settings button- page.find("#work-packages-settings-button").click+ page.find_by_id('work-packages-settings-button').click# expect disabled sharing menu itemwithin "#settingsDropdown" do- # expect(page).to have_button("Share iCalendar ...", disabled: true) # disabled selector not working- expect(page).to have_selector(".menu-item", text: "Share iCalendar ...")- page.click_button("Share iCalendar ...")-+ # expect(page).to have_button("Share iCalendar", disabled: true) # disabled selector not working+ expect(page).to have_selector(".menu-item", text: "Share iCalendar")+ page.click_button("Share iCalendar")endexpect(page).to have_selector('.spot-modal--header', text: "Share iCalendar")@@ -144,18 +139,15 @@ describe 'Calendar sharing via ical', js: true do# https://copyprogramming.com/howto/emulating-a-clipboard-copy-paste-with-selinum-capybaraendend-end- context 'user without sufficient permissions' do-+ context 'without sufficient permissions' dobefore dologin_as user_without_sharing_permissioncalendar.visit!endcontext 'on persisted calendar query' do-it 'shows disabled sharing menu item' dovisit project_calendars_path(project)@@ -165,22 +157,18 @@ describe 'Calendar sharing via ical', js: true doexpect(page).to have_selector("#work-packages-settings-button")# click on settings button- page.find("#work-packages-settings-button").click+ page.find_by_id('work-packages-settings-button').click# expect disabled sharing menu itemwithin "#settingsDropdown" do- # expect(page).to have_button("Share iCalendar ...", disabled: true) # disabled selector not working- expect(page).to have_selector(".menu-item.inactive", text: "Share iCalendar ...")- page.click_button("Share iCalendar ...")+ # expect(page).to have_button("Share iCalendar", disabled: true) # disabled selector not working+ expect(page).to have_selector(".menu-item.inactive", text: "Share iCalendar")+ page.click_button("Share iCalendar")# modal should not be shown- expect(page).not_to have_selector('.spot-modal--header', text: "Share calendar")+ expect(page).not_to have_selector('.spot-modal--header', text: "Share iCalendar")end-end-end-end-enddiff --git a/modules/calendar/spec/features/calendars_spec.rb b/modules/calendar/spec/features/calendars_spec.rbindex 176aee3d8ae..c0c53de7391 100644--- a/modules/calendar/spec/features/calendars_spec.rb+++ b/modules/calendar/spec/features/calendars_spec.rb@@ -39,29 +39,29 @@ describe 'Work package calendars', js: true docreate(:work_package,subject: 'Current work package',project:,- start_date: Date.today.at_beginning_of_month + 15.days,- due_date: Date.today.at_beginning_of_month + 15.days)+ start_date: Time.zone.today.at_beginning_of_month + 15.days,+ due_date: Time.zone.today.at_beginning_of_month + 15.days)endlet!(:another_current_work_package) docreate(:work_package,subject: 'Another current work package',project:,- start_date: Date.today.at_beginning_of_month + 12.days,- due_date: Date.today.at_beginning_of_month + 18.days)+ start_date: Time.zone.today.at_beginning_of_month + 12.days,+ due_date: Time.zone.today.at_beginning_of_month + 18.days)endlet!(:future_work_package) docreate(:work_package,subject: 'Future work package',project:,- start_date: Date.today.at_beginning_of_month.next_month + 15.days,- due_date: Date.today.at_beginning_of_month.next_month + 15.days)+ start_date: Time.zone.today.at_beginning_of_month.next_month + 15.days,+ due_date: Time.zone.today.at_beginning_of_month.next_month + 15.days)endlet!(:another_future_work_package) docreate(:work_package,subject: 'Another future work package',project:,- start_date: Date.today.at_beginning_of_month.next_month + 12.days,- due_date: Date.today.at_beginning_of_month.next_month + 18.days)+ start_date: Time.zone.today.at_beginning_of_month.next_month + 12.days,+ due_date: Time.zone.today.at_beginning_of_month.next_month + 18.days)endlet(:filters) { Components::WorkPackages::Filters.new }let(:current_wp_split_screen) { Pages::SplitWorkPackage.new(current_work_package, project) }diff --git a/modules/calendar/spec/routing/calendar_routing_spec.rb b/modules/calendar/spec/routing/calendar_routing_spec.rbindex 6ec12551b98..b811f716a9c 100644--- a/modules/calendar/spec/routing/calendar_routing_spec.rb+++ b/modules/calendar/spec/routing/calendar_routing_spec.rb@@ -51,8 +51,8 @@ describe Calendar::CalendarsController doit doexpect(get('/projects/1/calendars/2/ical')).to route_to(controller: 'calendar/ical',- action: 'ical',- id: '2',- project_id: '1')+ action: 'ical',+ id: '2',+ project_id: '1')endenddiff --git a/modules/calendar/spec/routing/ical_routing_spec.rb b/modules/calendar/spec/routing/ical_routing_spec.rbindex 81235ab16c1..0e889759367 100644--- a/modules/calendar/spec/routing/ical_routing_spec.rb+++ b/modules/calendar/spec/routing/ical_routing_spec.rb@@ -31,8 +31,8 @@ require 'spec_helper'describe Calendar::IcalController doit doexpect(get('/projects/1/calendars/2/ical')).to route_to(controller: 'calendar/ical',- action: 'ical',- id: '2',- project_id: '1')+ action: 'ical',+ id: '2',+ project_id: '1')endenddiff --git a/modules/calendar/spec/services/create_ical_service_spec.rb b/modules/calendar/spec/services/create_ical_service_spec.rbindex a5b1b256acf..32c0fae042c 100644--- a/modules/calendar/spec/services/create_ical_service_spec.rb+++ b/modules/calendar/spec/services/create_ical_service_spec.rb@@ -29,30 +29,29 @@require 'spec_helper'describe Calendar::CreateIcalService, type: :model do-let(:project) { create(:project) }let(:user) { create(:user) }- let(:work_package_without_dates) do- create(:work_package, project: project)+ let(:work_package_without_dates) do+ create(:work_package, project:)end- let(:work_package_with_due_date) do- create(:work_package, project: project,- due_date: Date.today+7.days)+ let(:work_package_with_due_date) do+ create(:work_package, project:,+ due_date: Time.zone.today + 7.days)end- let(:work_package_with_start_date) do- create(:work_package, project: project,- start_date: Date.today+14.days)+ let(:work_package_with_start_date) do+ create(:work_package, project:,+ start_date: Time.zone.today + 14.days)end- let(:work_package_with_start_and_due_date) do- create(:work_package, project: project,- start_date: Date.tomorrow, due_date: Date.today+7.days)+ let(:work_package_with_start_and_due_date) do+ create(:work_package, project:,+ start_date: Date.tomorrow, due_date: Time.zone.today + 7.days)end- let(:work_package_with_due_date_and_assignee) do- create(:work_package, project: project,- due_date: Date.today+30.days, assigned_to: user )+ let(:work_package_with_due_date_and_assignee) do+ create(:work_package, project:,+ due_date: Time.zone.today + 30.days, assigned_to: user)end- let(:work_packages) do+ let(:work_packages) do[work_package_without_dates,work_package_with_due_date,@@ -62,91 +61,87 @@ describe Calendar::CreateIcalService, type: :model do]endlet(:query_name) { "Query Name" }-+let(:instance) do- described_class.new()+ described_class.newendlet(:freezed_date_time) { DateTime.now }- context 'converts work_packages to an ical string' do-- before(:each) do- Timecop.freeze(freezed_date_time)- end-- subject do- instance.call(- work_packages: work_packages,- calendar_name: query_name- )- end-- it 'which contains all required ical fields in the correct format and order' do-- expected_ical_string = <<-EOICAL.gsub("\r ", "").gsub("\r", "")-BEGIN:VCALENDAR-VERSION:2.0-PRODID:-//OpenProject GmbH//OpenProject Core Project//EN-CALSCALE:GREGORIAN-X-WR-CALNAME:#{query_name}-BEGIN:VEVENT-DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}Z-UID:#{work_package_with_due_date.id}@localhost:3000-DTSTART;VALUE=DATE:#{work_package_with_due_date.due_date.strftime('%Y%m%d')}-DTEND;VALUE=DATE:#{(work_package_with_due_date.due_date+1.day).strftime('%Y%m%d')}-DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_due_date.status.name}\nAssignee: \nPriority: #{work_package_with_due_date.priority.name}\n\nDescription:\n #{work_package_with_due_date.description}-LOCATION:http://localhost:3000/work_packages/#{work_package_with_due_date.id}-ORGANIZER:Bob Bobbit-SUMMARY:#{work_package_with_due_date.name}-END:VEVENT-BEGIN:VEVENT-DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}Z-UID:#{work_package_with_start_date.id}@localhost:3000-DTSTART;VALUE=DATE:#{work_package_with_start_date.start_date.strftime('%Y%m%d')}-DTEND;VALUE=DATE:#{(work_package_with_start_date.start_date+1.day).strftime('%Y%m%d')}-DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_start_date.status.name}\nAssignee: \nPriority: #{work_package_with_start_date.priority.name}\n\nDescription:\n #{work_package_with_start_date.description}-LOCATION:http://localhost:3000/work_packages/#{work_package_with_start_date.id}-ORGANIZER:Bob Bobbit-SUMMARY:#{work_package_with_start_date.name}-END:VEVENT-BEGIN:VEVENT-DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}Z-UID:#{work_package_with_start_and_due_date.id}@localhost:3000-DTSTART;VALUE=DATE:#{work_package_with_start_and_due_date.start_date.strftime('%Y%m%d')}-DTEND;VALUE=DATE:#{(work_package_with_start_and_due_date.due_date+1.day).strftime('%Y%m%d')}-DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_start_and_due_date.status.name}\nAssignee: \nPriority: #{work_package_with_start_and_due_date.priority.name}\n\nDescription:\n #{work_package_with_start_and_due_date.description}-LOCATION:http://localhost:3000/work_packages/#{work_package_with_start_and_due_date.id}-ORGANIZER:Bob Bobbit-SUMMARY:#{work_package_with_start_and_due_date.name}-END:VEVENT-BEGIN:VEVENT-DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}Z-UID:#{work_package_with_due_date_and_assignee.id}@localhost:3000-DTSTART;VALUE=DATE:#{work_package_with_due_date_and_assignee.due_date.strftime('%Y%m%d')}-DTEND;VALUE=DATE:#{(work_package_with_due_date_and_assignee.due_date+1.day).strftime('%Y%m%d')}-DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_due_date_and_assignee.status.name}\nAssignee: #{work_package_with_due_date_and_assignee.assigned_to.name}\nPriority: #{work_package_with_due_date_and_assignee.priority.name}\n\nDescription:\n #{work_package_with_due_date_and_assignee.description}-LOCATION:http://localhost:3000/work_packages/#{work_package_with_due_date_and_assignee.id}-ORGANIZER:Bob Bobbit-SUMMARY:#{work_package_with_due_date_and_assignee.name}-ATTENDEE:#{work_package_with_due_date_and_assignee.assigned_to.name}-END:VEVENT-END:VCALENDAR- EOICAL+ before do+ Timecop.freeze(freezed_date_time)+ end- expect(subject.result.gsub("\r\n ", "").gsub("\r", "").gsub("\\n", "\n"))- .to eql(expected_ical_string)- end+ subject do+ instance.call(+ work_packages:,+ calendar_name: query_name+ )+ end- it 'is a success' do- expect(subject)- .to be_success- end+ after do+ Timecop.return+ end- after(:each) do- Timecop.return- end+ # rubocop:disable RSpec/ExampleLength+ it 'converts work_packages to an ical string which contains all required ical fields in the correct format and order' do+ expected_ical_string = <<~EOICAL.gsub("\r ", "").gsub("\r", "")+ BEGIN:VCALENDAR+ VERSION:2.0+ PRODID:-//OpenProject GmbH//OpenProject Core Project//EN+ CALSCALE:GREGORIAN+ X-WR-CALNAME:#{query_name}+ BEGIN:VEVENT+ DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}Z+ UID:#{work_package_with_due_date.id}@localhost:3000+ DTSTART;VALUE=DATE:#{work_package_with_due_date.due_date.strftime('%Y%m%d')}+ DTEND;VALUE=DATE:#{(work_package_with_due_date.due_date + 1.day).strftime('%Y%m%d')}+ DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_due_date.status.name}\nAssignee: \nPriority: #{work_package_with_due_date.priority.name}\n\nDescription:\n #{work_package_with_due_date.description}+ LOCATION:http://localhost:3000/work_packages/#{work_package_with_due_date.id}+ ORGANIZER:Bob Bobbit+ SUMMARY:#{work_package_with_due_date.name}+ END:VEVENT+ BEGIN:VEVENT+ DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}Z+ UID:#{work_package_with_start_date.id}@localhost:3000+ DTSTART;VALUE=DATE:#{work_package_with_start_date.start_date.strftime('%Y%m%d')}+ DTEND;VALUE=DATE:#{(work_package_with_start_date.start_date + 1.day).strftime('%Y%m%d')}+ DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_start_date.status.name}\nAssignee: \nPriority: #{work_package_with_start_date.priority.name}\n\nDescription:\n #{work_package_with_start_date.description}+ LOCATION:http://localhost:3000/work_packages/#{work_package_with_start_date.id}+ ORGANIZER:Bob Bobbit+ SUMMARY:#{work_package_with_start_date.name}+ END:VEVENT+ BEGIN:VEVENT+ DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}Z+ UID:#{work_package_with_start_and_due_date.id}@localhost:3000+ DTSTART;VALUE=DATE:#{work_package_with_start_and_due_date.start_date.strftime('%Y%m%d')}+ DTEND;VALUE=DATE:#{(work_package_with_start_and_due_date.due_date + 1.day).strftime('%Y%m%d')}+ DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_start_and_due_date.status.name}\nAssignee: \nPriority: #{work_package_with_start_and_due_date.priority.name}\n\nDescription:\n #{work_package_with_start_and_due_date.description}+ LOCATION:http://localhost:3000/work_packages/#{work_package_with_start_and_due_date.id}+ ORGANIZER:Bob Bobbit+ SUMMARY:#{work_package_with_start_and_due_date.name}+ END:VEVENT+ BEGIN:VEVENT+ DTSTAMP:#{freezed_date_time.strftime('%Y%m%dT%H%M%S')}Z+ UID:#{work_package_with_due_date_and_assignee.id}@localhost:3000+ DTSTART;VALUE=DATE:#{work_package_with_due_date_and_assignee.due_date.strftime('%Y%m%d')}+ DTEND;VALUE=DATE:#{(work_package_with_due_date_and_assignee.due_date + 1.day).strftime('%Y%m%d')}+ DESCRIPTION:Project: #{project.name}\nType: None\nStatus: #{work_package_with_due_date_and_assignee.status.name}\nAssignee: #{work_package_with_due_date_and_assignee.assigned_to.name}\nPriority: #{work_package_with_due_date_and_assignee.priority.name}\n\nDescription:\n #{work_package_with_due_date_and_assignee.description}+ LOCATION:http://localhost:3000/work_packages/#{work_package_with_due_date_and_assignee.id}+ ORGANIZER:Bob Bobbit+ SUMMARY:#{work_package_with_due_date_and_assignee.name}+ ATTENDEE:#{work_package_with_due_date_and_assignee.assigned_to.name}+ END:VEVENT+ END:VCALENDAR+ EOICAL+ expect(subject.result.gsub("\r\n ", "").gsub("\r", "").gsub("\\n", "\n"))+ .to eql(expected_ical_string)end+ # rubocop:enable RSpec/ExampleLength+ it 'is a success' do+ expect(subject)+ .to be_success+ endenddiff --git a/modules/calendar/spec/services/resolve_and_authorize_query_spec.rb b/modules/calendar/spec/services/resolve_and_authorize_query_spec.rbindex 11741eac1b6..e65fd579b2d 100644--- a/modules/calendar/spec/services/resolve_and_authorize_query_spec.rb+++ b/modules/calendar/spec/services/resolve_and_authorize_query_spec.rb@@ -29,17 +29,17 @@require 'spec_helper'describe Calendar::ResolveAndAuthorizeQueryService, type: :model do- let(:user_1) do+ let(:user1) docreate(:user,member_in_project: project,member_with_permissions: sufficient_permissions)end- let(:user_2_without_permission) do+ let(:user2_without_permission) docreate(:user,member_in_project: project,member_with_permissions: insufficient_permissions)end- let(:user_3_not_member) do+ let(:user3_not_member) docreate(:user,member_in_project: nil)end@@ -48,24 +48,23 @@ describe Calendar::ResolveAndAuthorizeQueryService, type: :model dolet(:project) { create(:project) }let(:query) docreate(:query,- project: project,- user: user_1,+ project:,+ user: user1,public: false)end-+let(:instance) do- described_class.new()+ described_class.newend- context 'resolves a query by a given query id if authenticated and permitted to share via ical url' do-+ context 'if authenticated and permitted to share via ical url' dobefore do- login_as(user_1)+ login_as(user1)end- subject { instance.call(user: user_1, query_id: query.id) }+ subject { instance.call(user: user1, query_id: query.id) }- it 'returns query as result ' do+ it 'resolves a query by a given query id and returns query as result' doexpect(subject.result).to eq queryend@@ -74,55 +73,53 @@ describe Calendar::ResolveAndAuthorizeQueryService, type: :model doexpect(subject).to be_successend-end-- context 'does not a query by a given query id if not authenticated' do+ context 'if not authenticated' dobefore do- login_as(user_2_without_permission)+ login_as(user2_without_permission)end- subject { instance.call(user: user_2_without_permission, query_id: query.id) }+ subject { instance.call(user: user2_without_permission, query_id: query.id) }- it 'raises ActiveRecord::RecordNotFound' do+ it 'does not resolve a query by a given query id and raises ActiveRecord::RecordNotFound' doexpect { subject }.to raise_error(ActiveRecord::RecordNotFound)end-end-- context 'does not resolve a query by a given query id if not member of project' do+ context 'if not member of project' dobefore do- login_as(user_3_not_member)+ login_as(user3_not_member)end- subject { instance.call(user: user_3_not_member, query_id: query.id) }+ subject { instance.call(user: user3_not_member, query_id: query.id) }- it 'raises ActiveRecord::RecordNotFound' do+ it 'does not resolve a query by a given query id and raises ActiveRecord::RecordNotFound' doexpect { subject }.to raise_error(ActiveRecord::RecordNotFound)end-end- context 'does not resolve query id is' do-+ context 'if query id is invalid' dobefore do- login_as(user_1)+ login_as(user1)end- subject { instance.call(user: user_1, query_id: SecureRandom.hex) }+ subject { instance.call(user: user1, query_id: SecureRandom.hex) }- it 'invalid and raises ActiveRecord::RecordNotFound' do+ it 'does not resolve query and raises ActiveRecord::RecordNotFound' doexpect { subject }.to raise_error(ActiveRecord::RecordNotFound)end+ end++ context 'if query id is nil' do+ before do+ login_as(user1)+ end- subject { instance.call(user: user_1, query_id: nil) }+ subject { instance.call(user: user1, query_id: nil) }- it 'nil and raises ActiveRecord::RecordNotFound' do+ it 'does not resolve query and raises ActiveRecord::RecordNotFound' doexpect { subject }.to raise_error(ActiveRecord::RecordNotFound)end-end-enddiff --git a/modules/calendar/spec/services/resolve_ical_user_service_spec.rb b/modules/calendar/spec/services/resolve_ical_user_service_spec.rbindex 445f7b7e403..9fd070e2368 100644--- a/modules/calendar/spec/services/resolve_ical_user_service_spec.rb+++ b/modules/calendar/spec/services/resolve_ical_user_service_spec.rb@@ -32,13 +32,12 @@ describe Calendar::ResolveIcalUserService, type: :model dolet(:user) { create(:user) }let(:valid_ical_token_value) { Token::Ical.create_and_return_value user }let(:invalid_ical_token_value) { valid_ical_token_value[0..-2] }-+let(:instance) do- described_class.new()+ described_class.newend- context 'resolves a user by a given valid ical token value' do-+ context 'for a given valid ical token value' dosubject { instance.call(ical_token: valid_ical_token_value) }it 'resolves the user as result' do@@ -50,27 +49,21 @@ describe Calendar::ResolveIcalUserService, type: :model doexpect(subject).to be_successend-end- context 'handles error when given ical token value is invalid' do-+ context 'when given ical token value is invalid' dosubject { instance.call(ical_token: invalid_ical_token_value) }it 'raises ActiveRecord::RecordNotFound' doexpect { subject }.to raise_error(ActiveRecord::RecordNotFound)end-end- context 'handles error when no ical token value is given' do-+ context 'when no ical token value is given' dosubject { instance.call(ical_token: nil) }it 'raises ActiveRecord::RecordNotFound' doexpect { subject }.to raise_error(ActiveRecord::RecordNotFound)end-end-enddiff --git a/modules/calendar/spec/services/resolve_work_packages_service_spec.rb b/modules/calendar/spec/services/resolve_work_packages_service_spec.rbindex 9c015931c1a..0bef4c9e8a7 100644--- a/modules/calendar/spec/services/resolve_work_packages_service_spec.rb+++ b/modules/calendar/spec/services/resolve_work_packages_service_spec.rb@@ -29,34 +29,33 @@require 'spec_helper'describe Calendar::ResolveWorkPackagesService, type: :model do- let(:user_1) do+ let(:user1) docreate(:user,member_in_project: project,member_with_permissions: permissions)endlet(:permissions) { %i[view_work_packages] }- let(:project) { create(:project, work_packages: [work_package_1]) }- let(:work_package_1) { create(:work_package) }+ let(:project) { create(:project, work_packages: [work_package1]) }+ let(:work_package1) { create(:work_package) }let(:query) docreate(:query,- project: project,- user: user_1,+ project:,+ user: user1,public: false)end-+let(:instance) do- described_class.new()+ described_class.newend- context 'resolves work_packages of a query' do-+ context 'for a valid query' dobefore do- login_as(user_1)+ login_as(user1)end- subject { instance.call(query: query) }+ subject { instance.call(query:) }- it 'returns work_packages of query as result ' do+ it 'returns work_packages of query as result' doexpect(subject.result).to match_array(query.results.work_packages)end@@ -65,21 +64,17 @@ describe Calendar::ResolveWorkPackagesService, type: :model doexpect(subject).to be_successend-end- context 'does not resolve work_packages if query is' do-+ context 'if query is nil' dobefore do- login_as(user_1)+ login_as(user1)end- subject { instance.call(query: nil) }+ subject { instance.call(query: nil) }- it 'nil and raises ActiveRecord::RecordNotFound' do+ it 'does not resolve work_packages and raises ActiveRecord::RecordNotFound' doexpect { subject }.to raise_error(ActiveRecord::RecordNotFound)end-end-end