Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions app/services/api/v1/deserialization_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ def translate_role(role:)
end

# Retrieve any JSON schema extensions for this application
# rubocop:disable Metrics/AbcSize
def app_extensions(json: {})
return {} unless json.present? && json[:extension].present?

app = ::ApplicationService.application_name.split('-').first.downcase
ext = json[:extension].select { |item| item[app.to_sym].present? }
ext.first.present? ? ext.first[app.to_sym] : {}
# Note the symbol of the dmproadmap json object
# nested in extensions which is the container for the json template object, etc.
ext = json[:extension].select { |item| item[:dmproadmap].present? }
ext.first.present? ? ext.first[:dmproadmap] : {}
end
# rubocop:enable Metrics/AbcSize

# Determines whether or not the value is a DOI/ARK
def doi?(value:)
Expand Down
6 changes: 5 additions & 1 deletion app/views/api/v1/plans/_show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
json.schema 'https://github.com/RDA-DMP-Common/RDA-DMP-Common-Standard/tree/master/examples/JSON/JSON-schema/1.0'

presenter = Api::V1::PlanPresenter.new(plan: plan)

# Note the symbol of the dmproadmap json object
# nested in extensions which is the container for the json template object, etc.

# A JSON representation of a Data Management Plan in the
# RDA Common Standard format
json.title plan.title
Expand Down Expand Up @@ -56,7 +60,7 @@ unless @minimal
end

json.extension [plan.template] do |template|
json.set! ApplicationService.application_name.split('-').first.to_sym do
json.set! :dmproadmap do
json.template do
json.id template.id
json.title template.title
Expand Down
2 changes: 1 addition & 1 deletion spec/services/api/v1/contextual_error_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
result = described_class.contextualize(errors: @plan.errors)
expect(result.length).to eql(2)
expect(result.first.start_with?('Contact/Contributor ')).to eql(true)
expect(result.first.include?(" can't be blank if no ")).to eql(true)
expect(result.first.include?("can't be blank")).to eql(true)
end
it 'returns errors if a Contributor Org is invalid' do
@plan.contributors.first.org.name = nil
Expand Down
6 changes: 2 additions & 4 deletions spec/services/api/v1/deserialization_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@
describe ':app_extensions(json:)' do
before(:each) do
@template = create(:template)
@app_name = ApplicationService.application_name.split('-').first&.downcase
@app_name = 'tester' unless @app_name.present?
end

it 'returns an empty hash is json is not present' do
Expand All @@ -135,13 +133,13 @@
end
it 'returns an empty hash if there is no extension for the current application' do
expected = { template: { id: @template.id } }
ApplicationService.expects(:application_name).returns('tester')
# ApplicationService.expects('dmproadmap').returns('tester')
json = { extension: [{ foo: expected }] }
expect(described_class.send(:app_extensions, json: json)).to eql({})
end
it 'returns the hash for the current application' do
expected = { template: { id: @template.id } }
json = { extension: [{ "#{@app_name}": expected }] }
json = { extension: [{ dmproadmap: expected }] }
result = described_class.send(:app_extensions, json: json)
expect(result).to eql(expected)
end
Expand Down
9 changes: 4 additions & 5 deletions spec/views/api/v1/plans/_show.json.jbuilder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@
expect(@json[:extension].length).to eql(1)
end
it 'includes the :template in :extension' do
app = ApplicationService.application_name.split('-').first
@section = @json[:extension].select { |hash| hash.keys.first == app }.first
expect(@section[app.to_sym].present?).to eql(true)
@section = @json[:extension].select { |hash| hash.keys.first == 'dmproadmap' }.first
expect(@section[:dmproadmap].present?).to eql(true)
tmplt = @plan.template
expect(@section[app.to_sym][:template][:id]).to eql(tmplt.id)
expect(@section[app.to_sym][:template][:title]).to eql(tmplt.title)
expect(@section[:dmproadmap][:template][:id]).to eql(tmplt.id)
expect(@section[:dmproadmap][:template][:title]).to eql(tmplt.title)
end
end

Expand Down