datacatalog 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES.md +2 -2
- data/LICENSE.md +11 -11
- data/README.md +34 -34
- data/VERSION +1 -1
- data/datacatalog.gemspec +2 -2
- data/lib/base.rb +77 -77
- data/lib/datacatalog.rb +8 -8
- data/lib/main.rb +41 -41
- data/sandbox_api.yml.example +2 -2
- data/spec/about_spec.rb +21 -21
- data/spec/api_key_spec.rb +145 -145
- data/spec/base_spec.rb +129 -129
- data/spec/datacatalog_spec.rb +36 -36
- data/spec/source_spec.rb +162 -162
- data/spec/spec.opts +4 -4
- data/spec/user_spec.rb +278 -278
- data/tasks/test_api.rake +1 -1
- metadata +2 -2
data/spec/base_spec.rb
CHANGED
@@ -1,129 +1,129 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
include DataCatalog
|
3
|
-
|
4
|
-
describe Base do
|
5
|
-
|
6
|
-
before do
|
7
|
-
setup_api
|
8
|
-
end
|
9
|
-
|
10
|
-
describe ".base_uri=" do
|
11
|
-
it "should set and normalize the base URI" do
|
12
|
-
setup_api
|
13
|
-
DataCatalog.base_uri = 'host.com'
|
14
|
-
DataCatalog.base_uri.should == 'http://host.com'
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should set the base URI to the default if it's not explicitly defined" do
|
18
|
-
DataCatalog.base_uri = ''
|
19
|
-
DataCatalog.base_uri.should == 'http://api.nationaldatacatalog.com'
|
20
|
-
Base.base_uri.should == 'http://api.nationaldatacatalog.com'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe ".check_status" do
|
25
|
-
it "should return nil on 200 OK" do
|
26
|
-
response = HTTParty::Response.new(nil, '{"foo":"bar"}', 200, 'OK', {})
|
27
|
-
Base.check_status(response).should be_nil
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should raise BadRequest on 400 Bad Request" do
|
31
|
-
response = HTTParty::Response.new(nil, '[]', 400, 'Bad Request', {})
|
32
|
-
executing do
|
33
|
-
Base.check_status(response)
|
34
|
-
end.should raise_error(BadRequest)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should raise Unauthorized on 401 Unauthorized" do
|
38
|
-
response = HTTParty::Response.new(nil, '', 401, 'Unauthorized', {})
|
39
|
-
executing do
|
40
|
-
Base.check_status(response)
|
41
|
-
end.should raise_error(Unauthorized)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "should raise NotFound on 404 Not Found" do
|
45
|
-
response = HTTParty::Response.new(nil, '[]', 404, 'Not Found', {})
|
46
|
-
executing do
|
47
|
-
Base.check_status(response)
|
48
|
-
end.should raise_error(NotFound)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should raise InternalServerError on 500 Internal Server Error" do
|
52
|
-
response = HTTParty::Response.new(nil, '', 500, 'Internal Server Error', {})
|
53
|
-
executing do
|
54
|
-
Base.check_status(response)
|
55
|
-
end.should raise_error(InternalServerError)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe ".error" do
|
60
|
-
it "should return an 'Unable to parse:' message when body is blank" do
|
61
|
-
response = HTTParty::Response.new(nil, '', 404, 'Not Found', {})
|
62
|
-
Base.error(response).should == %(Unable to parse: "")
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should return 'Response was empty' when body is an empty JSON object" do
|
66
|
-
response = HTTParty::Response.new(nil, '{}', 404, 'Not Found', {})
|
67
|
-
Base.error(response).should == "Response was empty"
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should return 'Response was empty' when body is an empty array" do
|
71
|
-
response = HTTParty::Response.new(nil, '[]', 404, 'Not Found', {})
|
72
|
-
Base.error(response).should == "Response was empty"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should return the contents of the errors hash when it exists" do
|
76
|
-
errors = '{"errors":["bad_error"]}'
|
77
|
-
response = HTTParty::Response.new(nil, errors, 400, 'Bad Request', {})
|
78
|
-
Base.error(response).should == '["bad_error"]'
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should return the contents of the response body when no errors hash exists" do
|
82
|
-
errors = '{"foo":["bar"]}'
|
83
|
-
response = HTTParty::Response.new(nil, errors, 400, 'Bad Request', {})
|
84
|
-
Base.error(response).should == '{"foo":["bar"]}'
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
describe ".many" do
|
89
|
-
it "should create an object from a filled array" do
|
90
|
-
array = Base.many([
|
91
|
-
{
|
92
|
-
:name => "Carl Malamud",
|
93
|
-
:email => "no-spam-carl@media.org"
|
94
|
-
},
|
95
|
-
{
|
96
|
-
:name => "Ellen Miller",
|
97
|
-
:email => "no-spam-ellen@sunlightfoundation.com"
|
98
|
-
}
|
99
|
-
])
|
100
|
-
array.map do |item|
|
101
|
-
item.should be_an_instance_of(Base)
|
102
|
-
end
|
103
|
-
array.map(&:name).should == ["Carl Malamud", "Ellen Miller"]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
describe ".one" do
|
108
|
-
it "should create an object from a filled hash" do
|
109
|
-
hash = Base.one({
|
110
|
-
:name => "John Smith",
|
111
|
-
:email => "john@email.com"
|
112
|
-
})
|
113
|
-
hash.should be_an_instance_of(Base)
|
114
|
-
hash.name.should == "John Smith"
|
115
|
-
hash.email.should == "john@email.com"
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should return nil from an empty hash" do
|
119
|
-
hash = Base.one({})
|
120
|
-
hash.should be_nil
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should return nil from nil" do
|
124
|
-
hash = Base.one(nil)
|
125
|
-
hash.should be_nil
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
include DataCatalog
|
3
|
+
|
4
|
+
describe Base do
|
5
|
+
|
6
|
+
before do
|
7
|
+
setup_api
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".base_uri=" do
|
11
|
+
it "should set and normalize the base URI" do
|
12
|
+
setup_api
|
13
|
+
DataCatalog.base_uri = 'host.com'
|
14
|
+
DataCatalog.base_uri.should == 'http://host.com'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set the base URI to the default if it's not explicitly defined" do
|
18
|
+
DataCatalog.base_uri = ''
|
19
|
+
DataCatalog.base_uri.should == 'http://api.nationaldatacatalog.com'
|
20
|
+
Base.base_uri.should == 'http://api.nationaldatacatalog.com'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe ".check_status" do
|
25
|
+
it "should return nil on 200 OK" do
|
26
|
+
response = HTTParty::Response.new(nil, '{"foo":"bar"}', 200, 'OK', {})
|
27
|
+
Base.check_status(response).should be_nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should raise BadRequest on 400 Bad Request" do
|
31
|
+
response = HTTParty::Response.new(nil, '[]', 400, 'Bad Request', {})
|
32
|
+
executing do
|
33
|
+
Base.check_status(response)
|
34
|
+
end.should raise_error(BadRequest)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should raise Unauthorized on 401 Unauthorized" do
|
38
|
+
response = HTTParty::Response.new(nil, '', 401, 'Unauthorized', {})
|
39
|
+
executing do
|
40
|
+
Base.check_status(response)
|
41
|
+
end.should raise_error(Unauthorized)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should raise NotFound on 404 Not Found" do
|
45
|
+
response = HTTParty::Response.new(nil, '[]', 404, 'Not Found', {})
|
46
|
+
executing do
|
47
|
+
Base.check_status(response)
|
48
|
+
end.should raise_error(NotFound)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise InternalServerError on 500 Internal Server Error" do
|
52
|
+
response = HTTParty::Response.new(nil, '', 500, 'Internal Server Error', {})
|
53
|
+
executing do
|
54
|
+
Base.check_status(response)
|
55
|
+
end.should raise_error(InternalServerError)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe ".error" do
|
60
|
+
it "should return an 'Unable to parse:' message when body is blank" do
|
61
|
+
response = HTTParty::Response.new(nil, '', 404, 'Not Found', {})
|
62
|
+
Base.error(response).should == %(Unable to parse: "")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should return 'Response was empty' when body is an empty JSON object" do
|
66
|
+
response = HTTParty::Response.new(nil, '{}', 404, 'Not Found', {})
|
67
|
+
Base.error(response).should == "Response was empty"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should return 'Response was empty' when body is an empty array" do
|
71
|
+
response = HTTParty::Response.new(nil, '[]', 404, 'Not Found', {})
|
72
|
+
Base.error(response).should == "Response was empty"
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should return the contents of the errors hash when it exists" do
|
76
|
+
errors = '{"errors":["bad_error"]}'
|
77
|
+
response = HTTParty::Response.new(nil, errors, 400, 'Bad Request', {})
|
78
|
+
Base.error(response).should == '["bad_error"]'
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return the contents of the response body when no errors hash exists" do
|
82
|
+
errors = '{"foo":["bar"]}'
|
83
|
+
response = HTTParty::Response.new(nil, errors, 400, 'Bad Request', {})
|
84
|
+
Base.error(response).should == '{"foo":["bar"]}'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe ".many" do
|
89
|
+
it "should create an object from a filled array" do
|
90
|
+
array = Base.many([
|
91
|
+
{
|
92
|
+
:name => "Carl Malamud",
|
93
|
+
:email => "no-spam-carl@media.org"
|
94
|
+
},
|
95
|
+
{
|
96
|
+
:name => "Ellen Miller",
|
97
|
+
:email => "no-spam-ellen@sunlightfoundation.com"
|
98
|
+
}
|
99
|
+
])
|
100
|
+
array.map do |item|
|
101
|
+
item.should be_an_instance_of(Base)
|
102
|
+
end
|
103
|
+
array.map(&:name).should == ["Carl Malamud", "Ellen Miller"]
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe ".one" do
|
108
|
+
it "should create an object from a filled hash" do
|
109
|
+
hash = Base.one({
|
110
|
+
:name => "John Smith",
|
111
|
+
:email => "john@email.com"
|
112
|
+
})
|
113
|
+
hash.should be_an_instance_of(Base)
|
114
|
+
hash.name.should == "John Smith"
|
115
|
+
hash.email.should == "john@email.com"
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return nil from an empty hash" do
|
119
|
+
hash = Base.one({})
|
120
|
+
hash.should be_nil
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should return nil from nil" do
|
124
|
+
hash = Base.one(nil)
|
125
|
+
hash.should be_nil
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
data/spec/datacatalog_spec.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
include DataCatalog
|
3
|
-
|
4
|
-
describe DataCatalog do
|
5
|
-
|
6
|
-
describe "module accessors" do
|
7
|
-
it "should access the API Key" do
|
8
|
-
DataCatalog.api_key = "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
|
9
|
-
DataCatalog.api_key.should == "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should access the base URI" do
|
13
|
-
DataCatalog.base_uri = 'http://somehost.com'
|
14
|
-
DataCatalog.base_uri.should == 'http://somehost.com'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".with_key" do
|
19
|
-
it "should set the API key within the block" do
|
20
|
-
regular_key = '4159179f32ff8fefd2c6d48b7e675e7736bf1357'
|
21
|
-
DataCatalog.api_key = regular_key
|
22
|
-
temporary_key = '0000123400001234000012340000123400001234'
|
23
|
-
DataCatalog.with_key(temporary_key) do
|
24
|
-
DataCatalog.api_key.should == temporary_key
|
25
|
-
end
|
26
|
-
DataCatalog.api_key.should == regular_key
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should return the last value in the block" do
|
30
|
-
DataCatalog.with_key("0000444400004444") do
|
31
|
-
42
|
32
|
-
end.should == 42
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
include DataCatalog
|
3
|
+
|
4
|
+
describe DataCatalog do
|
5
|
+
|
6
|
+
describe "module accessors" do
|
7
|
+
it "should access the API Key" do
|
8
|
+
DataCatalog.api_key = "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
|
9
|
+
DataCatalog.api_key.should == "4159179f32ff8fefd2c6d48b7e675e7736bf1357"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should access the base URI" do
|
13
|
+
DataCatalog.base_uri = 'http://somehost.com'
|
14
|
+
DataCatalog.base_uri.should == 'http://somehost.com'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ".with_key" do
|
19
|
+
it "should set the API key within the block" do
|
20
|
+
regular_key = '4159179f32ff8fefd2c6d48b7e675e7736bf1357'
|
21
|
+
DataCatalog.api_key = regular_key
|
22
|
+
temporary_key = '0000123400001234000012340000123400001234'
|
23
|
+
DataCatalog.with_key(temporary_key) do
|
24
|
+
DataCatalog.api_key.should == temporary_key
|
25
|
+
end
|
26
|
+
DataCatalog.api_key.should == regular_key
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return the last value in the block" do
|
30
|
+
DataCatalog.with_key("0000444400004444") do
|
31
|
+
42
|
32
|
+
end.should == 42
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/spec/source_spec.rb
CHANGED
@@ -1,162 +1,162 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
include DataCatalog
|
3
|
-
|
4
|
-
module SourceHelpers
|
5
|
-
def create_source(params={})
|
6
|
-
valid_params = {
|
7
|
-
:title => "Some FCC Data",
|
8
|
-
:url => "http://fcc.gov/somedata.csv"
|
9
|
-
}
|
10
|
-
Source.create(valid_params.merge(params))
|
11
|
-
end
|
12
|
-
|
13
|
-
def create_3_sources
|
14
|
-
%w(FCC NASA DOE).each do |name|
|
15
|
-
Source.create({
|
16
|
-
:title => "#{name} Data",
|
17
|
-
:url => "http://#{name.downcase}.gov/data.xml"
|
18
|
-
})
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe Source do
|
24
|
-
include SourceHelpers
|
25
|
-
|
26
|
-
before do
|
27
|
-
setup_api
|
28
|
-
clean_slate
|
29
|
-
end
|
30
|
-
|
31
|
-
describe ".all" do
|
32
|
-
before do
|
33
|
-
create_3_sources
|
34
|
-
@sources = Source.all
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should return an enumeration of sources" do
|
38
|
-
@sources.each do |source|
|
39
|
-
source.should be_an_instance_of(Source)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should return correct titles" do
|
44
|
-
expected = ["FCC Data", "NASA Data", "DOE Data"]
|
45
|
-
@sources.map(&:title).sort.should == expected.sort
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe ".all with conditions" do
|
50
|
-
before do
|
51
|
-
create_3_sources
|
52
|
-
@sources = Source.all(:title => "NASA Data")
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should return an enumeration of sources" do
|
56
|
-
@sources.each do |source|
|
57
|
-
source.should be_an_instance_of(Source)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should return correct titles" do
|
62
|
-
expected = ["NASA Data"]
|
63
|
-
@sources.map(&:title).sort.should == expected.sort
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe ".create" do
|
68
|
-
it "should create a new source from basic params" do
|
69
|
-
source = create_source
|
70
|
-
source.should be_an_instance_of(Source)
|
71
|
-
source.url.should == "http://fcc.gov/somedata.csv"
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should create a new source from custom params" do
|
75
|
-
source = create_source({ :custom => {
|
76
|
-
"0" => {
|
77
|
-
:label => "License",
|
78
|
-
:description => "License",
|
79
|
-
:type => "string",
|
80
|
-
:value => "Public Domain"
|
81
|
-
}
|
82
|
-
}})
|
83
|
-
source.should be_an_instance_of(Source)
|
84
|
-
source.url.should == "http://fcc.gov/somedata.csv"
|
85
|
-
source.custom.should == {
|
86
|
-
"0" => {
|
87
|
-
"label" => "License",
|
88
|
-
"description" => "License",
|
89
|
-
"type" => "string",
|
90
|
-
"value" => "Public Domain"
|
91
|
-
}
|
92
|
-
}
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe ".first" do
|
97
|
-
before do
|
98
|
-
create_3_sources
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should return a source" do
|
102
|
-
source = Source.first(:title => "NASA Data")
|
103
|
-
source.should be_an_instance_of(Source)
|
104
|
-
source.title.should == "NASA Data"
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should return nil if nothing found" do
|
108
|
-
source = Source.first(:title => "UFO Data")
|
109
|
-
source.should be_nil
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe ".get" do
|
114
|
-
before do
|
115
|
-
@source = create_source
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should return a source" do
|
119
|
-
source = Source.get(@source.id)
|
120
|
-
source.should be_an_instance_of(Source)
|
121
|
-
source.title.should == "Some FCC Data"
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should raise NotFound if no source exists" do
|
125
|
-
executing do
|
126
|
-
Source.get(mangle(@source.id))
|
127
|
-
end.should raise_error(NotFound)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe ".update" do
|
132
|
-
before do
|
133
|
-
@source = create_source
|
134
|
-
end
|
135
|
-
|
136
|
-
it "should update an existing source from valid params" do
|
137
|
-
source = Source.update(@source.id, {
|
138
|
-
:url => "http://fec.gov/newdata.csv"
|
139
|
-
})
|
140
|
-
source.should be_an_instance_of(Source)
|
141
|
-
source.url.should == "http://fec.gov/newdata.csv"
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe ".destroy" do
|
146
|
-
before do
|
147
|
-
@source = create_source
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should destroy an existing source" do
|
151
|
-
result = Source.destroy(@source.id)
|
152
|
-
result.should be_true
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should raise NotFound when attempting to destroy non-existing source" do
|
156
|
-
executing do
|
157
|
-
Source.destroy(mangle(@source.id))
|
158
|
-
end.should raise_error(NotFound)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
include DataCatalog
|
3
|
+
|
4
|
+
module SourceHelpers
|
5
|
+
def create_source(params={})
|
6
|
+
valid_params = {
|
7
|
+
:title => "Some FCC Data",
|
8
|
+
:url => "http://fcc.gov/somedata.csv"
|
9
|
+
}
|
10
|
+
Source.create(valid_params.merge(params))
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_3_sources
|
14
|
+
%w(FCC NASA DOE).each do |name|
|
15
|
+
Source.create({
|
16
|
+
:title => "#{name} Data",
|
17
|
+
:url => "http://#{name.downcase}.gov/data.xml"
|
18
|
+
})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe Source do
|
24
|
+
include SourceHelpers
|
25
|
+
|
26
|
+
before do
|
27
|
+
setup_api
|
28
|
+
clean_slate
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".all" do
|
32
|
+
before do
|
33
|
+
create_3_sources
|
34
|
+
@sources = Source.all
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return an enumeration of sources" do
|
38
|
+
@sources.each do |source|
|
39
|
+
source.should be_an_instance_of(Source)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return correct titles" do
|
44
|
+
expected = ["FCC Data", "NASA Data", "DOE Data"]
|
45
|
+
@sources.map(&:title).sort.should == expected.sort
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".all with conditions" do
|
50
|
+
before do
|
51
|
+
create_3_sources
|
52
|
+
@sources = Source.all(:title => "NASA Data")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return an enumeration of sources" do
|
56
|
+
@sources.each do |source|
|
57
|
+
source.should be_an_instance_of(Source)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return correct titles" do
|
62
|
+
expected = ["NASA Data"]
|
63
|
+
@sources.map(&:title).sort.should == expected.sort
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe ".create" do
|
68
|
+
it "should create a new source from basic params" do
|
69
|
+
source = create_source
|
70
|
+
source.should be_an_instance_of(Source)
|
71
|
+
source.url.should == "http://fcc.gov/somedata.csv"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should create a new source from custom params" do
|
75
|
+
source = create_source({ :custom => {
|
76
|
+
"0" => {
|
77
|
+
:label => "License",
|
78
|
+
:description => "License",
|
79
|
+
:type => "string",
|
80
|
+
:value => "Public Domain"
|
81
|
+
}
|
82
|
+
}})
|
83
|
+
source.should be_an_instance_of(Source)
|
84
|
+
source.url.should == "http://fcc.gov/somedata.csv"
|
85
|
+
source.custom.should == {
|
86
|
+
"0" => {
|
87
|
+
"label" => "License",
|
88
|
+
"description" => "License",
|
89
|
+
"type" => "string",
|
90
|
+
"value" => "Public Domain"
|
91
|
+
}
|
92
|
+
}
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe ".first" do
|
97
|
+
before do
|
98
|
+
create_3_sources
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return a source" do
|
102
|
+
source = Source.first(:title => "NASA Data")
|
103
|
+
source.should be_an_instance_of(Source)
|
104
|
+
source.title.should == "NASA Data"
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return nil if nothing found" do
|
108
|
+
source = Source.first(:title => "UFO Data")
|
109
|
+
source.should be_nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe ".get" do
|
114
|
+
before do
|
115
|
+
@source = create_source
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return a source" do
|
119
|
+
source = Source.get(@source.id)
|
120
|
+
source.should be_an_instance_of(Source)
|
121
|
+
source.title.should == "Some FCC Data"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should raise NotFound if no source exists" do
|
125
|
+
executing do
|
126
|
+
Source.get(mangle(@source.id))
|
127
|
+
end.should raise_error(NotFound)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe ".update" do
|
132
|
+
before do
|
133
|
+
@source = create_source
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should update an existing source from valid params" do
|
137
|
+
source = Source.update(@source.id, {
|
138
|
+
:url => "http://fec.gov/newdata.csv"
|
139
|
+
})
|
140
|
+
source.should be_an_instance_of(Source)
|
141
|
+
source.url.should == "http://fec.gov/newdata.csv"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe ".destroy" do
|
146
|
+
before do
|
147
|
+
@source = create_source
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should destroy an existing source" do
|
151
|
+
result = Source.destroy(@source.id)
|
152
|
+
result.should be_true
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should raise NotFound when attempting to destroy non-existing source" do
|
156
|
+
executing do
|
157
|
+
Source.destroy(mangle(@source.id))
|
158
|
+
end.should raise_error(NotFound)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|