Merge pull request #857 from opf/feature/api_expose_work_package_priorities_3347
[FEATURE] API expose work package priorities 3347pull/825/head
commit
eff50a0be6
@ -0,0 +1,52 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2013 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. |
||||
#++ |
||||
|
||||
# resolves either a given status (show) or returns a list of available statuses |
||||
# if the controller is called nested inside a project, it returns only the |
||||
# statuses that can be reached by the workflows of the project |
||||
module Api |
||||
module V2 |
||||
class WorkPackagePrioritiesController < ApplicationController |
||||
include PaginationHelper |
||||
|
||||
include ::Api::V2::ApiController |
||||
|
||||
unloadable |
||||
|
||||
accept_key_auth :index |
||||
|
||||
def index |
||||
@priorities = IssuePriority.all |
||||
|
||||
respond_to do |format| |
||||
format.api |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,32 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2013 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. |
||||
#++ |
||||
collection @priorities => :work_package_priorities |
||||
attributes :id, |
||||
:name, |
||||
:position, |
||||
:is_default |
@ -0,0 +1,69 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2013 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 File.expand_path('../../../../spec_helper', __FILE__) |
||||
|
||||
describe Api::V2::WorkPackagePrioritiesController do |
||||
let(:current_user) { FactoryGirl.create(:admin) } |
||||
|
||||
before { User.stub(:current).and_return current_user } |
||||
|
||||
describe '#index' do |
||||
shared_examples_for 'valid work package priority index request' do |
||||
it { expect(response).to be_success } |
||||
|
||||
it { expect(response).to render_template('api/v2/work_package_priorities/index', format: ['api']) } |
||||
end |
||||
|
||||
describe 'w/o priorities' do |
||||
before { get :index, format: :xml } |
||||
|
||||
it { expect(assigns(:priorities)).to be_empty } |
||||
|
||||
it_behaves_like 'valid work package priority index request' |
||||
end |
||||
|
||||
describe 'w/o priorities' do |
||||
let!(:priority_0) { FactoryGirl.create(:priority) } |
||||
let!(:priority_1) { FactoryGirl.create(:priority, |
||||
position: 1) } |
||||
let!(:priority_2) { FactoryGirl.create(:priority, |
||||
position: 2, |
||||
is_default: true) } |
||||
|
||||
before { get :index, format: :xml } |
||||
|
||||
it { expect(assigns(:priorities)).not_to be_empty } |
||||
|
||||
it { expect(assigns(:priorities).count).to eq(3) } |
||||
|
||||
it_behaves_like 'valid work package priority index request' |
||||
end |
||||
end |
||||
end |
||||
|
@ -0,0 +1,40 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2013 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::V2::WorkPackagePrioritiesController do |
||||
|
||||
describe "index" do |
||||
it { expect(get("/api/v2/work_package_priorities")).to route_to(controller: 'api/v2/work_package_priorities', |
||||
action: 'index')} |
||||
end |
||||
|
||||
end |
||||
|
||||
|
@ -0,0 +1,98 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2013 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 File.expand_path('../../../../../spec_helper', __FILE__) |
||||
|
||||
describe 'api/v2/work_package_priorities/index.api.rabl' do |
||||
|
||||
before { params[:format] = 'xml' } |
||||
|
||||
describe 'with no work package priorities available' do |
||||
before do |
||||
assign(:priorities, []) |
||||
render |
||||
end |
||||
|
||||
subject { response.body } |
||||
|
||||
it 'renders an empty work_package_priorities document' do |
||||
expect(subject).to have_selector('work_package_priorities', count: 1) |
||||
expect(subject).to have_selector('work_package_priorities[type=array]') do |tag| |
||||
expect(tag).to have_selector('work_package_priority', count: 0) |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'with 3 work package priorities available' do |
||||
let!(:priority_0) { FactoryGirl.create(:priority) } |
||||
let!(:priority_1) { FactoryGirl.create(:priority, |
||||
position: 1) } |
||||
let!(:priority_2) { FactoryGirl.create(:priority, |
||||
position: 2, |
||||
is_default: true) } |
||||
|
||||
before do |
||||
assign(:priorities, [priority_0, priority_1, priority_2]) |
||||
render |
||||
end |
||||
|
||||
subject { Nokogiri.XML(response.body) } |
||||
|
||||
it { expect(subject).to have_selector('work_package_priorities work_package_priority', count: 3) } |
||||
|
||||
context 'priority 0' do |
||||
it 'has empty position' do |
||||
expect(subject).to have_selector('work_package_priorities work_package_priority id', text: priority_0.id) do |tag| |
||||
expect(tag.parent).to have_selector('position', text: nil) |
||||
end |
||||
end |
||||
|
||||
it 'has empty default setting' do |
||||
expect(subject).to have_selector('work_package_priorities work_package_priority id', text: priority_0.id) do |tag| |
||||
expect(tag.parent).to have_selector('is_default', text: nil) |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'priority 1' do |
||||
it 'has position' do |
||||
expect(subject).to have_selector('work_package_priorities work_package_priority id', text: priority_1.id) do |tag| |
||||
expect(tag.parent).to have_selector('position', text: priority_1.position) |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'priority 2' do |
||||
it 'has default value set' do |
||||
expect(subject).to have_selector('work_package_priorities work_package_priority id', text: priority_2.id) do |tag| |
||||
expect(tag.parent).to have_selector('position', text: priority_2.is_default) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue