add query form stub - not production ready

pull/5233/head
Jens Ulferts 8 years ago committed by Markus Kahl
parent d79ca74c9d
commit 4c32d17ede
  1. 47
      lib/api/v3/queries/form_representer.rb
  2. 11
      lib/api/v3/queries/queries_api.rb
  3. 12
      lib/api/v3/queries/queries_by_project_api.rb
  4. 14
      lib/api/v3/queries/query_representer.rb
  5. 8
      lib/api/v3/utilities/path_helper.rb
  6. 12
      spec/lib/api/v3/queries/query_representer_spec.rb
  7. 12
      spec/lib/api/v3/utilities/path_helper_spec.rb
  8. 18
      spec/requests/api/v3/queries/queries_by_project_resource_spec.rb
  9. 18
      spec/requests/api/v3/queries/query_resource_spec.rb

@ -0,0 +1,47 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
module API
module V3
module Queries
class FormRepresenter < ::API::Decorators::Form
def payload_representer
# TODO: Flesh out
{}
end
def schema_representer
Schemas::QuerySchemaRepresenter.new(represented,
form_embedded: true,
current_user: current_user)
end
end
end
end
end

@ -88,6 +88,17 @@ module API
end
end
namespace 'form' do
post do
query = Query.new_default(name: 'default',
user: current_user)
status 200
FormRepresenter.new(query,
current_user: current_user)
end
end
params do
requires :id, desc: 'Query id'
end

@ -49,6 +49,18 @@ module API
query_representer_response(query, params)
end
end
namespace 'form' do
post do
query = Query.new_default(name: 'default',
user: current_user,
project: @project)
status 200
FormRepresenter.new(query,
current_user: current_user)
end
end
end
end
end

@ -103,7 +103,7 @@ module API
link :schema do
href = if represented.project
api_v3_paths.query_project_schema(represented.project.id)
api_v3_paths.query_project_schema(represented.project.identifier)
else
api_v3_paths.query_schema
end
@ -112,6 +112,18 @@ module API
}
end
link :update do
href = if represented.project
api_v3_paths.query_project_form(represented.project.identifier)
else
api_v3_paths.query_form
end
{
href: href,
method: :post
}
end
linked_property :user
linked_property :project

@ -147,6 +147,10 @@ module API
"#{project(id)}/queries/default"
end
def self.query_form
"#{queries}/form"
end
def self.query_star(id)
"#{query(id)}/star"
end
@ -179,6 +183,10 @@ module API
"#{queries}/filter_instance_schemas/#{id}"
end
def self.query_project_form(id)
"#{project(id)}/queries/form"
end
def self.query_project_filter_instance_schemas(id)
"#{project(id)}/queries/filter_instance_schemas"
end

@ -72,7 +72,12 @@ describe ::API::V3::Queries::QueryRepresenter do
it_behaves_like 'has an untitled link' do
let(:link) { 'schema' }
let(:href) { api_v3_paths.query_project_schema(project.id) }
let(:href) { api_v3_paths.query_project_schema(project.identifier) }
end
it_behaves_like 'has an untitled link' do
let(:link) { 'update' }
let(:href) { api_v3_paths.query_project_form(project.identifier) }
end
context 'has no project' do
@ -87,6 +92,11 @@ describe ::API::V3::Queries::QueryRepresenter do
let(:href) { api_v3_paths.query_schema }
end
it_behaves_like 'has an untitled link' do
let(:link) { 'update' }
let(:href) { api_v3_paths.query_form }
end
it_behaves_like 'has an untitled link' do
let(:link) { 'results' }
let(:href) do

@ -248,6 +248,12 @@ describe ::API::V3::Utilities::PathHelper do
it_behaves_like 'api v3 path', '/projects/42/queries/default'
end
describe '#query_form' do
subject { helper.query_form }
it_behaves_like 'api v3 path', '/queries/form'
end
describe '#query_star' do
subject { helper.query_star 1 }
@ -296,6 +302,12 @@ describe ::API::V3::Utilities::PathHelper do
it_behaves_like 'api v3 path', '/queries/filter_instance_schemas/bogus'
end
describe '#query_project_form' do
subject { helper.query_project_form(42) }
it_behaves_like 'api v3 path', '/projects/42/queries/form'
end
describe '#query_project_filter_instance_schemas' do
subject { helper.query_project_filter_instance_schemas(42) }

@ -55,4 +55,22 @@ describe 'API v3 Query resource', type: :request do
end
end
end
describe '#post projects/:project_id/queries/form' do
let(:path) { api_v3_paths.query_project_form(project.identifier) }
before do
post path
end
it 'succeeds' do
expect(last_response.status).to eq(200)
end
it 'returns the form' do
expect(last_response.body)
.to be_json_eql('Form'.to_json)
.at_path('_type')
end
end
end

@ -425,4 +425,22 @@ describe 'API v3 Query resource', type: :request do
end
end
end
describe '#post queries/form' do
let(:path) { api_v3_paths.query_form }
before do
post path
end
it 'succeeds' do
expect(last_response.status).to eq(200)
end
it 'returns the form' do
expect(last_response.body)
.to be_json_eql('Form'.to_json)
.at_path('_type')
end
end
end

Loading…
Cancel
Save