sinatra_resource 0.4.21 → 0.4.22
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +18 -0
- data/Gemfile.lock +51 -0
- data/README.mdown +1 -1
- data/VERSION +1 -1
- data/examples/datacatalog/.bundle/config +2 -0
- data/examples/datacatalog/Gemfile +14 -0
- data/examples/datacatalog/Gemfile.lock +33 -0
- data/examples/datacatalog/Rakefile +2 -2
- data/examples/datacatalog/app.rb +0 -2
- data/examples/datacatalog/config/config.rb +5 -7
- data/examples/datacatalog/lib/base.rb +2 -2
- data/examples/datacatalog/lib/resource.rb +5 -5
- data/examples/datacatalog/lib/roles.rb +2 -2
- data/examples/datacatalog/model_helpers/search.rb +6 -6
- data/examples/datacatalog/models/categorization.rb +1 -1
- data/examples/datacatalog/models/note.rb +1 -1
- data/examples/datacatalog/models/source.rb +3 -3
- data/examples/datacatalog/models/usage.rb +2 -2
- data/examples/datacatalog/models/user.rb +7 -7
- data/examples/datacatalog/resources/categories.rb +7 -7
- data/examples/datacatalog/resources/categories_sources.rb +4 -4
- data/examples/datacatalog/resources/notes.rb +1 -1
- data/examples/datacatalog/resources/sources.rb +3 -3
- data/examples/datacatalog/resources/sources_usages.rb +3 -3
- data/examples/datacatalog/resources/users.rb +3 -3
- data/examples/datacatalog/tasks/db.rake +2 -2
- data/examples/datacatalog/tasks/test.rake +1 -1
- data/examples/datacatalog/test/helpers/assertions/assert_include.rb +1 -1
- data/examples/datacatalog/test/helpers/assertions/assert_not_include.rb +1 -1
- data/examples/datacatalog/test/helpers/lib/model_factories.rb +7 -7
- data/examples/datacatalog/test/helpers/lib/model_helpers.rb +1 -1
- data/examples/datacatalog/test/helpers/lib/request_helpers.rb +7 -7
- data/examples/datacatalog/test/helpers/resource_test_helper.rb +1 -1
- data/examples/datacatalog/test/helpers/shared/api_keys.rb +11 -11
- data/examples/datacatalog/test/helpers/shared/common_body_responses.rb +1 -1
- data/examples/datacatalog/test/helpers/shared/model_counts.rb +2 -2
- data/examples/datacatalog/test/helpers/shared/status_codes.rb +4 -4
- data/examples/datacatalog/test/helpers/test_cases/resource_test_case.rb +4 -4
- data/examples/datacatalog/test/helpers/test_helper.rb +4 -10
- data/examples/datacatalog/test/models/categorization_test.rb +6 -6
- data/examples/datacatalog/test/models/category_test.rb +8 -8
- data/examples/datacatalog/test/models/note_test.rb +6 -6
- data/examples/datacatalog/test/models/search_test.rb +4 -4
- data/examples/datacatalog/test/models/source_test.rb +5 -5
- data/examples/datacatalog/test/models/user_test.rb +11 -11
- data/examples/datacatalog/test/resources/categories/categories_delete_test.rb +12 -12
- data/examples/datacatalog/test/resources/categories/categories_get_many_test.rb +9 -9
- data/examples/datacatalog/test/resources/categories/categories_get_one_test.rb +7 -7
- data/examples/datacatalog/test/resources/categories/categories_post_test.rb +16 -16
- data/examples/datacatalog/test/resources/categories/categories_put_test.rb +17 -17
- data/examples/datacatalog/test/resources/categories_sources/categories_sources_delete_test.rb +25 -25
- data/examples/datacatalog/test/resources/categories_sources/categories_sources_get_many_test.rb +5 -5
- data/examples/datacatalog/test/resources/categories_sources/categories_sources_get_one_test.rb +15 -15
- data/examples/datacatalog/test/resources/categories_sources/categories_sources_post_test.rb +31 -31
- data/examples/datacatalog/test/resources/categories_sources/categories_sources_put_test.rb +41 -41
- data/examples/datacatalog/test/resources/notes/notes_get_many_test.rb +15 -15
- data/examples/datacatalog/test/resources/notes/notes_get_one_test.rb +7 -7
- data/examples/datacatalog/test/resources/notes/notes_post_test.rb +12 -12
- data/examples/datacatalog/test/resources/sources/sources_delete_test.rb +12 -12
- data/examples/datacatalog/test/resources/sources/sources_get_many_search_test.rb +20 -20
- data/examples/datacatalog/test/resources/sources/sources_get_many_test.rb +8 -8
- data/examples/datacatalog/test/resources/sources/sources_get_one_test.rb +17 -9
- data/examples/datacatalog/test/resources/sources/sources_post_test.rb +13 -13
- data/examples/datacatalog/test/resources/sources/sources_put_test.rb +30 -30
- data/examples/datacatalog/test/resources/sources_usages/sources_usages_delete_test.rb +24 -24
- data/examples/datacatalog/test/resources/sources_usages/sources_usages_get_many_filter_test.rb +9 -9
- data/examples/datacatalog/test/resources/sources_usages/sources_usages_get_many_test.rb +9 -9
- data/examples/datacatalog/test/resources/sources_usages/sources_usages_get_one_test.rb +15 -15
- data/examples/datacatalog/test/resources/sources_usages/sources_usages_post_test.rb +16 -16
- data/examples/datacatalog/test/resources/sources_usages/sources_usages_put_test.rb +33 -33
- data/examples/datacatalog/test/resources/users/users_delete_test.rb +21 -21
- data/examples/datacatalog/test/resources/users/users_get_many_test.rb +16 -16
- data/examples/datacatalog/test/resources/users/users_get_one_test.rb +8 -8
- data/examples/datacatalog/test/resources/users/users_post_test.rb +13 -13
- data/examples/datacatalog/test/resources/users/users_put_test.rb +18 -18
- data/lib/builder/action_definitions.rb +8 -8
- data/lib/builder/helpers.rb +10 -12
- data/lib/builder/mongo_helpers.rb +13 -14
- data/lib/builder.rb +10 -10
- data/lib/exceptions.rb +1 -1
- data/lib/resource.rb +20 -20
- data/lib/roles.rb +2 -2
- data/lib/utility.rb +2 -2
- data/notes/permissions.mdown +6 -6
- data/sinatra_resource.gemspec +9 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/utility_spec.rb +2 -2
- metadata +30 -4
@@ -19,56 +19,56 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
19
19
|
after do
|
20
20
|
@source.destroy
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
context "put /:id" do
|
24
24
|
context "anonymous" do
|
25
25
|
before do
|
26
26
|
put "/#{@source.id}", @valid_params
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
use "return 401 because the API key is missing"
|
30
30
|
use "source unchanged"
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
context "incorrect API key" do
|
34
34
|
before do
|
35
35
|
put "/#{@source.id}", @valid_params.merge(:api_key => BAD_API_KEY)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
use "return 401 because the API key is invalid"
|
39
39
|
use "source unchanged"
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
%w(basic).each do |role|
|
44
44
|
[:id, :created_at, :updated_at, :categories, :junk].each do |invalid|
|
45
45
|
context "#{role} : put /:id but with #{invalid}" do
|
46
46
|
before do
|
47
47
|
put "/#{@source.id}", valid_params_for(role).merge(invalid => 9)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
use "return 401 because the API key is unauthorized"
|
51
51
|
use "source unchanged"
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
[:title, :url].each do |erase|
|
56
56
|
context "#{role} : put /:id but blanking out #{erase}" do
|
57
57
|
before do
|
58
58
|
put "/#{@source.id}", valid_params_for(role).merge(erase => "")
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
use "return 401 because the API key is unauthorized"
|
62
62
|
use "source unchanged"
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
[:title, :url].each do |missing|
|
67
67
|
context "#{role} : put /:id without #{missing}" do
|
68
68
|
before do
|
69
69
|
put "/#{@source.id}", valid_params_for(role).delete_if { |k, v| k == missing }
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
use "return 401 because the API key is unauthorized"
|
73
73
|
use "source unchanged"
|
74
74
|
end
|
@@ -78,28 +78,28 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
78
78
|
before do
|
79
79
|
put "/#{FAKE_ID}", valid_params_for(role)
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
use "return 401 because the API key is unauthorized"
|
83
83
|
use "source unchanged"
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
context "#{role} : put /:id with valid params" do
|
87
87
|
before do
|
88
88
|
put "/#{@source.id}", valid_params_for(role)
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
use "return 401 because the API key is unauthorized"
|
92
92
|
use "source unchanged"
|
93
93
|
end
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
%w(curator).each do |role|
|
97
97
|
[:raw, :created_at, :updated_at, :categories, :junk].each do |invalid|
|
98
98
|
context "#{role} : put /:id but with #{invalid}" do
|
99
99
|
before do
|
100
100
|
put "/#{@source.id}", valid_params_for(role).merge(invalid => 9)
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
use "return 400 Bad Request"
|
104
104
|
use "source unchanged"
|
105
105
|
invalid_param invalid
|
@@ -111,31 +111,31 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
111
111
|
before do
|
112
112
|
put "/#{FAKE_ID}", valid_params_for(role).merge(erase => "")
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
use "return 404 Not Found with empty response body"
|
116
116
|
# (The 404 'takes precedence' over the 400.)
|
117
117
|
use "source unchanged"
|
118
118
|
end
|
119
|
-
end
|
119
|
+
end
|
120
120
|
|
121
121
|
[:title, :url].each do |erase|
|
122
122
|
context "#{role} : put /:id but blanking out #{erase}" do
|
123
123
|
before do
|
124
124
|
put "/#{@source.id}", valid_params_for(role).merge(erase => "")
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
use "return 400 Bad Request"
|
128
128
|
use "source unchanged"
|
129
129
|
missing_param erase
|
130
130
|
end
|
131
|
-
end
|
131
|
+
end
|
132
132
|
|
133
133
|
[:title, :url].each do |missing|
|
134
134
|
context "#{role} : put /:id without #{missing}" do
|
135
135
|
before do
|
136
136
|
put "/#{@source.id}", valid_params_for(role).delete_if { |k, v| k == missing }
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
use "return 200 Ok"
|
140
140
|
doc_properties %w(title url id created_at updated_at categories)
|
141
141
|
|
@@ -153,7 +153,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
153
153
|
before do
|
154
154
|
put "/#{FAKE_ID}", valid_params_for(role)
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
use "return 404 Not Found with empty response body"
|
158
158
|
use "source unchanged"
|
159
159
|
end
|
@@ -162,7 +162,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
162
162
|
before do
|
163
163
|
put "/#{@source.id}", valid_params_for(role)
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
use "return 200 Ok"
|
167
167
|
doc_properties %w(title url id created_at updated_at categories)
|
168
168
|
|
@@ -174,7 +174,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
174
174
|
end
|
175
175
|
end
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
%w(admin).each do |role|
|
179
179
|
context "#{role} : put /:fake_id with no params" do
|
180
180
|
before do
|
@@ -201,7 +201,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
201
201
|
put "/#{@source.id}", valid_params_for(role).
|
202
202
|
merge(@extra_admin_params).merge(invalid => 9)
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
use "return 400 Bad Request"
|
206
206
|
use "source unchanged"
|
207
207
|
invalid_param invalid
|
@@ -214,7 +214,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
214
214
|
put "/#{FAKE_ID}", valid_params_for(role).
|
215
215
|
merge(@extra_admin_params).merge(erase => "")
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
use "return 404 Not Found with empty response body"
|
219
219
|
# (The 404 'takes precedence' over the 400.)
|
220
220
|
use "source unchanged"
|
@@ -227,12 +227,12 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
227
227
|
put "/#{@source.id}", valid_params_for(role).
|
228
228
|
merge(@extra_admin_params).merge(erase => "")
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
use "return 400 Bad Request"
|
232
232
|
use "source unchanged"
|
233
233
|
missing_param erase
|
234
234
|
end
|
235
|
-
end
|
235
|
+
end
|
236
236
|
|
237
237
|
[:title, :url].each do |missing|
|
238
238
|
context "#{role} : put /:id without #{missing}" do
|
@@ -240,7 +240,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
240
240
|
put "/#{@source.id}", valid_params_for(role).
|
241
241
|
merge(@extra_admin_params).delete_if { |k, v| k == missing }
|
242
242
|
end
|
243
|
-
|
243
|
+
|
244
244
|
use "return 200 Ok"
|
245
245
|
doc_properties %w(title url id created_at updated_at categories)
|
246
246
|
|
@@ -258,7 +258,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
258
258
|
before do
|
259
259
|
put "/#{FAKE_ID}", valid_params_for(role).merge(@extra_admin_params)
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
use "return 404 Not Found with empty response body"
|
263
263
|
use "source unchanged"
|
264
264
|
end
|
@@ -267,7 +267,7 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
267
267
|
before do
|
268
268
|
put "/#{@source.id}", valid_params_for(role).merge(@extra_admin_params)
|
269
269
|
end
|
270
|
-
|
270
|
+
|
271
271
|
use "return 200 Ok"
|
272
272
|
doc_properties %w(title url id created_at updated_at categories)
|
273
273
|
|
@@ -5,7 +5,7 @@ class SourcesUsagesDeleteResourceTest < ResourceTestCase
|
|
5
5
|
include DataCatalog
|
6
6
|
|
7
7
|
def app; Sources end
|
8
|
-
|
8
|
+
|
9
9
|
before do
|
10
10
|
@source = create_source
|
11
11
|
@source.usages << new_usage
|
@@ -24,16 +24,16 @@ class SourcesUsagesDeleteResourceTest < ResourceTestCase
|
|
24
24
|
before do
|
25
25
|
delete "/#{@source.id}/usages/#{@usage_id}"
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
use "return 401 because the API key is missing"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
context "incorrect API key" do
|
32
32
|
before do
|
33
33
|
delete "/#{@source.id}/usages/#{@usage_id}",
|
34
34
|
:api_key => BAD_API_KEY
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
use "return 401 because the API key is invalid"
|
38
38
|
end
|
39
39
|
end
|
@@ -44,51 +44,51 @@ class SourcesUsagesDeleteResourceTest < ResourceTestCase
|
|
44
44
|
delete "/#{FAKE_ID}/usages/#{FAKE_ID}",
|
45
45
|
:api_key => api_key_for(role)
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
use "return 404 Not Found with empty response body"
|
49
49
|
use "no change in usage count"
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
context "#{role} : delete /:fake_id/usages/:id" do
|
53
53
|
before do
|
54
54
|
delete "/#{FAKE_ID}/usages/#{@usage_id}",
|
55
55
|
:api_key => api_key_for(role)
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
use "return 404 Not Found with empty response body"
|
59
59
|
use "no change in usage count"
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
context "#{role} : delete /:id/usages/:fake_id" do
|
63
63
|
before do
|
64
64
|
delete "/#{@source.id}/usages/#{FAKE_ID}", :api_key => api_key_for(role)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
use "return 401 because the API key is unauthorized"
|
68
68
|
use "no change in usage count"
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
context "#{role} : delete /:id/usages/:not_related_id" do
|
72
72
|
before do
|
73
73
|
delete "/#{@source.id}/usages/#{@other_usage_id}",
|
74
74
|
:api_key => api_key_for(role)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
use "return 401 because the API key is unauthorized"
|
78
78
|
use "no change in usage count"
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
context "#{role} : delete /:id/usages/:id" do
|
82
82
|
before do
|
83
83
|
delete "/#{@source.id}/usages/#{@usage_id}",
|
84
84
|
:api_key => api_key_for(role)
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
use "return 401 because the API key is unauthorized"
|
88
88
|
use "no change in usage count"
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
%w(curator).each do |role|
|
93
93
|
# %w(curator admin).each do |role|
|
94
94
|
context "#{role} : delete /:fake_id/usages/:fake_id" do
|
@@ -96,50 +96,50 @@ class SourcesUsagesDeleteResourceTest < ResourceTestCase
|
|
96
96
|
delete "/#{FAKE_ID}/usages/#{FAKE_ID}",
|
97
97
|
:api_key => api_key_for(role)
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
use "return 404 Not Found with empty response body"
|
101
101
|
use "no change in usage count"
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
context "#{role} : delete /:fake_id/usages/:id" do
|
105
105
|
before do
|
106
106
|
delete "/#{FAKE_ID}/usages/#{@usage_id}",
|
107
107
|
:api_key => api_key_for(role)
|
108
108
|
end
|
109
|
-
|
109
|
+
|
110
110
|
use "return 404 Not Found with empty response body"
|
111
111
|
use "no change in usage count"
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
context "#{role} : delete /:id/usages/:fake_id" do
|
115
115
|
before do
|
116
116
|
delete "/#{@source.id}/usages/#{FAKE_ID}",
|
117
117
|
:api_key => api_key_for(role)
|
118
118
|
end
|
119
|
-
|
119
|
+
|
120
120
|
use "return 404 Not Found with empty response body"
|
121
121
|
use "no change in usage count"
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
context "#{role} : delete /:id/usages/:not_related_id" do
|
125
125
|
before do
|
126
126
|
delete "/#{@source.id}/usages/#{@other_usage_id}",
|
127
127
|
:api_key => api_key_for(role)
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
use "return 404 Not Found with empty response body"
|
131
131
|
use "no change in usage count"
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
context "#{role} : delete /:id/usages/:id" do
|
135
135
|
before do
|
136
136
|
delete "/#{@source.id}/usages/#{@usage_id}",
|
137
137
|
:api_key => api_key_for(role)
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
use "return 204 No Content"
|
141
141
|
use "one less usage"
|
142
142
|
end
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
end
|
data/examples/datacatalog/test/resources/sources_usages/sources_usages_get_many_filter_test.rb
CHANGED
@@ -27,7 +27,7 @@ class SourcesUsagesGetManyFilterResourceTest < ResourceTestCase
|
|
27
27
|
@source = @sources[1]
|
28
28
|
@search = SEARCH_FILTERS[0]
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
after do
|
32
32
|
@sources.each { |x| x.destroy }
|
33
33
|
end
|
@@ -37,16 +37,16 @@ class SourcesUsagesGetManyFilterResourceTest < ResourceTestCase
|
|
37
37
|
before do
|
38
38
|
get "/#{@source.id}/usages", @search
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
use "return 401 because the API key is missing"
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
context "incorrect API key" do
|
45
45
|
before do
|
46
46
|
get "/#{@source.id}/usages", @search.merge(
|
47
47
|
:api_key => BAD_API_KEY)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
use "return 401 because the API key is invalid"
|
51
51
|
end
|
52
52
|
end
|
@@ -57,10 +57,10 @@ class SourcesUsagesGetManyFilterResourceTest < ResourceTestCase
|
|
57
57
|
get "/#{FAKE_ID}/usages", @search.merge(
|
58
58
|
:api_key => api_key_for(role))
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
use "return 404 Not Found with empty response body"
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
SEARCH_FILTERS.each do |search|
|
65
65
|
context "#{role} : get /:id/usages" do
|
66
66
|
before do
|
@@ -68,13 +68,13 @@ class SourcesUsagesGetManyFilterResourceTest < ResourceTestCase
|
|
68
68
|
:api_key => api_key_for(role))
|
69
69
|
@members = parsed_response_body['members']
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
use "return 200 Ok"
|
73
|
-
|
73
|
+
|
74
74
|
test "body should have 2 sources" do
|
75
75
|
assert_equal 2, @members.length
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
test "body should have correct source titles" do
|
79
79
|
actual = @members.map { |e| e["title"] }
|
80
80
|
assert_equal ["Usage 0", "Usage 2"], actual.sort
|
@@ -20,7 +20,7 @@ class SourcesUsagesGetManyResourceTest < ResourceTestCase
|
|
20
20
|
end
|
21
21
|
@other_source.save
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
after do
|
25
25
|
@other_source.destroy
|
26
26
|
@source.destroy
|
@@ -31,15 +31,15 @@ class SourcesUsagesGetManyResourceTest < ResourceTestCase
|
|
31
31
|
before do
|
32
32
|
get "/#{@source.id}/usages"
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
use "return 401 because the API key is missing"
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
context "incorrect API key" do
|
39
39
|
before do
|
40
40
|
get "/#{@source.id}/usages", :api_key => BAD_API_KEY
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
use "return 401 because the API key is invalid"
|
44
44
|
end
|
45
45
|
end
|
@@ -49,22 +49,22 @@ class SourcesUsagesGetManyResourceTest < ResourceTestCase
|
|
49
49
|
before do
|
50
50
|
get "/#{FAKE_ID}/usages", :api_key => api_key_for(role)
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
use "return 404 Not Found with empty response body"
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
context "#{role} : get /:id/usages" do
|
57
57
|
before do
|
58
58
|
get "/#{@source.id}/usages", :api_key => api_key_for(role)
|
59
59
|
@members = parsed_response_body['members']
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
use "return 200 Ok"
|
63
|
-
|
63
|
+
|
64
64
|
test "body should have 3 sources" do
|
65
65
|
assert_equal 3, @members.length
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
test "body should have correct source titles" do
|
69
69
|
actual = @members.map { |e| e["title"] }
|
70
70
|
assert_equal @usage_titles, actual.sort
|
@@ -5,7 +5,7 @@ class SourcesUsagesGetOneResourceTest < ResourceTestCase
|
|
5
5
|
include DataCatalog
|
6
6
|
|
7
7
|
def app; Sources end
|
8
|
-
|
8
|
+
|
9
9
|
before do
|
10
10
|
@source = create_source
|
11
11
|
@source.usages << new_usage
|
@@ -28,62 +28,62 @@ class SourcesUsagesGetOneResourceTest < ResourceTestCase
|
|
28
28
|
before do
|
29
29
|
get "/#{@source.id}/usages/#{@usage_id}"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
use "return 401 because the API key is missing"
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
context "incorrect API key" do
|
36
36
|
before do
|
37
37
|
get "/#{@source.id}/usages/#{@usage_id}", :api_key => BAD_API_KEY
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
use "return 401 because the API key is invalid"
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
%w(basic).each do |role|
|
45
45
|
# %w(basic curator admin).each do |role|
|
46
46
|
context "#{role} : get /:fake_id/usages/:fake_id" do
|
47
47
|
before do
|
48
48
|
get "/#{FAKE_ID}/usages/#{FAKE_ID}", :api_key => api_key_for(role)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
use "return 404 Not Found with empty response body"
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
context "#{role} : get /:fake_id/usages/:id" do
|
55
55
|
before do
|
56
56
|
get "/#{FAKE_ID}/usages/#{@usage_id}", :api_key => api_key_for(role)
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
use "return 404 Not Found with empty response body"
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
context "#{role} : get /:id/usages/:fake_id" do
|
63
63
|
before do
|
64
64
|
get "/#{@source.id}/usages/#{FAKE_ID}", :api_key => api_key_for(role)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
use "return 404 Not Found with empty response body"
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
context "#{role} : get /:id/usages/:not_related_id" do
|
71
71
|
before do
|
72
72
|
get "/#{@source.id}/usages/#{@other_usage_id}",
|
73
73
|
:api_key => api_key_for(role)
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
use "return 404 Not Found with empty response body"
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
context "#{role} : get /:id/usages/:id" do
|
80
80
|
before do
|
81
81
|
get "/#{@source.id}/usages/#{@usage_id}", :api_key => api_key_for(role)
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
use "return 200 Ok"
|
85
85
|
doc_properties %w(title url description id)
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
end
|
@@ -18,53 +18,53 @@ class SourcesUsagesPostResourceTest < ResourceTestCase
|
|
18
18
|
after do
|
19
19
|
@source.destroy
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
context "post /:id/usages" do
|
23
23
|
context "anonymous" do
|
24
24
|
before do
|
25
25
|
post "/#{@source.id}/usages"
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
use "return 401 because the API key is missing"
|
29
29
|
use "no change in usage count"
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
context "incorrect API key" do
|
33
33
|
before do
|
34
34
|
post "/#{@source.id}/usages", :api_key => BAD_API_KEY
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
use "return 401 because the API key is invalid"
|
38
38
|
use "no change in usage count"
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
%w(basic).each do |role|
|
43
43
|
context "#{role} : post /:fake_id/usages" do
|
44
44
|
before do
|
45
45
|
post "/#{FAKE_ID}/usages", :api_key => api_key_for(role)
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
use "return 404 Not Found with empty response body"
|
49
49
|
use "no change in usage count"
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
context "#{role} : post /:id/usages" do
|
53
53
|
before do
|
54
54
|
post "/#{@source.id}/usages", :api_key => api_key_for(role)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
use "return 401 because the API key is unauthorized"
|
58
58
|
use "no change in usage count"
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
%w(curator admin).each do |role|
|
63
63
|
context "#{role} : post /:fake_id/usages" do
|
64
64
|
before do
|
65
65
|
post "/#{FAKE_ID}/usages", :api_key => api_key_for(role)
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
use "return 404 Not Found with empty response body"
|
69
69
|
use "no change in usage count"
|
70
70
|
end
|
@@ -78,20 +78,20 @@ class SourcesUsagesPostResourceTest < ResourceTestCase
|
|
78
78
|
# post "/#{@source.id}/usages",
|
79
79
|
# valid_params_for(role).delete_if { |k, v| k == missing }
|
80
80
|
# end
|
81
|
-
#
|
81
|
+
#
|
82
82
|
# use "return 400 Bad Request"
|
83
83
|
# use "no change in usage count"
|
84
84
|
# missing_param missing
|
85
85
|
# end
|
86
86
|
# end
|
87
|
-
|
87
|
+
|
88
88
|
[:junk].each do |invalid|
|
89
89
|
context "#{role} : post /:id/usages/ but with #{invalid}" do
|
90
90
|
before do
|
91
91
|
post "/#{@source.id}/usages", valid_params_for(role).
|
92
92
|
merge(invalid => 9)
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
use "return 400 Bad Request"
|
96
96
|
use "no change in usage count"
|
97
97
|
invalid_param invalid
|
@@ -102,12 +102,12 @@ class SourcesUsagesPostResourceTest < ResourceTestCase
|
|
102
102
|
before do
|
103
103
|
post "/#{@source.id}/usages", valid_params_for(role)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
use "return 201 Created"
|
107
107
|
nested_location_header "sources", :source, "usages"
|
108
108
|
use "one new usage"
|
109
109
|
doc_properties %w(title url description id)
|
110
|
-
|
110
|
+
|
111
111
|
test "new usage created correctly" do
|
112
112
|
source = Source.find_by_id(@source.id)
|
113
113
|
# TODO: use reload instead
|
@@ -120,5 +120,5 @@ class SourcesUsagesPostResourceTest < ResourceTestCase
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
end
|