extract helper for self links

pull/2516/head
Jan Sandbrink 10 years ago
parent 51081271af
commit 327c53cb94
  1. 9
      lib/api/decorators/single.rb
  2. 8
      lib/api/v3/priorities/priority_representer.rb
  3. 7
      lib/api/v3/projects/project_representer.rb
  4. 8
      lib/api/v3/statuses/status_representer.rb
  5. 7
      lib/api/v3/users/user_representer.rb
  6. 7
      lib/api/v3/versions/version_representer.rb
  7. 7
      lib/api/v3/work_packages/work_package_representer.rb
  8. 12
      spec/lib/api/v3/statuses/status_representer_spec.rb
  9. 5
      spec/lib/api/v3/work_packages/work_package_representer_spec.rb

@ -51,6 +51,15 @@ module API
exec_context: :decorator,
render_nil: false
def self.self_link(path, title_getter: -> (*) { represented.name })
link :self do
link_object = { href: api_v3_paths.send(path, represented.id) }
link_object[:title] = self.instance_eval(&title_getter)
link_object
end
end
def self.linked_property(property,
path: property,
backing_field: property,

@ -34,12 +34,8 @@ module API
module V3
module Priorities
class PriorityRepresenter < ::API::Decorators::Single
link :self do
{
href: api_v3_paths.priority(represented.id),
title: represented.name
}
end
self_link :priority
property :id, render_nil: true
property :name

@ -35,12 +35,7 @@ module API
module Projects
class ProjectRepresenter < ::API::Decorators::Single
link :self do
{
href: api_v3_paths.project(represented.id),
title: "#{represented.name}"
}
end
self_link :project
link 'categories' do
{ href: api_v3_paths.categories(represented.id) }

@ -31,12 +31,8 @@ module API
module V3
module Statuses
class StatusRepresenter < ::API::Decorators::Single
link :self do
{
href: api_v3_paths.status(represented.id),
title: "#{represented.name}"
}
end
self_link :status
property :id, render_nil: true
property :name

@ -36,12 +36,7 @@ module API
class UserRepresenter < ::API::Decorators::Single
include AvatarHelper
link :self do
{
href: api_v3_paths.user(represented.id),
title: "#{represented.name} - #{represented.login}"
}
end
self_link :user
link :lock do
{

@ -35,12 +35,7 @@ module API
module Versions
class VersionRepresenter < ::API::Decorators::Single
link :self do
{
href: api_v3_paths.version(represented.id),
title: represented.name
}
end
self_link :version
linked_property :definingProject,
path: :project,

@ -35,12 +35,7 @@ module API
module WorkPackages
class WorkPackageRepresenter < ::API::Decorators::Single
link :self do
{
href: api_v3_paths.work_package(represented.id),
title: represented.subject
}
end
self_link :work_package, title_getter: -> (*) { represented.subject }
link :update do
{

@ -61,13 +61,11 @@ describe ::API::V3::Statuses::StatusRepresenter do
it { is_expected.to have_json_type(Object).at_path('_links') }
describe 'self' do
let(:href) { "/api/v3/statuses/#{status.id}".to_json }
it { is_expected.to have_json_path('_links/self/href') }
it { is_expected.to have_json_path('_links/self/title') }
it { is_expected.to be_json_eql(href).at_path('_links/self/href') }
it { is_expected.to be_json_eql(status.name.to_json).at_path('_links/self/title') }
it_behaves_like 'has a titled link' do
let(:link) { 'self' }
let(:href) { "/api/v3/statuses/#{status.id}" }
let(:title) { status.name }
end
end
end
end

@ -235,11 +235,6 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
describe '_links' do
it { is_expected.to have_json_type(Object).at_path('_links') }
it 'should link to self' do
expect(subject).to have_json_path('_links/self/href')
expect(subject).to have_json_path('_links/self/title')
end
it_behaves_like 'has a titled link' do
let(:link) { 'self' }
let(:href) { "/api/v3/work_packages/#{work_package.id}" }

Loading…
Cancel
Save