restrack 1.1.3 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module RESTRack
2
-
2
+
3
3
  # All RESTRack controllers should descend from ResourceController. This class
4
4
  # provides the methods for your controllers.
5
5
  #
@@ -7,7 +7,7 @@ module RESTRack
7
7
  # Collection URI (/widgets/): | index | replace | create | drop
8
8
  # Element URI (/widgets/42): | show | update | add | destroy
9
9
  #
10
-
10
+
11
11
  class ResourceController
12
12
  attr_reader :action, :id
13
13
  class << self; attr_accessor :key_type; end
@@ -22,7 +22,8 @@ module RESTRack
22
22
  @resource_request = resource_request
23
23
  @request = @resource_request.request
24
24
  @params = @resource_request.params
25
- @input = @resource_request.input
25
+ @post_params = @resource_request.post_params
26
+ @get_params = @resource_request.get_params
26
27
  self
27
28
  end
28
29
 
@@ -42,14 +43,14 @@ module RESTRack
42
43
  #def update(id); end
43
44
  #def add(id); end
44
45
  #def destroy(id); end
45
-
46
+
46
47
  def method_missing(method_sym, *arguments, &block)
47
48
  raise HTTP405MethodNotAllowed, 'Method not provided on controller.'
48
49
  end
49
50
 
50
51
  # all internal methods are protected rather than private so that calling methods *could* be overriden if necessary.
51
52
  protected
52
-
53
+
53
54
  # This method allows one to access a related resource, without providing a direct link to specific relation(s).
54
55
  def self.pass_through_to(entity, opts = {})
55
56
  entity_name = opts[:as] || entity
@@ -96,7 +97,7 @@ module RESTRack
96
97
  end
97
98
  )
98
99
  end
99
-
100
+
100
101
  # This method defines that there are multiple links to members from an entity collection (an array of entity identifiers).
101
102
  # This adds an accessor instance method whose name is the entity's class.
102
103
  def self.has_defined_relationships_to(entity, opts = {}, &get_entity_id_from_relation_id)
@@ -178,7 +179,7 @@ module RESTRack
178
179
  end
179
180
  id
180
181
  end
181
-
182
+
182
183
  # Get action from HTTP verb
183
184
  def get_action_from_context
184
185
  if @resource_request.request.get?
@@ -1,7 +1,7 @@
1
1
  module RESTRack
2
2
  # The ResourceRequest class handles all incoming requests.
3
3
  class ResourceRequest
4
- attr_reader :request, :request_id, :input, :params
4
+ attr_reader :request, :request_id, :params, :post_params, :get_params
5
5
  attr_accessor :mime_type, :url_chain
6
6
 
7
7
  # Initialize the ResourceRequest by assigning a request_id and determining the path, format, and controller of the resource.
@@ -20,8 +20,15 @@ module RESTRack
20
20
 
21
21
  def prepare
22
22
  # Pull input data from POST body
23
- @input = parse_body( @request )
24
- @params = get_params( @request )
23
+ @post_params = parse_body( @request )
24
+ @get_params = parse_query_string( @request )
25
+ @params = {}
26
+ # TODO: Test this!
27
+ if @post_params.is_a? Hash
28
+ @params = @post_params.merge( @get_params )
29
+ else
30
+ @params = @get_params
31
+ end
25
32
  # Setup up the initial routing.
26
33
  @url_chain = @request.path_info.split('/')
27
34
  @url_chain.shift if @url_chain[0] == ''
@@ -49,7 +56,7 @@ module RESTRack
49
56
  @active_controller = instantiate_controller( @active_resource_name )
50
57
  end
51
58
 
52
- # Send out the typed resource's output, this must occur after a call to run.
59
+ # Send out the typed resource's output.
53
60
  def response
54
61
  RESTRack.log.debug "{#{@request_id}} Retrieving Output"
55
62
  package( @active_controller.call )
@@ -75,23 +82,23 @@ module RESTRack
75
82
 
76
83
  # Pull input data from POST body
77
84
  def parse_body(request)
78
- input = request.body.read
85
+ post_params = request.body.read
79
86
  unless request.content_type.blank?
80
87
  request_mime_type = MIME::Type.new( request.content_type )
81
88
  if request_mime_type.like?( RESTRack.mime_type_for( :JSON ) )
82
- input = JSON.parse( input )
89
+ post_params = JSON.parse( post_params ) rescue post_params
83
90
  elsif request_mime_type.like?( RESTRack.mime_type_for( :XML ) )
84
- input = XmlSimple.xml_in( input, 'ForceArray' => false )
91
+ post_params = XmlSimple.xml_in( post_params, 'ForceArray' => false ) rescue post_params
85
92
  elsif request_mime_type.like?( RESTRack.mime_type_for( :YAML ) )
86
- input = YAML.parse( input )
93
+ post_params = YAML.parse( post_params ) rescue post_params
87
94
  end
88
95
  end
