From 9e8d051027ff00573bfaddae03cdd65ed5adad71 Mon Sep 17 00:00:00 2001 From: Jan Sandbrink Date: Tue, 25 Aug 2015 15:44:52 +0200 Subject: [PATCH] reintroduce form_embedded argument for schema we can't live without it :/ --- lib/api/decorators/schema.rb | 10 +++++++++- lib/api/v3/work_packages/form_representer.rb | 1 + .../work_package_schema_representer_spec.rb | 18 ++++++------------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/api/decorators/schema.rb b/lib/api/decorators/schema.rb index f51706efa1..35ef3240af 100644 --- a/lib/api/decorators/schema.rb +++ b/lib/api/decorators/schema.rb @@ -79,7 +79,9 @@ module API required: call_or_use(required), writable: call_or_use(writable)) - representer.allowed_values_href = instance_eval(&href_callback) + if form_embedded + representer.allowed_values_href = instance_eval(&href_callback) + end representer }, @@ -126,6 +128,12 @@ module API end end + attr_reader :form_embedded + def initialize(represented, context = {}) + @form_embedded = context.delete(:form_embedded) + super + end + private def call_or_use(object) diff --git a/lib/api/v3/work_packages/form_representer.rb b/lib/api/v3/work_packages/form_representer.rb index 7ba1478e42..570deaf9e2 100644 --- a/lib/api/v3/work_packages/form_representer.rb +++ b/lib/api/v3/work_packages/form_representer.rb @@ -49,6 +49,7 @@ module API getter: -> (*) { schema = Schema::SpecificWorkPackageSchema.new(work_package: represented) Schema::WorkPackageSchemaRepresenter.create(schema, + form_embedded: true, current_user: current_user) } property :validation_errors, embedded: true, exec_context: :decorator diff --git a/spec/lib/api/v3/work_packages/work_package_schema_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_schema_representer_spec.rb index d9013c91a3..7772cb3df4 100644 --- a/spec/lib/api/v3/work_packages/work_package_schema_representer_spec.rb +++ b/spec/lib/api/v3/work_packages/work_package_schema_representer_spec.rb @@ -39,10 +39,12 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do let(:schema) { ::API::V3::WorkPackages::Schema::SpecificWorkPackageSchema.new(work_package: work_package) } - let(:embedded) { false } + let(:self_link) { '/a/self/link' } + let(:embedded) { true } let(:representer) { described_class.create(schema, form_embedded: embedded, + self_link: self_link, current_user: current_user) } @@ -77,7 +79,7 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do end context 'when not embedded' do - let(:embedded) { false } + before do allow(schema).to receive(allowed_values_method).and_return(nil) end it_behaves_like 'does not link to allowed values' do let(:path) { json_path } @@ -88,16 +90,11 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do describe 'self link' do it_behaves_like 'has an untitled link' do let(:link) { 'self' } - let(:href) { - api_v3_paths.work_package_schema(work_package.project.id, work_package.type.id) - } + let(:href) { self_link } end context 'embedded in a form' do - let(:embedded) { true } - - # In a form there is no guarantee that the current state contains a valid WP - let(:work_package) { FactoryGirl.build(:work_package, type: nil) } + let(:self_link) { nil } it_behaves_like 'has no link' do let(:link) { 'self' } @@ -123,7 +120,6 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do context 'lockVersion disabled' do let(:representer) { described_class.create(schema, - form_embedded: embedded, current_user: current_user, hide_lock_version: true) } @@ -450,8 +446,6 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do end describe 'responsible and assignee' do - let(:embedded) { true } - let(:base_href) { "/api/v3/projects/#{work_package.project.id}" } describe 'assignee' do