Module: RubyAMF::Test
- Defined in:
- lib/rubyamf/test.rb
Overview
Contains helpers to make testing AMF controller testing simple. Rails users can simply use create_call
and create_flex_call
to create requests and run them using dispatch_rails
. Users of other rack-based frameworks will need to handle properly dispatching the request to the right middleware. create_call_type
creates a rack environment similar to what you would get from RubyAMF::RequestParser, so you can just pass it to whatever your processing middleware is.
Rails Example:
env = RubyAMF::Test.create_call 3, "TestController.get_user", 5
res = RubyAMF::Test.dispatch_rails env
res.mapping_scope.should == "testing"
res.result.class.name.should == "User"
Class Method Summary collapse
-
.create_call(amf_version, target, *args) ⇒ Object
Creates a rack environment for the standard call type.
-
.create_call_type(type, amf_version, target, *args) ⇒ Object
Creates a rack environment hash that can be used to dispatch the given call.
-
.create_flex_call(target, *args) ⇒ Object
Creates a rack environment for the flex call type.
-
.dispatch_rails(env) ⇒ Object
Dispatches the given rack environment to RubyAMF::Rails::RequestProcessor, which calls the specified controllers.
Class Method Details
.create_call(amf_version, target, *args) ⇒ Object
Creates a rack environment for the standard call type
43 44 45 |
# File 'lib/rubyamf/test.rb', line 43 def create_call amf_version, target, *args create_call_type :standard, amf_version, target, *args end |
.create_call_type(type, amf_version, target, *args) ⇒ Object
Creates a rack environment hash that can be used to dispatch the given call. The environment that is created can be directly dispatched to RubyAMF::Rails::RequestProcessor or your own middleware. The type can either be :standard
or :flex
, with the flex type using the same style as RemoteObject
does.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rubyamf/test.rb', line 25 def create_call_type type, amf_version, target, *args amf_req = RubyAMF::Envelope.new :amf_version => amf_version if type == :standard amf_req.call target, *args elsif type == :flex amf_req.call_flex target, *args else raise "Invalid call type: #{type}" end env = ::Rack::MockRequest.env_for(RubyAMF.configuration.gateway_path, :method => "post", :input => amf_req.to_s, "CONTENT_TYPE" => RubyAMF::MIME_TYPE) env["REQUEST_URI"] = env["PATH_INFO"] # Rails 2.3.X needs this env['rubyamf.request'] = amf_req env['rubyamf.response'] = RubyAMF::Envelope.new env end |
.create_flex_call(target, *args) ⇒ Object
Creates a rack environment for the flex call type
48 49 50 |
# File 'lib/rubyamf/test.rb', line 48 def create_flex_call target, *args create_call_type :flex, 3, target, *args end |
.dispatch_rails(env) ⇒ Object
Dispatches the given rack environment to RubyAMF::Rails::RequestProcessor, which calls the specified controllers. Returns the response RubyAMF::Envelope.
54 55 56 57 58 |
# File 'lib/rubyamf/test.rb', line 54 def dispatch_rails env middleware = RubyAMF::Rails::RequestProcessor.new nil middleware.call env env['rubyamf.response'] end |