89
- RESTRack.log.debug "{#{@request_id}} #{request_mime_type.to_s} data in:\n" + input.pretty_inspect
90
- input
96
+ RESTRack.log.debug "{#{@request_id}} #{request_mime_type.to_s} data in:\n" + post_params.pretty_inspect
97
+ post_params
91
98
  end
92
99
 
93
- def get_params(request)
94
- params = request.GET
100
+ def parse_query_string(request)
101
+ get_params = request.GET
95
102
  end
96
103
 
97
104
  # Determine the MIME type of the request from the extension provided.
@@ -114,7 +121,7 @@ module RESTRack
114
121
  RESTRack.log.debug "{#{@request_id}} Locating Resource #{resource_name}"
115
122
  begin
116
123
  return RESTRack.controller_class_for( resource_name ).__init(self)
117
- rescue
124
+ rescue Exception => e
118
125
  raise HTTP404ResourceNotFound, "The resource #{RESTRack::CONFIG[:SERVICE_NAME]}::#{RESTRack.controller_name(resource_name)} could not be instantiated."
119
126
  end
120
127
  end
@@ -138,6 +145,11 @@ module RESTRack
138
145
  else
139
146
  @output = data
140
147
  end
148
+ if @output.respond_to?(:each)
149
+ return @output
150
+ else
151
+ return [@output]
152
+ end
141
153
  end
142
154
 
143
155
  # Use Builder to generate the XML.
@@ -1,3 +1,3 @@
1
1
  module RESTRack
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.5"
3
3
  end
@@ -37,19 +37,19 @@ module RESTRack
37
37
  end
38
38
  case
39
39
  when exception.is_a?( HTTP400BadRequest )
40
- return [400, {'Content-Type' => 'text/plain'}, exception.message + "\nThe request cannot be fulfilled due to bad syntax." ]
40
+ return [400, {'Content-Type' => 'text/plain'}, [exception.message || "The request cannot be fulfilled due to bad syntax."] ]
41
41
  when exception.is_a?( HTTP401Unauthorized )
42
- return [401, {'Content-Type' => 'text/plain'}, exception.message + "\nYou have failed authentication for access to the resource." ]
42
+ return [401, {'Content-Type' => 'text/plain'}, [exception.message || "You have failed authentication for access to the resource."] ]
43
43
  when exception.is_a?( HTTP403Forbidden )
44
- return [403, {'Content-Type' => 'text/plain'}, exception.message + "\nYou are forbidden to access that resource." ]
44
+ return [403, {'Content-Type' => 'text/plain'}, [exception.message || "You are forbidden to access that resource."] ]
45
45
  when exception.is_a?( HTTP404ResourceNotFound )
46
- return [404, {'Content-Type' => 'text/plain'}, exception.message + "\nThe resource you requested could not be found." ]
46
+ return [404, {'Content-Type' => 'text/plain'}, [exception.message || "The resource you requested could not be found."] ]
47
47
  when exception.is_a?( HTTP405MethodNotAllowed )
48
- return [405, {'Content-Type' => 'text/plain'}, exception.message + "\nThe resource you requested does not support the request method provided." ]
48
+ return [405, {'Content-Type' => 'text/plain'}, [exception.message || "The resource you requested does not support the request method provided."] ]
49
49
  when exception.is_a?( HTTP409Conflict )
50
- return [409, {'Content-Type' => 'text/plain'}, exception.message + "\nThe resource you requested is in a conflicted state." ]
50
+ return [409, {'Content-Type' => 'text/plain'}, [exception.message || "The resource you requested is in a conflicted state."] ]
51
51
  when exception.is_a?( HTTP410Gone )
52
- return [410, {'Content-Type' => 'text/plain'}, exception.message + "\nThe resource you requested is no longer available." ]
52
+ return [410, {'Content-Type' => 'text/plain'}, [exception.message || "The resource you requested is no longer available."] ]
53
53
  else # HTTP500ServerError
54
54
  msg = exception.message + "\n\n" + exception.backtrace.join("\n")
55
55
  if resource_request && resource_request.request_id
@@ -57,7 +57,7 @@ module RESTRack
57
57
  else
58
58
  RESTRack.log.error msg
59
59
  end
60
- return [500, {'Content-Type' => 'text/plain'}, msg ]
60
+ return [500, {'Content-Type' => 'text/plain'}, [msg] ]
61
61
  end # case Exception
62
62
  end # method caught
63
63
 
@@ -20,6 +20,6 @@
20
20
  :DEFAULT_RESOURCE: bazu
21
21
 
22
22
  # These are the resources which can be accessed from the root of your web service. If left empty, all resources are available at the root.
