Merge pull request #1634 from opf/feature/api-auxiliary-resources

pull/1646/head
Hagen Schink 10 years ago
commit 1eefc86a2d
  1. 10
      lib/api/root.rb
  2. 4
      lib/api/v3/activities/activities_api.rb
  3. 8
      lib/api/v3/activities/activity_representer.rb
  4. 6
      lib/api/v3/attachments/attachment_representer.rb
  5. 2
      lib/api/v3/attachments/attachments_api.rb
  6. 49
      lib/api/v3/priorities/priorities_api.rb
  7. 57
      lib/api/v3/priorities/priority_collection_representer.rb
  8. 43
      lib/api/v3/priorities/priority_model.rb
  9. 54
      lib/api/v3/priorities/priority_representer.rb
  10. 53
      lib/api/v3/projects/project_model.rb
  11. 74
      lib/api/v3/projects/project_representer.rb
  12. 57
      lib/api/v3/projects/projects_api.rb
  13. 6
      lib/api/v3/queries/queries_api.rb
  14. 2
      lib/api/v3/queries/query_representer.rb
  15. 2
      lib/api/v3/relations/relations_api.rb
  16. 7
      lib/api/v3/root.rb
  17. 58
      lib/api/v3/root_representer.rb
  18. 57
      lib/api/v3/statuses/status_collection_representer.rb
  19. 43
      lib/api/v3/statuses/status_model.rb
  20. 54
      lib/api/v3/statuses/status_representer.rb
  21. 49
      lib/api/v3/statuses/statuses_api.rb
  22. 4
      lib/api/v3/users/user_representer.rb
  23. 5
      lib/api/v3/users/users_api.rb
  24. 64
      lib/api/v3/versions/version_collection_representer.rb
  25. 43
      lib/api/v3/versions/version_model.rb
  26. 54
      lib/api/v3/versions/version_representer.rb
  27. 49
      lib/api/v3/versions/versions_api.rb
  28. 50
      lib/api/v3/work_packages/available_status_collection_representer.rb
  29. 8
      lib/api/v3/work_packages/relation_representer.rb
  30. 67
      lib/api/v3/work_packages/statuses_api.rb
  31. 37
      lib/api/v3/work_packages/work_package_representer.rb
  32. 12
      lib/api/v3/work_packages/work_packages_api.rb
  33. 4
      spec/api/query_resource_spec.rb
  34. 54
      spec/lib/api/v3/priorities/priority_collection_representer_spec.rb
  35. 37
      spec/lib/api/v3/priorities/priority_model_spec.rb
  36. 51
      spec/lib/api/v3/priorities/priority_representer_spec.rb
  37. 44
      spec/lib/api/v3/projects/project_model_spec.rb
  38. 63
      spec/lib/api/v3/projects/project_representer_spec.rb
  39. 57
      spec/lib/api/v3/root_representer_spec.rb
  40. 25
      spec/lib/api/v3/statuses/shared/status_collection_representer.rb
  41. 42
      spec/lib/api/v3/statuses/status_collection_representer_spec.rb
  42. 37
      spec/lib/api/v3/statuses/status_model_spec.rb
  43. 51
      spec/lib/api/v3/statuses/status_representer_spec.rb
  44. 64
      spec/lib/api/v3/versions/version_collection_representer_spec.rb
  45. 37
      spec/lib/api/v3/versions/version_model_spec.rb
  46. 51
      spec/lib/api/v3/versions/version_representer_spec.rb
  47. 46
      spec/lib/api/v3/work_packages/available_status_collection_representer_spec.rb
  48. 67
      spec/requests/api/v3/priority_resource_spec.rb
  49. 86
      spec/requests/api/v3/project_resource_spec.rb
  50. 52
      spec/requests/api/v3/root_resource_spec.rb
  51. 67
      spec/requests/api/v3/status_resource_spec.rb
  52. 40
      spec/requests/api/v3/version_resource_spec.rb
  53. 98
      spec/requests/api/v3/work_packages/available_statuses_endpoint_spec.rb

@ -34,8 +34,16 @@
module API
class Root < Grape::API
prefix :api
class Formatter
def call(object, env)
object.respond_to?(:to_json) ? object.to_json : MultiJson.dump(object)
end
end
content_type 'hal+json', 'application/hal+json'
format 'hal+json'
formatter 'hal+json', Formatter.new
helpers do
def current_user
@ -56,7 +64,7 @@ module API
def build_representer(obj, model_klass, representer_klass, options = {})
model = (obj.kind_of?(Array)) ? obj.map{ |o| model_klass.new(o) } : model_klass.new(obj)
representer_klass.new(model, options).to_json
representer_klass.new(model, options)
end
end

@ -46,7 +46,7 @@ module API
get do
authorize(:view_project, context: @activity.journable.project)
@representer.to_json
@representer
end
helpers do
@ -55,7 +55,7 @@ module API
model = ::API::V3::Activities::ActivityModel.new(activity)
representer = ::API::V3::Activities::ActivityRepresenter.new(model)
representer.to_json
representer
else
errors = activity.errors.full_messages.join(", ")
fail Errors::Validation.new(activity, description: errors)

