Merge pull request #1634 from opf/feature/api-auxiliary-resources
commit
1eefc86a2d
@ -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 |
@ -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 |
@ -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 |
@ -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 |
||||||
|
|
@ -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…
Reference in new issue