Skip to content

Commit

Permalink
adapted model specs to new data model
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 23, 2015
1 parent 827f58e commit 8ccaf24
Show file tree
Hide file tree
Showing 33 changed files with 253 additions and 253 deletions.
14 changes: 7 additions & 7 deletions spec/models/article_coverage_spec.rb
Expand Up @@ -21,13 +21,13 @@
expect(subject.get_data(work)).to eq(error: "Article not found", status: 404)
end

it "should report if there are no events and event_count returned by the Article Coverage API" do
it "should report if there are no events returned by the Article Coverage API" do
work = FactoryGirl.build(:work, :doi => "10.1371/journal.pone.0008775")
response = subject.get_data(work)
expect(subject.get_data(work)).to eq(error: "Article not found", status: 404)
end

it "should report if there are events and event_count returned by the Article Coverage API" do
it "should report if there are events returned by the Article Coverage API" do
response = subject.get_data(work)
expect(response["doi"]).to eq(work.doi)
expect(response["referrals"].length).to eq(8)
Expand All @@ -52,7 +52,7 @@
it "should report if the doi is missing" do
work = FactoryGirl.build(:work, :doi => nil)
result = {}
expect(subject.parse_data(result, work)).to eq(:events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :event_count=>0, :event_metrics=>{:pdf=>nil, :html=>nil, :shares=>nil, :groups=>nil, :comments=>0, :likes=>nil, :citations=>nil, :total=>0}, :extra=>nil)
expect(subject.parse_data(result, work)).to eq(:events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :total=>0, :event_metrics=>{:pdf=>nil, :html=>nil, :shares=>nil, :groups=>nil, :comments=>0, :likes=>nil, :citations=>nil, :total=>0}, :extra=>nil)
end

it "should report if work doesn't exist in Article Coverage source" do
Expand All @@ -61,14 +61,14 @@
expect(response).to eq(result)
end

it "should report if there are no events and event_count returned by the Article Coverage API" do
it "should report if there are no events returned by the Article Coverage API" do
body = File.read(fixture_path + 'article_coverage_curated_nil.json')
result = JSON.parse(body)
response = subject.parse_data(result, work)
expect(response).to eq(:events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :event_count=>0, :event_metrics=>{:pdf=>nil, :html=>nil, :shares=>nil, :groups=>nil, :comments=>0, :likes=>nil, :citations=>nil, :total=>0}, :extra=>nil)
expect(response).to eq(:events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :total=>0, :event_metrics=>{:pdf=>nil, :html=>nil, :shares=>nil, :groups=>nil, :comments=>0, :likes=>nil, :citations=>nil, :total=>0}, :extra=>nil)
end

it "should report if there are events and event_count returned by the Article Coverage API" do
it "should report if there are events returned by the Article Coverage API" do
body = File.read(fixture_path + 'article_coverage.json')
result = JSON.parse(body)
response = subject.parse_data(result, work)
Expand All @@ -79,7 +79,7 @@
expect(response[:events_by_month].length).to eq(1)
expect(response[:events_by_month].first).to eq(year: 2013, month: 11, total: 2)

expect(response[:event_count]).to eq(2)
expect(response[:total]).to eq(2)
event = response[:events].first
expect(event['URL']).to eq("http://www.huffingtonpost.com/2013/11/08/personal-hygiene-facts_n_4217839.html")
expect(event['author']).to be_nil
Expand Down
16 changes: 8 additions & 8 deletions spec/models/citeulike_spec.rb
Expand Up @@ -11,7 +11,7 @@
expect(subject.get_data(work)).to eq({})
end

it "should report if there are no events and event_count returned by the CiteULike API" do
it "should report if there are no events returned by the CiteULike API" do
work = FactoryGirl.build(:work, :doi => "10.1371/journal.pone.0116034")
response = subject.get_data(work)
expect(response).to eq("posts"=>nil)
Expand All @@ -25,7 +25,7 @@
expect(stub).to have_been_requested
end

it "should report if there are events and event_count returned by the CiteULike API" do
it "should report if there are events returned by the CiteULike API" do
response = subject.get_data(work)
expect(response["posts"]["post"].length).to eq(2)
post = response["posts"]["post"].first
Expand All @@ -46,15 +46,15 @@
end

context "parse_data" do
let(:null_response) { { events: [], :events_by_day=>[], :events_by_month=>[], events_url: nil, event_count: 0, event_metrics: { pdf: nil, html: nil, shares: 0, groups: nil, comments: nil, likes: nil, citations: nil, total: 0 }, extra: nil } }
let(:null_response) { { events: [], :events_by_day=>[], :events_by_month=>[], events_url: nil, total: 0, event_metrics: { pdf: nil, html: nil, shares: 0, groups: nil, comments: nil, likes: nil, citations: nil, total: 0 }, extra: nil } }

it "should report if the doi is missing" do
work = FactoryGirl.build(:work, :doi => nil)
result = {}
expect(subject.parse_data(result, work)).to eq(events: [], :events_by_day=>[], :events_by_month=>[], events_url: nil, event_count: 0, event_metrics: { pdf: nil, html: nil, shares: 0, groups: nil, comments: nil, likes: nil, citations: nil, total: 0 }, extra: nil)
expect(subject.parse_data(result, work)).to eq(events: [], :events_by_day=>[], :events_by_month=>[], events_url: nil, total: 0, event_metrics: { pdf: nil, html: nil, shares: 0, groups: nil, comments: nil, likes: nil, citations: nil, total: 0 }, extra: nil)
end

it "should report if there are no events and event_count returned by the CiteULike API" do
it "should report if there are no events returned by the CiteULike API" do
body = File.read(fixture_path + 'citeulike_nil.xml')
result = Hash.from_xml(body)
expect(subject.parse_data(result, work)).to eq(null_response)
Expand All @@ -66,7 +66,7 @@
expect(subject.parse_data(result, work)).to eq(null_response)
end

it "should report if there are events and event_count returned by the CiteULike API" do
it "should report if there are events returned by the CiteULike API" do
body = File.read(fixture_path + 'citeulike.xml')
result = Hash.from_xml(body)

Expand All @@ -75,7 +75,7 @@
expect(response[:events_by_month].length).to eq(21)
expect(response[:events_by_month].first).to eq(year: 2006, month: 6, total: 2)
expect(response[:events_url]).to eq(subject.get_events_url(work))
expect(response[:event_count]).to eq(25)
expect(response[:total]).to eq(25)
event = response[:events].first
expect(event['URL']).to eq("http://www.citeulike.org/user/dbogartoit/article/694959")
expect(event['author']).to be_nil
Expand All @@ -95,7 +95,7 @@
expect(response[:events_by_month].length).to eq(1)
expect(response[:events_by_month].first).to eq(year: 2006, month: 6, total: 1)
expect(response[:events_url]).to eq(subject.get_events_url(work))
expect(response[:event_count]).to eq(1)
expect(response[:total]).to eq(1)
event = response[:events].first
expect(event['URL']).to eq("http://www.citeulike.org/user/dbogartoit/article/694959")
expect(event['author']).to be_nil
Expand Down
2 changes: 1 addition & 1 deletion spec/models/copernicus_spec.rb
Expand Up @@ -61,7 +61,7 @@
end

context "parse_data" do
let(:null_response) { { :events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :event_count=>0, :event_metrics=>{:pdf=>0, :html=>0, :shares=>nil, :groups=>nil, :comments=>nil, :likes=>nil, :citations=>nil, :total=>0 }, :extra=>{} } }
let(:null_response) { { :events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :total=>0, :html=>0, :pdf=>0, :event_metrics=>{:pdf=>0, :html=>0, :shares=>nil, :groups=>nil, :comments=>nil, :likes=>nil, :citations=>nil, :total=>0 }, :extra=>{} } }

it "should report if the doi is missing" do
work = FactoryGirl.build(:work, :doi => nil)
Expand Down
14 changes: 7 additions & 7 deletions spec/models/counter_spec.rb
Expand Up @@ -99,7 +99,7 @@
expect(subject.get_data(work)).to eq({})
end

it "should report if there are no events and event_count returned by the Counter API" do
it "should report if there are no events returned by the Counter API" do
work = FactoryGirl.build(:work, :doi => "10.1371/journal.pone.0044294")
body = File.read(fixture_path + 'counter_nil.xml')
stub = stub_request(:get, subject.get_query_url(work)).to_return(:body => body)
Expand All @@ -109,7 +109,7 @@
expect(stub).to have_been_requested
end

it "should report if there are events and event_count returned by the Counter API" do
it "should report if there are events returned by the Counter API" do
response = subject.get_data(work)
expect(response["rest"]["response"]["criteria"]).to eq("year"=>"all", "month"=>"all", "journal"=>"all", "doi"=>work.doi)
expect(response["rest"]["response"]["results"]["total"]["total"]).to eq("5514")
Expand All @@ -130,7 +130,7 @@
end

context "parse_data" do
let(:null_response) { { events: [], :events_by_day=>[], :events_by_month=>[], events_url: nil, event_count: 0, event_metrics: { pdf: 0, html: 0, shares: nil, groups: nil, comments: nil, likes: nil, citations: nil, total: 0 }, extra: [] } }
let(:null_response) { { events: [], :events_by_day=>[], :events_by_month=>[], total: 0, html: 0, pdf: 0, event_metrics: { pdf: 0, html: 0, shares: nil, groups: nil, comments: nil, likes: nil, citations: nil, total: 0 }, extra: [] } }

it "should report if the doi is missing" do
work = FactoryGirl.build(:work, :doi => nil)
Expand All @@ -146,24 +146,24 @@
expect(subject.parse_data(result, work)).to eq(null_response)
end

it "should report if there are no events and event_count returned by the Counter API" do
it "should report if there are no events returned by the Counter API" do
body = File.read(fixture_path + 'counter_nil.xml')
result = Hash.from_xml(body)
result.extend Hashie::Extensions::DeepFetch
response = subject.parse_data(result, work)
expect(response).to eq(null_response)
end

it "should report if there are events and event_count returned by the Counter API" do
it "should report if there are events returned by the Counter API" do
body = File.read(fixture_path + 'counter.xml')
result = Hash.from_xml(body)
result.extend Hashie::Extensions::DeepFetch
response = subject.parse_data(result, work)
expect(response[:extra].length).to eq(37)
expect(response[:events_by_month].length).to eq(37)
expect(response[:events_by_month].first).to eq(month: 1, year: 2010, html: 299, pdf: 90)
expect(response[:events_by_month].first).to eq(month: 1, year: 2010, html: 299, pdf: 90, total: 390)
expect(response[:events_url]).to be_nil
expect(response[:event_count]).to eq(3387)
expect(response[:total]).to eq(3387)
expect(response[:event_metrics]).to eq(pdf: 447, html: 2919, shares: nil, groups: nil, comments: nil, likes: nil, citations: nil, total: 3387)
end

Expand Down
26 changes: 13 additions & 13 deletions spec/models/cross_ref_spec.rb
Expand Up @@ -46,7 +46,7 @@
end

context "get_data from the CrossRef API" do
it "should report if there are no events and event_count returned by the CrossRef API" do
it "should report if there are no events returned by the CrossRef API" do
body = File.read(fixture_path + 'cross_ref_nil.xml')
url = subject.get_query_url(work)
stub = stub_request(:get, url).to_return(:body => body)
Expand All @@ -55,7 +55,7 @@
expect(stub).to have_been_requested
end

it "should report if there are events and event_count returned by the CrossRef API" do
it "should report if there are events returned by the CrossRef API" do
body = File.read(fixture_path + 'cross_ref.xml')
stub = stub_request(:get, subject.get_query_url(work)).to_return(:body => body)
response = subject.get_data(work)
Expand Down Expand Up @@ -84,7 +84,7 @@
expect(url).to eq("http://www.crossref.org/openurl/?pid=openurl_username&id=doi:#{work.doi_escaped}&noredirect=true")
end

it "should report if there is an event_count of zero returned by the CrossRef OpenURL API" do
it "should report if there is an event count of zero returned by the CrossRef OpenURL API" do
body = File.read(fixture_path + 'cross_ref_openurl_nil.xml')

stub = stub_request(:get, url).to_return(:body => body)
Expand All @@ -93,7 +93,7 @@
expect(stub).to have_been_requested
end

it "should report if there is an event_count greater than zero returned by the CrossRef OpenURL API" do
it "should report if there is an event count greater than zero returned by the CrossRef OpenURL API" do
body = File.read(fixture_path + 'cross_ref_openurl.xml')
stub = stub_request(:get, url).to_return(:body => body)
response = subject.get_data(work)
Expand All @@ -115,7 +115,7 @@
end

context "parse_data from the CrossRef API" do
let(:null_response) { { :events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :event_count=>0, :event_metrics=>{:pdf=>nil, :html=>nil, :shares=>nil, :groups=>nil, :comments=>nil, :likes=>nil, :citations=>0, :total=>0 }, :extra=>nil } }
let(:null_response) { { :events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :total=>0, :event_metrics=>{:pdf=>nil, :html=>nil, :shares=>nil, :groups=>nil, :comments=>nil, :likes=>nil, :citations=>0, :total=>0 }, :extra=>nil } }

it "should report if the doi is missing" do
work = FactoryGirl.build(:work, :doi => nil)
Expand All @@ -124,21 +124,21 @@
expect(subject.parse_data(result, work)).to eq(null_response)
end

it "should report if there are no events and event_count returned by the CrossRef API" do
it "should report if there are no events returned by the CrossRef API" do
body = File.read(fixture_path + 'cross_ref_nil.xml')
result = Hash.from_xml(body)
result.extend Hashie::Extensions::DeepFetch
response = subject.parse_data(result, work)
expect(response).to eq(null_response)
end

it "should report if there are events and event_count returned by the CrossRef API" do
it "should report if there are events returned by the CrossRef API" do
body = File.read(fixture_path + 'cross_ref.xml')
result = Hash.from_xml(body)
result.extend Hashie::Extensions::DeepFetch
response = subject.parse_data(result, work)
expect(response[:events].length).to eq(31)
expect(response[:event_count]).to eq(31)
expect(response[:total]).to eq(31)

event = response[:events].first
expect(event["DOI"]).to eq("10.3758/s13423-011-0070-4")
Expand All @@ -159,7 +159,7 @@
result.extend Hashie::Extensions::DeepFetch
response = subject.parse_data(result, work)
expect(response[:events].length).to eq(1)
expect(response[:event_count]).to eq(1)
expect(response[:total]).to eq(1)

event = response[:events].first
expect(event["DOI"]).to eq("10.3758/s13423-011-0070-4")
Expand All @@ -180,28 +180,28 @@

context "parse_data from the CrossRef OpenURL API" do
let(:work) { FactoryGirl.create(:work, doi: "10.1007/s00248-010-9734-2", canonical_url: "http://link.springer.com/work/10.1007%2Fs00248-010-9734-2#page-1", publisher_id: nil) }
let(:null_response) { { :events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :event_count=>0, :event_metrics=>{:pdf=>nil, :html=>nil, :shares=>nil, :groups=>nil, :comments=>nil, :likes=>nil, :citations=>0, :total=>0 }, :extra=>nil } }
let(:null_response) { { :events=>[], :events_by_day=>[], :events_by_month=>[], :events_url=>nil, :total=>0, :event_metrics=>{:pdf=>nil, :html=>nil, :shares=>nil, :groups=>nil, :comments=>nil, :likes=>nil, :citations=>0, :total=>0 }, :extra=>nil } }

it "should report if the doi is missing" do
result = {}
result.extend Hashie::Extensions::DeepFetch
expect(subject.parse_data(result, work)).to eq(null_response)
end

it "should report if there is an event_count of zero returned by the CrossRef OpenURL API" do
it "should report if there is an event count of zero returned by the CrossRef OpenURL API" do
body = File.read(fixture_path + 'cross_ref_openurl_nil.xml')
result = Hash.from_xml(body)
result.extend Hashie::Extensions::DeepFetch
response = subject.parse_data(result, work)
expect(response).to eq(null_response)
end

it "should report if there is an event_count greater than zero returned by the CrossRef OpenURL API" do
it "should report if there is an event count greater than zero returned by the CrossRef OpenURL API" do
body = File.read(fixture_path + 'cross_ref_openurl.xml')
result = Hash.from_xml(body)
result.extend Hashie::Extensions::DeepFetch
response = subject.parse_data(result, work)
expect(response[:event_count]).to eq(13)
expect(response[:total]).to eq(13)
end

it "should catch timeout errors with the CrossRef OpenURL API" do
Expand Down
14 changes: 7 additions & 7 deletions spec/models/datacite_spec.rb
Expand Up @@ -11,14 +11,14 @@
expect(subject.get_data(work)).to eq({})
end

it "should report if there are no events and event_count returned by the Datacite API" do
it "should report if there are no events returned by the Datacite API" do
work = FactoryGirl.build(:work, :doi => "10.1371/journal.pone.0043007")
response = subject.get_data(work)
expect(response["response"]["numFound"]).to eq(0)
expect(response["response"]["docs"]).to be_empty
end

it "should report if there are events and event_count returned by the Datacite API" do
it "should report if there are events returned by the Datacite API" do
response = subject.get_data(work)
expect(response["response"]["numFound"]).to eq(1)
doc = response["response"]["docs"].first
Expand All @@ -39,25 +39,25 @@
end

context "parse_data" do
let(:null_response) { { events: [], :events_by_day=>[], :events_by_month=>[], events_url: nil, event_count: 0, event_metrics: { pdf: nil, html: nil, shares: nil, groups: nil, comments: nil, likes: nil, citations: 0, total: 0 }, :extra=>nil } }
let(:null_response) { { events: [], :events_by_day=>[], :events_by_month=>[], events_url: nil, total: 0, event_metrics: { pdf: nil, html: nil, shares: nil, groups: nil, comments: nil, likes: nil, citations: 0, total: 0 }, :extra=>nil } }

it "should report if the doi is missing" do
work = FactoryGirl.build(:work, :doi => nil)
result = {}
expect(subject.parse_data(result, work)).to eq(events: [], :events_by_day=>[], :events_by_month=>[], events_url: nil, event_count: 0, event_metrics: { pdf: nil, html: nil, shares: nil, groups: nil, comments: nil, likes: nil, citations: 0, total: 0 }, :extra=>nil)
expect(subject.parse_data(result, work)).to eq(events: [], :events_by_day=>[], :events_by_month=>[], events_url: nil, total: 0, event_metrics: { pdf: nil, html: nil, shares: nil, groups: nil, comments: nil, likes: nil, citations: 0, total: 0 }, :extra=>nil)
end

it "should report if there are no events and event_count returned by the Datacite API" do
it "should report if there are no events returned by the Datacite API" do
body = File.read(fixture_path + 'datacite_nil.json')
result = JSON.parse(body)
expect(subject.parse_data(result, work)).to eq(null_response)
end

it "should report if there are events and event_count returned by the Datacite API" do
it "should report if there are events returned by the Datacite API" do
body = File.read(fixture_path + 'datacite.json')
result = JSON.parse(body)
response = subject.parse_data(result, work)
expect(response[:event_count]).to eq(1)
expect(response[:total]).to eq(1)
expect(response[:events_url]).to eq("http://search.datacite.org/ui?q=relatedIdentifier:#{work.doi_escaped}")
event = response[:events].first
expect(event["URL"]).to eq("http://dx.doi.org/10.5061/DRYAD.8515")
Expand Down

0 comments on commit 8ccaf24

Please sign in to comment.