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
Adjust remind_at param to be consistent with form behaviour
Kabiru Mwenjae74f25a7df66
diff --git a/app/services/reminders/set_attributes_service.rb b/app/services/reminders/set_attributes_service.rbindex af6afe5f4a7..6c52a2f3708 100644--- a/app/services/reminders/set_attributes_service.rb+++ b/app/services/reminders/set_attributes_service.rb@@ -31,17 +31,14 @@module Remindersclass SetAttributesService < ::BaseServices::SetAttributesdef perform(params = {})- remind_at_date = params.delete(:remind_at_date)- remind_at_time = params.delete(:remind_at_time)+ remind_at_params = params.extract!(:remind_at_date, :remind_at_time)- if remind_at_date.present? && remind_at_time.present?- params[:remind_at] = User.current.time_zone.parse("#{remind_at_date} #{remind_at_time}")- end+ build_remind_at_from_params(params, remind_at_params) unless params.key?(:remind_at)contract_call = superif contract_call.failure?- prepare_errors_from_result({ remind_at_date:, remind_at_time: }, contract_call)+ prepare_errors_from_result(remind_at_params, contract_call)endcontract_call@@ -49,6 +46,14 @@ module Remindersprivate+ def build_remind_at_from_params(params, remind_at_params)+ return params if remind_at_params.empty?++ date = remind_at_params[:remind_at_date]+ time = remind_at_params[:remind_at_time]+ params[:remind_at] = date.present? && time.present? ? User.current.time_zone.parse("#{date} #{time}") : nil+ end+# At the form level, we split the date and time into two form fields.# In order to be a bit more informative of which field is causing# the remind_at attribute to be in the past/invalid, we need todiff --git a/spec/features/work_packages/reminders_spec.rb b/spec/features/work_packages/reminders_spec.rbindex 7d0a6824770..c3988842868 100644--- a/spec/features/work_packages/reminders_spec.rb+++ b/spec/features/work_packages/reminders_spec.rb@@ -135,7 +135,7 @@ RSpec.describe "Work package reminder modal",expect(Reminder.upcoming_and_visible_to(user_with_permissions).count).to eq(0)end- it "renders an error flash when the reminder modal is opened in edit mode" \+ it "renders an error flash when the reminder modal is opened in edit mode " \"and the notification for it is fired and subsequently clicking save",with_settings: { notifications_polling_interval: 1_000 } doReminders::CreateService.new(user: current_user).call(@@ -336,6 +336,19 @@ RSpec.describe "Work package reminder modal",expect(page).to have_field("Time", with: reminder.remind_at.in_time_zone(current_user.time_zone).strftime("%H:%M"))expect(page).to have_field("Note", with: reminder.note)expect(page).to have_button("Save")++ # Edit form renders validation errors+ fill_in "Date", with: ""+ fill_in "Time", with: ""++ click_link_or_button "Save"++ wait_for_network_idle+ expect(page).to have_css(".FormControl-inlineValidation", text: "Date can't be blank.")+ expect(page).to have_css(".FormControl-inlineValidation", text: "Time can't be blank.")+ expect(page).to have_field("Date", with: "")+ expect(page).to have_field("Time", with: "09:00") # Default time+ expect(page).to have_field("Note", with: reminder.note)endendenddiff --git a/spec/services/reminders/set_attributes_service_spec.rb b/spec/services/reminders/set_attributes_service_spec.rbindex bc2ee7f23d5..1f49dcd2914 100644--- a/spec/services/reminders/set_attributes_service_spec.rb+++ b/spec/services/reminders/set_attributes_service_spec.rb@@ -64,6 +64,28 @@ RSpec.describe Reminders::SetAttributesService do)end+ context "when the `remind_at` attribute is specified" do+ it "does not override the remind_at attribute", :freeze_time do+ params = {+ remind_at: current_user.time_zone.parse("2027-10-01 08:00"),+ remind_at_date: "2023-10-01",+ remind_at_time: "12:00",+ note: "Some notes",+ remindable:,+ creator: user+ }++ model_result = service.perform(params).result++ expect(model_result).to have_attributes(+ remind_at: current_user.time_zone.parse("2027-10-01 08:00"),+ note: "Some notes",+ remindable:,+ creator: user+ )+ end+ end+context "when remind_at_date or remind_at_time is not provided" doit "does not set the remind_at attribute" doaggregate_failures "one is nil" do@@ -82,6 +104,20 @@ RSpec.describe Reminders::SetAttributesService doendendend++ context "when the model instance already has a remind_at set" do+ let(:model_instance) { build_stubbed(:reminder, remind_at: 1.day.from_now) }++ context "and neither remind_at, remind_at_date nor remind_at_time are provided" do+ it "does not change the remind_at attribute" do+ contract_call = service.perform({})++ model_result = contract_call.result+ expect(model_result.remind_at).to eq(model_instance.remind_at)+ expect(model_result.remind_at).to be_present+ end+ end+ endenddescribe "Error results handling" do