Conflicts: app/models/work_package.rb lib/api/v3/work_packages/schema/work_package_schema.rb spec/lib/api/v3/work_packages/schema/work_package_schema_spec.rb spec/lib/api/v3/work_packages/work_package_schema_representer_spec.rbpull/2655/head
commit
7e3f2da2e9
@ -0,0 +1,129 @@ |
|||||||
|
//-- copyright
|
||||||
|
// OpenProject is a project management system.
|
||||||
|
// Copyright (C) 2012-2015 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($) { |
||||||
|
/* |
||||||
|
* @see /app/views/custom_fields/_form.html.erb |
||||||
|
*/ |
||||||
|
$(function() { |
||||||
|
var customFieldForm = $('#custom_field_form'); |
||||||
|
|
||||||
|
if (customFieldForm.length === 0) { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// collect the nodes involved
|
||||||
|
var format = $('#custom_field_field_format'), |
||||||
|
lengthField = $('#custom_field_length'), |
||||||
|
regexpField = $('#custom_field_regexp'), |
||||||
|
possibleValues = $('#custom_field_possible_values_attributes'), |
||||||
|
defaultValueFields = $('#custom_field_default_value_attributes'), |
||||||
|
spanDefaultTextMulti = $('#default_value_text_multi'), |
||||||
|
spanDefaultTextSingle = $('#default_value_text_single'), |
||||||
|
spanDefaultBool = $('#default_value_bool'); |
||||||
|
|
||||||
|
var deactivate = function(element) { |
||||||
|
element.hide().find('input, textarea').not('.destroy_flag').attr('disabled', true); |
||||||
|
}, |
||||||
|
activate = function(element) { |
||||||
|
element.show().find('input, textarea').not('.destroy_flag').removeAttr('disabled'); |
||||||
|
}, |
||||||
|
toggleVisibility = function(method, args) { |
||||||
|
var fields = Array.prototype.slice.call(args); |
||||||
|
$.each(fields, function(idx, field) { |
||||||
|
field.closest('.form--field, .form--grouping')[method](); |
||||||
|
}); |
||||||
|
}, |
||||||
|
hide = function() { toggleVisibility('hide', arguments); }, |
||||||
|
show = function() { toggleVisibility('show', arguments); }, |
||||||
|
toggleFormat = function() { |
||||||
|
var searchable = $('#searchable_container'), |
||||||
|
unsearchable = function() { searchable.attr('checked', false).hide(); }; |
||||||
|
|
||||||
|
// defaults (reset these fields before doing anything else)
|
||||||
|
$.each([spanDefaultBool, spanDefaultTextSingle], function(idx, element) { |
||||||
|
deactivate(element); |
||||||
|
}); |
||||||
|
show(defaultValueFields); |
||||||
|
activate(spanDefaultTextMulti); |
||||||
|
|
||||||
|
switch (format.val()) { |
||||||
|
case 'list': |
||||||
|
hide(lengthField, regexpField); |
||||||
|
show(searchable); |
||||||
|
activate(possibleValues); |
||||||
|
break; |
||||||
|
case 'bool': |
||||||
|
activate(spanDefaultBool); |
||||||
|
deactivate(spanDefaultTextMulti); |
||||||
|
deactivate(possibleValues); |
||||||
|
hide(lengthField, regexpField, searchable); |
||||||
|
unsearchable(); |
||||||
|
break; |
||||||
|
case 'date': |
||||||
|
activate(spanDefaultTextSingle); |
||||||
|
deactivate(spanDefaultTextMulti); |
||||||
|
deactivate(possibleValues); |
||||||
|
hide(lengthField, regexpField); |
||||||
|
unsearchable(); |
||||||
|
break; |
||||||
|
case 'float': |
||||||
|
case 'int': |
||||||
|
activate(spanDefaultTextSingle); |
||||||
|
deactivate(spanDefaultTextMulti); |
||||||
|
deactivate(possibleValues); |
||||||
|
show(lengthField, regexpField); |
||||||
|
unsearchable(); |
||||||
|
break; |
||||||
|
case 'user': |
||||||
|
case 'version': |
||||||
|
deactivate(defaultValueFields); |
||||||
|
deactivate(possibleValues); |
||||||
|
hide(lengthField, regexpField, defaultValueFields); |
||||||
|
unsearchable(); |
||||||
|
break; |
||||||
|
default: |
||||||
|
show(lengthField, regexpField, searchable); |
||||||
|
deactivate(possibleValues); |
||||||
|
break; |
||||||
|
} |
||||||
|
}; |
||||||
|
|
||||||
|
// assign the switch format function to the select field
|
||||||
|
format.on('change', toggleFormat).trigger('change'); |
||||||
|
}); |
||||||
|
|
||||||
|
$(function() { |
||||||
|
var localeSelectors = $('.locale_selector'); |
||||||
|
|
||||||
|
localeSelectors.change(function () { |
||||||
|
var lang = $(this).val(), |
||||||
|
span = $(this).closest('.translation'); |
||||||
|
span.attr('lang', lang); |
||||||
|
}).trigger('change'); |
||||||
|
}); |
||||||
|
}(jQuery)); |
@ -0,0 +1,30 @@ |
|||||||
|
<%#-- copyright |
||||||
|
OpenProject is a project management system. |
||||||
|
Copyright (C) 2012-2015 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. |
||||||
|
|
||||||
|
++#%> |
||||||
|
|
||||||
|
jQuery('#work_package_fixed_version_id').empty().append("<%= escape_javascript(version_options_for_select(versions, version)) %>"); |
@ -0,0 +1,38 @@ |
|||||||
|
#-- encoding: UTF-8 |
||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2015 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 Types |
||||||
|
class TypeCollectionRepresenter < ::API::Decorators::Collection |
||||||
|
element_decorator ::API::V3::Types::TypeRepresenter |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,57 @@ |
|||||||
|
#-- encoding: UTF-8 |
||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2015 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 Types |
||||||
|
class TypeRepresenter < ::API::Decorators::Single |
||||||
|
self_link |
||||||
|
|
||||||
|
property :id |
||||||
|
property :name |
||||||
|
property :color, |
||||||
|
getter: -> (*) { color.hexcode if color }, |
||||||
|
render_nil: true |
||||||
|
property :position |
||||||
|
property :is_default |
||||||
|
property :is_milestone |
||||||
|
property :created_at, |
||||||
|
exec_context: :decorator, |
||||||
|
getter: -> (*) { datetime_formatter.format_datetime(represented.created_at) } |
||||||
|
property :updated_at, |
||||||
|
exec_context: :decorator, |
||||||
|
getter: -> (*) { datetime_formatter.format_datetime(represented.updated_at) } |
||||||
|
|
||||||
|
def _type |
||||||
|
'Type' |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,60 @@ |
|||||||
|
#-- encoding: UTF-8 |
||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2015 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 Types |
||||||
|
class TypesAPI < Grape::API |
||||||
|
resources :types do |
||||||
|
before do |
||||||
|
authorize_any([:view_work_packages, :manage_types], global: true) |
||||||
|
end |
||||||
|
|
||||||
|
get do |
||||||
|
types = Type.all |
||||||
|
TypeCollectionRepresenter.new(types, |
||||||
|
types.count, |
||||||
|
api_v3_paths.types) |
||||||
|
end |
||||||
|
|
||||||
|
namespace ':id' do |
||||||
|
before do |
||||||
|
type = Type.find(params[:id]) |
||||||
|
@representer = ::API::V3::Types::TypeRepresenter.new(type) |
||||||
|
end |
||||||
|
|
||||||
|
get do |
||||||
|
@representer |
||||||
|
end |
||||||
|
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 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 Types |
||||||
|
class TypesByProjectAPI < Grape::API |
||||||
|
resources :types do |
||||||
|
before do |
||||||
|
authorize_any [:view_work_packages, :manage_types], projects: @project |
||||||
|
end |
||||||
|
|
||||||
|
get do |
||||||
|
types = @project.types |
||||||
|
TypeCollectionRepresenter.new(types, |
||||||
|
types.count, |
||||||
|
api_v3_paths.types_by_project(@project.id), |
||||||
|
context: { current_user: current_user }) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,106 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2015 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::Types::TypeRepresenter do |
||||||
|
let(:type) { FactoryGirl.build_stubbed(:type, color: FactoryGirl.build(:color)) } |
||||||
|
let(:representer) { described_class.new(type) } |
||||||
|
|
||||||
|
include API::V3::Utilities::PathHelper |
||||||
|
|
||||||
|
context 'generation' do |
||||||
|
subject { representer.to_json } |
||||||
|
|
||||||
|
describe 'links' do |
||||||
|
it_behaves_like 'has a titled link' do |
||||||
|
let(:link) { 'self' } |
||||||
|
let(:href) { api_v3_paths.type(type.id) } |
||||||
|
let(:title) { type.name } |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it 'indicates its id' do |
||||||
|
is_expected.to be_json_eql(type.id.to_json).at_path('id') |
||||||
|
end |
||||||
|
|
||||||
|
it 'indicates its name' do |
||||||
|
is_expected.to be_json_eql(type.name.to_json).at_path('name') |
||||||
|
end |
||||||
|
|
||||||
|
it 'indicates its color' do |
||||||
|
is_expected.to be_json_eql(type.color.hexcode.to_json).at_path('color') |
||||||
|
end |
||||||
|
|
||||||
|
context 'no color set' do |
||||||
|
let(:type) { FactoryGirl.build(:type, color: nil) } |
||||||
|
|
||||||
|
it 'indicates a missing color' do |
||||||
|
is_expected.to be_json_eql(nil.to_json).at_path('color') |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it 'indicates its position' do |
||||||
|
is_expected.to be_json_eql(type.position.to_json).at_path('position') |
||||||
|
end |
||||||
|
|
||||||
|
it 'indicates that it is not the default type' do |
||||||
|
is_expected.to be_json_eql(false.to_json).at_path('isDefault') |
||||||
|
end |
||||||
|
|
||||||
|
context 'as default type' do |
||||||
|
let(:type) { FactoryGirl.build(:type, is_default: true) } |
||||||
|
|
||||||
|
it 'indicates that it is the default type' do |
||||||
|
is_expected.to be_json_eql(true.to_json).at_path('isDefault') |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it 'indicates that it is not a milestone' do |
||||||
|
is_expected.to be_json_eql(false.to_json).at_path('isMilestone') |
||||||
|
end |
||||||
|
|
||||||
|
context 'as milestone' do |
||||||
|
let(:type) { FactoryGirl.build(:type, is_milestone: true) } |
||||||
|
|
||||||
|
it 'indicates that it is a milestone' do |
||||||
|
is_expected.to be_json_eql(true.to_json).at_path('isMilestone') |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
it_behaves_like 'has UTC ISO 8601 date and time' do |
||||||
|
let(:date) { type.created_at } |
||||||
|
let(:json_path) { 'createdAt' } |
||||||
|
end |
||||||
|
|
||||||
|
it_behaves_like 'has UTC ISO 8601 date and time' do |
||||||
|
let(:date) { type.updated_at } |
||||||
|
let(:json_path) { 'updatedAt' } |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,159 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2015 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::WorkPackages::WorkPackageContract do |
||||||
|
let(:work_package) do |
||||||
|
FactoryGirl.create(:work_package, |
||||||
|
done_ratio: 50, |
||||||
|
estimated_hours: 6.0, |
||||||
|
project: project) |
||||||
|
end |
||||||
|
let(:member) { FactoryGirl.create(:user, member_in_project: project, member_through_role: role) } |
||||||
|
let (:project) { FactoryGirl.create(:project) } |
||||||
|
let(:current_user) { member } |
||||||
|
let(:permissions) { |
||||||
|
[ |
||||||
|
:view_work_packages, |
||||||
|
:view_work_package_watchers, |
||||||
|
:edit_work_packages, |
||||||
|
:add_work_package_watchers, |
||||||
|
:delete_work_package_watchers, |
||||||
|
:manage_work_package_relations, |
||||||
|
:add_work_package_notes |
||||||
|
] |
||||||
|
} |
||||||
|
let(:role) { FactoryGirl.create :role, permissions: permissions } |
||||||
|
let(:changed_values) { [] } |
||||||
|
|
||||||
|
subject(:contract) { described_class.new(work_package, current_user) } |
||||||
|
|
||||||
|
before do |
||||||
|
allow(work_package).to receive(:changed).and_return(changed_values) |
||||||
|
end |
||||||
|
|
||||||
|
describe 'estimated hours' do |
||||||
|
context 'is no parent' do |
||||||
|
before do |
||||||
|
contract.validate |
||||||
|
end |
||||||
|
|
||||||
|
context 'has not changed' do |
||||||
|
it('is valid') { expect(contract.errors.empty?).to be true } |
||||||
|
end |
||||||
|
|
||||||
|
context 'has changed' do |
||||||
|
let(:changed_values) { ['estimated_hours'] } |
||||||
|
|
||||||
|
it('is valid') { expect(contract.errors.empty?).to be true } |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'is a parent' do |
||||||
|
before do |
||||||
|
child |
||||||
|
work_package.reload |
||||||
|
contract.validate |
||||||
|
end |
||||||
|
let(:child) do |
||||||
|
FactoryGirl.create(:work_package, parent_id: work_package.id, project: project) |
||||||
|
end |
||||||
|
|
||||||
|
context 'has not changed' do |
||||||
|
it('is valid') { expect(contract.errors.empty?).to be true } |
||||||
|
end |
||||||
|
|
||||||
|
context 'has changed' do |
||||||
|
let(:changed_values) { ['estimated_hours'] } |
||||||
|
|
||||||
|
it('is invalid') do |
||||||
|
expect(contract.errors[:error_readonly]).to match_array(changed_values) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe 'percentage done' do |
||||||
|
context 'has not changed' do |
||||||
|
before do |
||||||
|
contract.validate |
||||||
|
end |
||||||
|
|
||||||
|
it('is valid') { expect(contract.errors.empty?).to be true } |
||||||
|
end |
||||||
|
|
||||||
|
context 'has changed' do |
||||||
|
before do |
||||||
|
contract.validate |
||||||
|
end |
||||||
|
|
||||||
|
let(:changed_values) { ['done_ratio'] } |
||||||
|
|
||||||
|
it('is valid') { expect(contract.errors.empty?).to be true } |
||||||
|
|
||||||
|
context 'is parent' do |
||||||
|
before do |
||||||
|
child |
||||||
|
work_package.reload |
||||||
|
contract.validate |
||||||
|
end |
||||||
|
|
||||||
|
let(:child) do |
||||||
|
FactoryGirl.create(:work_package, parent_id: work_package.id, project: project) |
||||||
|
end |
||||||
|
|
||||||
|
it('is invalid') do |
||||||
|
expect(contract.errors[:error_readonly]).to match_array(changed_values) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'done ratio inferred by status' do |
||||||
|
before do |
||||||
|
allow(Setting).to receive(:work_package_done_ratio).and_return('status') |
||||||
|
contract.validate |
||||||
|
end |
||||||
|
|
||||||
|
it('is invalid') do |
||||||
|
expect(contract.errors[:error_readonly]).to match_array(changed_values) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'done ratio disabled' do |
||||||
|
before do |
||||||
|
allow(Setting).to receive(:work_package_done_ratio).and_return('disabled') |
||||||
|
contract.validate |
||||||
|
end |
||||||
|
|
||||||
|
it('is invalid') do |
||||||
|
expect(contract.errors[:error_readonly]).to match_array(changed_values) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,60 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2015 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 CustomValue::FormatStrategy do |
||||||
|
let(:custom_value) { |
||||||
|
double('CustomValue', |
||||||
|
value: value) |
||||||
|
} |
||||||
|
|
||||||
|
describe '#value_present?' do |
||||||
|
subject { described_class.new(custom_value).value_present? } |
||||||
|
|
||||||
|
context 'value is nil' do |
||||||
|
let(:value) { nil } |
||||||
|
it { is_expected.to eql(false) } |
||||||
|
end |
||||||
|
|
||||||
|
context 'value is empty string' do |
||||||
|
let(:value) { '' } |
||||||
|
it { is_expected.to eql(false) } |
||||||
|
end |
||||||
|
|
||||||
|
context 'value is present string' do |
||||||
|
let(:value) { 'foo' } |
||||||
|
it { is_expected.to eql(true) } |
||||||
|
end |
||||||
|
|
||||||
|
context 'value is present integer' do |
||||||
|
let(:value) { 42 } |
||||||
|
it { is_expected.to eql(true) } |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,113 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2015 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 Type resource' do |
||||||
|
include Rack::Test::Methods |
||||||
|
|
||||||
|
let(:role) { FactoryGirl.create(:role, permissions: [:view_work_packages]) } |
||||||
|
let(:project) { FactoryGirl.create(:project, no_types: true, is_public: false) } |
||||||
|
let(:current_user) do |
||||||
|
FactoryGirl.create(:user, |
||||||
|
member_in_project: project, |
||||||
|
member_through_role: role) |
||||||
|
end |
||||||
|
|
||||||
|
let!(:types) { FactoryGirl.create_list(:type, 4) } |
||||||
|
|
||||||
|
describe 'types' do |
||||||
|
describe '#get' do |
||||||
|
let(:get_path) { '/api/v3/types' } |
||||||
|
subject(:response) { last_response } |
||||||
|
|
||||||
|
context 'logged in user' do |
||||||
|
before do |
||||||
|
allow(User).to receive(:current).and_return current_user |
||||||
|
|
||||||
|
get get_path |
||||||
|
end |
||||||
|
|
||||||
|
it_behaves_like 'API V3 collection response', 4, 4, 'Type' |
||||||
|
end |
||||||
|
|
||||||
|
context 'not logged in user' do |
||||||
|
before do |
||||||
|
get get_path |
||||||
|
end |
||||||
|
|
||||||
|
it_behaves_like 'error response', |
||||||
|
403, |
||||||
|
'MissingPermission', |
||||||
|
I18n.t('api_v3.errors.code_403') |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe 'types/:id' do |
||||||
|
describe '#get' do |
||||||
|
let(:status) { types.first } |
||||||
|
let(:get_path) { "/api/v3/types/#{status.id}" } |
||||||
|
|
||||||
|
subject(:response) { last_response } |
||||||
|
|
||||||
|
context 'logged in user' do |
||||||
|
before do |
||||||
|
allow(User).to receive(:current).and_return(current_user) |
||||||
|
|
||||||
|
get get_path |
||||||
|
end |
||||||
|
|
||||||
|
context 'valid type id' do |
||||||
|
it { expect(response.status).to eq(200) } |
||||||
|
end |
||||||
|
|
||||||
|
context 'invalid type id' do |
||||||
|
let(:get_path) { '/api/v3/types/bogus' } |
||||||
|
|
||||||
|
it_behaves_like 'not found' do |
||||||
|
let(:id) { 'bogus' } |
||||||
|
let(:type) { 'Type' } |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'not logged in user' do |
||||||
|
before do |
||||||
|
get get_path |
||||||
|
end |
||||||
|
|
||||||
|
it_behaves_like 'error response', |
||||||
|
403, |
||||||
|
'MissingPermission', |
||||||
|
I18n.t('api_v3.errors.code_403') |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,95 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2015 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/projects/:id/types' do |
||||||
|
include Rack::Test::Methods |
||||||
|
|
||||||
|
let(:role) { FactoryGirl.create(:role, permissions: [:view_work_packages]) } |
||||||
|
let(:project) { FactoryGirl.create(:project, no_types: true, is_public: false) } |
||||||
|
let(:requested_project) { project } |
||||||
|
let(:current_user) do |
||||||
|
FactoryGirl.create(:user, |
||||||
|
member_in_project: project, |
||||||
|
member_through_role: role) |
||||||
|
end |
||||||
|
|
||||||
|
let!(:irrelevant_types) { FactoryGirl.create_list(:type, 4) } |
||||||
|
let!(:expected_types) { FactoryGirl.create_list(:type, 4) } |
||||||
|
|
||||||
|
describe '#get' do |
||||||
|
let(:get_path) { "/api/v3/projects/#{requested_project.id}/types" } |
||||||
|
subject(:response) { last_response } |
||||||
|
|
||||||
|
before do |
||||||
|
project.types << expected_types |
||||||
|
end |
||||||
|
|
||||||
|
context 'logged in user' do |
||||||
|
before do |
||||||
|
allow(User).to receive(:current).and_return current_user |
||||||
|
|
||||||
|
get get_path |
||||||
|
end |
||||||
|
|
||||||
|
it_behaves_like 'API V3 collection response', 4, 4, 'Type' |
||||||
|
|
||||||
|
it 'only contains expected types' do |
||||||
|
actual_types = JSON.parse(subject.body)['_embedded']['elements'] |
||||||
|
actual_type_ids = actual_types.map { |hash| hash['id'] } |
||||||
|
expected_type_ids = expected_types.map(&:id) |
||||||
|
|
||||||
|
expect(actual_type_ids).to match_array expected_type_ids |
||||||
|
end |
||||||
|
|
||||||
|
# N.B. this test depends on order, while this is not strictly neccessary |
||||||
|
it 'only contains expected types' do |
||||||
|
(0..3).each do |i| |
||||||
|
expected_id = expected_types[i].id.to_json |
||||||
|
expect(subject.body).to be_json_eql(expected_id).at_path("_embedded/elements/#{i}/id") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'in a foreign project' do |
||||||
|
let(:requested_project) { FactoryGirl.create(:project, is_public: false) } |
||||||
|
|
||||||
|
it_behaves_like 'not found' |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context 'not logged in user' do |
||||||
|
before do |
||||||
|
get get_path |
||||||
|
end |
||||||
|
|
||||||
|
it_behaves_like 'not found' |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue