datacatalog 0.3.0 → 0.3.1
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 +5 -2
- data/lib/base.rb +85 -77
- data/lib/datacatalog.rb +8 -8
- data/lib/main.rb +41 -41
- data/lib/resources/organization.rb +31 -0
- data/sandbox_api.yml.example +2 -2
- data/spec/about_spec.rb +42 -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/organization_spec.rb +124 -0
- data/spec/source_spec.rb +162 -162
- data/spec/spec.opts +3 -4
- data/spec/spec_helper.rb +15 -25
- data/spec/user_spec.rb +279 -278
- metadata +5 -2
data/spec/spec.opts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
--color
|
2
|
-
--timeout
|
3
|
-
20
|
4
|
-
--diff
|
1
|
+
--color
|
2
|
+
--timeout
|
3
|
+
20
|
data/spec/spec_helper.rb
CHANGED
@@ -8,35 +8,25 @@ end
|
|
8
8
|
alias :executing :lambda
|
9
9
|
|
10
10
|
def clean_slate
|
11
|
+
|
11
12
|
DataCatalog::User.all.each do |u|
|
12
13
|
DataCatalog::User.destroy(u.id) unless u.name == "Primary Admin"
|
13
14
|
end
|
14
|
-
|
15
|
-
|
15
|
+
|
16
|
+
classes = [DataCatalog::Source, DataCatalog::Organization]
|
17
|
+
classes.each do |class_constant|
|
18
|
+
class_constant.all.each do |instance|
|
19
|
+
class_constant.destroy(instance.id)
|
20
|
+
end
|
16
21
|
end
|
22
|
+
|
17
23
|
end
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
sliced = []
|
27
|
-
array.each_slice(2) { |s| sliced << s.reverse }
|
28
|
-
result = sliced.flatten.join
|
29
|
-
raise "mangle failed" if result == string
|
30
|
-
result
|
31
|
-
end
|
32
|
-
else
|
33
|
-
# Converts a valid ID into a almost-but-not-quite valid one.
|
34
|
-
# Here is an example of what it does:
|
35
|
-
# From ... 4ac2520b25b7e7056600034e
|
36
|
-
# To ... e4300066507e7b52b0252ca4
|
37
|
-
def mangle(string)
|
38
|
-
result = string.reverse
|
39
|
-
raise "mangle failed" if result == string
|
40
|
-
result
|
41
|
-
end
|
25
|
+
def mangle(string)
|
26
|
+
array = string.chars.to_a
|
27
|
+
sliced = []
|
28
|
+
array.each_slice(2) { |s| sliced << s.reverse }
|
29
|
+
result = sliced.flatten.join
|
30
|
+
raise "mangle failed" if result == string
|
31
|
+
result
|
42
32
|
end
|
data/spec/user_spec.rb
CHANGED
@@ -1,278 +1,279 @@
|
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
user.
|
87
|
-
user.
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
user.
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
user.
|
104
|
-
user.
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
@u.
|
121
|
-
@u.
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
keys
|
127
|
-
keys.
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
@u.
|
153
|
-
@u.
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
keys
|
159
|
-
keys.
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
user.
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
result.
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
@user.
|
214
|
-
|
215
|
-
:
|
216
|
-
|
217
|
-
|
218
|
-
@user.api_keys.
|
219
|
-
@user.
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
:
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
:
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
@user.api_keys.
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
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
|
+
@user.created_at.should be_an_instance_of(Time)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should raise BadRequest when invalid params are passed in" do
|
74
|
+
executing do
|
75
|
+
User.create({ :garbage_field => "junk" })
|
76
|
+
end.should raise_error(BadRequest)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe ".first" do
|
81
|
+
before do
|
82
|
+
create_3_users
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should return a user" do
|
86
|
+
user = User.first(:name => "User-1")
|
87
|
+
user.should be_an_instance_of(User)
|
88
|
+
user.name.should == "User-1"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return nil if nothing found" do
|
92
|
+
user = User.first(:name => "Elvis")
|
93
|
+
user.should be_nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe ".get_by_api_key" do
|
98
|
+
before do
|
99
|
+
@user = create_user
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should return a user" do
|
103
|
+
user = User.get_by_api_key(@user.primary_api_key)
|
104
|
+
user.should be_an_instance_of(User)
|
105
|
+
user.email.should == "ted@email.com"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe ".get" do
|
110
|
+
before do
|
111
|
+
@user = create_user_with_2_keys
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "user exists" do
|
115
|
+
before do
|
116
|
+
@u = User.get(@user.id)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return a user" do
|
120
|
+
@u.should be_an_instance_of(User)
|
121
|
+
@u.name.should == "Ted Smith"
|
122
|
+
@u.email.should == "ted@email.com"
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should include 2 api_keys" do
|
126
|
+
keys = @u.api_keys
|
127
|
+
keys.map(&:key_type).should == %w(primary application)
|
128
|
+
keys.each do |key|
|
129
|
+
key.should be_an_instance_of(ApiKey)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should raise NotFound if no user exists" do
|
135
|
+
executing do
|
136
|
+
User.get(mangle(@user.id))
|
137
|
+
end.should raise_error(NotFound)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe ".get_by_api_key" do
|
142
|
+
before do
|
143
|
+
@user = create_user_with_2_keys
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "API key exists" do
|
147
|
+
before do
|
148
|
+
@u = User.get_by_api_key(@user.primary_api_key)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return a user" do
|
152
|
+
@u.should be_an_instance_of(User)
|
153
|
+
@u.name.should == "Ted Smith"
|
154
|
+
@u.email.should == "ted@email.com"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should include 2 api_keys" do
|
158
|
+
keys = @u.api_keys
|
159
|
+
keys.map(&:key_type).should == %w(primary application)
|
160
|
+
keys.each do |key|
|
161
|
+
key.should be_an_instance_of(ApiKey)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should raise NotFound if API key does not exist" do
|
167
|
+
executing do
|
168
|
+
User.get_by_api_key(mangle(@user.primary_api_key))
|
169
|
+
end.should raise_error(NotFound)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe ".update" do
|
174
|
+
before do
|
175
|
+
@user = create_user
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should update a user when valid params are passed in" do
|
179
|
+
user = User.update(@user.id, { :name => "Jane Smith" })
|
180
|
+
user.name.should == "Jane Smith"
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should raise BadRequest when invalid params are passed in" do
|
184
|
+
executing do
|
185
|
+
User.update(@user.id, { :garbage => "junk" })
|
186
|
+
end.should raise_error(BadRequest)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe ".destroy" do
|
191
|
+
before do
|
192
|
+
@user = create_user
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should destroy an existing user" do
|
196
|
+
result = User.destroy(@user.id)
|
197
|
+
result.should be_true
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should raise NotFound when non-existing user" do
|
201
|
+
executing do
|
202
|
+
User.destroy(mangle(@user.id))
|
203
|
+
end.should raise_error(NotFound)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "#generate_api_key!" do
|
208
|
+
before do
|
209
|
+
@user = create_user
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should generate a new key for the user" do
|
213
|
+
@user.api_keys.length.should == 1
|
214
|
+
@user.generate_api_key!({
|
215
|
+
:purpose => "Civic hacking with my awesome app",
|
216
|
+
:key_type => "application"
|
217
|
+
}).should be_true
|
218
|
+
@user.api_keys.length.should == 2
|
219
|
+
@user.api_keys.last[:purpose].should == "Civic hacking with my awesome app"
|
220
|
+
@user.application_api_keys.length.should == 1
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should raise BadRequest when attempting to create a primary key" do
|
224
|
+
executing do
|
225
|
+
@user.generate_api_key!({
|
226
|
+
:purpose => "Civic hacking with my awesome app",
|
227
|
+
:key_type => "primary"
|
228
|
+
})
|
229
|
+
end.should raise_error(BadRequest)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "#update_api_key!" do
|
234
|
+
before do
|
235
|
+
@user = create_user_with_2_keys
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should update a key for the user" do
|
239
|
+
@user.update_api_key!(@user.api_keys[1].id, {
|
240
|
+
:key_type => "valet",
|
241
|
+
:purpose => "To be more awesome"
|
242
|
+
}).should be_true
|
243
|
+
@user.api_keys[1].purpose.should == "To be more awesome"
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should raise NotFound if updating a key that doesn't exist" do
|
247
|
+
executing do
|
248
|
+
@user.update_api_key!(mangle(@user.api_keys[1].id), {})
|
249
|
+
end.should raise_error(NotFound)
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should raise BadRequest if primary key's type is changed" do
|
253
|
+
executing do
|
254
|
+
@user.update_api_key!(@user.api_keys[0].id, {
|
255
|
+
:key_type => "valet"
|
256
|
+
})
|
257
|
+
end.should raise_error(BadRequest)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe "#delete_api_key!" do
|
262
|
+
before do
|
263
|
+
@user = create_user_with_2_keys
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should delete a key for the user" do
|
267
|
+
@user.delete_api_key!(@user.api_keys[1].id).should be_true
|
268
|
+
@user.api_keys.length.should == 1
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should raise Conflict if deleting the primary key" do
|
272
|
+
executing do
|
273
|
+
@user.delete_api_key!(@user.api_keys[0].id)
|
274
|
+
end.should raise_error(Conflict)
|
275
|
+
@user.api_keys.length.should == 2
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|