sinatra_resource 0.4.21 → 0.4.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -5,7 +5,7 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
|
|
5
5
|
include DataCatalog
|
6
6
|
|
7
7
|
def app; Categories end
|
8
|
-
|
8
|
+
|
9
9
|
before do
|
10
10
|
@category = create_category
|
11
11
|
@source = create_source
|
@@ -20,121 +20,121 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
|
|
20
20
|
}
|
21
21
|
@extra_admin_params = { :raw => { "key" => "value" } }
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
after do
|
25
25
|
@categorization.destroy
|
26
26
|
@source.destroy
|
27
27
|
@category.destroy
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
context "post /:id/sources" do
|
31
31
|
context "anonymous" do
|
32
32
|
before do
|
33
33
|
post "/#{@category.id}/sources"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
use "return 401 because the API key is missing"
|
37
37
|
use "no change in source count"
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
context "incorrect API key" do
|
41
41
|
before do
|
42
42
|
post "/#{@category.id}/sources", :api_key => BAD_API_KEY
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
use "return 401 because the API key is invalid"
|
46
46
|
use "no change in source count"
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
%w(basic).each do |role|
|
51
51
|
context "#{role} : post /:fake_id/sources" do
|
52
52
|
before do
|
53
53
|
post "/#{FAKE_ID}/sources", :api_key => api_key_for(role)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
use "return 404 Not Found with empty response body"
|
57
57
|
use "no change in source count"
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
context "#{role} : post /:id/sources" do
|
61
61
|
before do
|
62
62
|
post "/#{@category.id}/sources", :api_key => api_key_for(role)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
use "return 401 because the API key is unauthorized"
|
66
66
|
use "no change in source count"
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
%w(curator).each do |role|
|
71
71
|
context "#{role} : post /:fake_id/sources" do
|
72
72
|
before do
|
73
73
|
post "/#{FAKE_ID}/sources", :api_key => api_key_for(role)
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
use "return 404 Not Found with empty response body"
|
77
77
|
use "no change in source count"
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
[:title, :url].each do |missing|
|
81
81
|
context "#{role} : post /:id/sources but missing #{missing}" do
|
82
82
|
before do
|
83
83
|
post "/#{@category.id}/sources",
|
84
84
|
valid_params_for(role).delete_if { |k, v| k == missing }
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
use "return 400 Bad Request"
|
88
88
|
use "no change in source count"
|
89
89
|
missing_param missing
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
[:raw, :id, :created_at, :updated_at, :junk].each do |invalid|
|
94
94
|
context "#{role} : post /:id/sources but with #{invalid}" do
|
95
95
|
before do
|
96
96
|
post "/#{@category.id}/sources", valid_params_for(role).
|
97
97
|
merge(invalid => 9)
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
use "return 400 Bad Request"
|
101
101
|
use "no change in source count"
|
102
102
|
invalid_param invalid
|
103
103
|
end
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
context "#{role} : post /:id/sources with valid params" do
|
107
107
|
before do
|
108
108
|
post "/#{@category.id}/sources", valid_params_for(role)
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
after do
|
112
112
|
Source.find_by_id(parsed_response_body["id"]).destroy
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
use "return 201 Created"
|
116
116
|
nested_location_header "categories", :category, "sources"
|
117
117
|
use "one new source"
|
118
118
|
doc_properties %w(title url raw id created_at updated_at)
|
119
|
-
|
119
|
+
|
120
120
|
test "source connected to category" do
|
121
121
|
source = Source.find_by_id(parsed_response_body["id"])
|
122
122
|
assert_equal [@category], source.categories
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
%w(admin).each do |role|
|
128
128
|
context "#{role} : post /:fake_id/sources" do
|
129
129
|
before do
|
130
130
|
post "/#{FAKE_ID}/sources",
|
131
131
|
valid_params_for(role).merge(@extra_admin_params)
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
use "return 404 Not Found with empty response body"
|
135
135
|
use "no change in source count"
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
[:title, :url].each do |missing|
|
139
139
|
context "#{role} : post /:id/sources but missing #{missing}" do
|
140
140
|
before do
|
@@ -142,46 +142,46 @@ class CategoriesSourcesPostResourceTest < ResourceTestCase
|
|
142
142
|
valid_params_for(role).merge(@extra_admin_params).
|
143
143
|
delete_if { |k, v| k == missing }
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
use "return 400 Bad Request"
|
147
147
|
use "no change in source count"
|
148
148
|
missing_param missing
|
149
149
|
end
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
[:id, :created_at, :updated_at, :junk].each do |invalid|
|
153
153
|
context "#{role} : post /:id/sources but with #{invalid}" do
|
154
154
|
before do
|
155
155
|
post "/#{@category.id}/sources", valid_params_for(role).
|
156
156
|
merge(@extra_admin_params).merge(invalid => 9)
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
use "return 400 Bad Request"
|
160
160
|
use "no change in source count"
|
161
161
|
invalid_param invalid
|
162
162
|
end
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
context "#{role} : post /:id/sources with valid params" do
|
166
166
|
before do
|
167
167
|
post "/#{@category.id}/sources",
|
168
168
|
valid_params_for(role).merge(@extra_admin_params)
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
after do
|
172
172
|
Source.find_by_id(parsed_response_body["id"]).destroy
|
173
173
|
end
|
174
|
-
|
174
|
+
|
175
175
|
use "return 201 Created"
|
176
176
|
nested_location_header "categories", :category, "sources"
|
177
177
|
use "one new source"
|
178
178
|
doc_properties %w(title url raw id created_at updated_at)
|
179
|
-
|
179
|
+
|
180
180
|
test "source connected to category" do
|
181
181
|
source = Source.find_by_id(parsed_response_body["id"])
|
182
182
|
assert_equal [@category], source.categories
|
183
183
|
end
|
184
184
|
end
|
185
185
|
end
|
186
|
-
|
186
|
+
|
187
187
|
end
|
@@ -5,7 +5,7 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
5
5
|
include DataCatalog
|
6
6
|
|
7
7
|
def app; Categories end
|
8
|
-
|
8
|
+
|
9
9
|
before do
|
10
10
|
@category = create_category
|
11
11
|
@source = create_source
|
@@ -41,16 +41,16 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
41
41
|
before do
|
42
42
|
put "/#{@category.id}/sources/#{@source.id}"
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
use "return 401 because the API key is missing"
|
46
46
|
use "source unchanged"
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
context "incorrect API key" do
|
50
50
|
before do
|
51
51
|
put "/#{@category.id}/sources/#{@source.id}", :api_key => BAD_API_KEY
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
use "return 401 because the API key is invalid"
|
55
55
|
use "source unchanged"
|
56
56
|
end
|
@@ -61,44 +61,44 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
61
61
|
before do
|
62
62
|
put "/#{FAKE_ID}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
use "return 404 Not Found with empty response body"
|
66
66
|
use "source unchanged"
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
context "#{role} : put /:fake_id/sources/:id" do
|
70
70
|
before do
|
71
71
|
put "/#{FAKE_ID}/sources/#{@source.id}", :api_key => api_key_for(role)
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
use "return 404 Not Found with empty response body"
|
75
75
|
use "source unchanged"
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
context "#{role} : put /:id/sources/:fake_id" do
|
79
79
|
before do
|
80
80
|
put "/#{@category.id}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
use "return 401 because the API key is unauthorized"
|
84
84
|
use "source unchanged"
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
context "#{role} : put /:id/sources/:not_related_id" do
|
88
88
|
before do
|
89
89
|
put "/#{@category.id}/sources/#{@other_source.id}",
|
90
90
|
:api_key => api_key_for(role)
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
use "return 401 because the API key is unauthorized"
|
94
94
|
use "source unchanged"
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
context "#{role} : put /:id/sources/:id" do
|
98
98
|
before do
|
99
99
|
put "/#{@category.id}/sources/#{@source.id}", :api_key => api_key_for(role)
|
100
100
|
end
|
101
|
-
|
101
|
+
|
102
102
|
use "return 401 because the API key is unauthorized"
|
103
103
|
use "source unchanged"
|
104
104
|
end
|
@@ -109,35 +109,35 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
109
109
|
before do
|
110
110
|
put "/#{FAKE_ID}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
use "return 404 Not Found with empty response body"
|
114
114
|
use "source unchanged"
|
115
115
|
end
|
116
|
-
|
116
|
+
|
117
117
|
context "#{role} : put /:fake_id/sources/:id" do
|
118
118
|
before do
|
119
119
|
put "/#{FAKE_ID}/sources/#{@source.id}", :api_key => api_key_for(role)
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
use "return 404 Not Found with empty response body"
|
123
123
|
use "source unchanged"
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
context "#{role} : put /:id/sources/:fake_id" do
|
127
127
|
before do
|
128
128
|
put "/#{@category.id}/sources/#{FAKE_ID}", :api_key => api_key_for(role)
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
use "return 404 Not Found with empty response body"
|
132
132
|
use "source unchanged"
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
context "#{role} : put /:id/sources/:not_related_id" do
|
136
136
|
before do
|
137
137
|
put "/#{@category.id}/sources/#{@other_source.id}",
|
138
138
|
:api_key => api_key_for(role)
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
use "return 404 Not Found with empty response body"
|
142
142
|
use "source unchanged"
|
143
143
|
end
|
@@ -148,7 +148,7 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
148
148
|
put "/#{@category.id}/sources/#{@source.id}",
|
149
149
|
valid_params_for(role).merge(invalid => 9)
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
use "return 400 Bad Request"
|
153
153
|
use "source unchanged"
|
154
154
|
invalid_param invalid
|
@@ -161,7 +161,7 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
161
161
|
put "/#{@category.id}/sources/#{@source.id}",
|
162
162
|
valid_params_for(role).merge(erase => "")
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
use "return 400 Bad Request"
|
166
166
|
use "source unchanged"
|
167
167
|
missing_param erase
|
@@ -174,7 +174,7 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
174
174
|
put "/#{@category.id}/sources/#{@source.id}",
|
175
175
|
valid_params_for(role).delete_if { |k, v| k == missing }
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
use "return 200 Ok"
|
179
179
|
doc_properties %w(title url raw id created_at updated_at)
|
180
180
|
|
@@ -187,7 +187,7 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
187
187
|
end
|
188
188
|
end
|
189
189
|
end
|
190
|
-
|
190
|
+
|
191
191
|
context "#{role} : put /:id/sources/:id with valid params" do
|
192
192
|
before do
|
193
193
|
put "/#{@category.id}/sources/#{@source.id}", valid_params_for(role)
|
@@ -195,7 +195,7 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
195
195
|
|
196
196
|
use "return 200 Ok"
|
197
197
|
doc_properties %w(title url raw id created_at updated_at)
|
198
|
-
|
198
|
+
|
199
199
|
test "should change correct fields in database" do
|
200
200
|
source = Source.find_by_id(@source.id)
|
201
201
|
@valid_params.each_pair do |key, value|
|
@@ -211,37 +211,37 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
211
211
|
put "/#{FAKE_ID}/sources/#{FAKE_ID}",
|
212
212
|
valid_params_for(role).merge(@extra_admin_params)
|
213
213
|
end
|
214
|
-
|
214
|
+
|
215
215
|
use "return 404 Not Found with empty response body"
|
216
216
|
use "source unchanged"
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
context "#{role} : put /:fake_id/sources/:id" do
|
220
220
|
before do
|
221
221
|
put "/#{FAKE_ID}/sources/#{@source.id}",
|
222
222
|
valid_params_for(role).merge(@extra_admin_params)
|
223
223
|
end
|
224
|
-
|
224
|
+
|
225
225
|
use "return 404 Not Found with empty response body"
|
226
226
|
use "source unchanged"
|
227
227
|
end
|
228
|
-
|
228
|
+
|
229
229
|
context "#{role} : put /:id/sources/:fake_id" do
|
230
230
|
before do
|
231
231
|
put "/#{@category.id}/sources/#{FAKE_ID}",
|
232
232
|
valid_params_for(role).merge(@extra_admin_params)
|
233
233
|
end
|
234
|
-
|
234
|
+
|
235
235
|
use "return 404 Not Found with empty response body"
|
236
236
|
use "source unchanged"
|
237
237
|
end
|
238
|
-
|
238
|
+
|
239
239
|
context "#{role} : put /:id/sources/:not_related_id" do
|
240
240
|
before do
|
241
241
|
put "/#{@category.id}/sources/#{@other_source.id}",
|
242
242
|
valid_params_for(role).merge(@extra_admin_params)
|
243
243
|
end
|
244
|
-
|
244
|
+
|
245
245
|
use "return 404 Not Found with empty response body"
|
246
246
|
use "source unchanged"
|
247
247
|
end
|
@@ -251,21 +251,21 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
251
251
|
put "/#{@category.id}/sources/#{@source.id}",
|
252
252
|
:api_key => api_key_for(role)
|
253
253
|
end
|
254
|
-
|
254
|
+
|
255
255
|
use "return 400 because no params were given"
|
256
256
|
use "source unchanged"
|
257
257
|
end
|
258
|
-
|
258
|
+
|
259
259
|
[:title, :url].each do |missing|
|
260
260
|
context "#{role} : put /:id/sources/:id without #{missing}" do
|
261
261
|
before do
|
262
262
|
put "/#{@category.id}/sources/#{@source.id}",
|
263
263
|
valid_params_for(role).merge(@extra_admin_params).delete_if { |k, v| k == missing }
|
264
264
|
end
|
265
|
-
|
265
|
+
|
266
266
|
use "return 200 Ok"
|
267
267
|
doc_properties %w(title url raw id created_at updated_at)
|
268
|
-
|
268
|
+
|
269
269
|
test "should change correct fields in database" do
|
270
270
|
source = Source.find_by_id(@source.id)
|
271
271
|
@valid_params.merge(@extra_admin_params).each_pair do |key, value|
|
@@ -282,7 +282,7 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
282
282
|
put "/#{@category.id}/sources/#{@source.id}",
|
283
283
|
valid_params_for(role).merge(@extra_admin_params).merge(erase => "")
|
284
284
|
end
|
285
|
-
|
285
|
+
|
286
286
|
use "return 400 Bad Request"
|
287
287
|
use "source unchanged"
|
288
288
|
missing_param erase
|
@@ -295,7 +295,7 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
295
295
|
put "/#{@category.id}/sources/#{@source.id}",
|
296
296
|
valid_params_for(role).merge(@extra_admin_params).merge(invalid => 9)
|
297
297
|
end
|
298
|
-
|
298
|
+
|
299
299
|
use "return 400 Bad Request"
|
300
300
|
use "source unchanged"
|
301
301
|
invalid_param invalid
|
@@ -307,10 +307,10 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
307
307
|
put "/#{@category.id}/sources/#{@source.id}",
|
308
308
|
valid_params_for(role).merge(@extra_admin_params)
|
309
309
|
end
|
310
|
-
|
310
|
+
|
311
311
|
use "return 200 Ok"
|
312
312
|
doc_properties %w(title url raw id created_at updated_at)
|
313
|
-
|
313
|
+
|
314
314
|
test "should change all fields in database" do
|
315
315
|
source = Source.find_by_id(@source.id)
|
316
316
|
@valid_params.merge(@extra_admin_params).each_pair do |key, value|
|
@@ -319,5 +319,5 @@ class CategoriesSourcesPutResourceTest < ResourceTestCase
|
|
319
319
|
end
|
320
320
|
end
|
321
321
|
end
|
322
|
-
|
322
|
+
|
323
323
|
end
|
@@ -21,39 +21,39 @@ class NotesGetManyResourceTest < ResourceTestCase
|
|
21
21
|
end
|
22
22
|
@note_texts = ["Note 0", "Note 1", "Note 2"].sort
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
after do
|
26
26
|
@notes.each { |x| x.destroy } if @notes
|
27
27
|
@users.each { |x| x.destroy }
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
context "get /" do
|
31
31
|
context "anonymous" do
|
32
32
|
before do
|
33
33
|
get "/"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
use "return 401 because the API key is missing"
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
context "incorrect API key" do
|
40
40
|
before do
|
41
41
|
get "/", :api_key => BAD_API_KEY
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
use "return 401 because the API key is invalid"
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
%w(basic curator).each do |role|
|
49
49
|
context "#{role} : get /" do
|
50
50
|
before do
|
51
51
|
get "/", :api_key => api_key_for(role)
|
52
52
|
@members = parsed_response_body['members']
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
use "return 200 Ok"
|
56
|
-
|
56
|
+
|
57
57
|
test "body should have an empty list" do
|
58
58
|
assert_equal [], @members
|
59
59
|
end
|
@@ -65,18 +65,18 @@ class NotesGetManyResourceTest < ResourceTestCase
|
|
65
65
|
get "/", :api_key => @users[0]._api_key
|
66
66
|
@members = parsed_response_body['members']
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
use "return 200 Ok"
|
70
|
-
|
70
|
+
|
71
71
|
test "body should have 1 note" do
|
72
72
|
assert_equal 1, @members.length
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
test "body should have correct note text" do
|
76
76
|
actual = @members.map { |e| e["text"] }
|
77
77
|
assert_equal ["Note 0"], actual.sort
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
test "members should only have correct attributes" do
|
81
81
|
correct = %w(text user_id id created_at updated_at)
|
82
82
|
@members.each do |member|
|
@@ -91,13 +91,13 @@ class NotesGetManyResourceTest < ResourceTestCase
|
|
91
91
|
get "/", :api_key => api_key_for(role)
|
92
92
|
@members = parsed_response_body['members']
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
use "return 200 Ok"
|
96
|
-
|
96
|
+
|
97
97
|
test "body should have 3 notes" do
|
98
98
|
assert_equal 3, @members.length
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
test "body should have correct note text" do
|
102
102
|
actual = @members.map { |e| e["text"] }
|
103
103
|
assert_equal @note_texts, actual.sort
|
@@ -5,7 +5,7 @@ class NotesGetOneResourceTest < ResourceTestCase
|
|
5
5
|
include DataCatalog
|
6
6
|
|
7
7
|
def app; Notes end
|
8
|
-
|
8
|
+
|
9
9
|
before do
|
10
10
|
@user = create_user
|
11
11
|
@note = create_note(
|
@@ -23,7 +23,7 @@ class NotesGetOneResourceTest < ResourceTestCase
|
|
23
23
|
before do
|
24
24
|
get "/#{@note.id}"
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
use "return 401 because the API key is missing"
|
28
28
|
end
|
29
29
|
|
@@ -31,7 +31,7 @@ class NotesGetOneResourceTest < ResourceTestCase
|
|
31
31
|
before do
|
32
32
|
get "/#{@note.id}", :api_key => BAD_API_KEY
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
use "return 401 because the API key is invalid"
|
36
36
|
end
|
37
37
|
end
|
@@ -41,15 +41,15 @@ class NotesGetOneResourceTest < ResourceTestCase
|
|
41
41
|
before do
|
42
42
|
get "/#{FAKE_ID}", :api_key => api_key_for(role)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
use "return 401 because the API key is unauthorized"
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
context "#{role} : get /:id" do
|
49
49
|
before do
|
50
50
|
get "/#{@note.id}", :api_key => api_key_for(role)
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
use "return 401 because the API key is unauthorized"
|
54
54
|
end
|
55
55
|
end
|
@@ -68,7 +68,7 @@ class NotesGetOneResourceTest < ResourceTestCase
|
|
68
68
|
before do
|
69
69
|
get "/#{FAKE_ID}", :api_key => api_key_for(role)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
use "return 404 Not Found with empty response body"
|
73
73
|
end
|
74
74
|
|