adapt to core changes w.r.t. APIv3 registration

- register attributes in redesigned way
- patch the right methods/classes for WP schema
pull/6827/head
Jan Sandbrink 9 years ago
parent 0e6715253c
commit 8f6926396b
  1. 7
      lib/open_project/backlogs/engine.rb
  2. 14
      lib/open_project/backlogs/patches/specific_work_package_schema_patch.rb
  3. 14
      spec/api/work_packages/specific_work_package_schema_spec.rb
  4. 6
      spec/api/work_packages/work_package_schema_representer_spec.rb

@ -135,7 +135,7 @@ module OpenProject::Backlogs
:Version,
:WorkPackagesHelper]
patch_with_namespace :API, :V3, :WorkPackages, :Schema, :WorkPackageSchema
patch_with_namespace :API, :V3, :WorkPackages, :Schema, :SpecificWorkPackageSchema
extend_api_response(:v3, :work_packages, :work_package) do
property :story_points,
@ -185,12 +185,11 @@ module OpenProject::Backlogs
type: 'Duration',
name_source: :remaining_hours,
required: false,
writable: -> (*) { represented.remaining_time_writable? },
show_if: -> (*) { represented.project.backlogs_enabled? }
end
allow_attribute_update :work_package, [:create, :update], :story_points
allow_attribute_update :work_package, [:create, :update], :remaining_hours do
add_api_attribute on: :work_package, ar_name: :story_points
add_api_attribute on: :work_package, ar_name: :remaining_hours, api_name: :remaining_time do
if !model.new_record? &&
!model.leaf? &&
model.changed.include?('remaining_hours')

@ -33,12 +33,12 @@
# See doc/COPYRIGHT.rdoc for more details.
#++
require_dependency 'api/v3/work_packages/schema/work_package_schema'
require_dependency 'api/v3/work_packages/schema/specific_work_package_schema'
module OpenProject::Backlogs::Patches::WorkPackageSchemaPatch
module OpenProject::Backlogs::Patches::SpecificWorkPackageSchemaPatch
def self.included(base)
base.class_eval do
include InstanceMethods
prepend InstanceMethods
extend ClassMethods
end
end
@ -47,8 +47,12 @@ module OpenProject::Backlogs::Patches::WorkPackageSchemaPatch
end
module InstanceMethods
def remaining_time_writable?
@work_package.nil? ? true : @work_package.leaf?
def writable?(property)
if property == :remaining_time
return @work_package.leaf?
end
super
end
end
end

@ -28,7 +28,7 @@
require 'spec_helper'
describe ::API::V3::WorkPackages::Schema::WorkPackageSchema do
describe ::API::V3::WorkPackages::Schema::SpecificWorkPackageSchema do
let(:project) { FactoryGirl.build(:project) }
let(:type) { FactoryGirl.build(:type) }
let(:work_package) {
@ -46,7 +46,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchema do
end
it 'is writable' do
expect(subject.remaining_time_writable?).to eql(true)
expect(subject.writable?(:remaining_time)).to eql(true)
end
end
@ -56,15 +56,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchema do
end
it 'is not writable' do
expect(subject.remaining_time_writable?).to eql(false)
end
end
context 'created from type and project' do
subject { described_class.new(project: project, type: type) }
it 'is always writable' do
expect(subject.remaining_time_writable?).to eql(true)
expect(subject.writable?(:remaining_time)).to eql(false)
end
end
end

@ -35,13 +35,14 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do
FactoryGirl.build(:user, member_in_project: work_package.project)
}
let(:schema) {
::API::V3::WorkPackages::Schema::WorkPackageSchema.new(work_package: work_package)
::API::V3::WorkPackages::Schema::SpecificWorkPackageSchema.new(work_package: work_package)
}
let(:representer) { described_class.create(schema, current_user: current_user) }
before do
allow(schema.project).to receive(:backlogs_enabled?).and_return(true)
allow(work_package.type).to receive(:story?).and_return(true)
allow(work_package).to receive(:leaf?).and_return(true)
end
describe 'storyPoints' do
@ -115,7 +116,8 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do
context 'remainingTime not writable' do
before do
allow(schema).to receive(:remaining_time_writable?).and_return(false)
allow(schema).to receive(:writable?).and_call_original
allow(schema).to receive(:writable?).with(:remaining_time).and_return(false)
end
it_behaves_like 'has basic schema properties' do
Loading…
Cancel
Save