23
- :ROOT_RESOURCE_ACCEPT: [ foo_bar ]
23
+ :ROOT_RESOURCE_ACCEPT: [ foo_bar, errors ]
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 ]
@@ -0,0 +1,46 @@
1
+ class SampleApp::ErrorsController < RESTRack::ResourceController
2
+
3
+ #module HTTPStatus
4
+ # class HTTP400BadRequest < Exception; end
5
+ # class HTTP401Unauthorized < Exception; end
6
+ # class HTTP403Forbidden < Exception; end
7
+ # class HTTP404ResourceNotFound < Exception; end
8
+ # class HTTP405MethodNotAllowed < Exception; end
9
+ # class HTTP409Conflict < Exception; end
10
+ # class HTTP410Gone < Exception; end
11
+ # class HTTP500ServerError < Exception; end
12
+ #end
13
+
14
+ def bad_request
15
+ raise HTTP400BadRequest, 'tester'
16
+ end
17
+
18
+ def unauthorized
19
+ raise HTTP401Unauthorized, 'tester'
20
+ end
21
+
22
+ def forbidden
23
+ raise HTTP403Forbidden, 'tester'
24
+ end
25
+
26
+ def resource_not_found
27
+ raise HTTP404ResourceNotFound, 'tester'
28
+ end
29
+
30
+ def method_not_allowed
31
+ raise HTTP405MethodNotAllowed, 'tester'
32
+ end
33
+
34
+ def conflict
35
+ raise HTTP409Conflict, 'tester'
36
+ end
37
+
38
+ def gone
39
+ raise HTTP410Gone, 'tester'
40
+ end
41
+
42
+ def server_error
43
+ raise HTTP500ServerError, 'tester'
44
+ end
45
+
46
+ end
@@ -24,7 +24,7 @@ class SampleApp::FooBarController < RESTRack::ResourceController
24
24
  has_relationships_to( :baza, :as => :children ) do |id|
25
25
  [1,2,3,4,5,6,7,8,9]
26
26
  end
27
-
27
+
28
28
  has_defined_relationships_to( :baza, :as => :def ) do |id|
29
29
  [1,8,9,17]
30
30
  end
@@ -97,17 +97,17 @@ class SampleApp::FooBarController < RESTRack::ResourceController
97
97
  end
98
98
 
99
99
  def echo
100
- return @input
100
+ return @post_params
101
101
  end
102
-
102
+
103
103
  def echo_get
104
104
  return @params.merge({ 'get?' => @resource_request.request.get?.to_s })
105
105
  end
106
-
106
+
107
107
  def custom_entity(id)
108
108
  return id
109
109
  end
110
-
110
+
111
111
  def custom_collection
112
112
  return [1,1,2,3,5,8,13,21,34]
113
113
  end
@@ -19,7 +19,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
19
19
  output = @ws.call(env)
20
20
  end
21
21
  test_val = { :foo => 'bar', :baz => 123 }.to_json
22
- assert_equal test_val, output[2]
22
+ assert_equal test_val, output[2][0]
23
23
  end
24
24
 
25
25
  def test_update
@@ -31,7 +31,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
31
31
  output = @ws.call(env)
32
32
  end
33
33
  test_val = { :success => true }.to_json
34
- assert_equal test_val, output[2]
34
+ assert_equal test_val, output[2][0]
35
35
  end
36
36
 
37
37
  def test_add
@@ -43,7 +43,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
43
43
  output = @ws.call(env)
44
44
  end
45
45
  test_val = { :success => true }.to_json
46
- assert_equal test_val, output[2]
46
+ assert_equal test_val, output[2][0]
47
47
  end
48
48
 
49
49
  def test_destroy
@@ -55,7 +55,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
55
55
  output = @ws.call(env)
56
56
  end
57
57
  test_val = { :success => true }.to_json
58
- assert_equal test_val, output[2]
58
+ assert_equal test_val, output[2][0]
59
59
  end
60
60
 
61
61
 
@@ -68,7 +68,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
68
68
  output = @ws.call(env)
69
69
  end
70
70
  test_val = [1,2,3,4,5,6,7].to_json
71
- assert_equal test_val, output[2]
71
+ assert_equal test_val, output[2][0]
72
72
  end
73
73
 
74
74
  def test_replace
@@ -80,7 +80,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
80
80
  output = @ws.call(env)
81
81
  end
82
82
  test_val = { :success => true }.to_json
83
- assert_equal test_val, output[2]
83
+ assert_equal test_val, output[2][0]
84
84
  end
85
85
 
86
86
  def test_create
@@ -92,7 +92,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
92
92
  output = @ws.call(env)
93
93
  end
94
94
  test_val = { :success => true }.to_json
95
- assert_equal test_val, output[2]
95
+ assert_equal test_val, output[2][0]
96
96
  end
97
97
 
98
98
  def test_drop
@@ -104,7 +104,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
104
104
  output = @ws.call(env)
105
105
  end
106
106
  test_val = { :success => true }.to_json
107
- assert_equal test_val, output[2]
107
+ assert_equal test_val, output[2][0]
108
108
  end
109
109
 
110
110
  def test_custom_entity_action
