Skip to content

Commit

Permalink
make citeulike spec work with vcr. #212
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 1, 2015
1 parent 4ed306c commit b26a5b4
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 10 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions spec/models/citeulike_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'rails_helper'

describe Citeulike, :type => :model do
describe Citeulike, type: :model, vcr: true do
subject { FactoryGirl.create(:citeulike) }

let(:work) { FactoryGirl.build(:work, :doi => "10.1371/journal.pone.0008776", published_on: "2006-06-01") }
let(:work) { FactoryGirl.build(:work, :doi => "10.1371/journal.pone.0115074", published_on: "2006-06-01") }

context "get_data" do
it "should report that there are no events if the doi is missing" do
Expand All @@ -12,11 +12,9 @@
end

it "should report if there are no events and event_count returned by the CiteULike API" do
body = File.read(fixture_path + 'citeulike_nil.xml')
stub = stub_request(:get, subject.get_query_url(work)).to_return(:body => body)
work = FactoryGirl.build(:work, :doi => "10.1371/journal.pone.0116034")
response = subject.get_data(work)
expect(response).to eq(Hash.from_xml(body))
expect(stub).to have_been_requested
expect(response).to eq("posts"=>nil)
end

it "should report if there is an incomplete response returned by the CiteULike API" do
Expand All @@ -28,11 +26,10 @@
end

it "should report if there are events and event_count returned by the CiteULike API" do
body = File.read(fixture_path + 'citeulike.xml')
stub = stub_request(:get, subject.get_query_url(work)).to_return(:body => body)
response = subject.get_data(work)
expect(response).to eq(Hash.from_xml(body))
expect(stub).to have_been_requested
expect(response["posts"]["post"].length).to eq(2)
post = response["posts"]["post"].first
expect(post["linkout"]["url"]).to eq(2)
end

it "should catch errors with the CiteULike API" do
Expand Down

0 comments on commit b26a5b4

Please sign in to comment.