Module | RubyAMF::Test |
In: |
lib/rubyamf/test.rb
|
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"
Creates a rack environment for the standard call type
# File lib/rubyamf/test.rb, line 43 43: def create_call amf_version, target, *args 44: create_call_type :standard, amf_version, target, *args 45: end
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.
# File lib/rubyamf/test.rb, line 25 25: def create_call_type type, amf_version, target, *args 26: amf_req = RubyAMF::Envelope.new :amf_version => amf_version 27: if type == :standard 28: amf_req.call target, *args 29: elsif type == :flex 30: amf_req.call_flex target, *args 31: else 32: raise "Invalid call type: #{type}" 33: end 34: 35: env = ::Rack::MockRequest.env_for(RubyAMF.configuration.gateway_path, :method => "post", :input => amf_req.to_s, "CONTENT_TYPE" => RubyAMF::MIME_TYPE) 36: env["REQUEST_URI"] = env["PATH_INFO"] # Rails 2.3.X needs this 37: env['rubyamf.request'] = amf_req 38: env['rubyamf.response'] = RubyAMF::Envelope.new 39: env 40: end
Creates a rack environment for the flex call type
# File lib/rubyamf/test.rb, line 48 48: def create_flex_call target, *args 49: create_call_type :flex, 3, target, *args 50: end
Dispatches the given rack environment to RubyAMF::Rails::RequestProcessor, which calls the specified controllers. Returns the response RubyAMF::Envelope.
# File lib/rubyamf/test.rb, line 54 54: def dispatch_rails env 55: middleware = RubyAMF::Rails::RequestProcessor.new nil 56: middleware.call env 57: env['rubyamf.response'] 58: end