deas-json 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/deas-json.gemspec +3 -2
- data/lib/deas-json/version.rb +1 -1
- data/lib/deas-json/view_handler.rb +3 -23
- data/test/system/rack_tests.rb +85 -0
- data/test/unit/view_handler_tests.rb +3 -97
- metadata +21 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f10592e8ae7579a179ff09c746c33237428123fc3f236d33f4aed052afde257636696eb27a9301d3f85a297a3e3563ce7213b6fa45f0d4aaed107775cf0b2860
|
4
|
+
data.tar.gz: bd4249d3019e86146d10a0e4686b8e67dab7e7f2e7852a8a59c069bcbbbfe91bde051be23569ee8afb26ebde75ae2ccc6a5ac651afc348feedb746e4b82352e8
|
5
5
|
SHA1:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 106b45bc2305eab2e914aa6ba24f7829716f09b8
|
7
|
+
data.tar.gz: 6b37408a031c490bb156b5429b67df18c2730286
|
data/deas-json.gemspec
CHANGED
@@ -18,9 +18,10 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.add_development_dependency("assert",
|
21
|
+
gem.add_development_dependency("assert", ["~> 2.16.3"])
|
22
|
+
gem.add_development_dependency("assert-rack-test", ["~> 1.0.5"])
|
22
23
|
|
23
|
-
gem.add_dependency("deas", ["~> 0.43.
|
24
|
+
gem.add_dependency("deas", ["~> 0.43.5"])
|
24
25
|
gem.add_dependency("much-plugin", ["~> 0.2.0"])
|
25
26
|
|
26
27
|
end
|
data/lib/deas-json/version.rb
CHANGED
@@ -6,33 +6,13 @@ module Deas::Json
|
|
6
6
|
module ViewHandler
|
7
7
|
include MuchPlugin
|
8
8
|
|
9
|
-
DEF_STATUS = 200.freeze
|
10
|
-
DEF_HEADERS = {}.freeze
|
11
|
-
DEF_BODY = '{}'.freeze
|
12
|
-
|
13
9
|
plugin_included do
|
14
10
|
include Deas::ViewHandler
|
15
|
-
include InstanceMethods
|
16
|
-
|
17
|
-
before_init{ content_type('.json', 'charset' => 'utf-8') }
|
18
|
-
end
|
19
11
|
|
20
|
-
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
# Some http clients will error when trying to parse an empty body when the
|
25
|
-
# content type is 'json'. This will default the body to a string that
|
26
|
-
# can be parsed to an empty json object.
|
27
|
-
# We call the `body` helper method to make sure it adhere's to the Rack spec
|
28
|
-
def halt(*args)
|
29
|
-
super(
|
30
|
-
args.first.instance_of?(::Fixnum) ? args.shift : DEF_STATUS,
|
31
|
-
args.first.kind_of?(::Hash) ? args.shift : DEF_HEADERS,
|
32
|
-
body(!args.first.to_s.empty? ? args.shift : DEF_BODY)
|
33
|
-
)
|
34
|
-
end
|
12
|
+
default_status 200
|
13
|
+
default_body ['{}']
|
35
14
|
|
15
|
+
before_init{ content_type('.json', 'charset' => 'utf-8') }
|
36
16
|
end
|
37
17
|
|
38
18
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'deas-json'
|
3
|
+
|
4
|
+
require 'assert-rack-test'
|
5
|
+
require 'deas'
|
6
|
+
|
7
|
+
module Deas::Json
|
8
|
+
|
9
|
+
class RackTestsContext < Assert::Context
|
10
|
+
include Assert::Rack::Test
|
11
|
+
|
12
|
+
def app; @app; end
|
13
|
+
end
|
14
|
+
|
15
|
+
class RackTests < RackTestsContext
|
16
|
+
desc "a Deas server rack app"
|
17
|
+
setup do
|
18
|
+
@status_val = Factory.integer
|
19
|
+
@body_val = Factory.text
|
20
|
+
|
21
|
+
@app = DeasTestServer.new
|
22
|
+
end
|
23
|
+
|
24
|
+
should "use given status/body values" do
|
25
|
+
get '/test.json', {
|
26
|
+
'status_val' => @status_val,
|
27
|
+
'body_val' => @body_val
|
28
|
+
}
|
29
|
+
|
30
|
+
assert_equal @status_val, last_response.status
|
31
|
+
assert_equal @body_val, last_response.body
|
32
|
+
end
|
33
|
+
|
34
|
+
should "default its status and body if not provided" do
|
35
|
+
get '/test.json'
|
36
|
+
|
37
|
+
assert_equal TestJsonHandler.default_status, last_response.status
|
38
|
+
assert_equal TestJsonHandler.default_body.first, last_response.body
|
39
|
+
end
|
40
|
+
|
41
|
+
should "default its body if not provided" do
|
42
|
+
get '/test.json', {
|
43
|
+
'status_val' => @status_val
|
44
|
+
}
|
45
|
+
|
46
|
+
assert_equal @status_val, last_response.status
|
47
|
+
assert_equal TestJsonHandler.default_body.first, last_response.body
|
48
|
+
end
|
49
|
+
|
50
|
+
should "default its status if not provided" do
|
51
|
+
get '/test.json', {
|
52
|
+
'body_val' => @body_val
|
53
|
+
}
|
54
|
+
|
55
|
+
assert_equal TestJsonHandler.default_status, last_response.status
|
56
|
+
assert_equal @body_val, last_response.body
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
class DeasTestServer
|
64
|
+
include Deas::Server
|
65
|
+
|
66
|
+
router do
|
67
|
+
get '/test.json', 'TestJsonHandler'
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
class TestJsonHandler
|
73
|
+
include Deas::Json::ViewHandler
|
74
|
+
|
75
|
+
attr_accessor :halt_args
|
76
|
+
|
77
|
+
def run!
|
78
|
+
halt *([
|
79
|
+
(params['status_val'].to_i if params['status_val']),
|
80
|
+
params['body_val']
|
81
|
+
].compact)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
@@ -20,10 +20,9 @@ module Deas::Json::ViewHandler
|
|
20
20
|
assert_includes Deas::ViewHandler, subject
|
21
21
|
end
|
22
22
|
|
23
|
-
should "
|
24
|
-
assert_equal 200,
|
25
|
-
assert_equal
|
26
|
-
assert_equal '{}', subject::DEF_BODY
|
23
|
+
should "override the default status and body values" do
|
24
|
+
assert_equal 200, subject.default_status
|
25
|
+
assert_equal ['{}'], subject.default_body
|
27
26
|
end
|
28
27
|
|
29
28
|
end
|
@@ -33,10 +32,6 @@ module Deas::Json::ViewHandler
|
|
33
32
|
|
34
33
|
desc "when init"
|
35
34
|
setup do
|
36
|
-
@status = Factory.integer
|
37
|
-
@headers = { Factory.string => Factory.string }
|
38
|
-
@body = [Factory.text]
|
39
|
-
|
40
35
|
@runner = test_runner(@handler_class)
|
41
36
|
@handler = @runner.handler
|
42
37
|
end
|
@@ -48,95 +43,6 @@ module Deas::Json::ViewHandler
|
|
48
43
|
assert_equal exp, subject.content_type_args.params
|
49
44
|
end
|
50
45
|
|
51
|
-
should "use all given args" do
|
52
|
-
@handler.halt_args = [@status, @headers, @body]
|
53
|
-
response = @runner.run
|
54
|
-
|
55
|
-
assert_equal @status, response.status
|
56
|
-
assert_equal @headers, response.headers
|
57
|
-
assert_equal @body, response.body
|
58
|
-
end
|
59
|
-
|
60
|
-
should "should adhere to the rack spec for its body" do
|
61
|
-
@handler.halt_args = [@status, @headers, @body.first]
|
62
|
-
response = @runner.run
|
63
|
-
|
64
|
-
assert_equal @status, response.status
|
65
|
-
assert_equal @headers, response.headers
|
66
|
-
assert_equal @body, response.body
|
67
|
-
end
|
68
|
-
|
69
|
-
should "default its status, headers and body if not provided" do
|
70
|
-
response = @runner.run
|
71
|
-
|
72
|
-
assert_equal DEF_STATUS, response.status
|
73
|
-
assert_equal DEF_HEADERS, response.headers
|
74
|
-
assert_equal [DEF_BODY], response.body
|
75
|
-
end
|
76
|
-
|
77
|
-
should "default its headers and body if not provided" do
|
78
|
-
@handler.halt_args = [@status]
|
79
|
-
response = @runner.run
|
80
|
-
|
81
|
-
assert_equal @status, response.status
|
82
|
-
assert_equal DEF_HEADERS, response.headers
|
83
|
-
assert_equal [DEF_BODY], response.body
|
84
|
-
end
|
85
|
-
|
86
|
-
should "default its status and body if not provided" do
|
87
|
-
@handler.halt_args = [@headers]
|
88
|
-
response = @runner.run
|
89
|
-
|
90
|
-
assert_equal DEF_STATUS, response.status
|
91
|
-
assert_equal @headers, response.headers
|
92
|
-
assert_equal [DEF_BODY], response.body
|
93
|
-
end
|
94
|
-
|
95
|
-
should "default its status and headers if not provided" do
|
96
|
-
@handler.halt_args = [@body]
|
97
|
-
response = @runner.run
|
98
|
-
|
99
|
-
assert_equal DEF_STATUS, response.status
|
100
|
-
assert_equal DEF_HEADERS, response.headers
|
101
|
-
assert_equal @body, response.body
|
102
|
-
end
|
103
|
-
|
104
|
-
should "default its status if not provided" do
|
105
|
-
@handler.halt_args = [@headers, @body]
|
106
|
-
response = @runner.run
|
107
|
-
|
108
|
-
assert_equal DEF_STATUS, response.status
|
109
|
-
assert_equal @headers, response.headers
|
110
|
-
assert_equal @body, response.body
|
111
|
-
end
|
112
|
-
|
113
|
-
should "default its headers if not provided" do
|
114
|
-
@handler.halt_args = [@status, @body]
|
115
|
-
response = @runner.run
|
116
|
-
|
117
|
-
assert_equal @status, response.status
|
118
|
-
assert_equal DEF_HEADERS, response.headers
|
119
|
-
assert_equal @body, response.body
|
120
|
-
end
|
121
|
-
|
122
|
-
should "default its body if not provided" do
|
123
|
-
@handler.halt_args = [@status, @headers, [nil, ''].sample]
|
124
|
-
response = @runner.run
|
125
|
-
|
126
|
-
assert_equal @status, response.status
|
127
|
-
assert_equal @headers, response.headers
|
128
|
-
assert_equal [DEF_BODY], response.body
|
129
|
-
end
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
class TestJsonHandler
|
134
|
-
include Deas::Json::ViewHandler
|
135
|
-
|
136
|
-
attr_accessor :halt_args
|
137
|
-
|
138
|
-
def run!; halt *(@halt_args || []).dup; end
|
139
|
-
|
140
46
|
end
|
141
47
|
|
142
48
|
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.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2018-04-
|
13
|
+
date: 2018-04-19 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: assert
|
@@ -23,25 +23,35 @@ dependencies:
|
|
23
23
|
type: :development
|
24
24
|
version_requirements: *id001
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
26
|
+
name: assert-rack-test
|
27
27
|
prerelease: false
|
28
28
|
requirement: &id002 !ruby/object:Gem::Requirement
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.
|
33
|
-
type: :
|
32
|
+
version: 1.0.5
|
33
|
+
type: :development
|
34
34
|
version_requirements: *id002
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: deas
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id003 !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 0.
|
42
|
+
version: 0.43.5
|
43
43
|
type: :runtime
|
44
44
|
version_requirements: *id003
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: much-plugin
|
47
|
+
prerelease: false
|
48
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 0.2.0
|
53
|
+
type: :runtime
|
54
|
+
version_requirements: *id004
|
45
55
|
description: JSON helpers for Deas apps
|
46
56
|
email:
|
47
57
|
- kelly@kellyredding.com
|
@@ -64,6 +74,7 @@ files:
|
|
64
74
|
- log/.gitkeep
|
65
75
|
- test/helper.rb
|
66
76
|
- test/support/factory.rb
|
77
|
+
- test/system/rack_tests.rb
|
67
78
|
- test/unit/view_handler_tests.rb
|
68
79
|
- tmp/.gitkeep
|
69
80
|
homepage: http://github.com/redding/deas-json
|
@@ -78,13 +89,13 @@ require_paths:
|
|
78
89
|
- lib
|
79
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
91
|
requirements:
|
81
|
-
- &
|
92
|
+
- &id005
|
82
93
|
- ">="
|
83
94
|
- !ruby/object:Gem::Version
|
84
95
|
version: "0"
|
85
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
97
|
requirements:
|
87
|
-
- *
|
98
|
+
- *id005
|
88
99
|
requirements: []
|
89
100
|
|
90
101
|
rubyforge_project:
|
@@ -95,4 +106,5 @@ summary: JSON helpers for Deas apps
|
|
95
106
|
test_files:
|
96
107
|
- test/helper.rb
|
97
108
|
- test/support/factory.rb
|
109
|
+
- test/system/rack_tests.rb
|
98
110
|
- test/unit/view_handler_tests.rb
|