maremma 2.2.2 → 2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,7 @@ describe Maremma do
5
5
  let(:url) { "http://example.org" }
6
6
  let(:data) { { "name" => "Fred" } }
7
7
  let(:post_data) { { "name" => "Jack" } }
8
+ let(:accept_header) { "text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5" }
8
9
 
9
10
  context "get" do
10
11
  it "get json" do
@@ -47,9 +48,9 @@ describe Maremma do
47
48
  expect(url).to eq("https://search.datacite.org/api?q=*%3A*&fl=doi%2Ctitle%2Cdescription%2Cpublisher%2CpublicationYear%2CresourceType%2CresourceTypeGeneral%2CrightsURI%2Cdatacentre_symbol%2Cxml%2Cminted%2Cupdated&fq=has_metadata%3Atrue&fq=is_active%3Atrue&facet=true&facet.field=resourceType_facet&facet.field=publicationYear&facet.field=datacentre_facet&facet.limit=10&f.resourceType_facet.facet.limit=15&wt=json")
48
49
  response = subject.get(url)
49
50
  facet_fields = response.fetch("data", {}).fetch("facet_counts", {}).fetch("facet_fields", {})
50
- expect(facet_fields["datacentre_facet"]).to eq(["CDL.DPLANET - Data-Planet", 861878, "BL.CCDC - The Cambridge Crystallographic Data Centre", 611424, "ETHZ.SEALS - E-Periodica", 511650, "ESTDOI.BIO - TÜ Loodusmuuseum", 487448, "CDL.DIGSCI - Digital Science", 387189, "TIB.R-GATE - ResearchGate", 373556, "GESIS.DIE - Deutsches Institut für Erwachsenenbildung", 373193, "ETHZ.EPICS-BA - E-Pics Bildarchiv", 348365, "TIB.PANGAEA - PANGAEA - Publishing Network for Geoscientific and Environmental Data", 345569, "BL.IMPERIAL - Imperial College London", 189735])
51
- expect(facet_fields["resourceType_facet"]).to eq(["Dataset", 2530173, "Text", 1309569, "Other", 872249, "Image", 694451, "Collection", 313746, "Software", 14683, "PhysicalObject", 6688, "Event", 6557, "Audiovisual", 6171, "Film", 967, "Model", 539, "InteractiveResource", 321, "Sound", 240, "Workflow", 218, "Service", 21])
52
- expect(facet_fields["publicationYear"]).to eq(["2015", 2044515, "2014", 922708, "2016", 395824, "2011", 337643, "2013", 333117, "2012", 211537, "2005", 162237, "2007", 158014, "2006", 144119, "2010", 142954])
51
+ expect(facet_fields["datacentre_facet"]).to eq(["CDL.DPLANET - Data-Planet", 862673, "BL.CCDC - The Cambridge Crystallographic Data Centre", 617281, "ETHZ.SEALS - E-Periodica", 511747, "ESTDOI.BIO - TÜ Loodusmuuseum", 487448, "CDL.DIGSCI - Digital Science", 431015, "TIB.R-GATE - ResearchGate", 391313, "GESIS.DIE - Deutsches Institut für Erwachsenenbildung", 373193, "ETHZ.EPICS-BA - E-Pics Bildarchiv", 355076, "TIB.PANGAEA - PANGAEA - Publishing Network for Geoscientific and Environmental Data", 346849, "BL.IMPERIAL - Imperial College London", 190482])
52
+ expect(facet_fields["resourceType_facet"]).to eq(["Dataset", 2598715, "Text", 1390919, "Other", 873873, "Image", 704151, "Collection", 351593, "Software", 15895, "Audiovisual", 7098, "Event", 6711, "PhysicalObject", 6680, "Film", 920, "Model", 556, "InteractiveResource", 372, "Sound", 243, "Workflow", 221, "Service", 21])
53
+ expect(facet_fields["publicationYear"]).to eq(["2015", 2040850, "2014", 936486, "2016", 522234, "2011", 339370, "2013", 335358, "2012", 214191, "2005", 163347, "2007", 159146, "2006", 146147, "2010", 144512])
53
54
  end
54
55
  end
55
56
 
@@ -227,6 +228,22 @@ describe Maremma do
227
228
  end
228
229
  end
229
230
 
231
+ context "content negotiation" do
232
+ it "redirects to URL", vcr: true do
233
+ url = "http://doi.org/10.5281/ZENODO.21430"
234
+ response = subject.get(url)
235
+ doc = Nokogiri::HTML(response.fetch("data", ""))
236
+ title = doc.at_css("head title").text
237
+ expect(title).to eq("DataCite-ORCID: 1.0 - Zenodo")
238
+ end
239
+
240
+ it "returns content as bibtex", vcr: true do
241
+ url = "https://doi.org/10.5281/ZENODO.21430"
242
+ response = subject.get(url, content_type: "application/x-bibtex")
243
+ expect(response.fetch("data", nil)).to eq("@data{198243d2-ed8a-4126-867e-5fff1e80dcfc,\n doi = {10.5281/ZENODO.21430},\n url = {http://dx.doi.org/10.5281/ZENODO.21430},\n author = {Martin Fenner; Karl Jonathan Ward; Gudmundur A. Thorisson; Robert Peters; },\n publisher = {Zenodo},\n title = {DataCite-ORCID: 1.0},\n year = {2015}\n}")
244
+ end
245
+ end
246
+
230
247
  context 'parse_error_response' do
