restrack 1.2.3 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,10 +50,12 @@ module RESTRack
50
50
  # I am AR bound
51
51
  errors = ARFormattedError.new(errors)
52
52
  end
53
- @output = @resource_request.package(errors)[0] # TODO: Remove this if change line 97 in resource_request.rb
53
+ @output = @resource_request.package(errors)
54
54
  end
55
+
55
56
  def package_error(error)
56
- package_errors(error)
57
+ errors = error.is_a?(String) ? [error] : error
58
+ package_errors(errors)
57
59
  end
58
60
 
59
61
  # This method allows one to access a related resource, without providing a direct link to specific relation(s).
@@ -94,11 +94,7 @@ module RESTRack
94
94
  else
95
95
  @output = data
96
96
  end
97
- if @output.respond_to?(:each) # TODO: Should this do this? Perhaps always bundle in array in web_service.rb
98
- return @output
99
- else
100
- return [@output]
101
- end
97
+ return @output
102
98
  end
103
99
 
104
100
  private
@@ -1,3 +1,3 @@
1
1
  module RESTRack
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.4"
3
3
  end
@@ -24,7 +24,7 @@ module RESTRack
24
24
  def valid( resource_request, response )
25
25
  RESTRack.log.debug "(#{resource_request.request_id}) HTTP200OK '#{resource_request.mime_type.to_s}' response data:\n" + response.to_s unless not response.respond_to?( :to_s )
26
26
  RESTRack.request_log.info "(#{resource_request.request_id}) HTTP200OK"
27
- return [200, {'Content-Type' => resource_request.content_type}, response ]
27
+ return [200, {'Content-Type' => resource_request.content_type}, [response] ]
28
28
  end
29
29
 
30
30
  # Return appropriate response code and messages per raised exception type.
@@ -53,12 +53,12 @@ module RESTRack
53
53
  when exception.is_a?( HTTP422ResourceInvalid )
54
54
  return [422, {'Content-Type' => 'text/plain'}, [exception.message || "Invalid attribute values sent for resource."] ]
55
55
  else # HTTP500ServerError
56
- msg = exception.message + "\n\n" + exception.backtrace.join("\n")
57
56
  if resource_request && resource_request.request_id
58
- RESTRack.log.error "(#{resource_request.request_id}) #{exception.class.to_s} " + msg
57
+ RESTRack.log.error "(#{resource_request.request_id}) #{exception.class.to_s} " + exception.message + "\n" + exception.backtrace.join("\n")
59
58
  else
60
- RESTRack.log.error "(<nil-reqid>) #{exception.class.to_s} " + msg
59
+ RESTRack.log.error "(<nil-reqid>) #{exception.class.to_s} " + exception.message + "\n" + exception.backtrace.join("\n")
61
60
  end
61
+ msg = (exception.message == exception.class.to_s) ? exception.backtrace.join("\n") : exception.message
62
62
  return [500, {'Content-Type' => 'text/plain'}, [msg] ]
63
63
  end # case Exception
64
64
  end # method caught
@@ -51,4 +51,8 @@ class SampleApp::ErrorsController < RESTRack::ResourceController
51
51
  raise HTTP500ServerError, package_error('tester')
52
52
  end
53
53
 
54
+ def server_error_with_backtrace
55
+ raise HTTP500ServerError
56
+ end
57
+
54
58
  end
@@ -31,7 +31,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
31
31
  output = @ws.call(env)
32
32
  end
33
33
  assert_equal response_code, output[0]
34
- assert_equal 'tester'.to_json, output[2][0]
34
+ assert_equal 'tester', JSON.parse(output[2][0])[0]
35
35
  end
36
36
 
37
37
  def test_unauthorized
@@ -44,6 +44,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
44
44
  output = @ws.call(env)
45
45
  end
46
46
  assert_equal response_code, output[0]
47
+ assert_equal 'tester', JSON.parse(output[2][0])[0]
47
48
  end
48
49
 
49
50
  def test_forbidden