@ -49,20 +49,20 @@ module API
property :_type, exec_context: :decorator
link :self do
{ href: "#{root_url}api/v3/activities/#{represented.model.id}", title: "#{represented.model.id}" }
{ href: "#{root_path}api/v3/activities/#{represented.model.id}", title: "#{represented.model.id}" }
end
link :workPackage do
{ href: "#{root_url}api/v3/work_packages/#{represented.model.journable.id}", title: "#{represented.model.journable.subject}" }
{ href: "#{root_path}api/v3/work_packages/#{represented.model.journable.id}", title: "#{represented.model.journable.subject}" }
end
link :user do
{ href: "#{root_url}api/v3/users/#{represented.model.user.id}", title: "#{represented.model.user.name} - #{represented.model.user.login}" }
{ href: "#{root_path}api/v3/users/#{represented.model.user.id}", title: "#{represented.model.user.name} - #{represented.model.user.login}" }
end
link :update do
{
href: "#{root_url}api/v3/activities/#{represented.model.id}",
href: "#{root_path}api/v3/activities/#{represented.model.id}",
method: :patch,
title: "#{represented.model.id}"
} if current_user_allowed_to_edit?

@ -43,17 +43,17 @@ module API
property :_type, exec_context: :decorator
link :self do
{ href: "#{root_url}api/v3/attachments/#{represented.model.id}", title: "#{represented.model.filename}" }
{ href: "#{root_path}api/v3/attachments/#{represented.model.id}", title: "#{represented.model.filename}" }
end
link :work_package do
work_package = represented.model.container
{ href: "#{root_url}api/v3/work_packages/#{work_package.id}", title: "#{work_package.subject}" } unless work_package.nil?
{ href: "#{root_path}api/v3/work_packages/#{work_package.id}", title: "#{work_package.subject}" } unless work_package.nil?
end
link :author do
author = represented.model.author
{ href: "#{root_url}api/v3/users/#{author.id}", title: "#{author.name} - #{author.login}" } unless author.nil?
{ href: "#{root_path}api/v3/users/#{author.id}", title: "#{author.name} - #{author.login}" } unless author.nil?
end
property :id, getter: -> (*) { model.id }, render_nil: true

@ -46,7 +46,7 @@ module API
get do
authorize(:view_project, context: @attachment.container.project)
@representer.to_json
@representer
end
end

@ -0,0 +1,49 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
module API
module V3
module Priorities
class PrioritiesAPI < Grape::API
resources :priorities do
before do
@priorities = IssuePriority.all
@priorities.map! { |priority| PriorityModel.new(priority) }
end
get do
PriorityCollectionRepresenter.new(@priorities)
end
end
end
end
end
end

@ -0,0 +1,57 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'roar/decorator'
require 'representable/json/collection'
require 'roar/representer/json/hal'
module API
module V3
module Priorities
class PriorityCollectionRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
include OpenProject::StaticRouting::UrlHelpers
self.as_strategy = API::Utilities::CamelCasingStrategy.new
link :self do
"#{root_path}api/v3/priorities"
end
property :_type, exec_context: :decorator
collection :priorities, embedded: true, extend: PriorityRepresenter, getter: ->(_) { self }
def _type
'Priorities'
end
end
end
end
end

@ -0,0 +1,43 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'reform'
require 'reform/form/coercion'
module API
module V3
module Priorities
class PriorityModel < Reform::Form
include Coercion
property :name, type: String
end
end
end
end

@ -0,0 +1,54 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'roar/decorator'
require 'roar/representer/json/hal'
module API
module V3
module Priorities
class PriorityRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
include Roar::Representer::Feature::Hypermedia
include OpenProject::StaticRouting::UrlHelpers
self.as_strategy = API::Utilities::CamelCasingStrategy.new
property :_type, exec_context: :decorator
property :id, getter: -> (*) { model.id }, render_nil: true
property :name
def _type
'Priority'
end
end
end
end
end

@ -0,0 +1,53 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'reform'
require 'reform/form/coercion'
module API
module V3
module Projects
class ProjectModel < Reform::Form
include Coercion
property :identifier, type: String, virtual: true
property :name, type: String
property :description, type: String
property :homepage, type: String
property :created_on, type: DateTime, virtual: true
property :updated_on, type: DateTime, virtual: true
def type
model.project_type.name if model.project_type
end
end
end
end
end

@ -0,0 +1,74 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'roar/decorator'
require 'roar/representer/json/hal'
module API
module V3
module Projects
class ProjectRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
include Roar::Representer::Feature::Hypermedia
include OpenProject::StaticRouting::UrlHelpers
self.as_strategy = API::Utilities::CamelCasingStrategy.new
property :_type, exec_context: :decorator
link :self do
{
href: "#{root_path}api/v3/projects/#{represented.model.id}",
title: "#{represented.name}"
}
end
link 'versions' do
"#{root_path}api/v3/projects/#{represented.model.id}/versions"
end
property :id, getter: -> (*) { model.id }, render_nil: true
property :identifier, render_nil: true
property :name, render_nil: true
property :description, render_nil: true
property :homepage
property :created_on, render_nil: true
property :updated_on, render_nil: true
property :type, render_nil: true
def _type
'Project'
end
end
end
end
end

@ -0,0 +1,57 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
module API
module V3
module Projects
class ProjectsAPI < Grape::API
resources :projects do
params do
requires :id, desc: 'Project id'
end
namespace ':id' do
before do
@project = Project.find(params[:id])
@model = ProjectModel.new(@project)
end
get do
authorize(:view_project, context: @project)
ProjectRepresenter.new(@model)
end
mount API::V3::Versions::VersionsAPI
end
end
end
end
end
end