@@ -116,9 +116,9 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
116
116
  output = @ws.call(env)
117
117
  end
118
118
  test_val = '7476'.to_json
119
- assert_equal test_val, output[2]
119
+ assert_equal test_val, output[2][0]
120
120
  end
121
-
121
+
122
122
  def test_custom_collection_action
123
123
  env = Rack::MockRequest.env_for('/foo_bar/custom_collection', {
124
124
  :method => 'GET'
@@ -128,7 +128,7 @@ class SampleApp::TestControllerActions < Test::Unit::TestCase
128
128
  output = @ws.call(env)
129
129
  end
130
130
  test_val = [1,1,2,3,5,8,13,21,34].to_json
131
- assert_equal test_val, output[2]
131
+ assert_equal test_val, output[2][0]
132
132
  end
133
133
 
134
134
  def test_missing
@@ -19,7 +19,7 @@ class SampleApp::TestControllerInputs < Test::Unit::TestCase
19
19
  output = @ws.call(env)
20
20
  end
21
21
  test_val = { :test => '1', :hello => 'world', 'get?' => 'true' }.to_json
22
- assert_equal test_val, output[2]
22
+ assert_equal test_val, output[2][0]
23
23
  end
24
24
 
25
25
  def test_FUBAR_params
@@ -31,7 +31,7 @@ class SampleApp::TestControllerInputs < Test::Unit::TestCase
31
31
  output = @ws.call(env)
32
32
  end
33
33
  test_val = { :test => '1', :hello => 'world', 'get?' => 'false' }.to_json
34
- assert_equal test_val, output[2]
34
+ assert_equal test_val, output[2][0]
35
35
  end
36
36
 
37
37
  def test_post_no_content_type
@@ -44,7 +44,7 @@ class SampleApp::TestControllerInputs < Test::Unit::TestCase
44
44
  assert_nothing_raised do
45
45
  output = @ws.call(env)
46
46
  end
47
- assert_equal test_val.to_json, output[2] # will be converted to json because of default response type
47
+ assert_equal test_val.to_json, output[2][0] # will be converted to json because of default response type
48
48
  end
49
49
 
50
50
  def test_post_json
@@ -58,7 +58,7 @@ class SampleApp::TestControllerInputs < Test::Unit::TestCase
58
58
  assert_nothing_raised do
59
59
  output = @ws.call(env)
60
60
  end
61
- assert_equal test_val, output[2]
61
+ assert_equal test_val, output[2][0]
62
62
  end
63
63
 
64
64
  def test_post_xml
@@ -72,7 +72,7 @@ class SampleApp::TestControllerInputs < Test::Unit::TestCase
72
72
  assert_nothing_raised do
73
73
  output = @ws.call(env)
74
74
  end
75
- assert_equal test_val, output[2]
75
+ assert_equal test_val, output[2][0]
76
76
  end
77
77
 
78
78
  def test_post_text
@@ -86,6 +86,6 @@ class SampleApp::TestControllerInputs < Test::Unit::TestCase
86
86
  assert_nothing_raised do
87
87
  output = @ws.call(env)
88
88
  end
89
- assert_equal test_val, output[2]
89
+ assert_equal test_val, output[2][0]
90
90
  end
91
91
  end
@@ -19,7 +19,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
19
19
  output = @ws.call(env)
20
20
  end
21
21
  test_val = { :BAZ => 'ALOHA!' }.to_json
22
- assert_equal test_val, output[2]
22
+ assert_equal test_val, output[2][0]
23
23
 
24
24
  env = Rack::MockRequest.env_for('/foo_bar/133/bata/abc', {
25
25
  :method => 'GET'
@@ -29,7 +29,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
29
29
  output = @ws.call(env)
30
30
  end
31
31
  test_val = { :OTHER => 'YUP' }.to_json
32
- assert_equal test_val, output[2]
32
+ assert_equal test_val, output[2][0]
33
33
 
34
34
  env = Rack::MockRequest.env_for('/foo_bar/144/bata/', {
35
35
  :method => 'GET'
@@ -39,7 +39,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
39
39
  output = @ws.call(env)
40
40
  end
41
41
  test_val = [1,2,3,4,5].to_json
42
- assert_equal test_val, output[2]
42
+ assert_equal test_val, output[2][0]
43
43
 
44
44
  env = Rack::MockRequest.env_for('/foo_bar/144/other_bata', {
45
45
  :method => 'GET'
@@ -49,7 +49,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
49
49
  output = @ws.call(env)
50
50
  end
51
51
  test_val = [1,2,3,4,5].to_json
52
- assert_equal test_val, output[2]
52
+ assert_equal test_val, output[2][0]
53
53
  end
54
54
 
55
55
  def test_has_relationship_to
@@ -61,7 +61,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
61
61
  output = @ws.call(env)
62
62
  end
63
63
  test_val = { :BAZ => 'ALOHA!' }.to_json
64
- assert_equal test_val, output[2]
64
+ assert_equal test_val, output[2][0]
65
65
 
66
66
  env = Rack::MockRequest.env_for('/foo_bar/133/baz', {
67
67
  :method => 'GET'
@@ -71,7 +71,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
71
71
  output = @ws.call(env)
72
72
  end
73
73
  test_val = { :OTHER => 'YUP' }.to_json
74
- assert_equal test_val, output[2]
74
+ assert_equal test_val, output[2][0]
75
75
 
76
76
  env = Rack::MockRequest.env_for('/foo_bar/144/baz/', {
77
77
  :method => 'GET'
@@ -81,7 +81,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
81
81
  output = @ws.call(env)
82
82
  end
83
83
  test_val = { :BAZ => 'ALOHA!' }.to_json
84
- assert_equal test_val, output[2]
84
+ assert_equal test_val, output[2][0]
85
85
 
86
86
  #------
87
87
 
@@ -93,7 +93,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
93
93
  output = @ws.call(env)
94
94
  end
95
95
  test_val = { :WOM => 'NOBAT!' }.to_json
96
- assert_equal test_val, output[2]
96
+ assert_equal test_val, output[2][0]
97
97
 
98
98
  env = Rack::MockRequest.env_for('/foo_bar/133/slugger', {
99
99
  :method => 'GET'
@@ -103,7 +103,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
103
103
  output = @ws.call(env)
104
104
  end
105
105
  test_val = { :SUHWING => 'BATTER' }.to_json
106
- assert_equal test_val, output[2]
106
+ assert_equal test_val, output[2][0]
107
107
 
108
108
  env = Rack::MockRequest.env_for('/foo_bar/144/slugger/', {
109
109
  :method => 'GET'
@@ -113,7 +113,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
113
113
  output = @ws.call(env)
114
114
  end
115
115
  test_val = { :WOM => 'NOBAT!' }.to_json
116
- assert_equal test_val, output[2]
116
+ assert_equal test_val, output[2][0]
117
117
  end
118
118
 
119
119
  def test_has_relationships_to
@@ -125,7 +125,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
125
125
  output = @ws.call(env)
126
126
  end
127
127
  test_val = { :BAZA => 'YESSIR' }.to_json
128
- assert_equal test_val, output[2]
128
+ assert_equal test_val, output[2][0]
129
129
 
130
130
  env = Rack::MockRequest.env_for('/foo_bar/133/children/7', {
131
131
  :method => 'GET'
@@ -135,7 +135,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
135
135
  output = @ws.call(env)
136
136
  end
137
137
  test_val = { :NOWAY => 'JOSE' }.to_json
138
- assert_equal test_val, output[2]
138
+ assert_equal test_val, output[2][0]
139
139
 
140
140
  env = Rack::MockRequest.env_for('/foo_bar/133/children/11', {
141
141
  :method => 'GET'
@@ -157,7 +157,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
157
157
  output = @ws.call(env)
158
158
  end
159
159
  test_val = { :BAZA => 'YESSIR' }.to_json
160
- assert_equal test_val, output[2]
160
+ assert_equal test_val, output[2][0]
161
161
 
162
162
  env = Rack::MockRequest.env_for('/foo_bar/133/def/8', {
163
163
  :method => 'GET'
@@ -167,7 +167,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
167
167
  output = @ws.call(env)
168
168
  end
169
169
  test_val = { :NOWAY => 'JOSE' }.to_json
170
- assert_equal test_val, output[2]
170
+ assert_equal test_val, output[2][0]
171
171
 
172
172
  # this should 404
173
173
  env = Rack::MockRequest.env_for('/foo_bar/133/def/11', {
@@ -199,7 +199,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
199
199
  output = @ws.call(env)
200
200
  end
201
201
  test_val = '1'
202
- assert_equal test_val, output[2]
202
+ assert_equal test_val, output[2][0]
203
203
 
204
204
  env = Rack::MockRequest.env_for('/foo_bar/133/maps/second', {
205
205
  :method => 'GET'
@@ -209,7 +209,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
209
209
  output = @ws.call(env)
210
210
  end
211
211
  test_val = '0'
212
- assert_equal test_val, output[2]
212
+ assert_equal test_val, output[2][0]
213
213
 
214
214
  env = Rack::MockRequest.env_for('/foo_bar/133/maps/third', {
215
215
  :method => 'GET'
@@ -219,7 +219,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
219
219
  output = @ws.call(env)
220
220
  end
221
221
  test_val = '0'
222
- assert_equal test_val, output[2]
222
+ assert_equal test_val, output[2][0]
223
223
  end
224
224
 
225
225
  def test_keyed_with_type
@@ -232,7 +232,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
232
232
  output = @ws.call(env)
233
233
  end
234
234
  test_val = { :BAZA => 'YESSIR' }.to_json
235
- assert_equal test_val, output[2]
235
+ assert_equal test_val, output[2][0]
236
236
  end
237
237
 
238
238
  end
@@ -0,0 +1,123 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'rack/test'
4
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','loader'))
5
+ require 'pp'
6
+
7
+ class SampleApp::TestControllerActions < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @ws = SampleApp::WebService.new
11
+ end
12
+
13
+ #module HTTPStatus
14
+ # class HTTP400BadRequest < Exception; end
15
+ # class HTTP401Unauthorized < Exception; end
16
+ # class HTTP403Forbidden < Exception; end
17
+ # class HTTP404ResourceNotFound < Exception; end
18
+ # class HTTP405MethodNotAllowed < Exception; end
19
+ # class HTTP409Conflict < Exception; end
20
+ # class HTTP410Gone < Exception; end
21
+ # class HTTP500ServerError < Exception; end
22
+ #end
23
+
24
+ def test_bad_request
25
+ response_code = 400
26
+ env = Rack::MockRequest.env_for('/errors/bad_request', {
27
+ :method => 'GET'
28
+ })
29
+ output = ''
30
+ assert_nothing_raised do
31
+ output = @ws.call(env)
32
+ end
33
+ assert_equal response_code, output[0]
34
+ assert_equal 'tester', output[2][0]
35
+ puts output.inspect
36
+ end
37
+
38
+ def test_unauthorized
39
+ response_code = 401
40
+ env = Rack::MockRequest.env_for('/errors/unauthorized', {
41
+ :method => 'GET'
42
+ })
43
+ output = ''
44
+ assert_nothing_raised do
45
+ output = @ws.call(env)
46
+ end
47
+ assert_equal response_code, output[0]
48
+ end
49
+
50
+ def test_forbidden
51
+ response_code = 403
52
+ env = Rack::MockRequest.env_for('/errors/forbidden', {
53
+ :method => 'GET'
54
+ })
55
+ output = ''
56
+ assert_nothing_raised do
57
+ output = @ws.call(env)
58
+ end
59
+ assert_equal response_code, output[0]
60
+ end
61
+
62
+ def test_resource_not_found
63
+ response_code = 404
64
+ env = Rack::MockRequest.env_for('/errors/resource_not_found', {
65
+ :method => 'GET'
66
+ })
67
+ output = ''
68
+ assert_nothing_raised do
69
+ output = @ws.call(env)
70
+ end
71
+ assert_equal response_code, output[0]
72
+ end
73
+
74
+ def test_method_not_allowed
75
+ response_code = 405
76
+ env = Rack::MockRequest.env_for('/errors/method_not_allowed', {
77
+ :method => 'GET'
78
+ })
79
+ output = ''
80
+ assert_nothing_raised do
81
+ output = @ws.call(env)
82
+ end
83
+ assert_equal response_code, output[0]
84
+ end
85
+
86
+ def test_conflict
87
+ response_code = 409
88
+ env = Rack::MockRequest.env_for('/errors/conflict', {
89
+ :method => 'GET'
90
+ })
91
+ output = ''
92
+ assert_nothing_raised do
93
+ output = @ws.call(env)
94
+ end
95
+ assert_equal response_code, output[0]
96
+ end
97
+
98
+ def test_gone
99
+ response_code = 410
100
+ env = Rack::MockRequest.env_for('/errors/gone', {
101
+ :method => 'GET'
102
+ })
103
+ output = ''
104
+ assert_nothing_raised do
105
+ output = @ws.call(env)
106
+ end
107
+ assert_equal response_code, output[0]
108
+ end
109
+
110
+ def test_server_error
111
+ response_code = 500
112
+ # This will/should spam the log
113
+ env = Rack::MockRequest.env_for('/errors/server_error', {
114
+ :method => 'GET'
115
+ })
116
+ output = ''
117
+ assert_nothing_raised do
118
+ output = @ws.call(env)
119
+ end
120
+ assert_equal response_code, output[0]
121
+ end
122
+
123
+ end
@@ -19,7 +19,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
19
19
  output = @ws.call(env)
20
20
  end
21
21
  test_val = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><data><foo>bar</foo><baz>123</baz></data>"
22
- assert_equal test_val, output[2]
22
+ assert_equal test_val, output[2][0]
23
23
  end
24
24
 
25
25
  def test_show_default_xml
@@ -31,7 +31,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
31
31
  output = @ws.call(env)
32
32
  end
33
33
  test_val = XmlSimple.xml_out([1,2,3,4,5,6,7], 'AttrPrefix' => true, 'XmlDeclaration' => true, 'NoIndent' => true)
34
- assert_equal test_val, output[2]
34
+ assert_equal test_val, output[2][0]
35
35
 
36
36
  env = Rack::MockRequest.env_for('/foo_bar.xml', {
37
37
  :method => 'GET'
@@ -41,7 +41,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
41
41
  output = @ws.call(env)
42
42
  end
43
43
  test_val = XmlSimple.xml_out([1,2,3,4,5,6,7], 'AttrPrefix' => true, 'XmlDeclaration' => true, 'NoIndent' => true)
44
- assert_equal test_val, output[2]
44
+ assert_equal test_val, output[2][0]
45
45
  end
46
46
 
47
47
  def test_show_json
@@ -53,7 +53,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
53
53
  output = @ws.call(env)
54
54
  end
55
55
  test_val = { :foo => 'bar', :baz => 123 }.to_json
56
- assert_equal test_val, output[2]
56
+ assert_equal test_val, output[2][0]
57
57
  end
58
58
 
59
59
  def test_complex_data_structure_json
@@ -65,7 +65,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
65
65
  output = @ws.call(env)
66
66
  end
67
67
  test_val = "{\"foo\":\"abc\",\"bar\":\"123\",\"baz\":456,\"more\":{\"one\":1,\"two\":[1,2],\"three\":\"deep_fu\"}}"
68
- assert_equal test_val, output[2]
68
+ assert_equal test_val, output[2][0]
69
69
 
70
70
  env = Rack::MockRequest.env_for('/foo_bar/42', {
71
71
  :method => 'GET'
@@ -84,7 +84,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
84
84
  4 => :four
85
85
  }
86
86
  }.to_json
87
- assert_equal test_val, output[2]
87
+ assert_equal test_val, output[2][0]
88
88
  end
89
89
 
90
90
  def test_complex_data_structure_xml
@@ -96,7 +96,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
96
96
  output = @ws.call(env)
97
97
  end
98
98
  test_val = "<?xml version='1.0' standalone='yes'?>\n<opt><foo>abc</foo><bar>123</bar><baz>456</baz><more><one>1</one><two>1</two><two>2</two><three>deep_fu</three></more></opt>"
99
- assert_equal test_val, output[2]
99
+ assert_equal test_val, output[2][0]
100
100
 
101
101
  env = Rack::MockRequest.env_for('/foo_bar/42/complex_show_xml_no_builder.xml', {
102
102
  :method => 'GET'
@@ -115,7 +115,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
115
115
  4 => :four
116
116
  }
117
117
  }, 'AttrPrefix' => true, 'XmlDeclaration' => true, 'NoIndent' => true)
118
- assert_equal test_val, output[2]
118
+ assert_equal test_val, output[2][0]
119
119
  end
120
120
 
121
121
  end
@@ -19,7 +19,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
19
19
  output = @ws.call(env)
20
20
  end
21
21
  test_val = { :BAZ => 'ALOHA!' }.to_json
22
- assert_equal test_val, output[2]
22
+ assert_equal test_val, output[2][0]
23
23
 
24
24
  env = Rack::MockRequest.env_for('/foo_bar/133/baz', {
25
25
  :method => 'GET'
@@ -29,7 +29,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
29
29
  output = @ws.call(env)
30
30
  end
31
31
  test_val = { :OTHER => 'YUP' }.to_json
32
- assert_equal test_val, output[2]
32
+ assert_equal test_val, output[2][0]
33
33
 
34
34
  env = Rack::MockRequest.env_for('/foo_bar/144/baz/', {
35
35
  :method => 'GET'
@@ -39,7 +39,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
39
39
  output = @ws.call(env)
40
40
  end
41
41
  test_val = { :BAZ => 'ALOHA!' }.to_json
42
- assert_equal test_val, output[2]
42
+ assert_equal test_val, output[2][0]
43
43
  end
44
44
 
45
45
  def test_has_relationships_to
@@ -51,7 +51,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
51
51
  output = @ws.call(env)
52
52
  end
53
53
  test_val = { :BAZA => 'YESSIR' }.to_json
54
- assert_equal test_val, output[2]
54
+ assert_equal test_val, output[2][0]
55
55
 
56
56
  env = Rack::MockRequest.env_for('/foo_bar/133/children/8', {
57
57
  :method => 'GET'
@@ -61,7 +61,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
61
61
  output = @ws.call(env)
62
62
  end
63
63
  test_val = { :NOWAY => 'JOSE' }.to_json
64
- assert_equal test_val, output[2]
64
+ assert_equal test_val, output[2][0]
65
65
 
66
66
  env = Rack::MockRequest.env_for('/foo_bar/133/children/11', {
67
67
  :method => 'GET'
@@ -82,7 +82,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
82
82
  output = @ws.call(env)
83
83
  end
84
84
  test_val = 1.to_json
85
- assert_equal test_val, output[2]
85
+ assert_equal test_val, output[2][0]
86
86
 
87
87
  env = Rack::MockRequest.env_for('/foo_bar/133/maps/second', {
88
88
  :method => 'GET'
@@ -92,7 +92,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
92
92
  output = @ws.call(env)
93
93
  end
94
94
  test_val = 0.to_json
95
- assert_equal test_val, output[2]
95
+ assert_equal test_val, output[2][0]
96
96
 
97
97
  env = Rack::MockRequest.env_for('/foo_bar/133/maps/third', {
98
98
  :method => 'GET'
@@ -102,7 +102,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
102
102
  output = @ws.call(env)
103
103
  end
104
104
  test_val = 0.to_json
105
- assert_equal test_val, output[2]
105
+ assert_equal test_val, output[2][0]
106
106
  end
107
107
 
108
108
  def test_keyed_with_type
@@ -115,7 +115,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
115
115
  output = @ws.call(env)
116
116
  end
117
117
  test_val = 1.to_json
118
- assert_equal test_val, output[2]
118
+ assert_equal test_val, output[2][0]
119
119
  end
120
120
 
121
121
  end
@@ -19,7 +19,7 @@ class SampleApp::TestControllerModifiers < Test::Unit::TestCase
19
19
  output = @ws.call(env)
20
20
  end
21
21
  test_val = [0,1,2,3].to_json
22
- assert_equal test_val, output[2]
22
+ assert_equal test_val, output[2][0]
23
23
 
24
24
 
25
25
  #"Hello from Bar with id of
@@ -20,7 +20,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
20
20
  end
21
21
  assert_equal 'text/x-yaml', output[1]['Content-Type']
22
22
  test_val = YAML.dump( { :foo => '123', :baz => 'bat' } )
23
- assert_equal test_val, output[2]
23
+ assert_equal test_val, output[2][0]
24
24
  end
25
25
 
26
26
  def test_text
@@ -33,7 +33,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
33
33
  end
34
34
  assert_equal 'text/plain', output[1]['Content-Type']
35
35
  test_val = 'Hello 123!'
36
- assert_equal test_val, output[2]
36
+ assert_equal test_val, output[2][0]
37
37
  end
38
38
 
39
39
  def test_image
@@ -45,7 +45,7 @@ class SampleApp::TestFormats < Test::Unit::TestCase
45
45
  output = @ws.call(env)
46
46
  end
47
47
  assert_equal 'image/png', output[1]['Content-Type']
48
- assert output[2].length
48
+ assert output[2][0].length
49
49
  end
50
50
 
51
51
  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.1.3
4
+ version: 1.1.5
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: 2011-09-08 00:00:00.000000000Z
12
+ date: 2011-09-14 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &17715460 !ruby/object:Gem::Requirement
16
+ requirement: &10175380 !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: *17715460
24
+ version_requirements: *10175380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-test
27
- requirement: &17715040 !ruby/object:Gem::Requirement
27
+ requirement: &10174660 !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: *17715040
35
+ version_requirements: *10174660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &17714620 !ruby/object:Gem::Requirement
38
+ requirement: &10173980 !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: *17714620
46
+ version_requirements: *10173980
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
- requirement: &17714200 !ruby/object:Gem::Requirement
49
+ requirement: &10173340 !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: *17714200
57
+ version_requirements: *10173340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: xml-simple
60
- requirement: &17713700 !ruby/object:Gem::Requirement
60
+ requirement: &10172580 !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: *17713700
68
+ version_requirements: *10172580
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: builder
71
- requirement: &17713280 !ruby/object:Gem::Requirement
71
+ requirement: &10171940 !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: *17713280
79
+ version_requirements: *10171940
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &17712820 !ruby/object:Gem::Requirement
82
+ requirement: &10171240 !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: *17712820
90
+ version_requirements: *10171240
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: mime-types
93
- requirement: &17736520 !ruby/object:Gem::Requirement
93
+ requirement: &10170660 !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: *17736520
101
+ version_requirements: *10170660
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
@@ -144,11 +144,13 @@ files:
144
144
  - test/sample_app_1/controllers/baz_controller.rb
145
145
  - test/sample_app_1/controllers/baza_controller.rb
146
146
  - test/sample_app_1/controllers/bazu_controller.rb
147
+ - test/sample_app_1/controllers/errors_controller.rb
147
148
  - test/sample_app_1/controllers/foo_bar_controller.rb
148
149
  - test/sample_app_1/loader.rb
149
150
  - test/sample_app_1/test/test_controller_actions.rb
150
151
  - test/sample_app_1/test/test_controller_inputs.rb
151
152
  - test/sample_app_1/test/test_controller_modifiers.rb
153
+ - test/sample_app_1/test/test_errors.rb
152
154
  - test/sample_app_1/test/test_formats.rb
153
155
  - test/sample_app_1/test/test_resource_request.rb
154
156
  - test/sample_app_1/test/test_web_service.rb
@@ -202,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
204
  version: '0'
203
205
  requirements: []
204
206
  rubyforge_project: restrack
205
- rubygems_version: 1.8.6
207
+ rubygems_version: 1.8.10
206
208
  signing_key:
207
209
  specification_version: 3
208
210
  summary: A lightweight MVC framework developed specifically for JSON (and XML) REST