Skip to content

Commit

Permalink
Merge pull request #22 from co-cddo/fix-mismatch-of-json-structure-wi…
Browse files Browse the repository at this point in the history
…th-x-gov-model

Fix miss-match of JSON structure with X-Gov metadata model
  • Loading branch information
RobNicholsGDS authored Mar 18, 2024
2 parents b72edf4 + fff3316 commit 310073b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 14 deletions.
5 changes: 0 additions & 5 deletions app/controllers/esdas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ class EsdasController < ApplicationController
before_action :set_esda, only: %i[show update destroy]
skip_before_action :verify_authenticity_token

# GET /esdas
# GET /esdas.json
def index
@esdas = Esda.all
end

# GET /esdas/1
# GET /esdas/1.json
def show; end

# POST /esdas
# POST /esdas.json
def create
@esda = Esda.new(metadata: params.dig(:esda, :metadata))
Expand All @@ -24,7 +21,6 @@ def create
end
end

# PATCH/PUT /esdas/1
# PATCH/PUT /esdas/1.json
def update
if @esda.update(esda_params)
Expand All @@ -34,7 +30,6 @@ def update
end
end

# DELETE /esdas/1
# DELETE /esdas/1.json
def destroy
@esda.destroy
Expand Down
2 changes: 1 addition & 1 deletion app/forms/creator_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CreatorForm < BaseForm
validates :creator, presence: true

def update_item
item.metadata["creator"] = creator
item.metadata["creator"] = [creator]
end

def creator
Expand Down
2 changes: 1 addition & 1 deletion app/forms/publisher_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class PublisherForm < BaseForm
validates :publisher, presence: true

def update_item
item.metadata["publisher"] = [publisher]
item.metadata["publisher"] = publisher
end

def publisher
Expand Down
2 changes: 1 addition & 1 deletion app/forms/related_resource_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class RelatedResourceForm < BaseForm
def update_item
item.metadata["relatedResource"] = from_params(:related_resource)
item.metadata["relatedResource"] = [from_params(:related_resource)]
end
end
4 changes: 2 additions & 2 deletions spec/forms/creator_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
let(:creator_form) { described_class.new(item:, params:) }

describe "#save" do
it "saves the creator to metadata" do
it "saves the creator to metadata in an array" do
creator_form.save
expect(item.reload.metadata["creator"]).to eq(organisation)
expect(item.reload.metadata["creator"]).to eq([organisation])
end

context "with blank entry" do
Expand Down
4 changes: 2 additions & 2 deletions spec/forms/publisher_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
let(:creator_form) { described_class.new(item:, params:) }

describe "#save" do
it "saves the publisher to metadata in an array" do
it "saves the publisher to metadata" do
creator_form.save
expect(item.reload.metadata["publisher"]).to eq([organisation])
expect(item.reload.metadata["publisher"]).to eq(organisation)
end

context "with blank entry" do
Expand Down
4 changes: 2 additions & 2 deletions spec/forms/related_resource_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
let(:related_resource_form) { described_class.new(item:, params:) }

describe "#save" do
it "saves the related resource to metadata" do
it "saves the related resource to metadata in an array" do
related_resource_form.save
expect(item.reload.metadata["relatedResource"]).to eq(related_resource)
expect(item.reload.metadata["relatedResource"]).to eq([related_resource])
end

context "when title blank" do
Expand Down

0 comments on commit 310073b

Please sign in to comment.