| Module | Merb::Test::MultipartRequestHelper |
| In: |
merb-core/lib/merb-core/test/helpers/multipart_request_helper.rb
merb-core/lib/merb-core/two-oh.rb |
Similar to dispatch_to but allows for sending files inside params.
| controller_klass<Controller>: | The controller class object that the action should be dispatched to. |
| action<Symbol>: | The action name, as a symbol. |
| params<Hash>: | An optional hash that will end up as params in the controller instance. |
| env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see fake_request). |
| &blk: | The block is executed in the context of the controller. |
dispatch_multipart_to(MyController, :create, :my_file => @a_file ) do |controller|
controller.stub!(:current_user).and_return(@user)
end
Set your option to contain a file object to simulate file uploads.
Does not use routes.
# File merb-core/lib/merb-core/test/helpers/multipart_request_helper.rb, line 111
111: def dispatch_multipart_to(controller_klass, action, params = {}, env = {}, &blk)
112: request = multipart_fake_request(env, params)
113: dispatch_request(request, controller_klass, action, &blk)
114: end
| env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see fake_request). |
| params<Hash>: | An optional hash that will end up as params in the controller instance. |
| FakeRequest: | A multipart Request object that is built based on the parameters. |
# File merb-core/lib/merb-core/test/helpers/multipart_request_helper.rb, line 166
166: def multipart_fake_request(env = {}, params = {})
167: if params.empty?
168: fake_request(env)
169: else
170: m = Post.new(params)
171: body, head = m.to_multipart
172: fake_request(env.merge( :content_type => head,
173: :content_length => body.length), :post_body => body)
174: end
175: end
An HTTP POST request that operates through the router and uses multipart parameters.
| path<String>: | The path that should go to the router as the request uri. |
| params<Hash>: | An optional hash that will end up as params in the controller instance. |
| env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see fake_request). |
| block<Proc>: | The block is executed in the context of the controller. |
To include an uploaded file, put a file object as a value in params.
# File merb-core/lib/merb-core/two-oh.rb, line 26
26: def multipart_post(path, params = {}, env = {})
27: env[:method] = "POST"
28: multipart_request(path, params, env)
29: end
An HTTP POST request that operates through the router and uses multipart parameters.
| path<String>: | The path that should go to the router as the request uri. |
| params<Hash>: | An optional hash that will end up as params in the controller instance. |
| env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see fake_request). |
| block<Proc>: | The block is executed in the context of the controller. |
To include an uploaded file, put a file object as a value in params.
# File merb-core/lib/merb-core/test/helpers/multipart_request_helper.rb, line 130
130: def multipart_post(path, params = {}, env = {}, &block)
131: env[:request_method] = "POST"
132: env[:test_with_multipart] = true
133: mock_request(path, params, env, &block)
134: end
An HTTP PUT request that operates through the router and uses multipart parameters.
| path<String>: | The path that should go to the router as the request uri. |
| params<Hash>: | An optional hash that will end up as params in the controller instance. |
| env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see fake_request). |
| block<Proc>: | The block is executed in the context of the controller. |
To include an uplaoded file, put a file object as a value in params.
# File merb-core/lib/merb-core/test/helpers/multipart_request_helper.rb, line 150
150: def multipart_put(path, params = {}, env = {}, &block)
151: env[:request_method] = "PUT"
152: env[:test_with_multipart] = true
153: mock_request(path, params, env, &block)
154: end
An HTTP PUT request that operates through the router and uses multipart parameters.
| path<String>: | The path that should go to the router as the request uri. |
| params<Hash>: | An optional hash that will end up as params in the controller instance. |
| env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see fake_request). |
| block<Proc>: | The block is executed in the context of the controller. |
To include an uplaoded file, put a file object as a value in params.
# File merb-core/lib/merb-core/two-oh.rb, line 45
45: def multipart_put(path, params = {}, env = {}, &block)
46: env[:method] = "PUT"
47: multipart_request(path, params, env)
48: end
# File merb-core/lib/merb-core/two-oh.rb, line 3
3: def multipart_request(path, params = {}, env = {})
4: multipart = Merb::Test::MultipartRequestHelper::Post.new(params)
5: body, head = multipart.to_multipart
6: env["CONTENT_TYPE"] = head
7: env["CONTENT_LENGTH"] = body.size
8: env[:input] = StringIO.new(body)
9: request(path, env)
10: end