cellect-server 1.3.2 → 1.3.3
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.
- checksums.yaml +4 -4
- data/lib/cellect/server/api/helpers.rb +22 -0
- data/lib/cellect/server/api/sets.rb +5 -0
- data/lib/cellect/server/api/users.rb +1 -0
- data/lib/cellect/version.rb +1 -1
- data/spec/server/api/add_seen_spec.rb +6 -0
- data/spec/server/api/add_spec.rb +32 -0
- data/spec/server/api/remove_spec.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad603f50ab4f1cb53a8d2f67792f1acae0484d14
|
4
|
+
data.tar.gz: 8c9c4df72fbddd0e1ae3f357f14dc6c3bac2c384
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49c3dbb9447b9f12920b49c8af8350e536b7318c2225228a8b1f64b8dc5e33fe6a2515d8dc8d0a2b2c63a39b2f16af844d2e1b94d5935c9c8abd978339a94dcd
|
7
|
+
data.tar.gz: 1e772e5a66f80a5557be992a73460e46b132c6bbe2ccca8786988f56db0467bb531f288bad6d1dfdde97b501c9d3d1a980236db78f406c927e607810c7ef9555
|
@@ -10,6 +10,28 @@ module Cellect
|
|
10
10
|
error! 'Not Found', 404
|
11
11
|
end
|
12
12
|
|
13
|
+
def bad_request
|
14
|
+
error! 'Bad Request', 400
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate_param(hash, key, expect: nil)
|
18
|
+
hash[key] && hash[key].is_a?(expect)
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid_subject_id_update?
|
22
|
+
validate_param update_params, :subject_id, expect: Fixnum
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_group_id_update?
|
26
|
+
return true unless workflow.grouped?
|
27
|
+
validate_param update_params, :group_id, expect: Fixnum
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid_priority_update?
|
31
|
+
return true unless workflow.prioritized?
|
32
|
+
validate_param update_params, :priority, expect: Numeric
|
33
|
+
end
|
34
|
+
|
13
35
|
def selector_params
|
14
36
|
{
|
15
37
|
limit: param_to_int(:limit, default: 5),
|
@@ -23,6 +23,9 @@ module Cellect
|
|
23
23
|
# priority: float, required if prioritized
|
24
24
|
put :add do
|
25
25
|
return four_oh_four unless workflow
|
26
|
+
return bad_request unless valid_subject_id_update?
|
27
|
+
return bad_request unless valid_group_id_update?
|
28
|
+
return bad_request unless valid_priority_update?
|
26
29
|
workflow.add(update_params)
|
27
30
|
nil
|
28
31
|
end
|
@@ -35,6 +38,8 @@ module Cellect
|
|
35
38
|
# group_id: integer, required if grouped
|
36
39
|
put :remove do
|
37
40
|
return four_oh_four unless workflow
|
41
|
+
return bad_request unless valid_subject_id_update?
|
42
|
+
return bad_request unless valid_group_id_update?
|
38
43
|
workflow.remove(update_params)
|
39
44
|
nil
|
40
45
|
end
|
data/lib/cellect/version.rb
CHANGED
@@ -19,6 +19,12 @@ module Cellect::Server
|
|
19
19
|
put "/workflows/#{ workflow_type }/users/123/add_seen", subject_id: 123
|
20
20
|
expect(last_response.status).to eq 200
|
21
21
|
end
|
22
|
+
|
23
|
+
it 'should handle invalid params' do
|
24
|
+
put "/workflows/#{ workflow_type }/users/123/add_seen", subject_id: '%(*ERRRR)'
|
25
|
+
expect(last_response.status).to eql 400
|
26
|
+
expect(last_response.body).to match /Bad Request/
|
27
|
+
end
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
data/spec/server/api/add_spec.rb
CHANGED
@@ -33,6 +33,38 @@ module Cellect::Server
|
|
33
33
|
put "/workflows/#{ workflow_type }/add", opts
|
34
34
|
expect(last_response.status).to eq 200
|
35
35
|
end
|
36
|
+
|
37
|
+
it 'should handle invalid subject_ids' do
|
38
|
+
bad_opts = opts.merge subject_id: '%(*ERRRR)'
|
39
|
+
put "/workflows/#{ workflow_type }/add", bad_opts
|
40
|
+
expect(last_response.status).to eql 400
|
41
|
+
expect(last_response.body).to match /Bad Request/
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should handle invalid group_ids' do
|
45
|
+
if workflow.grouped?
|
46
|
+
bad_opts = opts.merge group_id: '%(*ERRRR)'
|
47
|
+
put "/workflows/#{ workflow_type }/add", bad_opts
|
48
|
+
expect(last_response.status).to eql 400
|
49
|
+
expect(last_response.body).to match /Bad Request/
|
50
|
+
else
|
51
|
+
put "/workflows/#{ workflow_type }/add", opts
|
52
|
+
expect(last_response).to be_ok
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should handle invalid priorities' do
|
57
|
+
bad_opts = opts.merge priority: '%(*ERRRR)'
|
58
|
+
|
59
|
+
if workflow.prioritized?
|
60
|
+
put "/workflows/#{ workflow_type }/add", bad_opts
|
61
|
+
expect(last_response.status).to eql 400
|
62
|
+
expect(last_response.body).to match /Bad Request/
|
63
|
+
else
|
64
|
+
put "/workflows/#{ workflow_type }/add", bad_opts
|
65
|
+
expect(last_response).to be_ok
|
66
|
+
end
|
67
|
+
end
|
36
68
|
end
|
37
69
|
end
|
38
70
|
end
|
@@ -28,6 +28,25 @@ module Cellect::Server
|
|
28
28
|
put "/workflows/#{ workflow_type }/remove", opts
|
29
29
|
expect(last_response.status).to eq 200
|
30
30
|
end
|
31
|
+
|
32
|
+
it 'should handle invalid subject_ids' do
|
33
|
+
bad_opts = opts.merge subject_id: '%(*ERRRR)'
|
34
|
+
put "/workflows/#{ workflow_type }/remove", bad_opts
|
35
|
+
expect(last_response.status).to eql 400
|
36
|
+
expect(last_response.body).to match /Bad Request/
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should handle invalid group_ids' do
|
40
|
+
if workflow.grouped?
|
41
|
+
bad_opts = opts.merge group_id: '%(*ERRRR)'
|
42
|
+
put "/workflows/#{ workflow_type }/remove", bad_opts
|
43
|
+
expect(last_response.status).to eql 400
|
44
|
+
expect(last_response.body).to match /Bad Request/
|
45
|
+
else
|
46
|
+
put "/workflows/#{ workflow_type }/remove", opts
|
47
|
+
expect(last_response).to be_ok
|
48
|
+
end
|
49
|
+
end
|
31
50
|
end
|
32
51
|
end
|
33
52
|
end
|