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
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../helpers/resource_test_helper')
|
2
2
|
|
3
3
|
class NotesPostResourceTest < ResourceTestCase
|
4
|
-
|
4
|
+
|
5
5
|
include DataCatalog
|
6
6
|
|
7
7
|
def app; Notes end
|
8
|
-
|
8
|
+
|
9
9
|
before do
|
10
10
|
@note_count = Note.all.length
|
11
11
|
@user = create_user
|
@@ -14,7 +14,7 @@ class NotesPostResourceTest < ResourceTestCase
|
|
14
14
|
:user_id => @user.id
|
15
15
|
}
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
after do
|
19
19
|
@user.destroy
|
20
20
|
end
|
@@ -24,7 +24,7 @@ class NotesPostResourceTest < ResourceTestCase
|
|
24
24
|
before do
|
25
25
|
post "/", @valid_params
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
use "return 401 because the API key is missing"
|
29
29
|
use "no change in note count"
|
30
30
|
end
|
@@ -33,7 +33,7 @@ class NotesPostResourceTest < ResourceTestCase
|
|
33
33
|
before do
|
34
34
|
post "/", @valid_params.merge(: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 note count"
|
39
39
|
end
|
@@ -45,39 +45,39 @@ class NotesPostResourceTest < ResourceTestCase
|
|
45
45
|
before do
|
46
46
|
post "/", valid_params_for(role).delete_if { |k, v| k == missing }
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
use "return 400 Bad Request"
|
50
50
|
use "no change in note count"
|
51
51
|
missing_param missing
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
[:id, :created_at, :updated_at, :junk].each do |invalid|
|
56
56
|
context "#{role} : post / but with #{invalid}" do
|
57
57
|
before do
|
58
58
|
post "/", valid_params_for(role).merge(invalid => 9)
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
use "return 400 Bad Request"
|
62
62
|
use "no change in note count"
|
63
63
|
invalid_param invalid
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
context "#{role} : post / with valid params" do
|
68
68
|
before do
|
69
69
|
post "/", valid_params_for(role)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
after do
|
73
73
|
Note.find_by_id(parsed_response_body["id"]).destroy
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
use "return 201 Created"
|
77
77
|
location_header "notes"
|
78
78
|
use "one new note"
|
79
79
|
doc_properties %w(text user_id id created_at updated_at)
|
80
|
-
|
80
|
+
|
81
81
|
test "should set all fields in database" do
|
82
82
|
note = Note.find_by_id(parsed_response_body["id"])
|
83
83
|
raise "Cannot find note" unless note
|
@@ -14,13 +14,13 @@ class SourcesDeleteResourceTest < ResourceTestCase
|
|
14
14
|
after do
|
15
15
|
@source.destroy
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
context "delete /:id" do
|
19
19
|
context "anonymous" do
|
20
20
|
before do
|
21
21
|
delete "/#{@source.id}"
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
use "return 401 because the API key is missing"
|
25
25
|
use "no change in source count"
|
26
26
|
end
|
@@ -29,18 +29,18 @@ class SourcesDeleteResourceTest < ResourceTestCase
|
|
29
29
|
before do
|
30
30
|
delete "/#{@source.id}", :api_key => BAD_API_KEY
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
use "return 401 because the API key is invalid"
|
34
34
|
use "no change in source count"
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
%w(basic).each do |role|
|
39
39
|
context "#{role} : delete /:fake_id" do
|
40
40
|
before do
|
41
41
|
delete "/#{FAKE_ID}", :api_key => api_key_for(role)
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
use "return 401 because the API key is unauthorized"
|
45
45
|
use "no change in source count"
|
46
46
|
end
|
@@ -51,7 +51,7 @@ class SourcesDeleteResourceTest < ResourceTestCase
|
|
51
51
|
:api_key => api_key_for(role),
|
52
52
|
:key => "value"
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
use "return 401 because the API key is unauthorized"
|
56
56
|
use "no change in source count"
|
57
57
|
end
|
@@ -60,7 +60,7 @@ class SourcesDeleteResourceTest < ResourceTestCase
|
|
60
60
|
before do
|
61
61
|
delete "/#{@source.id}", :api_key => api_key_for(role)
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
use "return 401 because the API key is unauthorized"
|
65
65
|
use "no change in source count"
|
66
66
|
end
|
@@ -71,7 +71,7 @@ class SourcesDeleteResourceTest < ResourceTestCase
|
|
71
71
|
before do
|
72
72
|
delete "/#{FAKE_ID}", :api_key => api_key_for(role)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
use "return 404 Not Found with empty response body"
|
76
76
|
use "no change in source count"
|
77
77
|
end
|
@@ -82,8 +82,8 @@ class SourcesDeleteResourceTest < ResourceTestCase
|
|
82
82
|
:api_key => api_key_for(role),
|
83
83
|
:key => "value"
|
84
84
|
end
|
85
|
-
|
86
|
-
use "return 400 because params were
|
85
|
+
|
86
|
+
use "return 400 because invalid params were present"
|
87
87
|
use "no change in source count"
|
88
88
|
end
|
89
89
|
|
@@ -91,10 +91,10 @@ class SourcesDeleteResourceTest < ResourceTestCase
|
|
91
91
|
before do
|
92
92
|
delete "/#{@source.id}", :api_key => api_key_for(role)
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
use "return 204 No Content"
|
96
96
|
use "one less source"
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
end
|
@@ -45,48 +45,48 @@ class SourcesGetManySearchResourceTest < ResourceTestCase
|
|
45
45
|
after do
|
46
46
|
@sources.each { |x| x.destroy } if @sources
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
context "search=arrest" do
|
50
50
|
before do
|
51
51
|
@search_params = { :search => "arrest" }
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
context "get /" do
|
55
55
|
context "anonymous" do
|
56
56
|
before do
|
57
57
|
get "/", @search_params
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
use "return 401 because the API key is missing"
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
context "incorrect API key" do
|
64
64
|
before do
|
65
65
|
get "/", @search_params.merge(:api_key => BAD_API_KEY)
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
use "return 401 because the API key is invalid"
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
%w(basic curator admin).each do |role|
|
73
73
|
context "#{role} : get /" do
|
74
74
|
before do
|
75
75
|
get "/", @search_params.merge(:api_key => api_key_for(role))
|
76
76
|
@members = parsed_response_body['members']
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
use "return 200 Ok"
|
80
|
-
|
80
|
+
|
81
81
|
test "body should have 1 source" do
|
82
82
|
assert_equal 1, @members.length
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
test "body should have correct source" do
|
86
86
|
assert_equal %{2007 Crime in the United States},
|
87
87
|
@members[0]['title']
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
test "members should only have correct attributes" do
|
91
91
|
correct = %w(title url categories id created_at updated_at)
|
92
92
|
@members.each do |member|
|
@@ -96,21 +96,21 @@ class SourcesGetManySearchResourceTest < ResourceTestCase
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
context "search=quotations" do
|
101
101
|
before do
|
102
102
|
@search_params = { :search => "quotations" }
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
%w(basic).each do |role|
|
106
106
|
context "#{role} : get /" do
|
107
107
|
before do
|
108
108
|
get "/", @search_params.merge(:api_key => api_key_for(role))
|
109
109
|
@members = parsed_response_body['members']
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
use "return 200 Ok"
|
113
|
-
|
113
|
+
|
114
114
|
test "body should have correct sources" do
|
115
115
|
titles = @members.map { |x| x['title'] }
|
116
116
|
assert_equal 2, titles.length
|
@@ -125,16 +125,16 @@ class SourcesGetManySearchResourceTest < ResourceTestCase
|
|
125
125
|
before do
|
126
126
|
@search_params = { :search => "flight delays" }
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
%w(basic).each do |role|
|
130
130
|
context "#{role} : get /" do
|
131
131
|
before do
|
132
132
|
get "/", @search_params.merge(:api_key => api_key_for(role))
|
133
133
|
@members = parsed_response_body['members']
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
use "return 200 Ok"
|
137
|
-
|
137
|
+
|
138
138
|
test "body should have correct sources" do
|
139
139
|
titles = @members.map { |x| x['title'] }
|
140
140
|
assert_equal 1, titles.length
|
@@ -148,16 +148,16 @@ class SourcesGetManySearchResourceTest < ResourceTestCase
|
|
148
148
|
before do
|
149
149
|
@search_params = { :search => "" }
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
%w(basic).each do |role|
|
153
153
|
context "#{role} : get /" do
|
154
154
|
before do
|
155
155
|
get "/", @search_params.merge(:api_key => api_key_for(role))
|
156
156
|
@members = parsed_response_body['members']
|
157
157
|
end
|
158
|
-
|
158
|
+
|
159
159
|
use "return 200 Ok"
|
160
|
-
|
160
|
+
|
161
161
|
test "body should have no sources" do
|
162
162
|
titles = @members.map { |x| x['title'] }
|
163
163
|
assert_equal 0, titles.length
|
@@ -13,25 +13,25 @@ class SourcesGetManyResourceTest < ResourceTestCase
|
|
13
13
|
end
|
14
14
|
@source_titles = ["Source 0", "Source 1", "Source 2"].sort
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
after do
|
18
18
|
@sources.each { |x| x.destroy } if @sources
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
context "get /" do
|
22
22
|
context "anonymous" do
|
23
23
|
before do
|
24
24
|
get "/"
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
use "return 401 because the API key is missing"
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
context "incorrect API key" do
|
31
31
|
before do
|
32
32
|
get "/", :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
|
@@ -42,13 +42,13 @@ class SourcesGetManyResourceTest < ResourceTestCase
|
|
42
42
|
get "/", :api_key => api_key_for(role)
|
43
43
|
@members = parsed_response_body['members']
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
use "return 200 Ok"
|
47
|
-
|
47
|
+
|
48
48
|
test "body should have 3 sources" do
|
49
49
|
assert_equal 3, @members.length
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
test "body should have correct source titles" do
|
53
53
|
actual = @members.map { |e| e["title"] }
|
54
54
|
assert_equal @source_titles, actual.sort
|
@@ -5,13 +5,15 @@ class SourcesGetOneResourceTest < ResourceTestCase
|
|
5
5
|
include DataCatalog
|
6
6
|
|
7
7
|
def app; Sources end
|
8
|
-
|
8
|
+
|
9
9
|
before do
|
10
|
+
Timecop.freeze(Time.local(2010, 7, 4, 15, 0, 0))
|
10
11
|
@source = create_source
|
11
12
|
end
|
12
13
|
|
13
14
|
after do
|
14
15
|
@source.destroy
|
16
|
+
Timecop.return
|
15
17
|
end
|
16
18
|
|
17
19
|
context "get /:id" do
|
@@ -19,7 +21,7 @@ class SourcesGetOneResourceTest < ResourceTestCase
|
|
19
21
|
before do
|
20
22
|
get "/#{@source.id}"
|
21
23
|
end
|
22
|
-
|
24
|
+
|
23
25
|
use "return 401 because the API key is missing"
|
24
26
|
end
|
25
27
|
|
@@ -27,7 +29,7 @@ class SourcesGetOneResourceTest < ResourceTestCase
|
|
27
29
|
before do
|
28
30
|
get "/#{@source.id}", :api_key => BAD_API_KEY
|
29
31
|
end
|
30
|
-
|
32
|
+
|
31
33
|
use "return 401 because the API key is invalid"
|
32
34
|
end
|
33
35
|
end
|
@@ -37,7 +39,7 @@ class SourcesGetOneResourceTest < ResourceTestCase
|
|
37
39
|
before do
|
38
40
|
get "/#{FAKE_ID}", :api_key => api_key_for(role)
|
39
41
|
end
|
40
|
-
|
42
|
+
|
41
43
|
use "return 404 Not Found with empty response body"
|
42
44
|
end
|
43
45
|
|
@@ -50,15 +52,15 @@ class SourcesGetOneResourceTest < ResourceTestCase
|
|
50
52
|
)
|
51
53
|
get "/#{@source.id}", :api_key => api_key_for(role)
|
52
54
|
end
|
53
|
-
|
55
|
+
|
54
56
|
after do
|
55
57
|
@category.destroy
|
56
58
|
@categorization.destroy
|
57
59
|
end
|
58
|
-
|
60
|
+
|
59
61
|
use "return 200 Ok"
|
60
62
|
doc_properties %w(title url categories id created_at updated_at)
|
61
|
-
|
63
|
+
|
62
64
|
test "body should have correct categories" do
|
63
65
|
expected = [
|
64
66
|
{
|
@@ -69,13 +71,19 @@ class SourcesGetOneResourceTest < ResourceTestCase
|
|
69
71
|
]
|
70
72
|
assert_equal expected, parsed_response_body["categories"]
|
71
73
|
end
|
74
|
+
|
75
|
+
test "correct timestamp format" do
|
76
|
+
parsed = parsed_response_body
|
77
|
+
assert_equal Time.local(2010, 7, 4, 15, 0, 0), parsed['created_at']
|
78
|
+
assert_equal Time.local(2010, 7, 4, 15, 0, 0), parsed['updated_at']
|
79
|
+
end
|
72
80
|
end
|
73
|
-
|
81
|
+
|
74
82
|
context "#{role} : get /:id?show=all" do
|
75
83
|
before do
|
76
84
|
get "/#{@source.id}?show=all", :api_key => api_key_for(role)
|
77
85
|
end
|
78
|
-
|
86
|
+
|
79
87
|
use "return 200 Ok"
|
80
88
|
doc_properties %w(title url raw categories id created_at updated_at)
|
81
89
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../../helpers/resource_test_helper')
|
2
2
|
|
3
3
|
class SourcesPostResourceTest < ResourceTestCase
|
4
|
-
|
4
|
+
|
5
5
|
include DataCatalog
|
6
6
|
|
7
7
|
def app; Sources end
|
8
|
-
|
8
|
+
|
9
9
|
before do
|
10
10
|
@source_count = Source.all.length
|
11
11
|
@valid_params = {
|
@@ -20,7 +20,7 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
20
20
|
before do
|
21
21
|
post "/", @valid_params
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
use "return 401 because the API key is missing"
|
25
25
|
use "no change in source count"
|
26
26
|
end
|
@@ -29,7 +29,7 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
29
29
|
before do
|
30
30
|
post "/", @valid_params.merge(:api_key => BAD_API_KEY)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
use "return 401 because the API key is invalid"
|
34
34
|
use "no change in source count"
|
35
35
|
end
|
@@ -52,7 +52,7 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
52
52
|
before do
|
53
53
|
post "/", valid_params_for(role).merge(invalid => 9)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
use "return 401 because the API key is unauthorized"
|
57
57
|
use "no change in source count"
|
58
58
|
end
|
@@ -62,12 +62,12 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
62
62
|
before do
|
63
63
|
post "/", valid_params_for(role)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
use "return 401 because the API key is unauthorized"
|
67
67
|
use "no change in source count"
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
%w(curator).each do |role|
|
72
72
|
[:title, :url].each do |missing|
|
73
73
|
context "#{role} : post / but missing #{missing}" do
|
@@ -86,13 +86,13 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
86
86
|
before do
|
87
87
|
post "/", valid_params_for(role).merge(invalid => 9)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
use "return 400 Bad Request"
|
91
91
|
use "no change in source count"
|
92
92
|
invalid_param invalid
|
93
93
|
end
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
context "#{role} : post / with valid params" do
|
97
97
|
before do
|
98
98
|
post "/", valid_params_for(role)
|
@@ -101,7 +101,7 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
101
101
|
after do
|
102
102
|
Source.find_by_id(parsed_response_body["id"]).destroy
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
use "return 201 Created"
|
106
106
|
location_header "sources"
|
107
107
|
use "one new source"
|
@@ -137,13 +137,13 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
137
137
|
post "/", valid_params_for(role).
|
138
138
|
merge(@extra_admin_params).merge(invalid => 9)
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
use "return 400 Bad Request"
|
142
142
|
use "no change in source count"
|
143
143
|
invalid_param invalid
|
144
144
|
end
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
context "#{role} : post / with valid params" do
|
148
148
|
before do
|
149
149
|
post "/", valid_params_for(role).merge(@extra_admin_params)
|
@@ -152,7 +152,7 @@ class SourcesPostResourceTest < ResourceTestCase
|
|
152
152
|
after do
|
153
153
|
Source.find_by_id(parsed_response_body["id"]).destroy
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
use "return 201 Created"
|
157
157
|
location_header "sources"
|
158
158
|
use "one new source"
|