restrack 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,7 +23,7 @@ module RESTRack
23
23
  @post_params = parse_body( @request )
24
24
  @get_params = parse_query_string( @request )
25
25
  @params = {}
26
- # TODO: Test this!
26
+ # TODO: symbolize!
27
27
  if @post_params.respond_to?(:merge)
28
28
  @params = @post_params.merge( @get_params )
29
29
  else
@@ -107,6 +107,12 @@ module RESTRack
107
107
  def parse_body(request)
108
108
  post_params = request.body.read
109
109
  RESTRack.log.debug "{#{@request_id}} #{request.content_type} raw POST data in:\n" + post_params
110
+ if RESTRack::CONFIG[:TRANSCODE]
111
+ post_params.encode!( RESTRack::CONFIG[:TRANSCODE] )
112
+ end
113
+ if RESTRack::CONFIG[:FORCE_ENCODING]
114
+ post_params = post_params.force_encoding( RESTRack::CONFIG[:FORCE_ENCODING] )
115
+ end
110
116
  unless request.content_type.blank?
111
117
  request_mime_type = MIME::Type.new( request.content_type )
112
118
  if request_mime_type.like?( RESTRack.mime_type_for( :JSON ) )
@@ -1,3 +1,3 @@
1
1
  module RESTRack
2
- VERSION = "1.4.0"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -24,4 +24,10 @@
24
24
  # These are the resources which cannot be accessed from the root of your web service. Use either this or ROOT_RESOURCE_ACCEPT as a blacklist or whitelist to establish routing (relationships defined in resource controllers define further routing).
25
25
  :ROOT_RESOURCE_DENY: [ baz ]
26
26
 
27
- :SHOW_STACK: true
27
+ # The stack trace will not be added to 500 response body by default, set to true to enable.
28
+ :SHOW_STACK: true
29
+
30
+ # String#encode will be called when this value is set
31
+ #:TRANSCODE: ISO-8859-1 # UTF-8
32
+ # String#force_encoding will be called when this value is set
33
+ #:FORCE_ENCODING: ISO-8859-1 # UTF-8
@@ -112,4 +112,8 @@ class SampleApp::FooBarController < RESTRack::ResourceController
112
112
  return [1,1,2,3,5,8,13,21,34]
113
113
  end
114
114
 
115
+ def show_encoding
116
+ return @post_params.encoding.to_s
117
+ end
118
+
115
119
  end
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
1
3
  require 'rubygems'
2
4
  require 'test/unit'
3
5
  require 'rack/test'
@@ -141,4 +143,138 @@ class SampleApp::TestResourceRequest < Test::Unit::TestCase
141
143
  assert_equal 403, output[0]
142
144
  end
143
145
 
