sinatra_resource 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/examples/datacatalog/resources/categories.rb +2 -2
- data/examples/datacatalog/test/resources/categories/categories_put_test.rb +47 -7
- data/examples/datacatalog/test/resources/sources/sources_put_test.rb +71 -9
- data/examples/datacatalog/test/resources/users/users_put_test.rb +46 -6
- data/lib/builder/action_definitions.rb +2 -2
- data/sinatra_resource.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
@@ -37,7 +37,7 @@ module DataCatalog
|
|
37
37
|
category.log += " after_create"
|
38
38
|
end
|
39
39
|
|
40
|
-
callback :before_update do |action|
|
40
|
+
callback :before_update do |action, category|
|
41
41
|
action.params["log"] = "before_update"
|
42
42
|
end
|
43
43
|
|
@@ -45,7 +45,7 @@ module DataCatalog
|
|
45
45
|
category.log += " after_update"
|
46
46
|
end
|
47
47
|
|
48
|
-
callback :before_destroy do |action|
|
48
|
+
callback :before_destroy do |action, category|
|
49
49
|
action.headers 'X-Test-Callbacks' => 'before_destroy'
|
50
50
|
end
|
51
51
|
|
@@ -39,6 +39,15 @@ class CategoriesPutResourceTest < ResourceTestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
%w(basic).each do |role|
|
42
|
+
context "#{role} : put /:id with no params" do
|
43
|
+
before do
|
44
|
+
put "/#{@category.id}", :api_key => api_key_for(role)
|
45
|
+
end
|
46
|
+
|
47
|
+
use "return 401 because the API key is unauthorized"
|
48
|
+
use "category unchanged"
|
49
|
+
end
|
50
|
+
|
42
51
|
[:created_at, :updated_at, :sources, :junk].each do |invalid|
|
43
52
|
context "#{role} : put /:id but with #{invalid}" do
|
44
53
|
before do
|
@@ -61,11 +70,11 @@ class CategoriesPutResourceTest < ResourceTestCase
|
|
61
70
|
end
|
62
71
|
end
|
63
72
|
|
64
|
-
context "#{role} : put /:
|
73
|
+
context "#{role} : put /:fake_id with valid params" do
|
65
74
|
before do
|
66
|
-
put "/#{
|
75
|
+
put "/#{FAKE_ID}", valid_params_for(role)
|
67
76
|
end
|
68
|
-
|
77
|
+
|
69
78
|
use "return 401 because the API key is unauthorized"
|
70
79
|
use "category unchanged"
|
71
80
|
end
|
@@ -81,6 +90,25 @@ class CategoriesPutResourceTest < ResourceTestCase
|
|
81
90
|
end
|
82
91
|
|
83
92
|
%w(curator admin).each do |role|
|
93
|
+
context "#{role} : put /:fake_id with no params" do
|
94
|
+
before do
|
95
|
+
put "/#{FAKE_ID}", :api_key => api_key_for(role)
|
96
|
+
end
|
97
|
+
|
98
|
+
use "return 400 because no params were given"
|
99
|
+
# (The 400 'takes precedence' over the 404.)
|
100
|
+
use "category unchanged"
|
101
|
+
end
|
102
|
+
|
103
|
+
context "#{role} : put /:id with no params" do
|
104
|
+
before do
|
105
|
+
put "/#{@category.id}", :api_key => api_key_for(role)
|
106
|
+
end
|
107
|
+
|
108
|
+
use "return 400 because no params were given"
|
109
|
+
use "category unchanged"
|
110
|
+
end
|
111
|
+
|
84
112
|
[:created_at, :updated_at, :sources, :junk].each do |invalid|
|
85
113
|
context "#{role} : put /:id but with #{invalid}" do
|
86
114
|
before do
|
@@ -93,6 +121,18 @@ class CategoriesPutResourceTest < ResourceTestCase
|
|
93
121
|
end
|
94
122
|
end
|
95
123
|
|
124
|
+
[:name].each do |erase|
|
125
|
+
context "#{role} : put /:fake_id but blanking out #{erase}" do
|
126
|
+
before do
|
127
|
+
put "/#{FAKE_ID}", valid_params_for(role).merge(erase => "")
|
128
|
+
end
|
129
|
+
|
130
|
+
use "return 404 Not Found with empty response body"
|
131
|
+
# (The 404 'takes precedence' over the 400.)
|
132
|
+
use "category unchanged"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
96
136
|
[:name].each do |erase|
|
97
137
|
context "#{role} : put /:id but blanking out #{erase}" do
|
98
138
|
before do
|
@@ -105,12 +145,12 @@ class CategoriesPutResourceTest < ResourceTestCase
|
|
105
145
|
end
|
106
146
|
end
|
107
147
|
|
108
|
-
context "#{role} : put /:
|
148
|
+
context "#{role} : put /:fake_id with valid params" do
|
109
149
|
before do
|
110
|
-
put "/#{
|
150
|
+
put "/#{FAKE_ID}", valid_params_for(role)
|
111
151
|
end
|
112
|
-
|
113
|
-
use "return
|
152
|
+
|
153
|
+
use "return 404 Not Found with empty response body"
|
114
154
|
use "category unchanged"
|
115
155
|
end
|
116
156
|
|
@@ -73,6 +73,15 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
73
73
|
use "source unchanged"
|
74
74
|
end
|
75
75
|
end
|
76
|
+
|
77
|
+
context "#{role} : put /:fake_id with valid params" do
|
78
|
+
before do
|
79
|
+
put "/#{FAKE_ID}", valid_params_for(role)
|
80
|
+
end
|
81
|
+
|
82
|
+
use "return 401 because the API key is unauthorized"
|
83
|
+
use "source unchanged"
|
84
|
+
end
|
76
85
|
|
77
86
|
context "#{role} : put /:id with valid params" do
|
78
87
|
before do
|
@@ -97,6 +106,18 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
97
106
|
end
|
98
107
|
end
|
99
108
|
|
109
|
+
[:title, :url].each do |erase|
|
110
|
+
context "#{role} : put /:fake_id but blanking out #{erase}" do
|
111
|
+
before do
|
112
|
+
put "/#{FAKE_ID}", valid_params_for(role).merge(erase => "")
|
113
|
+
end
|
114
|
+
|
115
|
+
use "return 404 Not Found with empty response body"
|
116
|
+
# (The 404 'takes precedence' over the 400.)
|
117
|
+
use "source unchanged"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
100
121
|
[:title, :url].each do |erase|
|
101
122
|
context "#{role} : put /:id but blanking out #{erase}" do
|
102
123
|
before do
|
@@ -128,6 +149,15 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
128
149
|
end
|
129
150
|
end
|
130
151
|
|
152
|
+
context "#{role} : put /:fake_id with valid params" do
|
153
|
+
before do
|
154
|
+
put "/#{FAKE_ID}", valid_params_for(role)
|
155
|
+
end
|
156
|
+
|
157
|
+
use "return 404 Not Found with empty response body"
|
158
|
+
use "source unchanged"
|
159
|
+
end
|
160
|
+
|
131
161
|
context "#{role} : put /:id with valid params" do
|
132
162
|
before do
|
133
163
|
put "/#{@source.id}", valid_params_for(role)
|
@@ -146,6 +176,25 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
146
176
|
end
|
147
177
|
|
148
178
|
%w(admin).each do |role|
|
179
|
+
context "#{role} : put /:fake_id with no params" do
|
180
|
+
before do
|
181
|
+
put "/#{FAKE_ID}", :api_key => api_key_for(role)
|
182
|
+
end
|
183
|
+
|
184
|
+
use "return 400 because no params were given"
|
185
|
+
# (The 400 'takes precedence' over the 404.)
|
186
|
+
use "source unchanged"
|
187
|
+
end
|
188
|
+
|
189
|
+
context "#{role} : put /:id with no params" do
|
190
|
+
before do
|
191
|
+
put "/#{@source.id}", :api_key => api_key_for(role)
|
192
|
+
end
|
193
|
+
|
194
|
+
use "return 400 because no params were given"
|
195
|
+
use "source unchanged"
|
196
|
+
end
|
197
|
+
|
149
198
|
[:created_at, :updated_at, :categories, :junk].each do |invalid|
|
150
199
|
context "#{role} : put /:id but with #{invalid}" do
|
151
200
|
before do
|
@@ -159,6 +208,19 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
159
208
|
end
|
160
209
|
end
|
161
210
|
|
211
|
+
[:title, :url].each do |erase|
|
212
|
+
context "#{role} : put /:fake_id but blanking out #{erase}" do
|
213
|
+
before do
|
214
|
+
put "/#{FAKE_ID}", valid_params_for(role).
|
215
|
+
merge(@extra_admin_params).merge(erase => "")
|
216
|
+
end
|
217
|
+
|
218
|
+
use "return 404 Not Found with empty response body"
|
219
|
+
# (The 404 'takes precedence' over the 400.)
|
220
|
+
use "source unchanged"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
162
224
|
[:title, :url].each do |erase|
|
163
225
|
context "#{role} : put /:id but blanking out #{erase}" do
|
164
226
|
before do
|
@@ -172,15 +234,6 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
172
234
|
end
|
173
235
|
end
|
174
236
|
|
175
|
-
context "#{role} : put /:id with no params" do
|
176
|
-
before do
|
177
|
-
put "/#{@source.id}", :api_key => api_key_for(role)
|
178
|
-
end
|
179
|
-
|
180
|
-
use "return 400 because no params were given"
|
181
|
-
use "source unchanged"
|
182
|
-
end
|
183
|
-
|
184
237
|
[:title, :url].each do |missing|
|
185
238
|
context "#{role} : put /:id without #{missing}" do
|
186
239
|
before do
|
@@ -201,6 +254,15 @@ class SourcesPutResourceTest < ResourceTestCase
|
|
201
254
|
end
|
202
255
|
end
|
203
256
|
|
257
|
+
context "#{role} : put /:fake_id with valid params" do
|
258
|
+
before do
|
259
|
+
put "/#{FAKE_ID}", valid_params_for(role).merge(@extra_admin_params)
|
260
|
+
end
|
261
|
+
|
262
|
+
use "return 404 Not Found with empty response body"
|
263
|
+
use "source unchanged"
|
264
|
+
end
|
265
|
+
|
204
266
|
context "#{role} : put /:id with valid params" do
|
205
267
|
before do
|
206
268
|
put "/#{@source.id}", valid_params_for(role).merge(@extra_admin_params)
|
@@ -77,6 +77,15 @@ class UsersPutResourceTest < ResourceTestCase
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
context "#{role} : put /:fake_id with valid params" do
|
81
|
+
before do
|
82
|
+
put "/#{FAKE_ID}", valid_params_for(role)
|
83
|
+
end
|
84
|
+
|
85
|
+
use "return 401 because the API key is unauthorized"
|
86
|
+
use "user unchanged"
|
87
|
+
end
|
88
|
+
|
80
89
|
context "#{role} : put /:id with valid params" do
|
81
90
|
before do
|
82
91
|
put "/#{@user.id}", valid_params_for(role)
|
@@ -88,6 +97,25 @@ class UsersPutResourceTest < ResourceTestCase
|
|
88
97
|
end
|
89
98
|
|
90
99
|
%w(admin).each do |role|
|
100
|
+
context "#{role} : put /:fake_id with no params" do
|
101
|
+
before do
|
102
|
+
put "/#{FAKE_ID}", :api_key => api_key_for(role)
|
103
|
+
end
|
104
|
+
|
105
|
+
use "return 400 because no params were given"
|
106
|
+
# (The 400 'takes precedence' over the 404.)
|
107
|
+
use "user unchanged"
|
108
|
+
end
|
109
|
+
|
110
|
+
context "#{role} : put /:id with no params" do
|
111
|
+
before do
|
112
|
+
put "/#{@user.id}", :api_key => api_key_for(role)
|
113
|
+
end
|
114
|
+
|
115
|
+
use "return 400 because no params were given"
|
116
|
+
use "user unchanged"
|
117
|
+
end
|
118
|
+
|
91
119
|
[:created_at, :updated_at, :junk].each do |invalid|
|
92
120
|
context "#{role} : put /:id but with #{invalid}" do
|
93
121
|
before do
|
@@ -114,13 +142,16 @@ class UsersPutResourceTest < ResourceTestCase
|
|
114
142
|
end
|
115
143
|
end
|
116
144
|
|
117
|
-
|
118
|
-
|
119
|
-
|
145
|
+
[:name, :role].each do |missing|
|
146
|
+
context "#{role} : put /:fake_id without #{missing}" do
|
147
|
+
before do
|
148
|
+
put "/#{FAKE_ID}", valid_params_for(role).
|
149
|
+
merge(@extra_admin_params).delete_if { |k, v| k == missing }
|
150
|
+
end
|
151
|
+
|
152
|
+
use "return 404 Not Found with empty response body"
|
153
|
+
use "user unchanged"
|
120
154
|
end
|
121
|
-
|
122
|
-
use "return 400 because no params were given"
|
123
|
-
use "user unchanged"
|
124
155
|
end
|
125
156
|
|
126
157
|
[:name, :role].each do |missing|
|
@@ -143,6 +174,15 @@ class UsersPutResourceTest < ResourceTestCase
|
|
143
174
|
end
|
144
175
|
end
|
145
176
|
|
177
|
+
context "#{role} : put /:fake_id with valid params" do
|
178
|
+
before do
|
179
|
+
put "/#{FAKE_ID}", valid_params_for(role).merge(@extra_admin_params)
|
180
|
+
end
|
181
|
+
|
182
|
+
use "return 404 Not Found with empty response body"
|
183
|
+
use "user unchanged"
|
184
|
+
end
|
185
|
+
|
146
186
|
context "#{role} : put /:id with valid params" do
|
147
187
|
before do
|
148
188
|
put "/#{@user.id}", valid_params_for(role).merge(@extra_admin_params)
|
@@ -43,7 +43,7 @@ module SinatraResource
|
|
43
43
|
check_related?(parent_document, association, id)
|
44
44
|
end
|
45
45
|
check_params(:update, role, resource_config, leaf)
|
46
|
-
do_callback(:before_update, resource_config,
|
46
|
+
do_callback(:before_update, resource_config, find_document!(model, id))
|
47
47
|
document = update_document!(model, id)
|
48
48
|
do_callback(:after_update, resource_config, document)
|
49
49
|
document
|
@@ -55,7 +55,7 @@ module SinatraResource
|
|
55
55
|
check_related?(parent_document, association, id)
|
56
56
|
end
|
57
57
|
check_params(:delete, role, resource_config, leaf)
|
58
|
-
do_callback(:before_destroy, resource_config,
|
58
|
+
do_callback(:before_destroy, resource_config, find_document!(model, id))
|
59
59
|
document = delete_document!(model, id)
|
60
60
|
do_callback(:after_destroy, resource_config, document)
|
61
61
|
document
|
data/sinatra_resource.gemspec
CHANGED