deas-json 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/deas-json.gemspec +3 -2
- data/lib/deas-json/version.rb +1 -1
- data/lib/deas-json/view_handler.rb +13 -18
- data/test/unit/view_handler_tests.rb +43 -42
- metadata +83 -47
- checksums.yaml +0 -7
- /data/{LICENSE.txt → LICENSE} +0 -0
data/Gemfile
CHANGED
data/deas-json.gemspec
CHANGED
@@ -18,8 +18,9 @@ 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", ["~> 2.
|
21
|
+
gem.add_development_dependency("assert", ["~> 2.15"])
|
22
22
|
|
23
|
-
gem.add_dependency("deas",
|
23
|
+
gem.add_dependency("deas", ["~> 0.39"])
|
24
|
+
gem.add_dependency("much-plugin", ["~> 0.1"])
|
24
25
|
|
25
26
|
end
|
data/lib/deas-json/version.rb
CHANGED
@@ -1,40 +1,35 @@
|
|
1
1
|
require 'deas/view_handler'
|
2
|
+
require 'much-plugin'
|
2
3
|
|
3
4
|
module Deas::Json
|
4
5
|
|
5
6
|
module ViewHandler
|
7
|
+
include MuchPlugin
|
6
8
|
|
7
|
-
DEF_STATUS =
|
9
|
+
DEF_STATUS = 200.freeze
|
8
10
|
DEF_HEADERS = {}.freeze
|
9
11
|
DEF_BODY = '{}'.freeze
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
plugin_included do
|
14
|
+
include Deas::ViewHandler
|
15
|
+
include InstanceMethods
|
16
|
+
|
17
|
+
before_init{ content_type('.json', 'charset' => 'utf-8') }
|
16
18
|
end
|
17
19
|
|
18
20
|
module InstanceMethods
|
19
21
|
|
20
|
-
def initialize(*args)
|
21
|
-
super(*args)
|
22
|
-
content_type :json
|
23
|
-
end
|
24
|
-
|
25
22
|
private
|
26
23
|
|
27
24
|
# Some http clients will error when trying to parse an empty body when the
|
28
25
|
# content type is 'json'. This will default the body to a string that
|
29
26
|
# can be parsed to an empty json object
|
30
27
|
def halt(*args)
|
31
|
-
super(
|
32
|
-
|
33
|
-
|
34
|
-
args.
|
35
|
-
|
36
|
-
]
|
37
|
-
super(status, headers, body)
|
28
|
+
super(
|
29
|
+
args.first.instance_of?(::Fixnum) ? args.shift : DEF_STATUS,
|
30
|
+
args.first.kind_of?(::Hash) ? args.shift : DEF_HEADERS,
|
31
|
+
args.first.respond_to?(:each) ? args.shift : DEF_BODY
|
32
|
+
)
|
38
33
|
end
|
39
34
|
|
40
35
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'assert'
|
2
2
|
require 'deas-json/view_handler'
|
3
3
|
|
4
|
-
require 'deas/test_helpers'
|
5
4
|
require 'deas/view_handler'
|
6
5
|
|
7
6
|
module Deas::Json::ViewHandler
|
@@ -13,12 +12,16 @@ module Deas::Json::ViewHandler
|
|
13
12
|
end
|
14
13
|
subject{ @handler_class }
|
15
14
|
|
15
|
+
should "use much-plugin" do
|
16
|
+
assert_includes MuchPlugin, Deas::Json::ViewHandler
|
17
|
+
end
|
18
|
+
|
16
19
|
should "be a deas view handler" do
|
17
20
|
assert_includes Deas::ViewHandler, subject
|
18
21
|
end
|
19
22
|
|
20
23
|
should "know its default status, headers and body values" do
|
21
|
-
assert_equal
|
24
|
+
assert_equal 200, subject::DEF_STATUS
|
22
25
|
assert_equal Hash.new, subject::DEF_HEADERS
|
23
26
|
assert_equal '{}', subject::DEF_BODY
|
24
27
|
end
|
@@ -26,28 +29,32 @@ module Deas::Json::ViewHandler
|
|
26
29
|
end
|
27
30
|
|
28
31
|
class InitTests < UnitTests
|
29
|
-
include Deas::TestHelpers
|
32
|
+
include Deas::ViewHandler::TestHelpers
|
30
33
|
|
31
34
|
desc "when init"
|
32
35
|
setup do
|
36
|
+
@status = Factory.integer
|
37
|
+
@headers = { Factory.string => Factory.string }
|
38
|
+
@body = [Factory.text]
|
39
|
+
|
33
40
|
@runner = test_runner(@handler_class)
|
34
41
|
@handler = @runner.handler
|
35
42
|
end
|
36
43
|
subject{ @runner }
|
37
44
|
|
38
45
|
should "force its content type to :json" do
|
39
|
-
assert_equal
|
46
|
+
assert_equal '.json', subject.content_type_args.extname
|
47
|
+
exp = { 'charset' => 'utf-8' }
|
48
|
+
assert_equal exp, subject.content_type_args.params
|
40
49
|
end
|
41
50
|
|
42
51
|
should "use all given args" do
|
43
|
-
@handler.
|
44
|
-
@handler.headers = { Factory.string => Factory.string }
|
45
|
-
@handler.body = Factory.text
|
52
|
+
@handler.halt_args = [@status, @headers, @body]
|
46
53
|
response = @runner.run
|
47
54
|
|
48
|
-
assert_equal @
|
49
|
-
assert_equal @
|
50
|
-
assert_equal @
|
55
|
+
assert_equal @status, response.status
|
56
|
+
assert_equal @headers, response.headers
|
57
|
+
assert_equal @body, response.body
|
51
58
|
end
|
52
59
|
|
53
60
|
should "default its status, headers and body if not provided" do
|
@@ -59,60 +66,57 @@ module Deas::Json::ViewHandler
|
|
59
66
|
end
|
60
67
|
|
61
68
|
should "default its headers and body if not provided" do
|
62
|
-
@handler.
|
69
|
+
@handler.halt_args = [@status]
|
63
70
|
response = @runner.run
|
64
71
|
|
65
|
-
assert_equal @
|
66
|
-
assert_equal DEF_HEADERS,
|
67
|
-
assert_equal DEF_BODY,
|
72
|
+
assert_equal @status, response.status
|
73
|
+
assert_equal DEF_HEADERS, response.headers
|
74
|
+
assert_equal DEF_BODY, response.body
|
68
75
|
end
|
69
76
|
|
70
77
|
should "default its status and body if not provided" do
|
71
|
-
@handler.
|
78
|
+
@handler.halt_args = [@headers]
|
72
79
|
response = @runner.run
|
73
80
|
|
74
|
-
assert_equal DEF_STATUS,
|
75
|
-
assert_equal @
|
76
|
-
assert_equal DEF_BODY,
|
81
|
+
assert_equal DEF_STATUS, response.status
|
82
|
+
assert_equal @headers, response.headers
|
83
|
+
assert_equal DEF_BODY, response.body
|
77
84
|
end
|
78
85
|
|
79
86
|
should "default its status and headers if not provided" do
|
80
|
-
@handler.
|
87
|
+
@handler.halt_args = [@body]
|
81
88
|
response = @runner.run
|
82
89
|
|
83
|
-
assert_equal DEF_STATUS,
|
84
|
-
assert_equal DEF_HEADERS,
|
85
|
-
assert_equal @
|
90
|
+
assert_equal DEF_STATUS, response.status
|
91
|
+
assert_equal DEF_HEADERS, response.headers
|
92
|
+
assert_equal @body, response.body
|
86
93
|
end
|
87
94
|
|
88
95
|
should "default its status if not provided" do
|
89
|
-
@handler.
|
90
|
-
@handler.body = Factory.text
|
96
|
+
@handler.halt_args = [@headers, @body]
|
91
97
|
response = @runner.run
|
92
98
|
|
93
|
-
assert_equal DEF_STATUS,
|
94
|
-
assert_equal @
|
95
|
-
assert_equal @
|
99
|
+
assert_equal DEF_STATUS, response.status
|
100
|
+
assert_equal @headers, response.headers
|
101
|
+
assert_equal @body, response.body
|
96
102
|
end
|
97
103
|
|
98
104
|
should "default its headers if not provided" do
|
99
|
-
@handler.
|
100
|
-
@handler.body = Factory.text
|
105
|
+
@handler.halt_args = [@status, @body]
|
101
106
|
response = @runner.run
|
102
107
|
|
103
|
-
assert_equal @
|
104
|
-
assert_equal DEF_HEADERS,
|
105
|
-
assert_equal @
|
108
|
+
assert_equal @status, response.status
|
109
|
+
assert_equal DEF_HEADERS, response.headers
|
110
|
+
assert_equal @body, response.body
|
106
111
|
end
|
107
112
|
|
108
113
|
should "default its body if not provided" do
|
109
|
-
@handler.
|
110
|
-
@handler.headers = { Factory.string => Factory.string }
|
114
|
+
@handler.halt_args = [@status, @headers]
|
111
115
|
response = @runner.run
|
112
116
|
|
113
|
-
assert_equal @
|
114
|
-
assert_equal @
|
115
|
-
assert_equal DEF_BODY,
|
117
|
+
assert_equal @status, response.status
|
118
|
+
assert_equal @headers, response.headers
|
119
|
+
assert_equal DEF_BODY, response.body
|
116
120
|
end
|
117
121
|
|
118
122
|
end
|
@@ -120,12 +124,9 @@ module Deas::Json::ViewHandler
|
|
120
124
|
class TestJsonHandler
|
121
125
|
include Deas::Json::ViewHandler
|
122
126
|
|
123
|
-
attr_accessor :
|
127
|
+
attr_accessor :halt_args
|
124
128
|
|
125
|
-
def run
|
126
|
-
args = [status, headers, body].compact
|
127
|
-
halt *args
|
128
|
-
end
|
129
|
+
def run!; halt *(@halt_args || []).dup; end
|
129
130
|
|
130
131
|
end
|
131
132
|
|
metadata
CHANGED
@@ -1,55 +1,82 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: deas-json
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
5
11
|
platform: ruby
|
6
|
-
authors:
|
12
|
+
authors:
|
7
13
|
- Kelly Redding
|
8
14
|
- Collin Redding
|
9
15
|
autorequire:
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
|
19
|
+
date: 2015-11-24 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 29
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 15
|
31
|
+
version: "2.15"
|
21
32
|
type: :development
|
33
|
+
name: assert
|
34
|
+
version_requirements: *id001
|
22
35
|
prerelease: false
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 69
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 39
|
46
|
+
version: "0.39"
|
47
|
+
type: :runtime
|
29
48
|
name: deas
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
49
|
+
version_requirements: *id002
|
50
|
+
prerelease: false
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 9
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
- 1
|
61
|
+
version: "0.1"
|
35
62
|
type: :runtime
|
63
|
+
name: much-plugin
|
64
|
+
version_requirements: *id003
|
36
65
|
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '0.34'
|
42
66
|
description: JSON helpers for Deas apps
|
43
|
-
email:
|
67
|
+
email:
|
44
68
|
- kelly@kellyredding.com
|
45
69
|
- collin.redding@me.com
|
46
70
|
executables: []
|
71
|
+
|
47
72
|
extensions: []
|
73
|
+
|
48
74
|
extra_rdoc_files: []
|
49
|
-
|
50
|
-
|
75
|
+
|
76
|
+
files:
|
77
|
+
- .gitignore
|
51
78
|
- Gemfile
|
52
|
-
- LICENSE
|
79
|
+
- LICENSE
|
53
80
|
- README.md
|
54
81
|
- Rakefile
|
55
82
|
- deas-json.gemspec
|
@@ -62,30 +89,39 @@ files:
|
|
62
89
|
- test/unit/view_handler_tests.rb
|
63
90
|
- tmp/.gitkeep
|
64
91
|
homepage: http://github.com/redding/deas-json
|
65
|
-
licenses:
|
92
|
+
licenses:
|
66
93
|
- MIT
|
67
|
-
metadata: {}
|
68
94
|
post_install_message:
|
69
95
|
rdoc_options: []
|
70
|
-
|
96
|
+
|
97
|
+
require_paths:
|
71
98
|
- lib
|
72
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
-
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
74
102
|
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
78
|
-
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
79
111
|
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
82
117
|
requirements: []
|
118
|
+
|
83
119
|
rubyforge_project:
|
84
|
-
rubygems_version:
|
120
|
+
rubygems_version: 1.8.29
|
85
121
|
signing_key:
|
86
|
-
specification_version:
|
122
|
+
specification_version: 3
|
87
123
|
summary: JSON helpers for Deas apps
|
88
|
-
test_files:
|
124
|
+
test_files:
|
89
125
|
- test/helper.rb
|
90
126
|
- test/support/factory.rb
|
91
127
|
- test/unit/view_handler_tests.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 55107842eeb3637f778f8e16577e0bee2fd0c200
|
4
|
-
data.tar.gz: d49484cda7e61e455a73545c21b3042d058b1215
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 0745d0de048a72bdcd85fb0a0f02116ae461cbe668eda971fe990abcf8ea4e36ffa5891af4979200fa6185c711fa404ba07d9a17be75e974c7db27be3a8ac29a
|
7
|
-
data.tar.gz: f9c60e7d663ae35c2a26ee4763b48687ff89686434db9185f990d940de36b63179b09202ae19e2e05024ab28cfe4aa0a8620e2c1d6e6eab4a8f350a2407a5aae
|
/data/{LICENSE.txt → LICENSE}
RENAMED
File without changes
|