fixup! Show date actual value without link

This commit is contained in:
Urban Rotnik 2019-04-02 14:21:06 +02:00
parent 8eaeeee9f8
commit 86ddbc68b6
4 changed files with 39 additions and 19 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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