Skip to content

Commit

Permalink
fix issn support
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Aug 8, 2019
1 parent 47e54c2 commit 972f98b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def set_client
def safe_params
fail JSON::ParserError, "You need to provide a payload following the JSONAPI spec" unless params[:data].present?
ActiveModelSerializers::Deserialization.jsonapi_parse!(
params, only: [:symbol, :name, "systemEmail", :domains, :provider, :url, "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [:issl, :electronic, :print] }, :certificate, { certificate: [] }, "serviceContact", { "serviceContact": [:email, "givenName", "familyName"] }, "salesforceId"],
params, only: [:symbol, :name, "systemEmail", :domains, :provider, :url, "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [:issnl, :electronic, :print] }, :certificate, { certificate: [] }, "serviceContact", { "serviceContact": [:email, "givenName", "familyName"] }, "salesforceId"],
keys: { "systemEmail" => :system_email, "salesforceId" => :salesforce_id, "targetId" => :target_id, "isActive" => :is_active, "passwordInput" => :password_input, "clientType" => :client_type, "alternateName" => :alternate_name, "repositoryType" => :repository_type, "serviceContact" => :service_contact }
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def set_repository
def safe_params
fail JSON::ParserError, "You need to provide a payload following the JSONAPI spec" unless params[:data].present?
ActiveModelSerializers::Deserialization.jsonapi_parse!(
params, only: [:symbol, :name, "systemEmail", :domains, :provider, :url, "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [:issl, :electronic, :print] }, :certificate, { certificate: [] }, "serviceContact", { "serviceContact": [:email, "givenName", "familyName"] }, "salesforceId"],
params, only: [:symbol, :name, "systemEmail", :domains, :provider, :url, "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [:issnl, :electronic, :print] }, :certificate, { certificate: [] }, "serviceContact", { "serviceContact": [:email, "givenName", "familyName"] }, "salesforceId"],
keys: { "systemEmail" => :system_email, "salesforceId" => :salesforce_id, "targetId" => :target_id, "isActive" => :is_active, "passwordInput" => :password_input, "clientType" => :client_type, "alternateName" => :alternate_name, "repositoryType" => :repository_type, "serviceContact" => :service_contact }
)
end
Expand Down
4 changes: 3 additions & 1 deletion app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ def to_jsonapi

def check_issn
Array.wrap(issn).each do |i|
if i["issnl"].present?
if !(i.is_a?(Hash))
errors.add(:issn, "ISSN should be an object and not a string.")
elsif i["issnl"].present?
errors.add(:issn, "ISSN-L #{i["issnl"]} is in the wrong format.") unless /\A\d{4}(-)?\d{3}[0-9X]+\z/.match(i["issnl"])
end
if i["electronic"].present?
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/client_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ClientSerializer
set_type :clients
set_id :uid

attributes :name, :symbol, :year, :contact_email, :alternate_name, :description, :language, :client_type, :domains, :url, :salesforce_id, :created, :updated
attributes :name, :symbol, :year, :contact_email, :alternate_name, :description, :language, :client_type, :domains, :issn, :url, :salesforce_id, :created, :updated

belongs_to :provider, record_type: :providers
belongs_to :consortium, record_type: :providers, serializer: ProviderSerializer, if: Proc.new { |client| client.consortium_id }
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/repository_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class RepositorySerializer
set_type :repositories
set_id :uid

attributes :name, :symbol, :re3data, :opendoar, :year, :system_email, :alternate_name, :description, :client_type, :repository_type, :language, :certificate, :domains, :url, :salesforce_id, :created, :updated
attributes :name, :symbol, :re3data, :opendoar, :year, :system_email, :alternate_name, :description, :client_type, :repository_type, :language, :certificate, :domains, :issn, :url, :salesforce_id, :created, :updated

belongs_to :provider, record_type: :providers
has_many :prefixes, record_type: :prefixes
Expand Down
21 changes: 21 additions & 0 deletions spec/requests/repositories_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@
end
end

context 'updating with ISSNs' do
let(:params) do
{ "data" => { "type" => "repositories",
"attributes" => {
"name" => "Journal of Insignificant Results",
"clientType" => "periodical",
"issn" => { "electronic" => "1544-9173",
"print" => "1545-7885" } }} }
end

it 'updates the record' do
put "/repositories/#{client.symbol}", params, headers

expect(last_response.status).to eq(200)
expect(json.dig('data', 'attributes', 'name')).to eq("Journal of Insignificant Results")
expect(json.dig('data', 'attributes', 'name')).not_to eq(client.name)
expect(json.dig('data', 'attributes', 'clientType')).to eq("periodical")
expect(json.dig('data', 'attributes', 'issn')).to eq("electronic"=>"1544-9173", "print"=>"1545-7885")
end
end

context 'when the request is invalid' do
let(:params) do
{ "data" => { "type" => "repositories",
Expand Down

0 comments on commit 972f98b

Please sign in to comment.