reintroduce form_embedded argument for schema

we can't live without it :/
pull/3338/head
Jan Sandbrink 9 years ago
parent a0023692e7
commit 9e8d051027
  1. 10
      lib/api/decorators/schema.rb
  2. 1
      lib/api/v3/work_packages/form_representer.rb
  3. 18
      spec/lib/api/v3/work_packages/work_package_schema_representer_spec.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)

@ -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

@ -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

Loading…
Cancel
Save