@ -59,16 +59,16 @@ module API
normalized_query_name, @query.id, title: @query.name
)
query_menu_item.save!
@representer.to_json
@representer
end
patch :unstar do
authorize({ controller: :queries, action: :unstar }, context: @query.project, allow: allowed_to_manage_stars?)
query_menu_item = @query.query_menu_item
return @representer.to_json if @query.query_menu_item.nil?
return @representer if @query.query_menu_item.nil?
query_menu_item.destroy
@query.reload
@representer.to_json
@representer
end
end

@ -43,7 +43,7 @@ module API
property :_type, exec_context: :decorator
link :self do
{ href: "#{root_url}api/v3/queries/#{represented.query.id}", title: "#{represented.name}" }
{ href: "#{root_path}api/v3/queries/#{represented.query.id}", title: "#{represented.name}" }
end
property :id, getter: -> (*) { query.id }, render_nil: true

@ -23,7 +23,7 @@ module API
model = ::API::V3::WorkPackages::RelationModel.new(relation)
representer = ::API::V3::WorkPackages::RelationRepresenter.new(model, work_package: relation.to)
relation.save!
representer.to_json
representer
else
fail Errors::Validation.new(relation)
end

@ -38,9 +38,16 @@ module API
mount ::API::V3::Activities::ActivitiesAPI
mount ::API::V3::Attachments::AttachmentsAPI
mount ::API::V3::Priorities::PrioritiesAPI
mount ::API::V3::Projects::ProjectsAPI
mount ::API::V3::Queries::QueriesAPI
mount ::API::V3::Statuses::StatusesAPI
mount ::API::V3::Users::UsersAPI
mount ::API::V3::WorkPackages::WorkPackagesAPI
get '/' do
RootRepresenter.new({})
end
end
end
end

@ -0,0 +1,58 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'roar/decorator'
require 'roar/representer/json/hal'
module API
module V3
class RootRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
include Roar::Representer::Feature::Hypermedia
include OpenProject::StaticRouting::UrlHelpers
self.as_strategy = ::API::Utilities::CamelCasingStrategy.new
link 'priorities' do
"#{root_path}api/v3/priorities"
end
link 'project' do
{
href: "#{root_path}api/v3/project/{project_id}",
templated: true
}
end
link 'statuses' do
"#{root_path}api/v3/statuses"
end
end
end
end

@ -0,0 +1,57 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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 status 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 status 2
# of the License, or (at your option) any later status.
#
# 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.
#++
require 'roar/decorator'
require 'representable/json/collection'
require 'roar/representer/json/hal'
module API
module V3
module Statuses
class StatusCollectionRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
include OpenProject::StaticRouting::UrlHelpers
self.as_strategy = API::Utilities::CamelCasingStrategy.new
link :self do
"#{root_path}api/v3/statuses"
end
property :_type, exec_context: :decorator
collection :statuses, embedded: true, extend: StatusRepresenter, getter: ->(_) { self }
def _type
'Statuses'
end
end
end
end
end

@ -0,0 +1,43 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'reform'
require 'reform/form/coercion'
module API
module V3
module Statuses
class StatusModel < Reform::Form
include Coercion
property :name, type: String
end
end
end
end

@ -0,0 +1,54 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'roar/decorator'
require 'roar/representer/json/hal'
module API
module V3
module Statuses
class StatusRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
include Roar::Representer::Feature::Hypermedia
include OpenProject::StaticRouting::UrlHelpers
self.as_strategy = API::Utilities::CamelCasingStrategy.new
property :_type, exec_context: :decorator
property :id, getter: -> (*) { model.id }, render_nil: true
property :name
def _type
'Status'
end
end
end
end
end

@ -0,0 +1,49 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
module API
module V3
module Statuses
class StatusesAPI < Grape::API
resources :statuses do
before do
@statuses = Status.all
@statuses.map! { |status| StatusModel.new(status) }
end
get do
StatusCollectionRepresenter.new(@statuses)
end
end
end
end
end
end

@ -52,12 +52,12 @@ module API
property :_type, exec_context: :decorator
link :self do
{ href: "#{root_url}api/v3/users/#{represented.model.id}", title: "#{represented.model.name} - #{represented.model.login}" }
{ href: "#{root_path}api/v3/users/#{represented.model.id}", title: "#{represented.model.name} - #{represented.model.login}" }
end
link :removeWatcher do
{
href: "#{root_url}/api/v3/work_packages/#{@work_package.id}/watchers/#{represented.model.id}",
href: "#{root_path}/api/v3/work_packages/#{@work_package.id}/watchers/#{represented.model.id}",
method: :delete,
title: 'Remove watcher'
} if @work_package && current_user_allowed_to(:delete_work_package_watchers, @work_package)

@ -40,12 +40,11 @@ module API
before do
@user = User.find(params[:id])
model = ::API::V3::Users::UserModel.new(@user)
@representer = ::API::V3::Users::UserRepresenter.new(model)
@model = UserModel.new(@user)
end
get do
@representer.to_json
UserRepresenter.new(@model)
end
end

@ -0,0 +1,64 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'roar/decorator'
require 'representable/json/collection'
require 'roar/representer/json/hal'
module API
module V3
module Versions
class VersionCollectionRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
include OpenProject::StaticRouting::UrlHelpers
self.as_strategy = API::Utilities::CamelCasingStrategy.new
attr_reader :project
def initialize(model, project:)
@project = project
super(model)
end
link :self do
"#{root_path}api/v3/projects/#{project.id}/versions"
end
property :_type, exec_context: :decorator
collection :versions, embedded: true, extend: VersionRepresenter, getter: ->(_) { self }
def _type
'Versions'
end
end
end
end
end

