parent
c93444aacb
commit
24e858c396
@ -0,0 +1,56 @@ |
||||
#-- copyright |
||||
# OpenProject Backlogs Plugin |
||||
# |
||||
# Copyright (C)2013-2014 the OpenProject Foundation (OPF) |
||||
# Copyright (C)2011 Stephan Eckardt, Tim Felgentreff, Marnen Laibow-Koser, Sandro Munda |
||||
# Copyright (C)2010-2011 friflaj |
||||
# Copyright (C)2010 Maxime Guilbot, Andrew Vit, Joakim Kolsjö, ibussieres, Daniel Passos, Jason Vasquez, jpic, Emiliano Heyns |
||||
# Copyright (C)2009-2010 Mark Maglana |
||||
# Copyright (C)2009 Joe Heck, Nate Lowrie |
||||
# |
||||
# 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 Backlogs is a derivative work based on ChiliProject Backlogs. |
||||
# The copyright follows: |
||||
# Copyright (C) 2010-2011 - Emiliano Heyns, Mark Maglana, friflaj |
||||
# Copyright (C) 2011 - Jens Ulferts, Gregor Schmidt - Finn GmbH - Berlin, Germany |
||||
# |
||||
# 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_dependency 'api/v3/work_packages/schema/work_package_schema' |
||||
|
||||
module OpenProject::Costs::Patches::WorkPackageSchemaPatch |
||||
def self.included(base) |
||||
base.class_eval do |
||||
unloadable |
||||
|
||||
include InstanceMethods |
||||
extend ClassMethods |
||||
end |
||||
end |
||||
|
||||
module ClassMethods |
||||
end |
||||
|
||||
module InstanceMethods |
||||
def assignable_cost_objects |
||||
project.try(:cost_objects) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,69 @@ |
||||
#-- 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::Schema::WorkPackageSchemaRepresenter do |
||||
let(:custom_field) { FactoryGirl.build(:custom_field) } |
||||
let(:work_package) { FactoryGirl.build(:work_package) } |
||||
let(:current_user) { |
||||
FactoryGirl.build(:user, member_in_project: work_package.project) |
||||
} |
||||
let(:schema) { |
||||
::API::V3::WorkPackages::Schema::WorkPackageSchema.new(work_package: work_package) |
||||
} |
||||
let(:representer) { described_class.create(schema, current_user: current_user) } |
||||
subject { representer.to_json } |
||||
|
||||
describe 'budget' do |
||||
it_behaves_like 'has basic schema properties' do |
||||
let(:path) { 'budget' } |
||||
let(:type) { 'Budget' } |
||||
let(:name) { I18n.t('attributes.cost_object') } |
||||
let(:required) { false } |
||||
let(:writable) { true } |
||||
end |
||||
|
||||
it_behaves_like 'has a collection of allowed values' do |
||||
let(:json_path) { 'budget' } |
||||
let(:href_path) { 'budgets' } |
||||
let(:factory) { :cost_object } |
||||
let(:allowed_values_method) { :assignable_cost_objects } |
||||
end |
||||
|
||||
context 'costs disabled' do |
||||
before do |
||||
allow(schema.project).to receive(:costs_enabled?).and_return(false) |
||||
end |
||||
|
||||
it 'has no schema for budget' do |
||||
is_expected.not_to have_json_path('budget') |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,54 @@ |
||||
#-- 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::Schema::WorkPackageSchema do |
||||
let(:project) { |
||||
double('Project', cost_objects: double('CostObjects')) |
||||
} |
||||
let(:type) { FactoryGirl.build(:type) } |
||||
let(:work_package) { FactoryGirl.build(:work_package, project: project, type: type) } |
||||
|
||||
describe '#assignable_cost_objects' do |
||||
subject { described_class.new(project: project, type: type) } |
||||
|
||||
it 'returns project.cost_objects' do |
||||
expect(subject.assignable_cost_objects).to eql(project.cost_objects) |
||||
end |
||||
|
||||
context 'project is nil' do |
||||
let(:project) { nil } |
||||
subject { described_class.new(work_package: work_package) } |
||||
|
||||
it 'returns nil' do |
||||
expect(subject.assignable_cost_objects).to eql(nil) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue