forked from usnationalarchives/federal_register
/
article_spec.rb
56 lines (50 loc) · 1.85 KB
/
article_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require File.dirname(__FILE__) + '/spec_helper'
describe FederalRegister::Article do
describe ".find" do
it "fetches the document by its document number" do
document_number = "2010-213"
FakeWeb.register_uri(
:get,
"http://www.federalregister.gov/api/v1/articles/#{document_number}.json",
:content_type =>"text/json",
:body => {:title => "Important Notice"}.to_json
)
FederalRegister::Article.find(document_number).title.should == 'Important Notice'
end
it "throws an error when a document doesn't exist" do
document_number = "some-random-document"
FakeWeb.register_uri(
:get,
"http://www.federalregister.gov/api/v1/articles/#{document_number}.json",
:content_type =>"text/json",
:status => 404
)
lambda{ FederalRegister::Article.find(document_number) }.should raise_error FederalRegister::Client::RecordNotFound
end
end
describe ".find_all" do
it "fetches multiple matching documents" do
FakeWeb.register_uri(
:get,
"http://www.federalregister.gov/api/v1/articles/abc,def.json",
:content_type =>"text/json",
:body => {:results => [{:document_number => "abc"}, {:document_number => "def"}]}.to_json
)
result_set = FederalRegister::Article.find_all('abc','def')
result_set.results.map(&:document_number).sort.should === ['abc','def']
end
end
describe ".search" do
before(:each) do
FakeWeb.register_uri(
:get,
"http://www.federalregister.gov/api/v1/articles.json?conditions[term]=Fish",
:content_type =>"text/json",
:body => {:count => 3}.to_json
)
end
it "returns a resultset object" do
FederalRegister::Article.search(:conditions => {:term => "Fish"}).should be_an_instance_of(FederalRegister::ResultSet)
end
end
end