allow giving projects by identifier; don't render titles

pull/5233/head
Markus Kahl 8 years ago
parent ec46419f3c
commit d3dd27aa68
  1. 2
      lib/api/v3/queries/query_payload_representer.rb
  2. 7
      lib/api/v3/queries/query_serialization.rb
  3. 23
      spec/requests/api/v3/queries/create_form_api_spec.rb

@ -60,7 +60,7 @@ module API
end
end
linked_property :project
linked_property :project, title_getter: ->(*) { nil }
property :name
property :filters,

@ -128,8 +128,13 @@ module API
def get_project_id(query_attributes)
href = query_attributes.dig("_links", "project", "href")
id = id_from_href "projects", href
id_from_href "projects", href
if id.to_i != 0
id # return numerical ID
else
Project.where(identifier: id).pluck(:id).first # lookup Project by identifier
end
end
def get_sort_criteria(query_attributes)

@ -157,10 +157,7 @@ describe "POST /api/v3/queries/form", type: :request do
end
it 'has the project set' do
project_link = {
"href" => "/api/v3/projects/#{project.id}",
"title" => project.name
}
project_link = { "href" => "/api/v3/projects/#{project.id}" }
expect(form.dig("_embedded", "payload", "_links", "project")).to eq project_link
end
@ -209,6 +206,24 @@ describe "POST /api/v3/queries/form", type: :request do
expect(form.dig("_embedded", "payload", "_links", "sortBy")).to eq sort_by
end
context "with the project referred to by its identifier" do
let(:override_params) do
links = parameters[:_links]
links[:project] = {
href: "/api/v3/projects/#{project.id}"
}
{ _links: links }
end
it "still finds the project" do
project_link = { "href" => "/api/v3/projects/#{project.id}" }
expect(form.dig("_embedded", "payload", "_links", "project")).to eq project_link
end
end
context "with an unknown filter" do
let(:override_params) do
filter = parameters[:filters][0]

Loading…
Cancel
Save