datacatalog 0.3.8 → 0.4.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/Rakefile +1 -1
- data/datacatalog.gemspec +3 -2
- data/lib/base.rb +15 -4
- data/lib/cursor.rb +98 -0
- data/lib/datacatalog.rb +1 -0
- data/lib/resources/api_key.rb +2 -2
- data/lib/resources/comment.rb +1 -1
- data/lib/resources/document.rb +1 -1
- data/lib/resources/favorite.rb +1 -1
- data/lib/resources/note.rb +1 -1
- data/lib/resources/organization.rb +3 -3
- data/lib/resources/rating.rb +1 -1
- data/lib/resources/source.rb +3 -3
- data/lib/resources/user.rb +2 -2
- data/spec/base_spec.rb +0 -19
- data/spec/comment_spec.rb +9 -7
- data/spec/document_spec.rb +17 -14
- data/spec/favorite_spec.rb +5 -9
- data/spec/note_spec.rb +18 -15
- data/spec/organization_spec.rb +26 -12
- data/spec/rating_spec.rb +17 -11
- data/spec/source_spec.rb +35 -2
- data/spec/spec_helper.rb +9 -8
- metadata +3 -2
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "datacatalog"
|
8
|
-
gem.version = '0.
|
8
|
+
gem.version = '0.4.0'
|
9
9
|
gem.rubyforge_project = "datacatalog"
|
10
10
|
gem.summary = %Q{Client for the National Data Catalog API}
|
11
11
|
gem.description = %Q{A Ruby client library for the National Data Catalog API}
|
data/datacatalog.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datacatalog}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Luigi Montanez", "David James"]
|
12
|
-
s.date = %q{2009-12-
|
12
|
+
s.date = %q{2009-12-03}
|
13
13
|
s.description = %q{A Ruby client library for the National Data Catalog API}
|
14
14
|
s.email = %q{luigi@sunlightfoundation.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
"Rakefile",
|
24
24
|
"datacatalog.gemspec",
|
25
25
|
"lib/base.rb",
|
26
|
+
"lib/cursor.rb",
|
26
27
|
"lib/datacatalog.rb",
|
27
28
|
"lib/main.rb",
|
28
29
|
"lib/resources/about.rb",
|
data/lib/base.rb
CHANGED
@@ -51,6 +51,15 @@ module DataCatalog
|
|
51
51
|
response
|
52
52
|
end
|
53
53
|
|
54
|
+
def self.cursor(uri, query_hash)
|
55
|
+
Cursor.new({
|
56
|
+
:klass => self,
|
57
|
+
:query_hash => query_hash,
|
58
|
+
:response => http_get(uri, :query => query_hash),
|
59
|
+
:uri => uri,
|
60
|
+
})
|
61
|
+
end
|
62
|
+
|
54
63
|
def self.error(response)
|
55
64
|
parsed_body = JSON.parse(response.body)
|
56
65
|
if parsed_body.empty?
|
@@ -64,8 +73,9 @@ module DataCatalog
|
|
64
73
|
"Unable to parse: #{response.body.inspect}"
|
65
74
|
end
|
66
75
|
|
67
|
-
def self.
|
68
|
-
|
76
|
+
def self._first(response)
|
77
|
+
item = response['members'][0]
|
78
|
+
item.blank? ? nil : new(item)
|
69
79
|
end
|
70
80
|
|
71
81
|
def self.one(response)
|
@@ -78,13 +88,14 @@ module DataCatalog
|
|
78
88
|
end
|
79
89
|
|
80
90
|
def self.filterize(conditions)
|
81
|
-
conditions.map do |k, v|
|
91
|
+
filtered_conditions = conditions.map do |k, v|
|
82
92
|
"#{k}" + if v.is_a?(Regexp)
|
83
93
|
%(:"#{v.source}")
|
84
94
|
else
|
85
95
|
%(="#{v}")
|
86
96
|
end
|
87
|
-
end
|
97
|
+
end
|
98
|
+
filtered_conditions.join(" ")
|
88
99
|
end
|
89
100
|
|
90
101
|
def method_missing(method_name, *args)
|
data/lib/cursor.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
module DataCatalog
|
2
|
+
|
3
|
+
class Cursor
|
4
|
+
|
5
|
+
attr_reader :document_count
|
6
|
+
attr_reader :page_count
|
7
|
+
attr_reader :page_size
|
8
|
+
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
def initialize(options)
|
12
|
+
@klass = options[:klass]
|
13
|
+
@query_hash = options[:query_hash]
|
14
|
+
@response = options[:response]
|
15
|
+
@uri = options[:uri]
|
16
|
+
|
17
|
+
@page_size = @response['page_size']
|
18
|
+
@document_count = @response['document_count']
|
19
|
+
@members = members(@response)
|
20
|
+
@page_count = @response['page_count']
|
21
|
+
end
|
22
|
+
|
23
|
+
def [](i)
|
24
|
+
member_at(i)
|
25
|
+
end
|
26
|
+
|
27
|
+
def each
|
28
|
+
@document_count.times { |i| yield member_at(i) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def first
|
32
|
+
member_at(0)
|
33
|
+
end
|
34
|
+
|
35
|
+
def last
|
36
|
+
member_at(@document_count - 1)
|
37
|
+
end
|
38
|
+
|
39
|
+
def length
|
40
|
+
@document_count
|
41
|
+
end
|
42
|
+
|
43
|
+
def page(page_number)
|
44
|
+
page_indices(page_number).map { |i| member_at(i) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def size
|
48
|
+
@members.size
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def fetch_members_near_index(index)
|
54
|
+
page_number = page_for_index(index)
|
55
|
+
response = response_for_page(page_number)
|
56
|
+
fetched = members(response)
|
57
|
+
range = page_indices(page_number)
|
58
|
+
range.each_with_index do |i, j|
|
59
|
+
@members[i] = fetched[j]
|
60
|
+
end
|
61
|
+
fetched.length
|
62
|
+
end
|
63
|
+
|
64
|
+
def member_at(index)
|
65
|
+
if index < 0
|
66
|
+
raise "index (#{index}) must be >= 0"
|
67
|
+
end
|
68
|
+
cached = @members[index]
|
69
|
+
return nil if @document_count == 0
|
70
|
+
return cached if cached
|
71
|
+
fetch_members_near_index(index)
|
72
|
+
fetched = @members[index]
|
73
|
+
raise "cannot find find member at index #{index}" unless fetched
|
74
|
+
fetched
|
75
|
+
end
|
76
|
+
|
77
|
+
def members(response)
|
78
|
+
response['members'].map { |x| @klass.new(x) }
|
79
|
+
end
|
80
|
+
|
81
|
+
def page_for_index(index)
|
82
|
+
(index / @page_size) + 1
|
83
|
+
end
|
84
|
+
|
85
|
+
def page_indices(page_number)
|
86
|
+
min = (page_number - 1) * @page_size
|
87
|
+
max = [min + @page_size - 1, @document_count - 1].min
|
88
|
+
(min .. max)
|
89
|
+
end
|
90
|
+
|
91
|
+
def response_for_page(page_number)
|
92
|
+
query_hash = @query_hash.merge(:page => page_number)
|
93
|
+
@klass.http_get(@uri, :query => query_hash)
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/lib/datacatalog.rb
CHANGED
data/lib/resources/api_key.rb
CHANGED
@@ -3,7 +3,7 @@ module DataCatalog
|
|
3
3
|
class ApiKey < Base
|
4
4
|
|
5
5
|
def self.all(user_id, conditions={})
|
6
|
-
|
6
|
+
cursor(uri(user_id), query_hash(conditions))
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.create(user_id, params={})
|
@@ -15,7 +15,7 @@ module DataCatalog
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.first(user_id, conditions={})
|
18
|
-
|
18
|
+
_first(http_get(uri(user_id), :query => query_hash(conditions)))
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.get(user_id, id)
|
data/lib/resources/comment.rb
CHANGED
data/lib/resources/document.rb
CHANGED
data/lib/resources/favorite.rb
CHANGED
data/lib/resources/note.rb
CHANGED
@@ -3,7 +3,7 @@ module DataCatalog
|
|
3
3
|
class Organization < Base
|
4
4
|
|
5
5
|
def self.all(conditions={})
|
6
|
-
|
6
|
+
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.create(params={})
|
@@ -15,7 +15,7 @@ module DataCatalog
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.first(conditions={})
|
18
|
-
|
18
|
+
_first(http_get(uri, :query => query_hash(conditions)))
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.get(id)
|
@@ -23,7 +23,7 @@ module DataCatalog
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.search(term)
|
26
|
-
|
26
|
+
cursor(uri, { :search => term })
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.update(id, params={})
|
data/lib/resources/rating.rb
CHANGED
data/lib/resources/source.rb
CHANGED
@@ -3,7 +3,7 @@ module DataCatalog
|
|
3
3
|
class Source < Base
|
4
4
|
|
5
5
|
def self.all(conditions={})
|
6
|
-
|
6
|
+
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.create(params={})
|
@@ -15,7 +15,7 @@ module DataCatalog
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.first(conditions={})
|
18
|
-
|
18
|
+
_first(http_get(uri, :query => query_hash(conditions)))
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.get(id)
|
@@ -23,7 +23,7 @@ module DataCatalog
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.search(term)
|
26
|
-
|
26
|
+
cursor(uri, { :search => term })
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.update(id, params={})
|
data/lib/resources/user.rb
CHANGED
@@ -3,7 +3,7 @@ module DataCatalog
|
|
3
3
|
class User < Base
|
4
4
|
|
5
5
|
def self.all(conditions={})
|
6
|
-
|
6
|
+
cursor(uri, query_hash(conditions))
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.create(params={})
|
@@ -15,7 +15,7 @@ module DataCatalog
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.first(conditions={})
|
18
|
-
|
18
|
+
_first(http_get(uri, :query => query_hash(conditions)))
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.get(id)
|
data/spec/base_spec.rb
CHANGED
@@ -85,25 +85,6 @@ describe Base do
|
|
85
85
|
end
|
86
86
|
end
|
87
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
88
|
describe ".one" do
|
108
89
|
it "should create an object from a filled hash" do
|
109
90
|
hash = Base.one({
|
data/spec/comment_spec.rb
CHANGED
@@ -6,13 +6,15 @@ describe Comment do
|
|
6
6
|
before do
|
7
7
|
setup_api
|
8
8
|
clean_slate
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@source = Source.create(
|
14
|
-
|
15
|
-
|
9
|
+
@user = User.create(
|
10
|
+
:name => "Ted Smith",
|
11
|
+
:email => "ted@email.com"
|
12
|
+
)
|
13
|
+
@source = Source.create(
|
14
|
+
:title => "Some FCC Data",
|
15
|
+
:url => "http://fcc.gov/somedata.csv",
|
16
|
+
:source_type => "dataset"
|
17
|
+
)
|
16
18
|
end
|
17
19
|
|
18
20
|
describe ".create" do
|
data/spec/document_spec.rb
CHANGED
@@ -6,18 +6,21 @@ describe Document do
|
|
6
6
|
before do
|
7
7
|
setup_api
|
8
8
|
clean_slate
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@source = Source.create(
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
@user = User.create(
|
10
|
+
:name => "Ted Smith",
|
11
|
+
:email => "ted@email.com"
|
12
|
+
)
|
13
|
+
@source = Source.create(
|
14
|
+
:title => "Some FCC Data",
|
15
|
+
:url => "http://fcc.gov/somedata.csv",
|
16
|
+
:source_type => "dataset"
|
17
|
+
)
|
17
18
|
DataCatalog.with_key(@user.primary_api_key) do
|
18
|
-
@document = Document.create(
|
19
|
+
@document = Document.create(
|
20
|
+
:source_id => @source.id,
|
21
|
+
:text => "This is community documentation."
|
22
|
+
)
|
19
23
|
end
|
20
|
-
|
21
24
|
end
|
22
25
|
|
23
26
|
describe ".create" do
|
@@ -49,11 +52,11 @@ describe Document do
|
|
49
52
|
|
50
53
|
describe ".all" do
|
51
54
|
|
52
|
-
it "should return
|
55
|
+
it "should return an enumeration of documents" do
|
53
56
|
documents = Document.all(:source_id => @source.id)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
documents.each do |o|
|
58
|
+
o.should be_an_instance_of(Document)
|
59
|
+
end
|
57
60
|
end
|
58
61
|
|
59
62
|
end # describe ".all"
|
data/spec/favorite_spec.rb
CHANGED
@@ -6,22 +6,18 @@ describe Favorite do
|
|
6
6
|
before do
|
7
7
|
setup_api
|
8
8
|
clean_slate
|
9
|
-
|
10
9
|
@user = User.create(
|
11
10
|
:name => "Ted Smith",
|
12
11
|
:email => "ted@email.com"
|
13
12
|
)
|
14
|
-
|
15
13
|
@source = Source.create(
|
16
14
|
:title => "Some FCC Data",
|
17
15
|
:url => "http://fcc.gov/somedata.csv",
|
18
16
|
:source_type => "dataset"
|
19
17
|
)
|
20
|
-
|
21
18
|
DataCatalog.with_key(@user.primary_api_key) do
|
22
19
|
@favorite = Favorite.create(:source_id => @source.id)
|
23
20
|
end
|
24
|
-
|
25
21
|
end
|
26
22
|
|
27
23
|
describe ".create" do
|
@@ -50,12 +46,12 @@ describe Favorite do
|
|
50
46
|
end # describe ".get"
|
51
47
|
|
52
48
|
describe ".all" do
|
53
|
-
|
54
|
-
it "should return
|
49
|
+
|
50
|
+
it "should return an enumeration of favorites" do
|
55
51
|
favorites = Favorite.all(:user_id => @user.id)
|
56
|
-
|
57
|
-
|
58
|
-
|
52
|
+
favorites.each do |o|
|
53
|
+
o.should be_an_instance_of(Favorite)
|
54
|
+
end
|
59
55
|
end
|
60
56
|
|
61
57
|
end # describe ".all"
|
data/spec/note_spec.rb
CHANGED
@@ -6,18 +6,21 @@ describe Note do
|
|
6
6
|
before do
|
7
7
|
setup_api
|
8
8
|
clean_slate
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
@source = Source.create(
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
@user = User.create(
|
10
|
+
:name => "Ted Smith",
|
11
|
+
:email => "ted@email.com"
|
12
|
+
)
|
13
|
+
@source = Source.create(
|
14
|
+
:title => "Some FCC Data",
|
15
|
+
:url => "http://fcc.gov/somedata.csv",
|
16
|
+
:source_type => "dataset"
|
17
|
+
)
|
17
18
|
DataCatalog.with_key(@user.primary_api_key) do
|
18
|
-
@note = Note.create(
|
19
|
+
@note = Note.create(
|
20
|
+
:source_id => @source.id,
|
21
|
+
:text => "This is my note."
|
22
|
+
)
|
19
23
|
end
|
20
|
-
|
21
24
|
end
|
22
25
|
|
23
26
|
describe ".create" do
|
@@ -48,12 +51,12 @@ describe Note do
|
|
48
51
|
end # describe ".get"
|
49
52
|
|
50
53
|
describe ".all" do
|
51
|
-
|
52
|
-
it "should return
|
54
|
+
|
55
|
+
it "should return an enumeration of notes" do
|
53
56
|
notes = Note.all(:user_id => @user.id)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
notes.each do |o|
|
58
|
+
o.should be_an_instance_of(Note)
|
59
|
+
end
|
57
60
|
end
|
58
61
|
|
59
62
|
end # describe ".all"
|
data/spec/organization_spec.rb
CHANGED
@@ -4,7 +4,11 @@ include DataCatalog
|
|
4
4
|
describe Organization do
|
5
5
|
|
6
6
|
def create_3_organizations
|
7
|
-
@organization_names = [
|
7
|
+
@organization_names = [
|
8
|
+
"Federal Communications Commission",
|
9
|
+
"Federal Election Commission",
|
10
|
+
"Department of State"
|
11
|
+
]
|
8
12
|
@organization_names.each do |name|
|
9
13
|
Organization.create(:name => name, :org_type => "governmental")
|
10
14
|
end
|
@@ -22,24 +26,34 @@ describe Organization do
|
|
22
26
|
end
|
23
27
|
|
24
28
|
it "should return an enumeration of Organizations" do
|
25
|
-
|
26
|
-
@organizations.each do |o|
|
29
|
+
Organization.all.each do |o|
|
27
30
|
o.should be_an_instance_of(Organization)
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
34
|
it "should return an enumeration with organization name set" do
|
32
|
-
|
33
|
-
@organizations.map(&:name).sort.should == @organization_names.sort
|
35
|
+
Organization.all.map(&:name).sort.should == @organization_names.sort
|
34
36
|
end
|
35
37
|
|
36
38
|
it "should return the matching organizations when options are passed in" do
|
37
|
-
|
38
|
-
|
39
|
+
orgs = Organization.all(:name => "Federal Communications Commission")
|
40
|
+
orgs.map(&:name).should == ["Federal Communications Commission"]
|
39
41
|
end
|
40
42
|
|
41
43
|
end # describe ".all"
|
42
44
|
|
45
|
+
describe ".search" do
|
46
|
+
before do
|
47
|
+
create_3_organizations
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return correct search result" do
|
51
|
+
@organizations = Organization.search("Federal")
|
52
|
+
@organizations.size.should == 2
|
53
|
+
@organizations.first.name.should == "Federal Communications Commission"
|
54
|
+
end
|
55
|
+
end # describe organizations
|
56
|
+
|
43
57
|
describe ".first" do
|
44
58
|
|
45
59
|
before do
|
@@ -47,8 +61,8 @@ describe Organization do
|
|
47
61
|
end
|
48
62
|
|
49
63
|
it "should return the matching organization when options are passed in" do
|
50
|
-
|
51
|
-
|
64
|
+
org = Organization.first(:name => "Federal Communications Commission")
|
65
|
+
org.name.should == "Federal Communications Commission"
|
52
66
|
end
|
53
67
|
|
54
68
|
end # describe ".first"
|
@@ -76,9 +90,9 @@ describe Organization do
|
|
76
90
|
describe ".create" do
|
77
91
|
|
78
92
|
it "should create a new organization when valid params are passed in" do
|
79
|
-
|
80
|
-
|
81
|
-
|
93
|
+
org = Organization.create(:name => "Federal Communications Commission", :org_type => "governmental")
|
94
|
+
org.should be_an_instance_of(Organization)
|
95
|
+
org.name.should == "Federal Communications Commission"
|
82
96
|
end
|
83
97
|
|
84
98
|
it "should raise BadRequest when a bad URL is passed in" do
|
data/spec/rating_spec.rb
CHANGED
@@ -6,18 +6,24 @@ describe Rating do
|
|
6
6
|
before do
|
7
7
|
setup_api
|
8
8
|
clean_slate
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
@user = User.create(
|
10
|
+
:name => "Ted Smith",
|
11
|
+
:email => "ted@email.com"
|
12
|
+
)
|
13
|
+
@user2 = User.create(
|
14
|
+
:name => "Chad Johnson",
|
15
|
+
:email => "chad@email.com"
|
16
|
+
)
|
17
|
+
@source = Source.create(
|
18
|
+
:title => "Some FCC Data",
|
19
|
+
:url => "http://fcc.gov/somedata.csv",
|
20
|
+
:source_type => "dataset"
|
21
|
+
)
|
19
22
|
DataCatalog.with_key(@user.primary_api_key) do
|
20
|
-
@comment = Comment.create(
|
23
|
+
@comment = Comment.create(
|
24
|
+
:source_id => @source.id,
|
25
|
+
:text => "This is a useful comment."
|
26
|
+
)
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
data/spec/source_spec.rb
CHANGED
@@ -20,6 +20,16 @@ module SourceHelpers
|
|
20
20
|
})
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
def create_30_sources
|
25
|
+
(1..30).each do |n|
|
26
|
+
Source.create({
|
27
|
+
:title => "Dataset #{n.to_s}",
|
28
|
+
:url => "http://awesome.gov/dataset#{n.to_s}.xml",
|
29
|
+
:source_type => "dataset"
|
30
|
+
})
|
31
|
+
end
|
32
|
+
end
|
23
33
|
end
|
24
34
|
|
25
35
|
describe Source do
|
@@ -35,17 +45,40 @@ describe Source do
|
|
35
45
|
create_3_sources
|
36
46
|
@sources = Source.all
|
37
47
|
end
|
48
|
+
|
49
|
+
it "should return an Enumerable object" do
|
50
|
+
@sources.is_a?(Enumerable).should == true
|
51
|
+
end
|
38
52
|
|
39
53
|
it "should return an enumeration of sources" do
|
40
54
|
@sources.each do |source|
|
41
55
|
source.should be_an_instance_of(Source)
|
42
56
|
end
|
43
57
|
end
|
44
|
-
|
58
|
+
|
45
59
|
it "should return correct titles" do
|
46
60
|
expected = ["FCC Data", "NASA Data", "DOE Data"]
|
47
61
|
@sources.map(&:title).sort.should == expected.sort
|
48
62
|
end
|
63
|
+
|
64
|
+
|
65
|
+
describe "with cursor" do
|
66
|
+
|
67
|
+
it "should raise an error on bad index" do
|
68
|
+
executing do
|
69
|
+
@sources.page(0)
|
70
|
+
end.should raise_error(RuntimeError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return 20 objects when there are more than 20" do
|
74
|
+
create_30_sources
|
75
|
+
sources = Source.all
|
76
|
+
sources.size.should == 20
|
77
|
+
sources.page(1).size.should == 20
|
78
|
+
sources.page(2).size.should == 13
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
49
82
|
end
|
50
83
|
|
51
84
|
describe ".all with conditions" do
|
@@ -77,7 +110,7 @@ describe Source do
|
|
77
110
|
@sources.first.title.should == "FCC Data"
|
78
111
|
end
|
79
112
|
end
|
80
|
-
|
113
|
+
|
81
114
|
describe ".create" do
|
82
115
|
it "should create a new source from basic params" do
|
83
116
|
source = create_source
|
data/spec/spec_helper.rb
CHANGED
@@ -7,19 +7,20 @@ end
|
|
7
7
|
|
8
8
|
alias :executing :lambda
|
9
9
|
|
10
|
-
|
10
|
+
KLASSES = [
|
11
|
+
DataCatalog::Source,
|
12
|
+
DataCatalog::Organization
|
13
|
+
]
|
11
14
|
|
15
|
+
def clean_slate
|
12
16
|
DataCatalog::User.all.each do |u|
|
13
17
|
DataCatalog::User.destroy(u.id) unless u.name == "Primary Admin"
|
14
18
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
class_constant.destroy(instance.id)
|
20
|
-
end
|
19
|
+
KLASSES.each do |klass|
|
20
|
+
to_delete = []
|
21
|
+
klass.all.each { |instance| to_delete << instance.id }
|
22
|
+
to_delete.each { |id| klass.destroy(id) }
|
21
23
|
end
|
22
|
-
|
23
24
|
end
|
24
25
|
|
25
26
|
def mangle(string)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datacatalog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luigi Montanez
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-12-
|
13
|
+
date: 2009-12-03 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- Rakefile
|
90
90
|
- datacatalog.gemspec
|
91
91
|
- lib/base.rb
|
92
|
+
- lib/cursor.rb
|
92
93
|
- lib/datacatalog.rb
|
93
94
|
- lib/main.rb
|
94
95
|
- lib/resources/about.rb
|