diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index e51fa5496..480f40edf 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -168,16 +168,17 @@ class MyModulesController < ApplicationController if due_date_changes # rubocop:disable Metrics/BlockNesting # temporary solution type_of = if due_date_changes[0].nil? # set due_date + message_items = { my_module_duedate: @my_module.due_date } :set_task_due_date elsif due_date_changes[1].nil? # remove due_date + message_items = { my_module_duedate: due_date_changes[0] } :remove_task_due_date else # change due_date + message_items = { my_module_duedate: @my_module.due_date } :change_task_due_date end # rubocop:enable Metrics/BlockNesting - log_activity(type_of, @my_module, my_module_duedate: { id: @my_module.id, - value_for: 'due_date', - value_type: 'time' }) + log_activity(type_of, @my_module, message_items) end end end diff --git a/app/helpers/global_activities_helper.rb b/app/helpers/global_activities_helper.rb index fdafa8f36..69c9a3b69 100644 --- a/app/helpers/global_activities_helper.rb +++ b/app/helpers/global_activities_helper.rb @@ -11,8 +11,8 @@ module GlobalActivitiesHelper parameters[key] = if value.is_a? String value - elsif value[:value_type] == 'time' # use saved date for printing - l(Time.parse(value[:value]), format: :full_date) + elsif value[:type] == 'Time' # use saved date for printing + l(Time.at(value[:value]), format: :full_date) else no_links ? generate_name(value) : generate_link(value, activity) end diff --git a/app/services/activities/create_activity_service.rb b/app/services/activities/create_activity_service.rb index 926a15735..ebdcd6a22 100644 --- a/app/services/activities/create_activity_service.rb +++ b/app/services/activities/create_activity_service.rb @@ -38,6 +38,14 @@ module Activities def enrich_message_items @message_items.each do |k, v| + if v.is_a? Time + @activity.message_items[k] = { + type: 'Time', + value: v.to_i + } + next + end + const = try_to_constantize k if const if v.is_a?(Hash) # Value is array, so you have getter specified @@ -50,11 +58,7 @@ module Activities end obj = const.find id - @activity.message_items[k] = { - type: const.to_s, - value: obj.public_send(getter_method).to_s, - id: id - } + @activity.message_items[k] = { type: const.to_s, value: obj.public_send(getter_method).to_s, id: id } @activity.message_items[k][:value_for] = getter_method @activity.message_items[k][:value_type] = value_type unless value_type.nil? else diff --git a/spec/services/activities/create_activity_service_spec.rb b/spec/services/activities/create_activity_service_spec.rb index 5782fc952..fcd3e1f12 100644 --- a/spec/services/activities/create_activity_service_spec.rb +++ b/spec/services/activities/create_activity_service_spec.rb @@ -103,8 +103,8 @@ describe Activities::CreateActivityService do end context 'when message item is an object with custom value getter' do - it 'adds project due date to message items as hash' do - project.update_attribute(:due_date, Date.tomorrow) + it 'adds project visibility to message items as hash' do + project.update_attribute(:visibility, 'hidden') activity = Activities::CreateActivityService .call(activity_type: :create_project, @@ -112,16 +112,31 @@ describe Activities::CreateActivityService do subject: project, team: team, message_items: { - project_duedate: { id: project.id, - value_for: 'due_date', value_type: 'time' } + project_visibility: { id: project.id, value_for: 'visibility' } }).activity expect(activity.message_items) - .to include(project_duedate: { id: project.id, - type: 'Project', - value_for: 'due_date', - value_type: 'time', - value: project.due_date.to_s }) + .to include(project_visibility: { id: project.id, + type: 'Project', + value_for: 'visibility', + value: project.visibility }) + end + end + + context 'when message item is an Time object' do + it 'adds time value and type to message items as hash' do + project.update_attribute(:visibility, 'hidden') + project.update_attribute(:due_date, Time.now) + + activity = Activities::CreateActivityService.call(activity_type: :create_project, + owner: user, + subject: project, + team: team, + message_items: { + project_duedate: project.due_date + }).activity + + expect(activity.message_items).to include(project_duedate: { type: 'Time', value: project.due_date.to_i }) end end end