@@ -56,6 +57,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
56
57
  output = @ws.call(env)
57
58
  end
58
59
  assert_equal response_code, output[0]
60
+ assert_equal 'tester', JSON.parse(output[2][0])[0]
59
61
  end
60
62
 
61
63
  def test_resource_not_found
@@ -68,6 +70,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
68
70
  output = @ws.call(env)
69
71
  end
70
72
  assert_equal response_code, output[0]
73
+ assert_equal 'tester', JSON.parse(output[2][0])[0]
71
74
  end
72
75
 
73
76
  def test_method_not_allowed
@@ -80,6 +83,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
80
83
  output = @ws.call(env)
81
84
  end
82
85
  assert_equal response_code, output[0]
86
+ assert_equal 'tester', JSON.parse(output[2][0])[0]
83
87
  end
84
88
 
85
89
  def test_conflict
@@ -92,6 +96,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
92
96
  output = @ws.call(env)
93
97
  end
94
98
  assert_equal response_code, output[0]
99
+ assert_equal 'tester', JSON.parse(output[2][0])[0]
95
100
  end
96
101
 
97
102
  def test_gone
@@ -104,6 +109,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
104
109
  output = @ws.call(env)
105
110
  end
106
111
  assert_equal response_code, output[0]
112
+ assert_equal 'tester', JSON.parse(output[2][0])[0]
107
113
  end
108
114
 
109
115
  def test_resource_invalid
@@ -117,6 +123,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
117
123
  end
118
124
  assert_equal response_code, output[0]
119
125
  assert JSON.parse(output[2][0]).has_key?('message')
126
+ assert_equal 'This is a WebDAV HTTP extension code used by ActiveResource to communicate validation errors, rather than 400.', JSON.parse(output[2][0])['message']
120
127
  end
121
128
 
122
129
  def test_resource_invalid_active_record_format
@@ -155,6 +162,21 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
155
162
  output = @ws.call(env)
156
163
  end
157
164
  assert_equal response_code, output[0]
165
+ assert_equal 'tester', JSON.parse(output[2][0])[0]
166
+ end
167
+
168
+ def test_server_error_with_backtrace
169
+ response_code = 500
170
+ # This will/should spam the log
171
+ env = Rack::MockRequest.env_for('/errors/server_error_with_backtrace', {
172
+ :method => 'GET'
173
+ })
174
+ output = ''
175
+ assert_nothing_raised do
176
+ output = @ws.call(env)
177
+ end
178
+ assert_equal response_code, output[0]
179
+ assert_not_equal 'tester', output[2][0]
158
180
  end
159
181
 
160
182
  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.2.3
4
+ version: 1.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-10 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &10448680 !ruby/object:Gem::Requirement
16
+ requirement: &23011460 !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: *10448680
24
+ version_requirements: *23011460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-test
27
- requirement: &10447720 !ruby/object:Gem::Requirement
27
+ requirement: &23010920 !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: *10447720
35
+ version_requirements: *23010920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &10446540 !ruby/object:Gem::Requirement
38
+ requirement: &23010360 !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: *10446540
46
+ version_requirements: *23010360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
- requirement: &10445940 !ruby/object:Gem::Requirement
49
+ requirement: &23009720 !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: *10445940
57
+ version_requirements: *23009720
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: xml-simple
60
- requirement: &10445300 !ruby/object:Gem::Requirement
60
+ requirement: &22957080 !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: *10445300
68
+ version_requirements: *22957080
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: builder
71
- requirement: &10444560 !ruby/object:Gem::Requirement
71
+ requirement: &22956200 !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: *10444560
79
+ version_requirements: *22956200
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &10439600 !ruby/object:Gem::Requirement
82
+ requirement: &22955320 !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: *10439600
90
+ version_requirements: *22955320
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: mime-types
93
- requirement: &10438800 !ruby/object:Gem::Requirement
93
+ requirement: &22954780 !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: *10438800
101
+ version_requirements: *22954780
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