rack-action 0.2.1 → 0.3.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.
- data/lib/rack/action.rb +9 -3
- data/rack-action.gemspec +1 -1
- data/test/rack/action_test.rb +16 -0
- metadata +2 -3
data/lib/rack/action.rb
CHANGED
@@ -5,7 +5,7 @@ require 'rack/filters'
|
|
5
5
|
|
6
6
|
module Rack
|
7
7
|
class Action
|
8
|
-
VERSION = '0.
|
8
|
+
VERSION = '0.3.0'
|
9
9
|
|
10
10
|
extend Filters
|
11
11
|
|
@@ -95,9 +95,12 @@ module Rack
|
|
95
95
|
# and writes the JSON String to the response.
|
96
96
|
#
|
97
97
|
# @param [Hash] data The data
|
98
|
+
# @param [Hash] options The options
|
99
|
+
# @option options [Fixnum] :status The response status code
|
98
100
|
# @return [String] The JSON
|
99
|
-
def json(data)
|
101
|
+
def json(data={}, options={})
|
100
102
|
response[CONTENT_TYPE] = APPLICATION_JSON
|
103
|
+
response.status = options[:status] if options.has_key?(:status)
|
101
104
|
response.write JSON.generate(data)
|
102
105
|
end
|
103
106
|
|
@@ -105,9 +108,12 @@ module Rack
|
|
105
108
|
# and writes the pretty-formatted JSON String to the response.
|
106
109
|
#
|
107
110
|
# @param [Hash] data The data
|
111
|
+
# @param [Hash] options The options
|
112
|
+
# @option options [Fixnum] :status The response status code
|
108
113
|
# @return [String] The JSON
|
109
|
-
def pretty_json(data)
|
114
|
+
def pretty_json(data={}, options={})
|
110
115
|
response[CONTENT_TYPE] = APPLICATION_JSON
|
116
|
+
response.status = options[:status] if options.has_key?(:status)
|
111
117
|
response.write JSON.pretty_generate(data)
|
112
118
|
end
|
113
119
|
|
data/rack-action.gemspec
CHANGED
data/test/rack/action_test.rb
CHANGED
@@ -44,6 +44,22 @@ class Rack::ActionTest < RackTest
|
|
44
44
|
assert_equal [expected], response.body
|
45
45
|
end
|
46
46
|
|
47
|
+
def test_json_respond_with_status_code
|
48
|
+
app = Class.new(Rack::Action) do
|
49
|
+
def respond
|
50
|
+
json({:hello => "world"}, :status => 420)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
expected = %{{"hello":"world"}}
|
54
|
+
|
55
|
+
response = get app, "/"
|
56
|
+
|
57
|
+
assert_equal 420, response.status
|
58
|
+
assert_equal expected.length, response.length
|
59
|
+
assert_equal 'application/json', response["Content-Type"]
|
60
|
+
assert_equal [expected], response.body
|
61
|
+
end
|
62
|
+
|
47
63
|
def test_pretty_json_respond
|
48
64
|
app = Class.new(Rack::Action) do
|
49
65
|
def respond
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-action
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -76,4 +76,3 @@ summary: a small, simple framework for generating Rack responses
|
|
76
76
|
test_files:
|
77
77
|
- test/rack/action_test.rb
|
78
78
|
- test/rack_test.rb
|
79
|
-
has_rdoc:
|