Skip to content

Commit

Permalink
enforce doi types. #331
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 4, 2019
1 parent 3f743f4 commit 29324a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
12 changes: 12 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,18 @@ def content_url=(value)
write_attribute(:content_url, Array.wrap(value))
end

def container=(value)
write_attribute(:container, value || {})
end

def types=(value)
write_attribute(:types, value || {})
end

def landing_page=(value)
write_attribute(:landing_page, value || {})
end

def identifier
normalize_doi(doi, sandbox: !Rails.env.production?)
end
Expand Down
16 changes: 12 additions & 4 deletions app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class DoiSerializer
Array.wrap(object.creators).map do |c|
c["affiliation"] = Array.wrap(c["affiliation"]).map do |a|
if params[:affiliation]
a.is_a?(Hash) ? a : { "name" => a }.compact
a
else
a.is_a?(Hash) ? a["name"] : a
a["name"]
end
end.compact
c
Expand All @@ -44,9 +44,9 @@ class DoiSerializer
Array.wrap(object.contributors).map do |c|
c["affiliation"] = Array.wrap(c["affiliation"]).map do |a|
if params[:affiliation]
a.is_a?(Hash) ? a : { "name" => a }.compact
a
else
a.is_a?(Hash) ? a["name"] : a
a["name"]
end
end.compact
c
Expand All @@ -57,6 +57,14 @@ class DoiSerializer
Array.wrap(object.rights_list)
end

attribute :container do |object|
object.container || {}
end

attribute :types do |object|
object.types || {}
end

attribute :state do |object|
object.aasm_state
end
Expand Down
2 changes: 1 addition & 1 deletion spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@
let(:doi) { create(:doi, container: container)}

it "convert" do
expect(Doi.convert_container_by_id(id: doi.id)).to eq(1)
expect(Doi.convert_container_by_id(id: doi.id)).to eq(0)
end
end

Expand Down

0 comments on commit 29324a1

Please sign in to comment.