restrack 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -158,6 +158,12 @@ module RESTRack
158
158
  @id = self.methods.include?(@resource_request.url_chain[0]) ? nil : @resource_request.url_chain.shift
159
159
  @action = term.to_sym
160
160
  else
161
+ begin
162
+ self.class.format_string_id(term)
163
+ rescue
164
+ # if this isn't a valid id then it must be a request for an action that doesn't exist (we tested it as an action name above)
165
+ raise HTTP405MethodNotAllowed, 'Action not provided or found and unknown HTTP request method.'
166
+ end
161
167
  @id = term
162
168
  term = @resource_request.url_chain.shift
163
169
  if term.nil?
@@ -180,9 +186,9 @@ module RESTRack
180
186
  self.key_type ||= String
181
187
  unless self.key_type.blank? or self.key_type.ancestors.include?(String)
182
188
  if self.key_type.ancestors.include?(Integer)
183
- id = id.to_i
189
+ id = Integer(id)
184
190
  elsif self.key_type.ancestors.include?(Float)
185
- id = id.to_f
191
+ id = Float(id)
186
192
  else
187
193
  raise HTTP500ServerError, "Invalid key identifier type specified on resource #{self.class.to_s}."
188
194
  end
@@ -1,3 +1,3 @@
1
1
  module RESTRack
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -55,11 +55,7 @@ module RESTRack
55
55
  when exception.is_a?( HTTP502BadGateway )
56
56
  return [502, {'Content-Type' => 'text/plain'}, [exception.message || "The server was acting as a gateway or proxy and received an invalid response from the upstream server."] ]
57
57
  else # HTTP500ServerError
58
- if resource_request && resource_request.request_id
59
- RESTRack.log.error "(#{resource_request.request_id}) #{exception.class.to_s} " + exception.message + "\n" + exception.backtrace.join("\n")
60
- else
61
- RESTRack.log.error "(<nil-reqid>) #{exception.class.to_s} " + exception.message + "\n" + exception.backtrace.join("\n")
62
- end
58
+ log_server_error( resource_request, exception )
63
59
  msg = ''
64
60
  if RESTRack::CONFIG[:SHOW_STACK]
65
61
  msg = (exception.message == exception.class.to_s) ? exception.backtrace.join("\n") : exception.message + "\nstack trace:\n" + exception.backtrace.join("\n")
@@ -70,5 +66,13 @@ module RESTRack
70
66
  end # case Exception
71
67
  end # method caught
72
68
 
69
+ def log_server_error( resource_request, exception )
70
+ if resource_request && resource_request.request_id
71
+ RESTRack.log.error "(#{resource_request.request_id}) #{exception.class.to_s} " + exception.message + "\n" + exception.backtrace.join("\n")
72
+ else
73
+ RESTRack.log.error "(<nil-reqid>) #{exception.class.to_s} " + exception.message + "\n" + exception.backtrace.join("\n")
74
+ end
75
+ end
76
+
73
77
  end # class WebService
74
78
  end # module RESTRack
@@ -2,6 +2,14 @@ class SampleApp::BazuController < RESTRack::ResourceController
2
2
 
3
3
  keyed_with_type Fixnum
4
4
 
5
+ def index
6
+ [
7
+ { :id => 1, :val => 111 },
8
+ { :id => 2, :val => 222 },
9
+ { :id => 3, :val => 333 }
10
+ ]
11
+ end
12
+
5
13
  def show(id)
6
14
  return 1 if id == 1
7
15
  return 0
@@ -48,14 +48,14 @@ class SampleApp::TestResourceRequest < Test::Unit::TestCase
48
48
 
49
49
  def test_default_resource
50
50
  # This should be handled by bazu_controller
51
- env = Rack::MockRequest.env_for('/', {
51
+ env = Rack::MockRequest.env_for('/bad_request', {
52
52
  :method => 'GET'
53
53
  })
54
54
  output = ''
55
55
  assert_nothing_raised do
56
56
  output = @ws.call(env)
57
57
  end
58
- # no index method defined/allowed
58
+ # no bad_request method defined/allowed
59
59
  assert_equal 405, output[0]
60
60
 
61
61
  # This should be handled by bazu_controller
@@ -67,5 +67,20 @@ class SampleApp::TestResourceRequest < Test::Unit::TestCase
67
67
  output = @ws.call(env)
68
68
  end
69
69
  assert_equal 200, output[0]
70
+
71
+ # the following request should hit the default controller's index method (BazuController)
72
+ env = Rack::MockRequest.env_for('', {
73
+ :method => 'GET'
74
+ })
75
+ output = ''
76
+ assert_nothing_raised do
77
+ output = @ws.call(env)
78
+ end
79
+ test_val = [
80
+ { :id => 1, :val => 111 },
81
+ { :id => 2, :val => 222 },
82
+ { :id => 3, :val => 333 }
83
+ ].to_json
84
+ assert_equal test_val, output[2][0]
70
85
  end
71
86
  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.1
4
+ version: 1.4.2
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-03-20 00:00:00.000000000Z
12
+ date: 2012-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &12274540 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12274540
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rack-test
27
- requirement: &12273680 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *12273680
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: i18n
38
- requirement: &12272300 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *12272300
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: json
49
- requirement: &12271880 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :runtime
56
71
  prerelease: false
57
- version_requirements: *12271880
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: xml-simple
60
- requirement: &12271240 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: 1.0.13
66
86
  type: :runtime
67
87
  prerelease: false
68
- version_requirements: *12271240
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 1.0.13
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: builder
71
- requirement: &12270460 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :runtime
78
103
  prerelease: false
79
- version_requirements: *12270460
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: activesupport
82
- requirement: &12269560 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :runtime
89
119
  prerelease: false
90
- version_requirements: *12269560
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: mime-types
93
- requirement: &12268400 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,7 +133,12 @@ dependencies:
98
133
  version: '0'
99
134
  type: :runtime
100
135
  prerelease: false
101
- version_requirements: *12268400
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  description: ! "\nRESTRack is a Rack-based MVC framework that makes it extremely easy
103
143
  to develop RESTful data services. It is inspired by\nRails, and follows a few of
104
144
  its conventions. But it has no routes file, routing relationships are done through\nsupplying
@@ -204,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
244
  version: '0'
205
245
  requirements: []
206
246
  rubyforge_project: restrack
207
- rubygems_version: 1.8.10
247
+ rubygems_version: 1.8.21
208
248
  signing_key:
209
249
  specification_version: 3
210
250
  summary: A lightweight MVC framework developed specifically for JSON (and XML) REST