@ -0,0 +1,43 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'reform'
require 'reform/form/coercion'
module API
module V3
module Versions
class VersionModel < Reform::Form
include Coercion
property :name, type: String
end
end
end
end

@ -0,0 +1,54 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'roar/decorator'
require 'roar/representer/json/hal'
module API
module V3
module Versions
class VersionRepresenter < Roar::Decorator
include Roar::Representer::JSON::HAL
include Roar::Representer::Feature::Hypermedia
include OpenProject::StaticRouting::UrlHelpers
self.as_strategy = API::Utilities::CamelCasingStrategy.new
property :_type, exec_context: :decorator
property :id, getter: -> (*) { model.id }, render_nil: true
property :name
def _type
'Version'
end
end
end
end
end

@ -0,0 +1,49 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
module API
module V3
module Versions
class VersionsAPI < Grape::API
resources :versions do
before do
@versions = @project.shared_versions.all
@versions.map! { |version| VersionModel.new(version) }
end
get do
VersionCollectionRepresenter.new(@versions, project: @project)
end
end
end
end
end
end

@ -0,0 +1,50 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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 status 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 status 2
# of the License, or (at your option) any later status.
#
# 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 WorkPackages
class AvailableStatusCollectionRepresenter < ::API::V3::Statuses::StatusCollectionRepresenter
link :self do |opts|
"#{work_package_url(opts[:work_package_id])}/available_statuses"
end
link :work_package do |opts|
work_package_url(opts[:work_package_id])
end
private
def work_package_url(work_package_id)
"#{root_path}api/v3/work_packages/#{work_package_id}"
end
end
end
end
end

@ -51,20 +51,20 @@ module API
property :_type, exec_context: :decorator
link :self do
{ href: "#{root_url}api/v3/relations/#{represented.model.id}" }
{ href: "#{root_path}api/v3/relations/#{represented.model.id}" }
end
link :relatedFrom do
{ href: "#{root_url}api/v3/work_packages/#{represented.model.from_id}" }
{ href: "#{root_path}api/v3/work_packages/#{represented.model.from_id}" }
end
link :relatedTo do
{ href: "#{root_url}api/v3/work_packages/#{represented.model.to_id}" }
{ href: "#{root_path}api/v3/work_packages/#{represented.model.to_id}" }
end
link :remove do
{
href: "#{root_url}api/v3/work_packages/#{represented.model.from.id}/relations/#{represented.model.id}",
href: "#{root_path}api/v3/work_packages/#{represented.model.from.id}/relations/#{represented.model.id}",
method: :delete,
title: "Remove relation"
} if current_user_allowed_to(:manage_work_package_relations)

@ -0,0 +1,67 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
module API
module V3
module WorkPackages
class StatusesAPI < Grape::API
class AvailableStatusesFormatter
# this is an ugly hack to get the work package id for the path to self
def work_package_id(env)
env['rack.routing_args'][:id]
end
def call(object, env)
if object.respond_to?(:to_json)
object.to_json(work_package_id: work_package_id(env))
else
MultiJson.dump(object)
end
end
end
formatter 'hal+json', AvailableStatusesFormatter.new
get '/available_statuses' do
authorize({ controller: :work_packages, action: :update }, context: work_package.project)
work_package.type = work_package.project.types.find_by_name(params[:type]) if params[:type]
statuses = work_package.new_statuses_allowed_to(current_user)
models = statuses.map { |status| ::API::V3::Statuses::StatusModel.new(status) }
represented = ::API::V3::WorkPackages::AvailableStatusCollectionRepresenter.new(models)
represented
end
end
end
end
end

