diff --git a/Gemfile.lock b/Gemfile.lock index 7ae6a9476..c395f951f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,7 +67,7 @@ GEM audited (4.9.0) activerecord (>= 4.2, < 6.1) aws-eventstream (1.0.3) - aws-partitions (1.269.0) + aws-partitions (1.271.0) aws-sdk-core (3.89.1) aws-eventstream (~> 1.0, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) @@ -76,7 +76,7 @@ GEM aws-sdk-kms (1.28.0) aws-sdk-core (~> 3, >= 3.71.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.60.1) + aws-sdk-s3 (1.60.2) aws-sdk-core (~> 3, >= 3.83.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.1) @@ -109,7 +109,7 @@ GEM latex-decode (~> 0.0) binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) - bolognese (1.4.1) + bolognese (1.4.3) activesupport (>= 4.2.5, < 6) benchmark_methods (~> 0.7) bibtex-ruby (~> 4.1) @@ -178,7 +178,7 @@ GEM css_parser (1.7.1) addressable dalli (2.7.10) - database_cleaner (1.8.1) + database_cleaner (1.8.2) debug_inspector (0.0.3) diff-lcs (1.3) diffy (3.3.0) @@ -231,14 +231,15 @@ GEM faraday (>= 0.15) fast_jsonapi (1.5) activesupport (>= 4.2) - ffi (1.12.1) + ffi (1.12.2) flipper (0.17.2) flipper-active_support_cache_store (0.17.2) activesupport (>= 4.2, < 7) flipper (~> 0.17.2) gender_detector (0.1.2) unicode_utils (>= 1.3.0) - git (1.5.0) + git (1.6.0) + rchardet (~> 1.8) globalid (0.4.2) activesupport (>= 4.2.0) google-protobuf (3.10.0.rc.1) @@ -254,7 +255,7 @@ GEM hamster (3.0.0) concurrent-ruby (~> 1.0) hashdiff (1.0.0) - hashie (4.0.0) + hashie (4.1.0) htmlentities (4.3.4) http-cookie (1.0.3) domain_name (~> 0.5) @@ -341,7 +342,7 @@ GEM minitest (5.14.0) money (6.13.7) i18n (>= 0.6.4, <= 2) - msgpack (1.3.1) + msgpack (1.3.3) multi_json (1.14.1) multipart-post (2.1.1) mysql2 (0.4.10) @@ -408,6 +409,7 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.10.1) ffi (~> 1.0) + rchardet (1.8.0) rdf (3.1.1) hamster (~> 3.0) link_header (~> 0.0, >= 0.0.8) @@ -449,7 +451,7 @@ GEM rspec-expectations (3.9.0) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) - rspec-graphql_matchers (1.1) + rspec-graphql_matchers (1.2) graphql (>= 1.8, < 2.0) rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) @@ -515,7 +517,7 @@ GEM regexp_parser (~> 1.3, >= 1.3.0) strip_attributes (1.9.0) activemodel (>= 3.0, < 7.0) - strong_migrations (0.6.1) + strong_migrations (0.6.2) activerecord (>= 5) sxp (1.1.0) rdf (~> 3.1) @@ -541,7 +543,7 @@ GEM uuid (2.3.9) macaddr (~> 1.0) vcr (3.0.3) - webmock (3.8.0) + webmock (3.8.1) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) diff --git a/app/models/doi.rb b/app/models/doi.rb index 6ba02581a..a1d445f77 100644 --- a/app/models/doi.rb +++ b/app/models/doi.rb @@ -923,7 +923,9 @@ def view_count end def views_over_time - views.pluck(:occurred_at, :total).map { |v| { year_month: v[0].present? ? v[0].utc.iso8601[0..6] : nil, total: v[1] } } + views.pluck(:occurred_at, :total) + .map { |v| { year_month: v[0].present? ? v[0].utc.iso8601[0..6] : nil, total: v[1] } } + .sort_by { |h| h[:year_month] } end def download_count @@ -931,7 +933,9 @@ def download_count end def downloads_over_time - downloads.pluck(:occurred_at, :total).map { |v| { year_month: v[0].present? ? v[0].utc.iso8601[0..6] : nil, total: v[1] } } + downloads.pluck(:occurred_at, :total) + .map { |v| { year_month: v[0].present? ? v[0].utc.iso8601[0..6] : nil, total: v[1] } } + .sort_by { |h| h[:year_month] } end def reference_ids diff --git a/spec/requests/dois_spec.rb b/spec/requests/dois_spec.rb index e8d0c6c12..ebb68a0be 100644 --- a/spec/requests/dois_spec.rb +++ b/spec/requests/dois_spec.rb @@ -855,6 +855,41 @@ end end + context 'when the date issued is changed to :tba' do + let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) } + let(:valid_attributes) do + { + "data" => { + "type" => "dois", + "attributes" => { + "url" => "http://www.bl.uk/pdf/pat.pdf", + "xml" => xml, + "dates" => { + "date" => ":tba", + "dateType" => "Issued" + }, + "event" => "publish" + } + } + } + end + + it 'updates the record' do + patch "/dois/#{doi.doi}", valid_attributes, headers + + expect(last_response.status).to eq(200) + expect(json.dig('data', 'attributes', 'url')).to eq("http://www.bl.uk/pdf/pat.pdf") + expect(json.dig('data', 'attributes', 'doi')).to eq(doi.doi.downcase) + expect(json.dig('data', 'attributes', 'dates')).to eq("date"=>":tba", "dateType"=>"Issued") + end + + it 'sets state to findable' do + patch "/dois/#{doi.doi}", valid_attributes, headers + + expect(json.dig('data', 'attributes', 'state')).to eq("findable") + end + end + context 'when the title is changed' do let(:xml) { Base64.strict_encode64(file_fixture('datacite.xml').read) } let(:titles) { [{ "title" => "Submitted chemical data for InChIKey=YAPQBXQYLJRXSA-UHFFFAOYSA-N" }] }