Extend revision representer with identifier and revision link

This commit extends the revision endpoint with a link
to the (non-api) revision view as well as the formatted
identifier from the Changeset model.
pull/3328/head
Oliver Günther 9 years ago
parent c4f9e6605b
commit 974f5566e8
  1. 3
      config/routes.rb
  2. 8
      lib/api/v3/repositories/revision_representer.rb
  3. 4
      lib/api/v3/utilities/path_helper.rb
  4. 15
      spec/lib/api/v3/repositories/revision_representer_spec.rb

@ -360,7 +360,8 @@ OpenProject::Application.routes.draw do
end
get '/revision(/:rev)', rev: /[a-z0-9\.\-_]+/,
action: :revision
action: :revision,
as: 'show_revision'
get '(/revisions/:rev)(/*path)', action: :show,
format: false,

@ -50,8 +50,16 @@ module API
} unless represented.user.nil?
end
link :showRevision do
{
href: api_v3_paths.show_revision(represented.project.identifier,
represented.identifier)
}
end
property :id
property :identifier
property :format_identifier, as: :formattedIdentifier
property :author, as: :authorName
property :message,
exec_context: :decorator,

@ -130,6 +130,10 @@ module API
path
end
def self.show_revision(project_id, identifier)
show_revision_project_repository_path(project_id, identifier)
end
def self.statuses
"#{root}/statuses"
end

@ -67,6 +67,14 @@ describe ::API::V3::Repositories::RevisionRepresenter do
it { is_expected.to be_json_eql('1234'.to_json).at_path('identifier') }
end
describe 'formattedIdentifier' do
before do
allow(revision).to receive(:format_identifier).and_return('123')
end
it { is_expected.to have_json_path('formattedIdentifier') }
it { is_expected.to be_json_eql('123'.to_json).at_path('formattedIdentifier') }
end
describe 'createdAt' do
it_behaves_like 'has UTC ISO 8601 date and time' do
let(:date) { revision.committed_on }
@ -123,5 +131,12 @@ describe ::API::V3::Repositories::RevisionRepresenter do
end
end
end
describe 'showRevision' do
it_behaves_like 'has an untitled link' do
let(:link) { 'showRevision' }
let(:href) { api_v3_paths.show_revision(project.identifier, revision.identifier) }
end
end
end
end

Loading…
Cancel
Save