datacatalog 0.4.15 → 0.4.16
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/Rakefile +6 -6
- data/datacatalog.gemspec +20 -17
- data/lib/base.rb +8 -8
- data/lib/cursor.rb +16 -12
- data/lib/main.rb +8 -8
- data/lib/resources/about.rb +4 -4
- data/lib/resources/api_key.rb +5 -5
- data/lib/resources/broken_link.rb +33 -0
- data/lib/resources/comment.rb +4 -4
- data/lib/resources/document.rb +2 -2
- data/lib/resources/download.rb +2 -2
- data/lib/resources/favorite.rb +3 -3
- data/lib/resources/import.rb +2 -2
- data/lib/resources/importer.rb +2 -2
- data/lib/resources/note.rb +2 -2
- data/lib/resources/organization.rb +1 -1
- data/lib/resources/rating.rb +4 -4
- data/lib/resources/report.rb +4 -4
- data/lib/resources/source.rb +2 -2
- data/lib/resources/user.rb +9 -9
- data/spec/about_spec.rb +5 -5
- data/spec/api_key_spec.rb +12 -12
- data/spec/base_spec.rb +16 -16
- data/spec/comment_spec.rb +9 -9
- data/spec/datacatalog_spec.rb +2 -2
- data/spec/document_spec.rb +18 -18
- data/spec/download_spec.rb +10 -10
- data/spec/empty_spec.rb +61 -0
- data/spec/favorite_spec.rb +14 -14
- data/spec/import_spec.rb +5 -5
- data/spec/importer_spec.rb +5 -5
- data/spec/note_spec.rb +16 -16
- data/spec/organization_spec.rb +20 -20
- data/spec/rating_spec.rb +20 -20
- data/spec/report_spec.rb +11 -11
- data/spec/source_spec.rb +26 -26
- data/spec/spec_helper.rb +10 -3
- data/spec/user_spec.rb +23 -23
- data/tasks/test_api.rake +3 -3
- metadata +20 -17
data/spec/importer_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
include DataCatalog
|
3
3
|
|
4
4
|
describe Importer do
|
5
|
-
|
5
|
+
|
6
6
|
before do
|
7
7
|
setup_api
|
8
8
|
clean_slate
|
@@ -55,7 +55,7 @@ describe Importer do
|
|
55
55
|
end.should raise_error(BadRequest)
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
describe ".all" do
|
60
60
|
it "should return an enumeration of 2 importers" do
|
61
61
|
importers = Importer.all
|
@@ -87,7 +87,7 @@ describe Importer do
|
|
87
87
|
it "should destroy an existing importer as an admin" do
|
88
88
|
Importer.destroy(@importers[0].id).should be_true
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
it "should not destroy an existing importer as a basic user" do
|
92
92
|
DataCatalog.with_key(@user.primary_api_key) do
|
93
93
|
executing do
|
@@ -95,12 +95,12 @@ describe Importer do
|
|
95
95
|
end.should raise_error(Unauthorized)
|
96
96
|
end
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
it "should raise NotFound when attempting to destroy non-existing importer" do
|
100
100
|
executing do
|
101
101
|
Importer.destroy(mangle(@importers[0].id))
|
102
102
|
end.should raise_error(NotFound)
|
103
103
|
end
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
end
|
data/spec/note_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
include DataCatalog
|
3
3
|
|
4
4
|
describe Note do
|
5
|
-
|
5
|
+
|
6
6
|
before do
|
7
7
|
setup_api
|
8
8
|
clean_slate
|
@@ -22,7 +22,7 @@ describe Note do
|
|
22
22
|
)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
describe ".create" do
|
27
27
|
|
28
28
|
it "should create a note when valid params are passed in" do
|
@@ -31,25 +31,25 @@ describe Note do
|
|
31
31
|
refreshed_source.notes.first.text.should == "This is my note."
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
end # describe ".create"
|
36
|
-
|
36
|
+
|
37
37
|
describe ".get" do
|
38
|
-
|
38
|
+
|
39
39
|
it "should return a note" do
|
40
40
|
note = Note.get(@note.id)
|
41
41
|
note.should be_an_instance_of(Note)
|
42
42
|
note.user_id.should == @user.id
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "should raise NotFound if no note exists" do
|
46
46
|
executing do
|
47
47
|
Note.get(mangle(@note.id))
|
48
48
|
end.should raise_error(NotFound)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
end # describe ".get"
|
52
|
-
|
52
|
+
|
53
53
|
describe ".all" do
|
54
54
|
|
55
55
|
it "should return an enumeration of notes" do
|
@@ -58,20 +58,20 @@ describe Note do
|
|
58
58
|
o.should be_an_instance_of(Note)
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
end # describe ".all"
|
63
|
-
|
63
|
+
|
64
64
|
describe ".update" do
|
65
65
|
|
66
66
|
it "should update an existing note with valid params" do
|
67
67
|
DataCatalog.with_key(@user.primary_api_key) do
|
68
68
|
Note.update(@note.id, :text => "This is my updated note.")
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
refreshed_note = Note.get(@note.id)
|
72
72
|
refreshed_note.text.should == "This is my updated note."
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
end # describe ".update"
|
76
76
|
|
77
77
|
describe ".destroy" do
|
@@ -79,19 +79,19 @@ describe Note do
|
|
79
79
|
it "should destroy an existing note as an admin" do
|
80
80
|
Note.destroy(@note.id).should be_true
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
it "should destroy an existing note as the user" do
|
84
84
|
DataCatalog.with_key(@user.primary_api_key) do
|
85
85
|
Note.destroy(@note.id).should be_true
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
it "should raise NotFound when attempting to destroy non-existing note" do
|
90
90
|
executing do
|
91
91
|
Note.destroy(mangle(@note.id))
|
92
92
|
end.should raise_error(NotFound)
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
end # describe ".destroy"
|
96
|
-
|
96
|
+
|
97
97
|
end
|
data/spec/organization_spec.rb
CHANGED
@@ -18,35 +18,35 @@ describe Organization do
|
|
18
18
|
setup_api
|
19
19
|
clean_slate
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
describe ".all" do
|
23
|
-
|
23
|
+
|
24
24
|
before do
|
25
25
|
create_3_organizations
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "should return an enumeration of Organizations" do
|
29
29
|
Organization.all.each do |o|
|
30
30
|
o.should be_an_instance_of(Organization)
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "should return an enumeration with organization name set" do
|
35
35
|
Organization.all.map(&:name).sort.should == @organization_names.sort
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "should return the matching organizations when options are passed in" do
|
39
39
|
orgs = Organization.all(:name => "Federal Communications Commission")
|
40
40
|
orgs.map(&:name).should == ["Federal Communications Commission"]
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end # describe ".all"
|
44
44
|
|
45
45
|
describe ".search" do
|
46
46
|
before do
|
47
47
|
create_3_organizations
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
it "should return correct search result" do
|
51
51
|
@organizations = Organization.search("Federal")
|
52
52
|
@organizations.size.should == 2
|
@@ -55,18 +55,18 @@ describe Organization do
|
|
55
55
|
end # describe organizations
|
56
56
|
|
57
57
|
describe ".first" do
|
58
|
-
|
58
|
+
|
59
59
|
before do
|
60
60
|
create_3_organizations
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
it "should return the matching organization when options are passed in" do
|
64
64
|
org = Organization.first(:name => "Federal Communications Commission")
|
65
65
|
org.name.should == "Federal Communications Commission"
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
end # describe ".first"
|
69
|
-
|
69
|
+
|
70
70
|
describe ".get" do
|
71
71
|
|
72
72
|
before do
|
@@ -78,23 +78,23 @@ describe Organization do
|
|
78
78
|
organization.should be_an_instance_of(Organization)
|
79
79
|
organization.name.should == "Federal Election Commission"
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
it "should raise NotFound if no source exists" do
|
83
83
|
executing do
|
84
84
|
Organization.get(mangle(@organization.id))
|
85
85
|
end.should raise_error(NotFound)
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
end # describe ".get"
|
89
89
|
|
90
90
|
describe ".create" do
|
91
|
-
|
91
|
+
|
92
92
|
it "should create a new organization when valid params are passed in" do
|
93
93
|
org = Organization.create(:name => "Federal Communications Commission", :org_type => "governmental")
|
94
94
|
org.should be_an_instance_of(Organization)
|
95
95
|
org.name.should == "Federal Communications Commission"
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
it "should raise BadRequest when a bad URL is passed in" do
|
99
99
|
executing do
|
100
100
|
Organization.create(:name => "Bad Org", :url => "htt:p//jlkj!3", :org_type => "governmental")
|
@@ -108,13 +108,13 @@ describe Organization do
|
|
108
108
|
before do
|
109
109
|
@organization = Organization.create(:name => "Federal Election Commission", :org_type => "governmental")
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
it "should update an existing organization from valid params" do
|
113
113
|
organization = Organization.update(@organization.id, { :url => "http://fec.gov/" })
|
114
114
|
organization.should be_an_instance_of(Organization)
|
115
115
|
organization.url.should == "http://fec.gov/"
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
end # describe ".update"
|
119
119
|
|
120
120
|
describe ".destroy" do
|
@@ -122,17 +122,17 @@ describe Organization do
|
|
122
122
|
before do
|
123
123
|
@organization = Organization.create(:name => "Federal Election Commission", :org_type => "governmental")
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
it "should destroy an existing organization" do
|
127
127
|
Organization.destroy(@organization.id).should be_true
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
it "should raise NotFound when attempting to destroy non-existing organization" do
|
131
131
|
executing do
|
132
132
|
Organization.destroy(mangle(@organization.id))
|
133
133
|
end.should raise_error(NotFound)
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
end # describe ".destroy"
|
137
137
|
|
138
138
|
end
|
data/spec/rating_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
include DataCatalog
|
3
3
|
|
4
4
|
describe Rating do
|
5
|
-
|
5
|
+
|
6
6
|
before do
|
7
7
|
setup_api
|
8
8
|
clean_slate
|
@@ -26,31 +26,31 @@ describe Rating do
|
|
26
26
|
)
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
describe ".create" do
|
31
31
|
|
32
32
|
it "should create a source rating when valid params are passed in" do
|
33
33
|
DataCatalog.with_key(@user.primary_api_key) do
|
34
34
|
@rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
refreshed_source = Source.get(@source.id)
|
38
38
|
refreshed_source.rating_stats.average.should == 5
|
39
39
|
refreshed_source.rating_stats.total.should == 5
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "should create a comment rating when valid params are passed in" do
|
43
43
|
DataCatalog.with_key(@user2.primary_api_key) do
|
44
44
|
@rating = Rating.create(:kind => "comment", :comment_id => @comment.id, :value => 1)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
refreshed_comment = Comment.get(@comment.id)
|
48
48
|
refreshed_comment.rating_stats.average.should == 1
|
49
49
|
refreshed_comment.rating_stats.total.should == 1
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
end # describe ".create"
|
53
|
-
|
53
|
+
|
54
54
|
describe ".get" do
|
55
55
|
|
56
56
|
before do
|
@@ -64,13 +64,13 @@ describe Rating do
|
|
64
64
|
rating.should be_an_instance_of(Rating)
|
65
65
|
rating.value.should == 5
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "should raise NotFound if no rating exists" do
|
69
69
|
executing do
|
70
70
|
Rating.get(mangle(@rating.id))
|
71
71
|
end.should raise_error(NotFound)
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
end # describe ".get"
|
75
75
|
|
76
76
|
describe ".all" do
|
@@ -93,9 +93,9 @@ describe Rating do
|
|
93
93
|
ratings[0].value.should == 5
|
94
94
|
ratings[1].value.should == 3
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
end # describe ".all"
|
98
|
-
|
98
|
+
|
99
99
|
describe ".update" do
|
100
100
|
|
101
101
|
before do
|
@@ -103,19 +103,19 @@ describe Rating do
|
|
103
103
|
@rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
it "should update an existing rating with valid params" do
|
108
108
|
DataCatalog.with_key(@user.primary_api_key) do
|
109
109
|
Rating.update(@rating.id, :value => 3)
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
refreshed_rating = Rating.get(@rating.id)
|
113
113
|
refreshed_rating.value.should == 3
|
114
114
|
refreshed_rating.previous_value.should == 5
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
end # describe ".update"
|
118
|
-
|
118
|
+
|
119
119
|
describe ".destroy" do
|
120
120
|
|
121
121
|
before do
|
@@ -123,23 +123,23 @@ describe Rating do
|
|
123
123
|
@rating = Rating.create(:kind => "source", :source_id => @source.id, :value => 5)
|
124
124
|
end
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
it "should destroy an existing rating as an admin" do
|
128
128
|
Rating.destroy(@rating.id).should be_true
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
it "should destroy an existing rating as the user" do
|
132
132
|
DataCatalog.with_key(@user.primary_api_key) do
|
133
133
|
Rating.destroy(@rating.id).should be_true
|
134
134
|
end
|
135
135
|
end
|
136
|
-
|
136
|
+
|
137
137
|
it "should raise NotFound when attempting to destroy non-existing rating" do
|
138
138
|
executing do
|
139
139
|
Rating.destroy(mangle(@rating.id))
|
140
140
|
end.should raise_error(NotFound)
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
end # describe ".destroy"
|
144
|
-
|
144
|
+
|
145
145
|
end
|
data/spec/report_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
2
2
|
include DataCatalog
|
3
3
|
|
4
4
|
describe Report do
|
5
|
-
|
5
|
+
|
6
6
|
before do
|
7
7
|
setup_api
|
8
8
|
clean_slate
|
@@ -12,7 +12,7 @@ describe Report do
|
|
12
12
|
:curator => true
|
13
13
|
)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
describe ".create" do
|
17
17
|
it "should create a new report when valid params are passed in" do
|
18
18
|
DataCatalog.with_key(@john.primary_api_key) do
|
@@ -28,7 +28,7 @@ describe Report do
|
|
28
28
|
refreshed_report.user_id.should == @john.id
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
describe ".get" do
|
33
33
|
before do
|
34
34
|
DataCatalog.with_key(@john.primary_api_key) do
|
@@ -38,20 +38,20 @@ describe Report do
|
|
38
38
|
)
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "should return a report" do
|
43
43
|
report = Report.get(@report.id)
|
44
44
|
report.should be_an_instance_of(Report)
|
45
45
|
report.text.should == "Report 1 by John"
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "should raise NotFound if no report exists" do
|
49
49
|
executing do
|
50
50
|
Report.get(mangle(@report.id))
|
51
51
|
end.should raise_error(NotFound)
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
describe ".all" do
|
56
56
|
before do
|
57
57
|
@jane = User.create(
|
@@ -64,7 +64,7 @@ describe Report do
|
|
64
64
|
Report.create(:text => "Report 2 by Jane", :status => "new")
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "should return a set of all user's reports" do
|
69
69
|
reports = Report.all(:user_id => @jane.id)
|
70
70
|
reports.first.should be_an_instance_of(Report)
|
@@ -73,7 +73,7 @@ describe Report do
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
describe ".update" do
|
78
78
|
before do
|
79
79
|
DataCatalog.with_key(@john.primary_api_key) do
|
@@ -83,7 +83,7 @@ describe Report do
|
|
83
83
|
)
|
84
84
|
end
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
it "should update an existing report with valid params" do
|
88
88
|
DataCatalog.with_key(@john.primary_api_key) do
|
89
89
|
Report.update(@report.id, :status => "open")
|
@@ -103,11 +103,11 @@ describe Report do
|
|
103
103
|
)
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
it "should destroy an existing report as an admin" do
|
108
108
|
Report.destroy(@report.id).should be_true
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
it "should destroy an existing report as the user" do
|
112
112
|
DataCatalog.with_key(@john.primary_api_key) do
|
113
113
|
Report.destroy(@report.id).should be_true
|