146
+ def test_transcode_defined
147
+ RESTRack::CONFIG.delete(:TRANSCODE)
148
+ RESTRack::CONFIG.delete(:FORCE_ENCODING)
149
+ RESTRack::CONFIG[:TRANSCODE] = 'ISO-8859-1'
150
+
151
+ env = Rack::MockRequest.env_for('/foo_bar/show_encoding', {
152
+ :method => 'POST',
153
+ :params => %Q|[
154
+ {
155
+ "bar": "baz"
156
+ }
157
+ ]|
158
+ })
159
+ output = ''
160
+ assert_nothing_raised do
161
+ output = @ws.call(env)
162
+ end
163
+ assert_equal ["\"ISO-8859-1\""], output[2]
164
+
165
+ env = Rack::MockRequest.env_for('/foo_bar/show_encoding', {
166
+ :method => 'POST',
167
+ :params => %Q|[
168
+ {
169
+ "bar": "€"
170
+ }
171
+ ]|
172
+ })
173
+ output = ''
174
+ assert_nothing_raised do
175
+ output = @ws.call(env)
176
+ end
177
+ assert_equal 500, output[0]
178
+ end
179
+
180
+ def test_transcode_not_defined
181
+ RESTRack::CONFIG.delete(:TRANSCODE)
182
+ RESTRack::CONFIG.delete(:FORCE_ENCODING)
183
+
184
+ env = Rack::MockRequest.env_for('/foo_bar/show_encoding', {
185
+ :method => 'POST',
186
+ :params => %Q|[
187
+ {
188
+ "bar": "baz"
189
+ }
190
+ ]|
191
+ })
192
+ output = ''
193
+ assert_nothing_raised do
194
+ output = @ws.call(env)
195
+ end
196
+ assert_equal ["\"ASCII-8BIT\""], output[2]
197
+
198
+ env = Rack::MockRequest.env_for('/foo_bar/show_encoding', {
199
+ :method => 'POST',
200
+ :params => %Q|[
201
+ {
202
+ "bar": "€"
203
+ }
204
+ ]|
205
+ })
206
+ output = ''
207
+ assert_nothing_raised do
208
+ output = @ws.call(env)
209
+ end
210
+ assert_equal 200, output[0]
211
+ end
212
+
213
+ def test_force_encoding_defined
214
+ RESTRack::CONFIG.delete(:TRANSCODE)
215
+ RESTRack::CONFIG.delete(:FORCE_ENCODING)
216
+ RESTRack::CONFIG[:FORCE_ENCODING] = 'ISO-8859-1'
217
+
218
+ env = Rack::MockRequest.env_for('/foo_bar/show_encoding', {
219
+ :method => 'POST',
220
+ :params => %Q|[
221
+ {
222
+ "bar": "baz"
223
+ }
224
+ ]|
225
+ })
226
+ output = ''
227
+ assert_nothing_raised do
228
+ output = @ws.call(env)
229
+ end
230
+ assert_equal ["\"ISO-8859-1\""], output[2]
231
+
232
+ env = Rack::MockRequest.env_for('/foo_bar/show_encoding', {
233
+ :method => 'POST',
234
+ :params => %Q|[
235
+ {
236
+ "bar": "€"
237
+ }
238
+ ]|
239
+ })
240
+ output = ''
241
+ assert_nothing_raised do
242
+ output = @ws.call(env)
243
+ end
244
+ assert_equal 200, output[0]
245
+ end
246
+
247
+ def test_force_encoding_not_defined
248
+ RESTRack::CONFIG.delete(:TRANSCODE)
249
+ RESTRack::CONFIG.delete(:FORCE_ENCODING)
250
+
251
+ env = Rack::MockRequest.env_for('/foo_bar/show_encoding', {
252
+ :method => 'POST',
253
+ :params => %Q|[
254
+ {
255
+ "bar": "baz"
256
+ }
257
+ ]|
258
+ })
259
+ output = ''
260
+ assert_nothing_raised do
261
+ output = @ws.call(env)
262
+ end
263
+ assert_equal ["\"ASCII-8BIT\""], output[2]
264
+
265
+ env = Rack::MockRequest.env_for('/foo_bar/show_encoding', {
266
+ :method => 'POST',
267
+ :params => %Q|[
268
+ {
269
+ "bar": "€"
270
+ }
271
+ ]|
272
+ })
273
+ output = ''
274
+ assert_nothing_raised do
275
+ output = @ws.call(env)
276
+ end
277
+ assert_equal 200, output[0]
278
+ end
279
+
144
280
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restrack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-22 00:00:00.000000000Z
12
+ date: 2012-03-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &20404520 !ruby/object:Gem::Requirement
16
+ requirement: &12274540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20404520
24
+ version_requirements: *12274540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-test
27
- requirement: &20404080 !ruby/object:Gem::Requirement
27
+ requirement: &12273680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *20404080
35
+ version_requirements: *12273680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &20403480 !ruby/object:Gem::Requirement
38
+ requirement: &12272300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *20403480
46
+ version_requirements: *12272300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
- requirement: &20402860 !ruby/object:Gem::Requirement
49
+ requirement: &12271880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *20402860
57
+ version_requirements: *12271880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: xml-simple
60
- requirement: &20402080 !ruby/object:Gem::Requirement
60
+ requirement: &12271240 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.13
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *20402080
68
+ version_requirements: *12271240
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: builder
71
- requirement: &20384600 !ruby/object:Gem::Requirement
71
+ requirement: &12270460 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *20384600
79
+ version_requirements: *12270460
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &20383940 !ruby/object:Gem::Requirement
82
+ requirement: &12269560 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *20383940
90
+ version_requirements: *12269560
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: mime-types
93
- requirement: &20383300 !ruby/object:Gem::Requirement
93
+ requirement: &12268400 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *20383300
101
+ version_requirements: *12268400
102
102
  description: ! "\nRESTRack is a Rack-based MVC framework that makes it extremely easy
103
103
  to develop RESTful data services. It is inspired by\nRails, and follows a few of
104
104
  its conventions. But it has no routes file, routing relationships are done through\nsupplying