Merge pull request #2521 from opf/fix/autoloading_date_time_formatter

Fix auto loading of DateTimeFormatter in development mode
pull/2541/head
Alex Coles 10 years ago
commit 6930247b51
  1. 4
      lib/api/decorators/single.rb
  2. 3
      lib/api/v3/activities/activity_representer.rb
  3. 1
      lib/api/v3/attachments/attachment_representer.rb
  4. 8
      lib/api/v3/projects/project_representer.rb
  5. 8
      lib/api/v3/users/user_representer.rb
  6. 18
      lib/api/v3/versions/version_representer.rb
  7. 14
      lib/api/v3/work_packages/form/work_package_payload_representer.rb
  8. 24
      lib/api/v3/work_packages/work_package_representer.rb
  9. 1
      spec/lib/api/v3/utilities/date_time_formatter_spec.rb

@ -53,6 +53,10 @@ module API
private
def datetime_formatter
API::V3::Utilities::DateTimeFormatter
end
def _type; end
end
end

@ -29,7 +29,8 @@
require 'roar/decorator'
require 'roar/json/hal'
require 'api/v3/utilities/date_time_formatter'
API::V3::Utilities::DateTimeFormatter
module API
module V3

@ -29,7 +29,6 @@
require 'roar/decorator'
require 'roar/json/hal'
require 'api/v3/utilities/date_time_formatter'
module API
module V3

@ -29,13 +29,11 @@
require 'roar/decorator'
require 'roar/json/hal'
require 'api/v3/utilities/date_time_formatter'
module API
module V3
module Projects
class ProjectRepresenter < ::API::Decorators::Single
include API::V3::Utilities
link :self do
{
@ -61,10 +59,12 @@ module API
property :created_on,
as: 'createdAt',
getter: -> (*) { DateTimeFormatter::format_datetime(created_on) }
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.created_on) }
property :updated_on,
as: 'updatedAt',
getter: -> (*) { DateTimeFormatter::format_datetime(updated_on) }
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.updated_on) }
property :type, getter: -> (*) { project_type.try(:name) }, render_nil: true

@ -29,14 +29,12 @@
require 'roar/decorator'
require 'roar/json/hal'
require 'api/v3/utilities/date_time_formatter'
module API
module V3
module Users
class UserRepresenter < ::API::Decorators::Single
include AvatarHelper
include API::V3::Utilities
link :self do
{
@ -89,10 +87,12 @@ module API
exec_context: :decorator
property :created_on,
as: 'createdAt',
getter: -> (*) { DateTimeFormatter::format_datetime(created_on) }
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.created_on) }
property :updated_on,
as: 'updatedAt',
getter: -> (*) { DateTimeFormatter::format_datetime(updated_on) }
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.updated_on) }
property :status, getter: -> (*) { status_name }, render_nil: true
def _type

@ -29,13 +29,11 @@
require 'roar/decorator'
require 'roar/json/hal'
require 'api/v3/utilities/date_time_formatter'
module API
module V3
module Versions
class VersionRepresenter < ::API::Decorators::Single
include API::V3::Utilities
link :self do
{
@ -71,19 +69,27 @@ module API
render_nil: true
property :start_date,
getter: -> (*) { DateTimeFormatter::format_date(start_date, allow_nil: true) },
exec_context: :decorator,
getter: -> (*) {
datetime_formatter.format_date(represented.start_date, allow_nil: true)
},
render_nil: true
property :due_date,
as: 'endDate',
getter: -> (*) { DateTimeFormatter::format_date(due_date, allow_nil: true) },
exec_context: :decorator,
getter: -> (*) {
datetime_formatter.format_date(represented.due_date, allow_nil: true)
},
render_nil: true
property :status, render_nil: true
property :created_on,
as: 'createdAt',
getter: -> (*) { DateTimeFormatter::format_datetime(created_on) }
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.created_on) }
property :updated_on,
as: 'updatedAt',
getter: -> (*) { DateTimeFormatter::format_datetime(updated_on) }
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.updated_on) }
def _type
'Version'