@ -50,7 +50,10 @@ module API
property :_type, exec_context: :decorator
link :self do
{ href: "#{root_url}api/v3/work_packages/#{represented.work_package.id}", title: represented.subject }
{
href: "#{root_path}api/v3/work_packages/#{represented.work_package.id}",
title: "#{represented.subject}"
}
end
link :update do
@ -63,35 +66,43 @@ module API
link :author do
{
href: "#{root_url}/api/v3/users/#{represented.work_package.author.id}",
href: "#{root_path}api/v3/users/#{represented.work_package.author.id}",
title: "#{represented.work_package.author.name} - #{represented.work_package.author.login}"
} unless represented.work_package.author.nil?
end
link :responsible do
{
href: "#{root_url}/api/v3/users/#{represented.work_package.responsible.id}",
href: "#{root_path}api/v3/users/#{represented.work_package.responsible.id}",
title: "#{represented.work_package.responsible.name} - #{represented.work_package.responsible.login}"
} unless represented.work_package.responsible.nil?
end
link :assignee do
{
href: "#{root_url}/api/v3/users/#{represented.work_package.assigned_to.id}",
href: "#{root_path}api/v3/users/#{represented.work_package.assigned_to.id}",
title: "#{represented.work_package.assigned_to.name} - #{represented.work_package.assigned_to.login}"
} unless represented.work_package.assigned_to.nil?
end
link :availableStatuses do
{
href: "#{root_path}api/v3/work_packages/#{represented.work_package.id}/available_statuses",
title: 'Available Statuses'
} if @current_user.allowed_to?({ controller: :work_packages, action: :update },
represented.work_package.project)
end
link :availableWatchers do
{
href: "#{root_url}api/v3/work_packages/#{represented.work_package.id}/available_watchers",
title: "Available Watchers"
href: "#{root_path}api/v3/work_packages/#{represented.work_package.id}/available_watchers",
title: 'Available Watchers'
}
end
link :watch do
{
href: "#{root_url}/api/v3/work_packages/#{represented.work_package.id}/watchers",
href: "#{root_path}api/v3/work_packages/#{represented.work_package.id}/watchers",
method: :post,
data: { user_id: @current_user.id },
title: 'Watch work package'
@ -102,7 +113,7 @@ module API
link :unwatch do
{
href: "#{root_url}/api/v3/work_packages/#{represented.work_package.id}/watchers/#{@current_user.id}",
href: "#{root_path}api/v3/work_packages/#{represented.work_package.id}/watchers/#{@current_user.id}",
method: :delete,
title: 'Unwatch work package'
} if current_user_allowed_to(:view_work_packages, represented.work_package) && represented.work_package.watcher_users.include?(@current_user)
@ -110,7 +121,7 @@ module API
link :addWatcher do
{
href: "#{root_url}/api/v3/work_packages/#{represented.work_package.id}/watchers{?user_id}",
href: "#{root_path}api/v3/work_packages/#{represented.work_package.id}/watchers{?user_id}",
method: :post,
title: 'Add watcher',
templated: true
@ -119,7 +130,7 @@ module API
link :addRelation do
{
href: "#{root_url}/api/v3/work_packages/#{represented.work_package.id}/relations",
href: "#{root_path}/api/v3/work_packages/#{represented.work_package.id}/relations",
method: :post,
title: 'Add relation'
} if current_user_allowed_to(:manage_work_package_relations, represented.work_package)
@ -127,7 +138,7 @@ module API
link :addComment do
{
href: "#{root_url}api/v3/work_packages/#{represented.work_package.id}/activities",
href: "#{root_path}api/v3/work_packages/#{represented.work_package.id}/activities",
method: :post,
title: 'Add comment'
} if current_user_allowed_to(:add_work_package_notes, represented.work_package)
@ -135,14 +146,14 @@ module API
link :parent do
{
href: "#{root_url}/api/v3/work_packages/#{represented.work_package.parent.id}",
href: "#{root_path}/api/v3/work_packages/#{represented.work_package.parent.id}",
title: represented.work_package.parent.subject
} unless represented.work_package.parent.nil? || !represented.work_package.parent.visible?
end
links :children do
visible_children.map do |child|
{ href: "#{root_url}/api/v3/work_packages/#{child.id}", title: child.subject }
{ href: "#{root_path}/api/v3/work_packages/#{child.id}", title: child.subject }
end unless visible_children.empty?
end

@ -38,6 +38,10 @@ module API
end
namespace ':id' do
helpers do
attr_reader :work_package
end
before do
@work_package = WorkPackage.find(params[:id])
model = ::API::V3::WorkPackages::WorkPackageModel.new(work_package: @work_package)
@ -46,7 +50,7 @@ module API
get do
authorize({ controller: :work_packages_api, action: :get }, context: @work_package.project)
@representer.to_json
@representer
end
patch do
@ -54,7 +58,7 @@ module API
@representer.from_json(request.POST.to_json)
@representer.represented.sync
if @representer.represented.work_package.valid? && @representer.represented.save
@representer.to_json
@representer
else
fail Errors::Validation.new(@representer.represented.work_package)
end
@ -68,7 +72,7 @@ module API
model = ::API::V3::Activities::ActivityModel.new(work_package.journals.last)
representer = ::API::V3::Activities::ActivityRepresenter.new(model, { current_user: current_user })
representer.to_json
representer
else
errors = work_package.errors.full_messages.join(", ")
fail Errors::Validation.new(work_package, description: errors)
@ -105,7 +109,9 @@ module API
end
mount ::API::V3::WorkPackages::WatchersAPI
mount ::API::V3::WorkPackages::StatusesAPI
mount ::API::V3::Relations::RelationsAPI
end
end

@ -49,7 +49,7 @@ describe 'API v3 Query resource', :type => :request do
"_type" => 'Query',
"_links" => {
"self" => {
"href" => "http://localhost:3000/api/v3/queries/#{query.id}",
"href" => "/api/v3/queries/#{query.id}",
"title" => query.name
}
},
@ -229,7 +229,7 @@ describe 'API v3 Query resource', :type => :request do
"_type" => 'Query',
"_links" => {
"self" => {
"href" => "http://localhost:3000/api/v3/queries/#{query.id}",
"href" => "/api/v3/queries/#{query.id}",
"title" => query.name
}
},

@ -0,0 +1,54 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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 status 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 status 2
# of the License, or (at your option) any later status.
#
# 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.
#++
require 'spec_helper'
describe ::API::V3::Priorities::PriorityCollectionRepresenter do
let(:priorities) { FactoryGirl.build_list(:priority, 3) }
let(:models) { priorities.map { |priority|
::API::V3::Priorities::PriorityModel.new(priority)
} }
let(:representer) { described_class.new(models) }
context 'generation' do
subject(:generated) { representer.to_json }
it { should include_json('Priorities'.to_json).at_path('_type') }
it { should have_json_type(Object).at_path('_links') }
it 'should link to self' do
expect(subject).to have_json_path('_links/self/href')
end
describe 'priorities' do
it { should have_json_path('_embedded/priorities') }
it { should have_json_size(3).at_path('_embedded/priorities') }
it { should have_json_path('_embedded/priorities/2/name') }
end
end
end

@ -0,0 +1,37 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Priorities::PriorityModel do
subject(:model) { ::API::V3::Priorities::PriorityModel.new(priority) }
let(:priority) { FactoryGirl.build(:priority, attributes) }
let(:attributes) { { name: 'Specific Priority' } }
its(:name) { should eq 'Specific Priority' }
end

@ -0,0 +1,51 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Priorities::PriorityRepresenter do
let(:priority) { FactoryGirl.build(:priority) }
let(:model) { ::API::V3::Priorities::PriorityModel.new(priority) }
let(:representer) { described_class.new(model) }
context 'generation' do
subject(:generated) { representer.to_json }
it { should include_json('Priority'.to_json).at_path('_type') }
xit { should have_json_type(Object).at_path('_links') }
xit 'should link to self' do
expect(subject).to have_json_path('_links/self/href')
end
describe 'priority' do
it { should have_json_path('id') }
it { should have_json_path('name') }
end
end
end

@ -0,0 +1,44 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Projects::ProjectModel do
subject(:model) { ::API::V3::Projects::ProjectModel.new(project) }
let(:project_type) {
FactoryGirl.build(:project_type, id: 1, name: 'Hypermedia-Ready Type')
}
let(:project) {
FactoryGirl.build(:project, attributes.merge(project_type: project_type))
}
let(:attributes) { { name: 'Hypermedia-Ready Project' } }
its(:name) { should eq 'Hypermedia-Ready Project' }
its(:type) { should eq 'Hypermedia-Ready Type' }
end

@ -0,0 +1,63 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Projects::ProjectRepresenter do
let(:project) { FactoryGirl.build(:project) }
let(:model) { ::API::V3::Projects::ProjectModel.new(project) }
let(:representer) { described_class.new(model) }
context 'generation' do
subject(:generated) { representer.to_json }
it { should include_json('Project'.to_json).at_path('_type') }
describe 'project' do
it { should have_json_path('id') }
it { should have_json_path('identifier') }
it { should have_json_path('name') }
it { should have_json_path('description') }
it { should have_json_path('createdOn') }
it { should have_json_path('updatedOn') }
it { should have_json_path('type') }
end
describe '_links' do
it { should have_json_type(Object).at_path('_links') }
it 'should link to self' do
expect(subject).to have_json_path('_links/self/href')
end
describe 'versions' do
it { should have_json_path('_links/versions') }
it { should have_json_path('_links/versions/href') }
end
end
end
end

@ -0,0 +1,57 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::RootRepresenter do
let(:representer) { described_class.new({}) }
context 'generation' do
subject(:generated) { representer.to_json }
describe '_links' do
it { should have_json_type(Object).at_path('_links') }
describe 'priorities' do
it { should have_json_path('_links/priorities') }
it { should have_json_path('_links/priorities/href') }
end
describe 'project' do
it { should have_json_path('_links/project') }
it { should have_json_path('_links/project/href') }
it { should have_json_path('_links/project/templated') }
end
describe 'statuses' do
it { should have_json_path('_links/statuses') }
it { should have_json_path('_links/statuses/href') }
end
end
end
end

@ -0,0 +1,25 @@
RSpec.shared_examples "status collection representer" do
let(:statuses) { FactoryGirl.build_list(:status, 3) }
let(:models) { statuses.map { |status|
::API::V3::Statuses::StatusModel.new(status)
} }
let(:representer) { described_class.new(models) }
context 'generation' do
subject(:generated) { representer.to_json }
it { should include_json('Statuses'.to_json).at_path('_type') }
it { should have_json_type(Object).at_path('_links') }
it 'should link to self' do
expect(subject).to have_json_path('_links/self/href')
end
describe 'statuses' do
it { should have_json_path('_embedded/statuses') }
it { should have_json_size(3).at_path('_embedded/statuses') }
it { should have_json_path('_embedded/statuses/2/name') }
end
end
end

@ -0,0 +1,42 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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 status 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 status 2
# of the License, or (at your option) any later status.
#
# 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.
#++
require 'spec_helper'
require 'lib/api/v3/statuses/shared/status_collection_representer'
describe ::API::V3::Statuses::StatusCollectionRepresenter do
include_examples 'status collection representer'
context 'generation' do
subject(:generated) { representer.to_json }
it 'should have link to self' do
expect(parse_json(subject)['_links']['self']['href']).to match(%r{api/v3/statuses$})
end
end
end

@ -0,0 +1,37 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Statuses::StatusModel do
subject(:model) { ::API::V3::Statuses::StatusModel.new(version) }
let(:version) { FactoryGirl.build(:status, attributes) }
let(:attributes) { { name: 'Specific Status' } }
its(:name) { should eq 'Specific Status' }
end

@ -0,0 +1,51 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Statuses::StatusRepresenter do
let(:status) { FactoryGirl.build(:status) }
let(:model) { ::API::V3::Statuses::StatusModel.new(status) }
let(:representer) { described_class.new(model) }
context 'generation' do
subject(:generated) { representer.to_json }
it { should include_json('Status'.to_json).at_path('_type') }
xit { should have_json_type(Object).at_path('_links') }
xit 'should link to self' do
expect(subject).to have_json_path('_links/self/href')
end
describe 'status' do
it { should have_json_path('id') }
it { should have_json_path('name') }
end
end
end

@ -0,0 +1,64 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Versions::VersionCollectionRepresenter do
let(:project) { FactoryGirl.build(:project, id: 666) }
let(:versions) { FactoryGirl.build_list(:version, 3) }
let(:models) { versions.map { |version|
::API::V3::Versions::VersionModel.new(version)
} }
let(:representer) { described_class.new(models, project: project) }
describe '#initialize' do
context 'with incorrect parameters' do
it 'should raise without a project' do
expect { described_class.new(models) }.to raise_error(ArgumentError)
end
end
end
context 'generation' do
subject(:generated) { representer.to_json }
it { should include_json('Versions'.to_json).at_path('_type') }
it { should have_json_type(Object).at_path('_links') }
it 'should link to self' do
expect(generated).to have_json_path('_links/self/href')
expect(parse_json(generated, '_links/self/href')).to match %r{/api/v3/projects/666/versions$}
end
describe 'versions' do
it { should have_json_path('_embedded/versions') }
it { should have_json_size(3).at_path('_embedded/versions') }
it { should have_json_path('_embedded/versions/2/name') }
end
end
end

@ -0,0 +1,37 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Versions::VersionModel do
subject(:model) { ::API::V3::Versions::VersionModel.new(version) }
let(:version) { FactoryGirl.build(:version, attributes) }
let(:attributes) { { name: 'Specific Version' } }
its(:name) { should eq 'Specific Version' }
end

@ -0,0 +1,51 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe ::API::V3::Versions::VersionRepresenter do
let(:version) { FactoryGirl.build(:version) }
let(:model) { ::API::V3::Versions::VersionModel.new(version) }
let(:representer) { described_class.new(model) }
context 'generation' do
subject(:generated) { representer.to_json }
it { should include_json('Version'.to_json).at_path('_type') }
xit { should have_json_type(Object).at_path('_links') }
xit 'should link to self' do
expect(subject).to have_json_path('_links/self/href')
end
describe 'version' do
it { should have_json_path('id') }
it { should have_json_path('name') }
end
end
end

@ -0,0 +1,46 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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 status 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 status 2
# of the License, or (at your option) any later status.
#
# 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.
#++
require 'spec_helper'
require 'lib/api/v3/statuses/shared/status_collection_representer'
describe ::API::V3::WorkPackages::AvailableStatusCollectionRepresenter do
include_examples 'status collection representer'
context 'generation' do
subject(:generated) { representer.to_json(work_package_id: 1) }
it 'should have link to self' do
expect(parse_json(subject, '_links/self/href')).to end_with('api/v3/work_packages/1/available_statuses')
end
it 'should have link to work_package' do
expect(parse_json(subject, '_links/work_package/href')).to end_with('api/v3/work_packages/1')
end
end
end

@ -0,0 +1,67 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
require 'rack/test'
describe 'API v3 Priority resource' do
include Rack::Test::Methods
let(:current_user) { FactoryGirl.create(:user) }
let(:role) { FactoryGirl.create(:role, permissions: []) }
let(:project) { FactoryGirl.create(:project, is_public: false) }
let(:priorities) { FactoryGirl.create_list(:priority, 2) }
describe '#get' do
subject(:response) { last_response }
context 'logged in user' do
let(:get_path) { "/api/v3/priorities" }
before do
allow(User).to receive(:current).and_return current_user
member = FactoryGirl.build(:member, user: current_user, project: project)
member.role_ids = [role.id]
member.save!
priorities
get get_path
end
it 'should respond with 200' do
expect(subject.status).to eq(200)
end
it 'should respond with priorities, scoped to project' do
expect(subject.body).to include_json('Priorities'.to_json).at_path('_type')
expect(subject.body).to have_json_size(2).at_path('_embedded/priorities')
end
end
end
end

@ -0,0 +1,86 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
require 'rack/test'
describe 'API v3 Project resource' do
include Rack::Test::Methods
let(:current_user) { FactoryGirl.create(:user) }
let(:project) { FactoryGirl.create(:project, is_public: false) }
let(:role) { FactoryGirl.create(:role) }
describe '#get' do
subject(:response) { last_response }
context 'logged in user' do
let(:get_path) { "/api/v3/projects/#{project.id}" }
before do
allow(User).to receive(:current).and_return current_user
member = FactoryGirl.build(:member, user: current_user, project: project)
member.role_ids = [role.id]
member.save!
get get_path
end
it 'should respond with 200' do
expect(subject.status).to eq(200)
end
it 'should respond with correct project' do
expect(subject.body).to include_json('Project'.to_json).at_path('_type')
expect(subject.body).to be_json_eql(project.identifier.to_json).at_path('identifier')
end
context 'requesting nonexistent project' do
let(:get_path) { "/api/v3/projects/9999" }
it 'should respond with 404' do
expect(subject.status).to eq(404)
end
it 'should respond with explanatory error message' do
expect(subject.body).to include_json('not_found'.to_json).at_path('title')
end
end
context 'requesting project without sufficient permissions' do
let(:another_project) { FactoryGirl.create(:project, is_public: false) }
let(:get_path) { "/api/v3/projects/#{another_project.id}" }
it 'should respond with 403' do
expect(subject.status).to eq(403)
end
it 'should respond with explanatory error message' do
expect(subject.body).to include_json('not_authorized'.to_json).at_path('title')
end
end
end
end
end

@ -0,0 +1,52 @@
require 'spec_helper'
require 'rack/test'
describe 'API v3 Root resource' do
include Rack::Test::Methods
let(:current_user) { FactoryGirl.create(:user) }
let(:role) { FactoryGirl.create(:role, permissions: []) }
let(:project) { FactoryGirl.create(:project, is_public: false) }
describe '#get' do
subject(:response) { last_response }
let(:get_path) { "/api/v3" }
context 'anonymous user' do
before do
get get_path
end
it 'should respond with 200' do
expect(subject.status).to eq(200)
end
it 'should respond with links' do
expect(subject.body).to have_json_path('_links/priorities')
expect(subject.body).to have_json_path('_links/project')
expect(subject.body).to have_json_path('_links/statuses')
end
end
context 'logged in user' do
before do
allow(User).to receive(:current).and_return current_user
member = FactoryGirl.build(:member, user: current_user, project: project)
member.role_ids = [role.id]
member.save!
get get_path
end
it 'should respond with 200' do
expect(subject.status).to eq(200)
end
it 'should respond with links' do
expect(subject.body).to have_json_path('_links/priorities')
expect(subject.body).to have_json_path('_links/project')
expect(subject.body).to have_json_path('_links/statuses')
end
end
end
end

@ -0,0 +1,67 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
require 'rack/test'
describe 'API v3 Status resource' do
include Rack::Test::Methods
let(:current_user) { FactoryGirl.create(:user) }
let(:role) { FactoryGirl.create(:role, permissions: []) }
let(:project) { FactoryGirl.create(:project, is_public: false) }
let(:statuses) { FactoryGirl.create_list(:status, 4) }
describe '#get' do
subject(:response) { last_response }
context 'logged in user' do
let(:get_path) { "/api/v3/statuses" }
before do
allow(User).to receive(:current).and_return current_user
member = FactoryGirl.build(:member, user: current_user, project: project)
member.role_ids = [role.id]
member.save!
statuses
get get_path
end
it 'should respond with 200' do
expect(subject.status).to eq(200)
end
it 'should respond with statuses, scoped to project' do
expect(subject.body).to include_json('Statuses'.to_json).at_path('_type')
expect(subject.body).to have_json_size(4).at_path('_embedded/statuses')
end
end
end
end

@ -0,0 +1,40 @@
require 'spec_helper'
require 'rack/test'
describe 'API v3 Version resource' do
include Rack::Test::Methods
let(:current_user) { FactoryGirl.create(:user) }
let(:role) { FactoryGirl.create(:role, permissions: []) }
let(:project) { FactoryGirl.create(:project, is_public: false) }
let(:versions) { FactoryGirl.create_list(:version, 4, project: project) }
let(:other_versions) { FactoryGirl.create_list(:version, 2) }
describe '#get' do
subject(:response) { last_response }
context 'logged in user' do
let(:get_path) { "/api/v3/projects/#{project.id}/versions" }
before do
allow(User).to receive(:current).and_return current_user
member = FactoryGirl.build(:member, user: current_user, project: project)
member.role_ids = [role.id]
member.save!
versions
other_versions
get get_path
end
it 'should respond with 200' do
expect(subject.status).to eq(200)
end
it 'should respond with versions, scoped to project' do
expect(subject.body).to include_json('Versions'.to_json).at_path('_type')
expect(subject.body).to have_json_size(4).at_path('_embedded/versions')
end
end
end
end

@ -0,0 +1,98 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2014 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-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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
require 'rack/test'
describe API::V3::WorkPackages::StatusesAPI do
include Rack::Test::Methods
def app
API::V3::Root
end
let(:authorized_user) do
FactoryGirl.create(:user, member_in_project: project,
member_through_role: authorized_role)
end
let(:unauthorized_user) do
FactoryGirl.create(:user, member_in_project: project,
member_through_role: unauthorized_role)
end
let(:authorized_role) { FactoryGirl.create(:role, permissions: [:edit_work_packages]) }
let(:unauthorized_role) { FactoryGirl.create(:role, permissions: []) }
let(:project) { FactoryGirl.create(:valid_project, is_public: false) }
let(:work_package) do
FactoryGirl.create(:work_package, project: project)
end
let(:status) do
FactoryGirl.create(:status)
end
describe '#get work_packages/:id/available_statuses' do
let(:get_path) { "/api/v3/work_packages/#{work_package.id}/available_statuses" }
subject(:response) { last_response }
context 'permitted user' do
let(:new_type) { project.types.first }
let(:new_status) { Status.where("id NOT IN (#{work_package.status.id})").first }
before do
allow(User).to receive(:current).and_return authorized_user
FactoryGirl.create(:workflow, old_status: work_package.status,
new_status: new_status,
role: authorized_role,
type_id: new_type.id)
get get_path, type: new_type.name
end
it 'should respond with 200' do
expect(subject.status).to eql(200)
end
it 'should return a json collection of all statuses' do
expect(parse_json(response.body, '_embedded/statuses/0/name')).to eql(new_status.name)
end
end
context 'unauthorized user' do
before do
allow(User).to receive(:current).and_return unauthorized_user
get get_path
end
it 'should respond with 403' do
expect(subject.status).to eql(403)
end
end
end
end
Loading…
Cancel
Save