deas-json 0.1.0 → 0.2.0
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/deas-json/version.rb +1 -1
- data/lib/deas-json/view_handler.rb +11 -1
- data/test/unit/view_handler_tests.rb +68 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55107842eeb3637f778f8e16577e0bee2fd0c200
|
4
|
+
data.tar.gz: d49484cda7e61e455a73545c21b3042d058b1215
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0745d0de048a72bdcd85fb0a0f02116ae461cbe668eda971fe990abcf8ea4e36ffa5891af4979200fa6185c711fa404ba07d9a17be75e974c7db27be3a8ac29a
|
7
|
+
data.tar.gz: f9c60e7d663ae35c2a26ee4763b48687ff89686434db9185f990d940de36b63179b09202ae19e2e05024ab28cfe4aa0a8620e2c1d6e6eab4a8f350a2407a5aae
|
data/lib/deas-json/version.rb
CHANGED
@@ -4,6 +4,10 @@ module Deas::Json
|
|
4
4
|
|
5
5
|
module ViewHandler
|
6
6
|
|
7
|
+
DEF_STATUS = nil
|
8
|
+
DEF_HEADERS = {}.freeze
|
9
|
+
DEF_BODY = '{}'.freeze
|
10
|
+
|
7
11
|
def self.included(klass)
|
8
12
|
klass.class_eval do
|
9
13
|
include Deas::ViewHandler
|
@@ -23,7 +27,13 @@ module Deas::Json
|
|
23
27
|
# Some http clients will error when trying to parse an empty body when the
|
24
28
|
# content type is 'json'. This will default the body to a string that
|
25
29
|
# can be parsed to an empty json object
|
26
|
-
def halt(
|
30
|
+
def halt(*args)
|
31
|
+
super(DEF_STATUS, DEF_HEADERS, DEF_BODY) if args.empty?
|
32
|
+
body, headers, status = [
|
33
|
+
!args.last.kind_of?(::Hash) && !args.last.kind_of?(::Integer) ? args.pop : DEF_BODY,
|
34
|
+
args.last.kind_of?(::Hash) ? args.pop : DEF_HEADERS,
|
35
|
+
args.first.kind_of?(::Integer) ? args.first : DEF_STATUS
|
36
|
+
]
|
27
37
|
super(status, headers, body)
|
28
38
|
end
|
29
39
|
|
@@ -17,6 +17,12 @@ module Deas::Json::ViewHandler
|
|
17
17
|
assert_includes Deas::ViewHandler, subject
|
18
18
|
end
|
19
19
|
|
20
|
+
should "know its default status, headers and body values" do
|
21
|
+
assert_equal nil, subject::DEF_STATUS
|
22
|
+
assert_equal Hash.new, subject::DEF_HEADERS
|
23
|
+
assert_equal '{}', subject::DEF_BODY
|
24
|
+
end
|
25
|
+
|
20
26
|
end
|
21
27
|
|
22
28
|
class InitTests < UnitTests
|
@@ -33,24 +39,80 @@ module Deas::Json::ViewHandler
|
|
33
39
|
assert_equal :json, subject.content_type.value
|
34
40
|
end
|
35
41
|
|
36
|
-
should "
|
42
|
+
should "use all given args" do
|
43
|
+
@handler.status = Factory.integer
|
44
|
+
@handler.headers = { Factory.string => Factory.string }
|
45
|
+
@handler.body = Factory.text
|
46
|
+
response = @runner.run
|
47
|
+
|
48
|
+
assert_equal @handler.status, response.status
|
49
|
+
assert_equal @handler.headers, response.headers
|
50
|
+
assert_equal @handler.body, response.body
|
51
|
+
end
|
52
|
+
|
53
|
+
should "default its status, headers and body if not provided" do
|
54
|
+
response = @runner.run
|
55
|
+
|
56
|
+
assert_equal DEF_STATUS, response.status
|
57
|
+
assert_equal DEF_HEADERS, response.headers
|
58
|
+
assert_equal DEF_BODY, response.body
|
59
|
+
end
|
60
|
+
|
61
|
+
should "default its headers and body if not provided" do
|
37
62
|
@handler.status = Factory.integer
|
38
63
|
response = @runner.run
|
39
64
|
|
40
65
|
assert_equal @handler.status, response.status
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
66
|
+
assert_equal DEF_HEADERS, response.headers
|
67
|
+
assert_equal DEF_BODY, response.body
|
43
68
|
end
|
44
69
|
|
45
|
-
should "
|
70
|
+
should "default its status and body if not provided" do
|
71
|
+
@handler.headers = { Factory.string => Factory.string }
|
72
|
+
response = @runner.run
|
73
|
+
|
74
|
+
assert_equal DEF_STATUS, response.status
|
75
|
+
assert_equal @handler.headers, response.headers
|
76
|
+
assert_equal DEF_BODY, response.body
|
77
|
+
end
|
78
|
+
|
79
|
+
should "default its status and headers if not provided" do
|
80
|
+
@handler.body = Factory.text
|
81
|
+
response = @runner.run
|
82
|
+
|
83
|
+
assert_equal DEF_STATUS, response.status
|
84
|
+
assert_equal DEF_HEADERS, response.headers
|
85
|
+
assert_equal @handler.body, response.body
|
86
|
+
end
|
87
|
+
|
88
|
+
should "default its status if not provided" do
|
89
|
+
@handler.headers = { Factory.string => Factory.string }
|
90
|
+
@handler.body = Factory.text
|
91
|
+
response = @runner.run
|
92
|
+
|
93
|
+
assert_equal DEF_STATUS, response.status
|
94
|
+
assert_equal @handler.headers, response.headers
|
95
|
+
assert_equal @handler.body, response.body
|
96
|
+
end
|
97
|
+
|
98
|
+
should "default its headers if not provided" do
|
99
|
+
@handler.status = Factory.integer
|
100
|
+
@handler.body = Factory.text
|
101
|
+
response = @runner.run
|
102
|
+
|
103
|
+
assert_equal @handler.status, response.status
|
104
|
+
assert_equal DEF_HEADERS, response.headers
|
105
|
+
assert_equal @handler.body, response.body
|
106
|
+
end
|
107
|
+
|
108
|
+
should "default its body if not provided" do
|
46
109
|
@handler.status = Factory.integer
|
47
110
|
@handler.headers = { Factory.string => Factory.string }
|
48
|
-
@handler.body = Factory.text
|
49
111
|
response = @runner.run
|
50
112
|
|
51
113
|
assert_equal @handler.status, response.status
|
52
114
|
assert_equal @handler.headers, response.headers
|
53
|
-
assert_equal
|
115
|
+
assert_equal DEF_BODY, response.body
|
54
116
|
end
|
55
117
|
|
56
118
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deas-json
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-06-
|
12
|
+
date: 2015-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: assert
|