datacatalog 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/spec.opts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
--color
|
2
|
-
--timeout
|
3
|
-
20
|
4
|
-
--diff
|
1
|
+
--color
|
2
|
+
--timeout
|
3
|
+
20
|
4
|
+
--diff
|
data/spec/user_spec.rb
CHANGED
@@ -1,278 +1,278 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
include DataCatalog
|
3
|
-
|
4
|
-
module UserHelpers
|
5
|
-
def create_user
|
6
|
-
User.create({
|
7
|
-
:name => "Ted Smith",
|
8
|
-
:email => "ted@email.com"
|
9
|
-
})
|
10
|
-
end
|
11
|
-
|
12
|
-
def create_user_with_2_keys
|
13
|
-
user = create_user
|
14
|
-
result = user.generate_api_key!(
|
15
|
-
:purpose => "Civic hacking with my awesome app",
|
16
|
-
:key_type => "application"
|
17
|
-
)
|
18
|
-
raise "generate_api_key! failed" unless result
|
19
|
-
raise "incorrect number of keys" unless user.api_keys.length == 2
|
20
|
-
user
|
21
|
-
end
|
22
|
-
|
23
|
-
def create_3_users
|
24
|
-
3.times do |n|
|
25
|
-
User.create(
|
26
|
-
:name => "User-#{n}",
|
27
|
-
:email => "user_#{n}@email.com"
|
28
|
-
)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe User do
|
34
|
-
include UserHelpers
|
35
|
-
|
36
|
-
before do
|
37
|
-
setup_api
|
38
|
-
clean_slate
|
39
|
-
end
|
40
|
-
|
41
|
-
describe ".all" do
|
42
|
-
before do
|
43
|
-
create_3_users
|
44
|
-
@users = User.all
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return an enumeration of users" do
|
48
|
-
@users.each do |u|
|
49
|
-
u.should be_an_instance_of(User)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should include four users" do
|
54
|
-
names = @users.map(&:name)
|
55
|
-
names.should include("User-0")
|
56
|
-
names.should include("User-1")
|
57
|
-
names.should include("User-2")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe ".create" do
|
62
|
-
before do
|
63
|
-
@user = create_user
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should create a new user when valid params are passed in" do
|
67
|
-
@user.should be_an_instance_of(User)
|
68
|
-
@user.name.should == "Ted Smith"
|
69
|
-
@user.email.should == "ted@email.com"
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should raise BadRequest when invalid params are passed in" do
|
73
|
-
executing do
|
74
|
-
User.create({ :garbage_field => "junk" })
|
75
|
-
end.should raise_error(BadRequest)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe ".first" do
|
80
|
-
before do
|
81
|
-
create_3_users
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should return a user" do
|
85
|
-
user = User.first(:name => "User-1")
|
86
|
-
user.should be_an_instance_of(User)
|
87
|
-
user.name.should == "User-1"
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should return nil if nothing found" do
|
91
|
-
user = User.first(:name => "Elvis")
|
92
|
-
user.should be_nil
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe ".get_by_api_key" do
|
97
|
-
before do
|
98
|
-
@user = create_user
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should return a user" do
|
102
|
-
user = User.get_by_api_key(@user.primary_api_key)
|
103
|
-
user.should be_an_instance_of(User)
|
104
|
-
user.email.should == "ted@email.com"
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe ".get" do
|
109
|
-
before do
|
110
|
-
@user = create_user_with_2_keys
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "user exists" do
|
114
|
-
before do
|
115
|
-
@u = User.get(@user.id)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "should return a user" do
|
119
|
-
@u.should be_an_instance_of(User)
|
120
|
-
@u.name.should == "Ted Smith"
|
121
|
-
@u.email.should == "ted@email.com"
|
122
|
-
end
|
123
|
-
|
124
|
-
it "should include 2 api_keys" do
|
125
|
-
keys = @u.api_keys
|
126
|
-
keys.map(&:key_type).should == %w(primary application)
|
127
|
-
keys.each do |key|
|
128
|
-
key.should be_an_instance_of(ApiKey)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
it "should raise NotFound if no user exists" do
|
134
|
-
executing do
|
135
|
-
User.get(mangle(@user.id))
|
136
|
-
end.should raise_error(NotFound)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe ".get_by_api_key" do
|
141
|
-
before do
|
142
|
-
@user = create_user_with_2_keys
|
143
|
-
end
|
144
|
-
|
145
|
-
describe "API key exists" do
|
146
|
-
before do
|
147
|
-
@u = User.get_by_api_key(@user.primary_api_key)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should return a user" do
|
151
|
-
@u.should be_an_instance_of(User)
|
152
|
-
@u.name.should == "Ted Smith"
|
153
|
-
@u.email.should == "ted@email.com"
|
154
|
-
end
|
155
|
-
|
156
|
-
it "should include 2 api_keys" do
|
157
|
-
keys = @u.api_keys
|
158
|
-
keys.map(&:key_type).should == %w(primary application)
|
159
|
-
keys.each do |key|
|
160
|
-
key.should be_an_instance_of(ApiKey)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should raise NotFound if API key does not exist" do
|
166
|
-
executing do
|
167
|
-
User.get_by_api_key(mangle(@user.primary_api_key))
|
168
|
-
end.should raise_error(NotFound)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
describe ".update" do
|
173
|
-
before do
|
174
|
-
@user = create_user
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should update a user when valid params are passed in" do
|
178
|
-
user = User.update(@user.id, { :name => "Jane Smith" })
|
179
|
-
user.name.should == "Jane Smith"
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should raise BadRequest when invalid params are passed in" do
|
183
|
-
executing do
|
184
|
-
User.update(@user.id, { :garbage => "junk" })
|
185
|
-
end.should raise_error(BadRequest)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
describe ".destroy" do
|
190
|
-
before do
|
191
|
-
@user = create_user
|
192
|
-
end
|
193
|
-
|
194
|
-
it "should destroy an existing user" do
|
195
|
-
result = User.destroy(@user.id)
|
196
|
-
result.should be_true
|
197
|
-
end
|
198
|
-
|
199
|
-
it "should raise NotFound when non-existing user" do
|
200
|
-
executing do
|
201
|
-
User.destroy(mangle(@user.id))
|
202
|
-
end.should raise_error(NotFound)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
describe "#generate_api_key!" do
|
207
|
-
before do
|
208
|
-
@user = create_user
|
209
|
-
end
|
210
|
-
|
211
|
-
it "should generate a new key for the user" do
|
212
|
-
@user.api_keys.length.should == 1
|
213
|
-
@user.generate_api_key!({
|
214
|
-
:purpose => "Civic hacking with my awesome app",
|
215
|
-
:key_type => "application"
|
216
|
-
}).should be_true
|
217
|
-
@user.api_keys.length.should == 2
|
218
|
-
@user.api_keys.last[:purpose].should == "Civic hacking with my awesome app"
|
219
|
-
@user.application_api_keys.length.should == 1
|
220
|
-
end
|
221
|
-
|
222
|
-
it "should raise BadRequest when attempting to create a primary key" do
|
223
|
-
executing do
|
224
|
-
@user.generate_api_key!({
|
225
|
-
:purpose => "Civic hacking with my awesome app",
|
226
|
-
:key_type => "primary"
|
227
|
-
})
|
228
|
-
end.should raise_error(BadRequest)
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
describe "#update_api_key!" do
|
233
|
-
before do
|
234
|
-
@user = create_user_with_2_keys
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should update a key for the user" do
|
238
|
-
@user.update_api_key!(@user.api_keys[1].id, {
|
239
|
-
:key_type => "valet",
|
240
|
-
:purpose => "To be more awesome"
|
241
|
-
}).should be_true
|
242
|
-
@user.api_keys[1].purpose.should == "To be more awesome"
|
243
|
-
end
|
244
|
-
|
245
|
-
it "should raise NotFound if updating a key that doesn't exist" do
|
246
|
-
executing do
|
247
|
-
@user.update_api_key!(mangle(@user.api_keys[1].id), {})
|
248
|
-
end.should raise_error(NotFound)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "should raise BadRequest if primary key's type is changed" do
|
252
|
-
executing do
|
253
|
-
@user.update_api_key!(@user.api_keys[0].id, {
|
254
|
-
:key_type => "valet"
|
255
|
-
})
|
256
|
-
end.should raise_error(BadRequest)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
describe "#delete_api_key!" do
|
261
|
-
before do
|
262
|
-
@user = create_user_with_2_keys
|
263
|
-
end
|
264
|
-
|
265
|
-
it "should delete a key for the user" do
|
266
|
-
@user.delete_api_key!(@user.api_keys[1].id).should be_true
|
267
|
-
@user.api_keys.length.should == 1
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should raise Conflict if deleting the primary key" do
|
271
|
-
executing do
|
272
|
-
@user.delete_api_key!(@user.api_keys[0].id)
|
273
|
-
end.should raise_error(Conflict)
|
274
|
-
@user.api_keys.length.should == 2
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
include DataCatalog
|
3
|
+
|
4
|
+
module UserHelpers
|
5
|
+
def create_user
|
6
|
+
User.create({
|
7
|
+
:name => "Ted Smith",
|
8
|
+
:email => "ted@email.com"
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_user_with_2_keys
|
13
|
+
user = create_user
|
14
|
+
result = user.generate_api_key!(
|
15
|
+
:purpose => "Civic hacking with my awesome app",
|
16
|
+
:key_type => "application"
|
17
|
+
)
|
18
|
+
raise "generate_api_key! failed" unless result
|
19
|
+
raise "incorrect number of keys" unless user.api_keys.length == 2
|
20
|
+
user
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_3_users
|
24
|
+
3.times do |n|
|
25
|
+
User.create(
|
26
|
+
:name => "User-#{n}",
|
27
|
+
:email => "user_#{n}@email.com"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe User do
|
34
|
+
include UserHelpers
|
35
|
+
|
36
|
+
before do
|
37
|
+
setup_api
|
38
|
+
clean_slate
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".all" do
|
42
|
+
before do
|
43
|
+
create_3_users
|
44
|
+
@users = User.all
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return an enumeration of users" do
|
48
|
+
@users.each do |u|
|
49
|
+
u.should be_an_instance_of(User)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should include four users" do
|
54
|
+
names = @users.map(&:name)
|
55
|
+
names.should include("User-0")
|
56
|
+
names.should include("User-1")
|
57
|
+
names.should include("User-2")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe ".create" do
|
62
|
+
before do
|
63
|
+
@user = create_user
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should create a new user when valid params are passed in" do
|
67
|
+
@user.should be_an_instance_of(User)
|
68
|
+
@user.name.should == "Ted Smith"
|
69
|
+
@user.email.should == "ted@email.com"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should raise BadRequest when invalid params are passed in" do
|
73
|
+
executing do
|
74
|
+
User.create({ :garbage_field => "junk" })
|
75
|
+
end.should raise_error(BadRequest)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe ".first" do
|
80
|
+
before do
|
81
|
+
create_3_users
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return a user" do
|
85
|
+
user = User.first(:name => "User-1")
|
86
|
+
user.should be_an_instance_of(User)
|
87
|
+
user.name.should == "User-1"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return nil if nothing found" do
|
91
|
+
user = User.first(:name => "Elvis")
|
92
|
+
user.should be_nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe ".get_by_api_key" do
|
97
|
+
before do
|
98
|
+
@user = create_user
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return a user" do
|
102
|
+
user = User.get_by_api_key(@user.primary_api_key)
|
103
|
+
user.should be_an_instance_of(User)
|
104
|
+
user.email.should == "ted@email.com"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe ".get" do
|
109
|
+
before do
|
110
|
+
@user = create_user_with_2_keys
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "user exists" do
|
114
|
+
before do
|
115
|
+
@u = User.get(@user.id)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return a user" do
|
119
|
+
@u.should be_an_instance_of(User)
|
120
|
+
@u.name.should == "Ted Smith"
|
121
|
+
@u.email.should == "ted@email.com"
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should include 2 api_keys" do
|
125
|
+
keys = @u.api_keys
|
126
|
+
keys.map(&:key_type).should == %w(primary application)
|
127
|
+
keys.each do |key|
|
128
|
+
key.should be_an_instance_of(ApiKey)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should raise NotFound if no user exists" do
|
134
|
+
executing do
|
135
|
+
User.get(mangle(@user.id))
|
136
|
+
end.should raise_error(NotFound)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe ".get_by_api_key" do
|
141
|
+
before do
|
142
|
+
@user = create_user_with_2_keys
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "API key exists" do
|
146
|
+
before do
|
147
|
+
@u = User.get_by_api_key(@user.primary_api_key)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should return a user" do
|
151
|
+
@u.should be_an_instance_of(User)
|
152
|
+
@u.name.should == "Ted Smith"
|
153
|
+
@u.email.should == "ted@email.com"
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should include 2 api_keys" do
|
157
|
+
keys = @u.api_keys
|
158
|
+
keys.map(&:key_type).should == %w(primary application)
|
159
|
+
keys.each do |key|
|
160
|
+
key.should be_an_instance_of(ApiKey)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should raise NotFound if API key does not exist" do
|
166
|
+
executing do
|
167
|
+
User.get_by_api_key(mangle(@user.primary_api_key))
|
168
|
+
end.should raise_error(NotFound)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe ".update" do
|
173
|
+
before do
|
174
|
+
@user = create_user
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should update a user when valid params are passed in" do
|
178
|
+
user = User.update(@user.id, { :name => "Jane Smith" })
|
179
|
+
user.name.should == "Jane Smith"
|
180
|
+
end
|
181
|
+
|
182
|
+
it "should raise BadRequest when invalid params are passed in" do
|
183
|
+
executing do
|
184
|
+
User.update(@user.id, { :garbage => "junk" })
|
185
|
+
end.should raise_error(BadRequest)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe ".destroy" do
|
190
|
+
before do
|
191
|
+
@user = create_user
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should destroy an existing user" do
|
195
|
+
result = User.destroy(@user.id)
|
196
|
+
result.should be_true
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should raise NotFound when non-existing user" do
|
200
|
+
executing do
|
201
|
+
User.destroy(mangle(@user.id))
|
202
|
+
end.should raise_error(NotFound)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "#generate_api_key!" do
|
207
|
+
before do
|
208
|
+
@user = create_user
|
209
|
+
end
|
210
|
+
|
211
|
+
it "should generate a new key for the user" do
|
212
|
+
@user.api_keys.length.should == 1
|
213
|
+
@user.generate_api_key!({
|
214
|
+
:purpose => "Civic hacking with my awesome app",
|
215
|
+
:key_type => "application"
|
216
|
+
}).should be_true
|
217
|
+
@user.api_keys.length.should == 2
|
218
|
+
@user.api_keys.last[:purpose].should == "Civic hacking with my awesome app"
|
219
|
+
@user.application_api_keys.length.should == 1
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should raise BadRequest when attempting to create a primary key" do
|
223
|
+
executing do
|
224
|
+
@user.generate_api_key!({
|
225
|
+
:purpose => "Civic hacking with my awesome app",
|
226
|
+
:key_type => "primary"
|
227
|
+
})
|
228
|
+
end.should raise_error(BadRequest)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe "#update_api_key!" do
|
233
|
+
before do
|
234
|
+
@user = create_user_with_2_keys
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should update a key for the user" do
|
238
|
+
@user.update_api_key!(@user.api_keys[1].id, {
|
239
|
+
:key_type => "valet",
|
240
|
+
:purpose => "To be more awesome"
|
241
|
+
}).should be_true
|
242
|
+
@user.api_keys[1].purpose.should == "To be more awesome"
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should raise NotFound if updating a key that doesn't exist" do
|
246
|
+
executing do
|
247
|
+
@user.update_api_key!(mangle(@user.api_keys[1].id), {})
|
248
|
+
end.should raise_error(NotFound)
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should raise BadRequest if primary key's type is changed" do
|
252
|
+
executing do
|
253
|
+
@user.update_api_key!(@user.api_keys[0].id, {
|
254
|
+
:key_type => "valet"
|
255
|
+
})
|
256
|
+
end.should raise_error(BadRequest)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe "#delete_api_key!" do
|
261
|
+
before do
|
262
|
+
@user = create_user_with_2_keys
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should delete a key for the user" do
|
266
|
+
@user.delete_api_key!(@user.api_keys[1].id).should be_true
|
267
|
+
@user.api_keys.length.should == 1
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should raise Conflict if deleting the primary key" do
|
271
|
+
executing do
|
272
|
+
@user.delete_api_key!(@user.api_keys[0].id)
|
273
|
+
end.should raise_error(Conflict)
|
274
|
+
@user.api_keys.length.should == 2
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|