restrack 1.6.7 → 1.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/restrack/generator/hooks.rb.erb +1 -1
- data/lib/restrack/resource_controller.rb +1 -1
- data/lib/restrack/response.rb +1 -1
- data/lib/restrack/version.rb +1 -1
- data/lib/restrack/web_service.rb +2 -2
- data/test/sample_app_5/controllers/hook_controller.rb +6 -1
- data/test/sample_app_5/hooks.rb +3 -2
- data/test/sample_app_5/loader.rb +1 -1
- data/test/sample_app_5/test/test_hooks.rb +48 -1
- metadata +2 -2
data/Rakefile
CHANGED
@@ -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(
|
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
|
data/lib/restrack/response.rb
CHANGED
data/lib/restrack/version.rb
CHANGED
data/lib/restrack/web_service.rb
CHANGED
@@ -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(
|
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
|
data/test/sample_app_5/hooks.rb
CHANGED
@@ -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(
|
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
|
data/test/sample_app_5/loader.rb
CHANGED
@@ -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
|
-
|
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.
|
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-
|
12
|
+
date: 2012-11-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|