restrack 1.6.7 → 1.6.8

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ task :default => [:test_all]
8
8
 
9
9
  desc 'Run all tests.'
10
10
  task :test_all do
11
- for n in 0..4
11
+ for n in 0..5
12
12
  Rake::Task['test'+n.to_s].invoke
13
13
  end
14
14
  end
@@ -7,7 +7,7 @@ module RESTRack
7
7
  end
8
8
  # Use this to execute code after all requests handled by your service.
9
9
  # For example, to do database connection per request you could commit transactions and/or teardown db connections here.
10
- def post_processor(request)
10
+ def post_processor(response)
11
11
 
12
12
  end
13
13
  end # class Hooks
@@ -13,7 +13,7 @@ module RESTRack
13
13
  class ResourceController
14
14
  extend RESTRack::ResourceRelations
15
15
 
16
- attr_reader :action, :id, :params
16
+ attr_reader :action, :id, :params, :resource_request
17
17
  class << self; attr_accessor :key_type; end
18
18
 
19
19
  # Base initialization method for resources and storage of request input
@@ -1,6 +1,6 @@
1
1
  module RESTRack
2
2
  class Response
3
- attr_reader :status, :content_type, :body, :mime_type, :headers
3
+ attr_reader :status, :content_type, :body, :mime_type, :headers, :request
4
4
 
5
5
  def initialize(request)
6
6
  @request = request
@@ -1,3 +1,3 @@
1
1
  module RESTRack
2
- VERSION = "1.6.7"
2
+ VERSION = "1.6.8"
3
3
  end
@@ -15,10 +15,10 @@ module RESTRack
15
15
  end
16
16
  response = RESTRack::Response.new(resource_request)
17
17
  unless @request_hook.nil? or (RESTRack::CONFIG.has_key?(:POST_PROCESSOR_DISABLED) and RESTRack::CONFIG[:POST_PROCESSOR_DISABLED])
18
- @request_hook.post_processor(resource_request)
18
+ @request_hook.post_processor(response)
19
19
  end
20
20
  return response.output
21
21
  end # method call
22
22
 
23
23
  end # class WebService
24
- end # module RESTRack
24
+ end # module RESTRack
@@ -7,5 +7,10 @@ class SampleApp5::HookController < RESTRack::ResourceController
7
7
  { 'neither' => true }
8
8
  end
9
9
  end
10
+
11
+ def dynamic_request
12
+ @resource_request.instance_variable_set('@error_code', 123456)
13
+ @resource_request.instance_variable_set('@error_message', 'Invalid password or email address combination')
14
+ end
10
15
 
11
- end
16
+ end
@@ -7,8 +7,9 @@ module RESTRack
7
7
  end
8
8
  # Use this to execute code after all requests handled by your service.
9
9
  # For example, to do database connection per request you could commit transactions and/or teardown db connections here.
10
- def post_processor(request)
10
+ def post_processor(response)
11
11
  $post_processor_executed = true
12
+ $response = response
12
13
  end
13
14
  end # class Hooks
14
- end # module RESTRack
15
+ end # module RESTRack
@@ -9,7 +9,7 @@ class SampleApp5::WebService < RESTRack::WebService; end
9
9
  RESTRack::CONFIG = RESTRack::load_config(File.join(File.dirname(__FILE__), 'config/constants.yaml'))
10
10
  RESTRack::CONFIG[:ROOT] = File.dirname(__FILE__)
11
11
 
12
- require File.join(RESTRack::CONFIG[:ROOT], 'hooks') if File.exists?(File.join(RESTRack::CONFIG[:ROOT], 'hooks'))
12
+ require File.join(RESTRack::CONFIG[:ROOT], 'hooks') if File.exists?(File.join(RESTRack::CONFIG[:ROOT], 'hooks.rb'))
13
13
 
14
14
  # Dynamically load all controllers
15
15
  Find.find( File.join(File.dirname(__FILE__), 'controllers') ) do |file|
@@ -20,6 +20,7 @@ class SampleApp5::TestHooks < Test::Unit::TestCase
20
20
  end
21
21
  test_val = { 'pre_processor_flag' => true.to_s }.to_json
22
22
  assert_equal test_val, output[2][0]
23
+ $post_processor_executed = nil
23
24
  end
24
25
 
25
26
  def test_pre_processor_disabled
@@ -34,6 +35,7 @@ class SampleApp5::TestHooks < Test::Unit::TestCase
34
35
  test_val = { 'pre_processor_flag' => nil.to_s }.to_json
35
36
  assert_equal test_val, output[2][0]
36
37
  RESTRack::CONFIG[:PRE_PROCESSOR_DISABLED] = false
38
+ $post_processor_executed = nil
37
39
  end
38
40
 
39
41
  def test_post_processor_enabled
@@ -59,5 +61,50 @@ class SampleApp5::TestHooks < Test::Unit::TestCase
59
61
  end
60
62
  assert !$post_processor_executed
61
63
  RESTRack::CONFIG[:POST_PROCESSOR_DISABLED] = false
64
+ $post_processor_executed = nil
65
+ end
66
+
67
+ def test_post_processor_has_response
68
+ RESTRack::CONFIG[:PRE_PROCESSOR_DISABLED] = false
69
+ RESTRack::CONFIG[:POST_PROCESSOR_DISABLED] = false
70
+ env = Rack::MockRequest.env_for('/hook/post_processor', {
71
+ :method => 'GET'
72
+ })
73
+ output = ''
74
+ assert_nothing_raised do
75
+ output = @ws.call(env)
76
+ end
77
+ assert $response.is_a? RESTRack::Response
78
+ $post_processor_executed = nil
79
+ end
80
+
81
+ def test_post_processor_has_http_status_in_response
82
+ RESTRack::CONFIG[:PRE_PROCESSOR_DISABLED] = false
83
+ RESTRack::CONFIG[:POST_PROCESSOR_DISABLED] = false
84
+ env = Rack::MockRequest.env_for('/hook/post_processor', {
85
+ :method => 'GET'
86
+ })
87
+ output = ''
88
+ assert_nothing_raised do
89
+ output = @ws.call(env)
90
+ end
91
+ assert_equal(200, $response.status)
92
+ $post_processor_executed = nil
93
+ end
94
+
95
+ def test_post_processor_allows_pass_through_of_dynamic_request_attributes
96
+ RESTRack::CONFIG[:PRE_PROCESSOR_DISABLED] = false
97
+ RESTRack::CONFIG[:POST_PROCESSOR_DISABLED] = false
98
+ env = Rack::MockRequest.env_for('/hook/dynamic_request', {
99
+ :method => 'GET'
100
+ })
101
+ output = ''
102
+ assert_nothing_raised do
103
+ output = @ws.call(env)
104
+ end
105
+ assert_equal(123456, $response.request.instance_variable_get('@error_code'))
106
+ assert_equal('Invalid password or email address combination', $response.request.instance_variable_get('@error_message'))
107
+ $post_processor_executed = nil
62
108
  end
63
- end
109
+
110
+ 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.6.7
4
+ version: 1.6.8
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: 2012-10-16 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack