commit
11f6942906
@ -0,0 +1,202 @@ |
|||||||
|
/*! |
||||||
|
Copyright (c) 2011, 2012 Julien Wajsberg <felash@gmail.com> |
||||||
|
All rights reserved. |
||||||
|
|
||||||
|
Official repository: https://github.com/julienw/jquery-trap-input
|
||||||
|
License is there: https://github.com/julienw/jquery-trap-input/blob/master/LICENSE
|
||||||
|
This is version 1.2.0. |
||||||
|
*/ |
||||||
|
|
||||||
|
(function( $, undefined ){ |
||||||
|
|
||||||
|
/* |
||||||
|
(this comment is after the first line of code so that uglifyjs removes it) |
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without |
||||||
|
modification, are permitted without condition. |
||||||
|
|
||||||
|
Although that's not an obligation, I would appreciate that you provide a |
||||||
|
link to the official repository. |
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
||||||
|
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED. |
||||||
|
*/ |
||||||
|
|
||||||
|
/*jshint boss: true, bitwise: true, curly: true, expr: true, newcap: true, noarg: true, nonew: true, latedef: true, regexdash: true */ |
||||||
|
|
||||||
|
var DATA_ISTRAPPING_KEY = "trap.isTrapping"; |
||||||
|
|
||||||
|
function onkeypress(e) { |
||||||
|
if (e.keyCode === 9) { |
||||||
|
var goReverse = !!(e.shiftKey); |
||||||
|
if (processTab(this, e.target, goReverse)) { |
||||||
|
e.preventDefault(); |
||||||
|
e.stopPropagation(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// will return true if we could process the tab event
|
||||||
|
// otherwise, return false
|
||||||
|
function processTab(container, elt, goReverse) { |
||||||
|
var $focussable = getFocusableElementsInContainer(container), |
||||||
|
curElt = elt, |
||||||
|
index, nextIndex, prevIndex, lastIndex; |
||||||
|
|
||||||
|
do { |
||||||
|
|
||||||
|
index = $focussable.index(curElt); |
||||||
|
nextIndex = index + 1; |
||||||
|
prevIndex = index - 1; |
||||||
|
lastIndex = $focussable.length - 1; |
||||||
|
|
||||||
|
switch(index) { |
||||||
|
case -1: |
||||||
|
return false; // that's strange, let the browser do its job
|
||||||
|
case 0: |
||||||
|
prevIndex = lastIndex; |
||||||
|
break; |
||||||
|
case lastIndex: |
||||||
|
nextIndex = 0; |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
if (goReverse) { |
||||||
|
nextIndex = prevIndex; |
||||||
|
} |
||||||
|
|
||||||
|
curElt = $focussable.get(nextIndex); |
||||||
|
// IE sometimes throws when an element is not visible
|
||||||
|
try { |
||||||
|
curElt.focus(); |
||||||
|
} catch(e) { |
||||||
|
} |
||||||
|
|
||||||
|
} while (elt === elt.ownerDocument.activeElement); |
||||||
|
|
||||||
|
return true;
|
||||||
|
} |
||||||
|
|
||||||
|
function filterKeepSpeciallyFocusable() { |
||||||
|
return this.tabIndex > 0; |
||||||
|
} |
||||||
|
|
||||||
|
function filterKeepNormalElements() { |
||||||
|
return !this.tabIndex; // true if no tabIndex or tabIndex == 0
|
||||||
|
} |
||||||
|
|
||||||
|
function sortFocusable(a, b) { |
||||||
|
return (a.t - b.t) || (a.i - b.i); |
||||||
|
} |
||||||
|
|
||||||
|
function getFocusableElementsInContainer(container) { |
||||||
|
var $container = $(container); |
||||||
|
var result = [], |
||||||
|
cnt = 0; |
||||||
|
|
||||||
|
fixIndexSelector.enable && fixIndexSelector.enable(); |
||||||
|
|
||||||
|
// leaving away command and details for now
|
||||||
|
$container.find("a[href], link[href], [draggable=true], [contenteditable=true], :input:enabled, [tabindex=0]") |
||||||
|
.filter(":visible") |
||||||
|
.filter(filterKeepNormalElements) |
||||||
|
.each(function(i, val) { |
||||||
|
result.push({ |
||||||
|
v: val, // value
|
||||||
|
t: 0, // tabIndex
|
||||||
|
i: cnt++ // index for stable sort
|
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
$container |
||||||
|
.find("[tabindex]") |
||||||
|
.filter(":visible") |
||||||
|
.filter(filterKeepSpeciallyFocusable) |
||||||
|
.each(function(i, val) { |
||||||
|
result.push({ |
||||||
|
v: val, // value
|
||||||
|
t: val.tabIndex, // tabIndex
|
||||||
|
i: cnt++ // index
|
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
fixIndexSelector.disable && fixIndexSelector.disable(); |
||||||
|
|
||||||
|
result = $.map(result.sort(sortFocusable), // needs stable sort
|
||||||
|
function(val) { |
||||||
|
return val.v; |
||||||
|
} |
||||||
|
); |
||||||
|
|
||||||
|
|
||||||
|
return $(result); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
function trap() { |
||||||
|
this.keydown(onkeypress); |
||||||
|
this.data(DATA_ISTRAPPING_KEY, true); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
function untrap() { |
||||||
|
this.unbind('keydown', onkeypress); |
||||||
|
this.removeData(DATA_ISTRAPPING_KEY); |
||||||
|
return this; |
||||||
|
} |
||||||
|
|
||||||
|
function isTrapping() { |
||||||
|
return !!this.data(DATA_ISTRAPPING_KEY); |
||||||
|
} |
||||||
|
|
||||||
|
$.fn.extend({ |
||||||
|
trap: trap, |
||||||
|
untrap: untrap, |
||||||
|
isTrapping: isTrapping |
||||||
|
}); |
||||||
|
|
||||||
|
// jQuery 1.6.x tabindex attr hooks management
|
||||||
|
// this triggers problems for tabindex attribute
|
||||||
|
// selectors in IE7-
|
||||||
|
// see https://github.com/julienw/jquery-trap-input/issues/3
|
||||||
|
|
||||||
|
var fixIndexSelector = {}; |
||||||
|
|
||||||
|
if ($.find.find && $.find.attr !== $.attr) { |
||||||
|
// jQuery uses Sizzle (this is jQuery >= 1.3)
|
||||||
|
// sizzle uses its own attribute handling (in jq 1.6.x and below)
|
||||||
|
(function() { |
||||||
|
var tabindexKey = "tabindex"; |
||||||
|
var sizzleAttrHandle = $.expr.attrHandle; |
||||||
|
|
||||||
|
// this function comes directly from jQuery 1.7.2 (propHooks.tabIndex.get)
|
||||||
|
// we have to put it here if we want to support jQuery < 1.6 which
|
||||||
|
// doesn't have an attrHooks object to reference.
|
||||||
|
function getTabindexAttr(elem) { |
||||||
|
// elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
|
||||||
|
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
|
||||||
|
var attributeNode = elem.getAttributeNode(tabindexKey); |
||||||
|
|
||||||
|
return attributeNode && attributeNode.specified ? |
||||||
|
parseInt( attributeNode.value, 10 ) : |
||||||
|
undefined; |
||||||
|
} |
||||||
|
|
||||||
|
function fixSizzleAttrHook() { |
||||||
|
// in jQ <= 1.6.x, we add to Sizzle the attrHook from jQuery's attr method
|
||||||
|
sizzleAttrHandle[tabindexKey] = sizzleAttrHandle.tabIndex = getTabindexAttr; |
||||||
|
} |
||||||
|
|
||||||
|
function unfixSizzleAttrHook() { |
||||||
|
delete sizzleAttrHandle[tabindexKey]; |
||||||
|
delete sizzleAttrHandle.tabIndex; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
fixIndexSelector = { |
||||||
|
enable: fixSizzleAttrHook, |
||||||
|
disable: unfixSizzleAttrHook |
||||||
|
}; |
||||||
|
})(); |
||||||
|
} |
||||||
|
})( jQuery ); |
@ -0,0 +1,143 @@ |
|||||||
|
//-- 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.
|
||||||
|
//++
|
||||||
|
|
||||||
|
(function($) { |
||||||
|
var TypesCheckboxes = function () { |
||||||
|
this.init(); |
||||||
|
}; |
||||||
|
|
||||||
|
TypesCheckboxes.prototype = $.extend(TypesCheckboxes.prototype, { |
||||||
|
init: function () { |
||||||
|
this.append_checkbox_listeners(); |
||||||
|
this.append_check_uncheck_all_listeners(); |
||||||
|
if (this.everything_unchecked()) { |
||||||
|
this.check_and_disable_standard_type(); |
||||||
|
} |
||||||
|
}, |
||||||
|
|
||||||
|
append_checkbox_listeners: function () { |
||||||
|
var self = this; |
||||||
|
this.all_checkboxes().on("change", function () { |
||||||
|
if (self.everything_unchecked()) { |
||||||
|
self.check_and_disable_standard_type(); |
||||||
|
self.display_explanation(); |
||||||
|
} else { |
||||||
|
self.hide_explanation(); |
||||||
|
self.enable_standard_type(); |
||||||
|
} |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
append_check_uncheck_all_listeners: function () { |
||||||
|
var self = this; |
||||||
|
$("#project_types #check_all_types").click(function (event) { |
||||||
|
self.enable_all_checkboxes(); |
||||||
|
self.check(self.all_checkboxes()); |
||||||
|
self.hide_explanation(); |
||||||
|
event.preventDefault(); |
||||||
|
}); |
||||||
|
$("#project_types #uncheck_all_types").click(function (event) { |
||||||
|
self.enable_all_checkboxes(); |
||||||
|
self.uncheck(self.all_except_standard()); |
||||||
|
self.check_and_disable_standard_type(); |
||||||
|
self.display_explanation(); |
||||||
|
event.preventDefault(); |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
everything_unchecked: function () { |
||||||
|
return !(this.all_except_standard().filter(":checked").length > 0); |
||||||
|
}, |
||||||
|
|
||||||
|
check_and_disable_standard_type: function () { |
||||||
|
var standard = this.standard_check_boxes(); |
||||||
|
this.check($(standard)); |
||||||
|
this.disable($(standard)); |
||||||
|
}, |
||||||
|
|
||||||
|
enable_standard_type: function () { |
||||||
|
this.enable(this.standard_check_boxes()); |
||||||
|
}, |
||||||
|
|
||||||
|
enable_all_checkboxes: function () { |
||||||
|
this.enable(this.all_checkboxes()) |
||||||
|
}, |
||||||
|
|
||||||
|
check: function (boxes) { |
||||||
|
$(boxes).prop("checked", true); |
||||||
|
}, |
||||||
|
|
||||||
|
uncheck: function (boxes) { |
||||||
|
$(boxes).prop("checked", false); |
||||||
|
}, |
||||||
|
|
||||||
|
disable: function (boxes) { |
||||||
|
var self = this; |
||||||
|
$(boxes).prop('disabled', true); |
||||||
|
$(boxes).each(function (ix, item) { |
||||||
|
self.hidden_type_field($(item)).prop("value", $(item).prop("value")); |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
enable: function (boxes) { |
||||||
|
var self = this; |
||||||
|
$(boxes).prop('disabled', false); |
||||||
|
$(boxes).each(function (ix, item) { |
||||||
|
self.hidden_type_field($(item)).prop("value", ""); |
||||||
|
}); |
||||||
|
}, |
||||||
|
|
||||||
|
display_explanation: function () { |
||||||
|
$("#types_flash_notice").show(); |
||||||
|
}, |
||||||
|
|
||||||
|
hide_explanation: function () { |
||||||
|
$("#types_flash_notice").hide(); |
||||||
|
}, |
||||||
|
|
||||||
|
all_checkboxes: function () { |
||||||
|
return $(".types :input[type='checkbox']"); |
||||||
|
}, |
||||||
|
|
||||||
|
all_except_standard: function () { |
||||||
|
return $(".types :input[type='checkbox'][data-standard='false']"); |
||||||
|
}, |
||||||
|
|
||||||
|
standard_check_boxes: function () { |
||||||
|
return $(".types :input[type='checkbox'][data-standard='true']"); |
||||||
|
}, |
||||||
|
|
||||||
|
hidden_type_field: function (for_box) { |
||||||
|
return $(".types :input[type='hidden'][data-for='" + $(for_box).prop("id") + "']"); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
|
$('document').ready(function () { |
||||||
|
new TypesCheckboxes(); |
||||||
|
}); |
||||||
|
})(jQuery); |
@ -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