OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/spec/lib/api/v3/support/schema_examples.rb

156 lines
4.6 KiB

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2021 the OpenProject GmbH
#
# 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-2013 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 docs/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
shared_examples_for 'has basic schema properties' do
it 'exists' do
is_expected.to have_json_path(path)
end
it 'has a type' do
is_expected.to be_json_eql(type.to_json).at_path("#{path}/type")
end
it 'has a name' do
is_expected.to be_json_eql(name.to_json).at_path("#{path}/name")
end
it 'indicates if it is required' do
is_expected.to be_json_eql(required.to_json).at_path("#{path}/required")
end
it 'indicates if it is writable' do
is_expected.to be_json_eql(writable.to_json).at_path("#{path}/writable")
end
it 'indicates if it has default' do
expected_has_default = if defined?(has_default)
has_default
else
false
end
is_expected
.to be_json_eql(expected_has_default.to_json)
.at_path("#{path}/hasDefault")
end
it 'indicates if it has a location' do
if defined?(location)
is_expected
.to be_json_eql(location.to_json)
.at_path("#{path}/location")
else
is_expected.not_to have_json_path("#{path}/location")
end
end
[34444] Projects copy APIv3 (#9149) * Create copy project endpoint * Add representers * Add _meta representer for copy module information * Add Meta payload representer * Extract parsing of copy attributes into service * Extract enqueue job for projects copy * Keep request object available in the bodied endpoint this allows us to access grape (e.g., for redirecting) * Add DelayedModify endpoint that redirects to job status * Use DelayedModify endpoint for copying projects * Add api paths for form/copy * Disable cache on ProjectCopyPayload * Add spec * Add resource spec * Extend schema for meta * Extend docs * Don't pass service result, but state as meta to forms * Use copy dependencies for naming copy options in API * Add description property for counting * Remove unused action attribute * Skip writable checks on meta property for payloads * Use prepend to allow create(...) usage with meta * Extend copy spec with custom fields usage * Add spec for copy flags * Add todos * Pass errors correctly to copy settings * Remove invalid parameters to copy that are now caught through project service * Remove duplicated validation * Linting * Make count a human readable, formattable description string * Make source count string readable * Provide the source project for generating the counts * Extract copying of attachments into sepearate dependent services This will allow the API to dynamically generate a copy association schema from each dependent service * Add spec for copy schema representer * Add payload representer spec * Also validate the model to pass the validations when copying * Make description optional and add note to schemas.apib * Add send_notifications to representer * Allow to configure sendNotifications * Allow bodied to receive a state process callback That allows us to manage the meta state on the API level, not on the service level * Make other services compatible with BaseCallable * Fix params passing from BaseCallable Wrapping a single hash into kwargs obviously loses their key indifference and we can't expect all services to use a single params object. Older services use kwargs * Copy wiki page with parent_id This will save some memory instead of memoizing the entire wiki page * Fix typo * Default to true for all copy associations That means if only a true value is passed, all other options will still be true * Do not try to copy attachments if the base dependency wasnt copied * Ensure null identifier gets rendered * Fix paths to the form and commit * Change redirect to an URL * Extend documentation on meta properties as table * Ensure we pass a default params if incoming params are nil Now that SetAttributes needs to splat params, they do no longer correctly get the no-param-default behavior of Ruby, so we need to explictly assign a default params hash * Fix expect for trailing path
4 years ago
it 'indicates if it has a description' do
if defined?(description)
is_expected
.to be_json_eql(description.to_json)
.at_path("#{path}/description/raw")
else
is_expected.not_to have_json_path("#{path}/description")
end
end
end
shared_examples_for 'indicates length requirements' do
it 'indicates its minimum length' do
if defined?(min_length)
is_expected
.to be_json_eql(min_length.to_json)
.at_path("#{path}/minLength")
else
is_expected
.not_to have_json_path("#{path}/minLength")
end
end
it 'indicates its maximum length' do
if defined?(max_length)
is_expected
.to be_json_eql(max_length.to_json)
.at_path("#{path}/maxLength")
else
is_expected
.not_to have_json_path("#{path}/maxLength")
end
end
end
shared_examples_for 'links to allowed values directly' do
it 'has the expected number of links' do
is_expected.to have_json_size(hrefs.size).at_path("#{path}/_links/allowedValues")
end
it 'contains links to the allowed values' do
index = 0
hrefs.each do |href|
href_path = "#{path}/_links/allowedValues/#{index}/href"
is_expected.to be_json_eql(href.to_json).at_path(href_path)
index += 1
end
end
end
shared_examples_for 'links to and embeds allowed values directly' do
it_behaves_like 'links to allowed values directly'
it 'has the expected number of embedded values' do
is_expected.to have_json_size(hrefs.size).at_path("#{path}/_embedded/allowedValues")
end
it 'embeds the allowed values' do
index = 0
hrefs.each do |href|
href_path = "#{path}/_embedded/allowedValues/#{index}/_links/self/href"
is_expected.to be_json_eql(href.to_json).at_path(href_path)
index += 1
end
end
end
shared_examples_for 'links to allowed values via collection link' do
it 'contains the link to the allowed values' do
is_expected.to be_json_eql(href.to_json).at_path("#{path}/_links/allowedValues/href")
end
end
shared_examples_for 'does not link to allowed values' do
it 'contains no link to the allowed values' do
is_expected.not_to have_json_path("#{path}/_links/allowedValues")
end
it 'does not embed allowed values' do
is_expected.not_to have_json_path("#{path}/_embedded/allowedValues")
end
end