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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61ae5145b44df2f3936dcf70381fe6385a4ee5df
4
- data.tar.gz: 1490ab77c5cafdc5f38c1f40cc11700b7c78e2ad
3
+ metadata.gz: 55107842eeb3637f778f8e16577e0bee2fd0c200
4
+ data.tar.gz: d49484cda7e61e455a73545c21b3042d058b1215
5
5
  SHA512:
6
- metadata.gz: df4da1f716409cb2ed13c095d088c0de7f080da51b2ae29d4a368ce705fa9f3e75c15bd3c02bffc557f88525d5fa67361e7ca44206f214b0469e712c7c0e859e
7
- data.tar.gz: 5462a69cfbbf3e42d502b6655b5665dc0b51ca5e74b033e3936cd97e5d26981280a242a5cc267cc8bff1d3737c2d62371a1d5fa84ed8d479215b187daa68d8a4
6
+ metadata.gz: 0745d0de048a72bdcd85fb0a0f02116ae461cbe668eda971fe990abcf8ea4e36ffa5891af4979200fa6185c711fa404ba07d9a17be75e974c7db27be3a8ac29a
7
+ data.tar.gz: f9c60e7d663ae35c2a26ee4763b48687ff89686434db9185f990d940de36b63179b09202ae19e2e05024ab28cfe4aa0a8620e2c1d6e6eab4a8f350a2407a5aae
@@ -1,4 +1,4 @@
1
1
  module Deas; end
2
2
  module Deas::Json
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
@@ -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(status, headers = {}, body = '{}')
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 "default its body and headers if not provided" do
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({}, response.headers)
42
- assert_equal '{}', response.body
66
+ assert_equal DEF_HEADERS, response.headers
67
+ assert_equal DEF_BODY, response.body
43
68
  end
44
69
 
45
- should "allow halting with a body and headers" do
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 @handler.body, response.body
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.1.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-07 00:00:00.000000000 Z
12
+ date: 2015-06-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: assert