@ -29,7 +29,6 @@
require 'roar/decorator'
require 'roar/json/hal'
require 'api/v3/utilities/date_time_formatter'
module API
module V3
@ -38,7 +37,6 @@ module API
class WorkPackagePayloadRepresenter < Roar::Decorator
include Roar::JSON::HAL
include Roar::Hypermedia
include API::V3::Utilities
self.as_strategy = ::API::Utilities::CamelCasingStrategy.new
@ -86,10 +84,10 @@ module API
property :start_date,
exec_context: :decorator,
getter: -> (*) {
DateTimeFormatter::format_date(represented.start_date, allow_nil: true)
datetime_formatter.format_date(represented.start_date, allow_nil: true)
},
setter: -> (value, *) {
represented.start_date = DateTimeFormatter::parse_date(value,
represented.start_date = datetime_formatter.parse_date(value,
'startDate',
allow_nil: true)
},
@ -97,10 +95,10 @@ module API
property :due_date,
exec_context: :decorator,
getter: -> (*) {
DateTimeFormatter::format_date(represented.due_date, allow_nil: true)
datetime_formatter.format_date(represented.due_date, allow_nil: true)
},
setter: -> (value, *) {
represented.due_date = DateTimeFormatter::parse_date(value,
represented.due_date = datetime_formatter.parse_date(value,
'dueDate',
allow_nil: true)
},
@ -120,6 +118,10 @@ module API
private
def datetime_formatter
API::V3::Utilities::DateTimeFormatter
end
def work_package_attribute_links_representer(represented)
::API::V3::WorkPackages::Form::WorkPackageAttributeLinksRepresenter.new represented
end

@ -29,13 +29,11 @@
require 'roar/decorator'
require 'roar/json/hal'
require 'api/v3/utilities/date_time_formatter'
module API
module V3
module WorkPackages
class WorkPackageRepresenter < ::API::Decorators::Single
include API::V3::Utilities
link :self do
{
@ -242,29 +240,31 @@ module API
render_nil: true
property :start_date,
exec_context: :decorator,
getter: -> (*) do
DateTimeFormatter::format_date(start_date, allow_nil: true)
datetime_formatter.format_date(represented.start_date, allow_nil: true)
end,
render_nil: true
property :due_date,
exec_context: :decorator,
getter: -> (*) do
DateTimeFormatter::format_date(due_date, allow_nil: true)
datetime_formatter.format_date(represented.due_date, allow_nil: true)
end,
render_nil: true
property :estimated_time,
exec_context: :decorator,
getter: -> (*) do
DateTimeFormatter::format_duration_from_hours(represented.estimated_hours,
datetime_formatter.format_duration_from_hours(represented.estimated_hours,
allow_nil: true)
end,
exec_context: :decorator,
render_nil: true,
writeable: false
property :spent_time,
exec_context: :decorator,
getter: -> (*) do
DateTimeFormatter::format_duration_from_hours(represented.spent_hours)
datetime_formatter.format_duration_from_hours(represented.spent_hours)
end,
writeable: false,
exec_context: :decorator,
if: -> (_) { current_user_allowed_to(:view_time_entries) }
property :percentage_done,
render_nil: true,
@ -279,8 +279,12 @@ module API
property :project_id, getter: -> (*) { project.id }
property :project_name, getter: -> (*) { project.try(:name) }
property :parent_id, writeable: true
property :created_at, getter: -> (*) { DateTimeFormatter::format_datetime(created_at) }
property :updated_at, getter: -> (*) { DateTimeFormatter::format_datetime(updated_at) }
property :created_at,
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.created_at) }
property :updated_at,
exec_context: :decorator,
getter: -> (*) { datetime_formatter.format_datetime(represented.updated_at) }
collection :custom_properties, exec_context: :decorator, render_nil: true

@ -27,7 +27,6 @@
#++
require 'spec_helper'
require 'api/v3/utilities/date_time_formatter'
describe :DateTimeFormatter do
subject { ::API::V3::Utilities::DateTimeFormatter }

Loading…
Cancel
Save