231
248
  it 'json' do
232
249
  string = '{ "error": "An error occured." }'
@@ -266,58 +283,58 @@ describe Maremma do
266
283
  end
267
284
  end
268
285
 
269
- context 'connection' do
286
+ context 'accept headers' do
270
287
  it 'default' do
271
- conn = subject.faraday_conn
272
- expect(conn.headers).to eq("Accept"=>"application/json",
273
- "User-Agent"=>"Maremma - https://github.com/datacite/maremma")
288
+ headers = subject.set_request_headers(url)
289
+ expect(headers).to eq("Accept"=>"text/html,application/json,application/xml;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5",
290
+ "User-Agent"=>"Maremma - https://github.com/datacite/maremma")
274
291
  end
275
292
 
276
293
  it 'json' do
277
- conn = subject.faraday_conn('json')
278
- expect(conn.headers).to eq("Accept"=>"application/json",
279
- "User-Agent"=>"Maremma - https://github.com/datacite/maremma")
294
+ headers = subject.set_request_headers(url, content_type: 'json')
295
+ expect(headers).to eq("Accept"=>"application/json",
296
+ "User-Agent"=>"Maremma - https://github.com/datacite/maremma")
280
297
  end
281
298
 
282
299
  it 'xml' do
283
- conn = subject.faraday_conn('xml')
284
- expect(conn.headers).to eq("Accept"=>"application/xml",
285
- "User-Agent"=>"Maremma - https://github.com/datacite/maremma")
300
+ headers = subject.set_request_headers(url, content_type: 'xml')
301
+ expect(headers).to eq("Accept"=>"application/xml",
302
+ "User-Agent"=>"Maremma - https://github.com/datacite/maremma")
286
303
  end
287
304
 
288
305
  it 'html' do
289
- conn = subject.faraday_conn('html')
290
- expect(conn.headers).to eq("Accept" => "text/html; charset=UTF-8",
291
- "User-Agent" => "Maremma - https://github.com/datacite/maremma")
306
+ headers = subject.set_request_headers(url, content_type: 'html')
307
+ expect(headers).to eq("Accept" => "text/html; charset=UTF-8",
308
+ "User-Agent" => "Maremma - https://github.com/datacite/maremma")
292
309
  end
293
310
 
294
311
  it 'other' do
295
- conn = subject.faraday_conn('application/x-bibtex')
296
- expect(conn.headers).to eq("Accept" => "application/x-bibtex",
297
- "User-Agent" => "Maremma - https://github.com/datacite/maremma")
312
+ headers = subject.set_request_headers(url, content_type: 'application/x-bibtex')
313
+ expect(headers).to eq("Accept" => "application/x-bibtex",
314
+ "User-Agent" => "Maremma - https://github.com/datacite/maremma")
298
315
  end
299
316
  end
300
317
 
301
318
  context 'authentication' do
302
319
  it 'no auth' do
303
320
  options = {}
304
- expect(subject.set_request_headers(url, options)).to eq("Host"=>"example.org")
321
+ expect(subject.set_request_headers(url, options)).to eq("User-Agent"=>"Maremma - https://github.com/datacite/maremma", "Accept"=>accept_header)
305
322
  end
306
323
 
307
324
  it 'bearer' do
308
325
  options = { bearer: 'mF_9.B5f-4.1JqM' }
309
- expect(subject.set_request_headers(url, options)).to eq("Host"=>"example.org", "Authorization"=>"Bearer mF_9.B5f-4.1JqM")
326
+ expect(subject.set_request_headers(url, options)).to eq("User-Agent"=>"Maremma - https://github.com/datacite/maremma", "Accept"=>accept_header, "Authorization"=>"Bearer mF_9.B5f-4.1JqM")
310
327
  end
311
328
 
312
329
  it 'token' do
313
330
  options = { token: '12345' }
314
- expect(subject.set_request_headers(url, options)).to eq("Host"=>"example.org", "Authorization"=>"Token token=12345")
331
+ expect(subject.set_request_headers(url, options)).to eq("User-Agent"=>"Maremma - https://github.com/datacite/maremma", "Accept"=>accept_header, "Authorization"=>"Token token=12345")
315
332
  end
316
333
 
317
334
  it 'basic' do
318
335
  options = { username: 'foo', password: '12345' }
319
336
  basic = Base64.encode64("foo:12345")
320
- expect(subject.set_request_headers(url, options)).to eq("Host"=>"example.org", "Authorization"=>"Basic #{basic}")
337
+ expect(subject.set_request_headers(url, options)).to eq("User-Agent"=>"Maremma - https://github.com/datacite/maremma", "Accept"=>accept_header, "Authorization"=>"Basic #{basic}")
321
338
  end
322
339
  end
323
340
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maremma
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: '2.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-01 00:00:00.000000000 Z
11
+ date: 2016-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -257,6 +257,8 @@ files:
257
257
  - lib/maremma.rb
258
258
  - lib/maremma/version.rb
259
259
  - maremma.gemspec
260
+ - spec/fixtures/vcr_cassettes/Maremma/content_negotiation/redirects_to_URL.yml
261
+ - spec/fixtures/vcr_cassettes/Maremma/content_negotiation/returns_content_as_bibtex.yml
260
262
  - spec/fixtures/vcr_cassettes/Maremma/get/get_json_with_params.yml
261
263
  - spec/maremma_spec.rb
262
264
  - spec/spec_helper.rb