Skip to content

Commit

Permalink
Merge pull request #911 from datacite/doi-enrichment-patch2
Browse files Browse the repository at this point in the history
Rework subject serialization in for repositoris
  • Loading branch information
jrhoads authored Jan 24, 2023
2 parents fc6e5a7 + a04337f commit 7d1f547
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 1 addition & 3 deletions app/serializers/repository_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ class RepositorySerializer
end
end

attribute :subjects,

Proc.new { |object, params| } do |object|
attribute :subjects do |object|
if object.subjects?
Array.wrap(object.subjects).map { |subject|
subject.transform_keys! do |key|
Expand Down
16 changes: 16 additions & 0 deletions spec/requests/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@
}
end

let(:empty_subject_attributes) do
{
"data" => {
"type" => "repositories",
"attributes" => {
"subjects" => nil,
},
},
}
end

it "updates the repository" do
put "/repositories/#{client.symbol}", update_attributes, headers
expect(json.dig("data", "attributes", "subjects")).to eq([
Expand All @@ -398,6 +409,11 @@
}
])
end

it "accepts an empty array" do
put "/repositories/#{client.symbol}", empty_subject_attributes, headers
expect(json.dig("data", "attributes", "subjects")).to match_array([])
end
end


Expand Down

0 comments on commit 7d1f547

Please sign in to comment.