diff options
author | Gibheer <gibheer@gmail.com> | 2013-08-14 08:12:39 +0200 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2013-08-14 08:12:39 +0200 |
commit | 603dce8628246a17009c3a5f30cb57e21b146672 (patch) | |
tree | 3db49a576aafba2d0878dda708ad21e0203b3760 /spec | |
parent | 00e0c0170385cc2bd8a9ac599f5462d75292efde (diff) |
add request method override for browsers
Browsers are not able to send put, delete or any other request from a
plain html form. This limits the possibilities with APIs so an override
was introduced in many frameworks in the form, that `_method` could be
defined in a post payload.
With this, zero also supports `_method` in the post payload to make it
possible to use all functions of the API with javascript through plain
html.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/zero/request/method_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/unit/zero/request/method_spec.rb b/spec/unit/zero/request/method_spec.rb index 42ea56a..b9352e1 100644 --- a/spec/unit/zero/request/method_spec.rb +++ b/spec/unit/zero/request/method_spec.rb @@ -5,4 +5,47 @@ describe Zero::Request, '#method' do let(:env) { EnvGenerator.get('/foo') } its(:method) { should == :get } + + context 'with post requests' do + context 'and _method defined' do + let(:env) do + EnvGenerator.post('/foo', { + :input => '_method=put', + 'CONTENT_TYPE' => 'multipart/form-data' + }) + end + it 'uses _method from the payload to change the method' do + expect(subject.method).to be(:put) + end + end + + context 'and _method not defined' do + let(:env) do + EnvGenerator.post('/foo', { + :input => 'foo=bar', + 'CONTENT_TYPE' => 'multipart/form-data' + }) + end + its(:method) { should == :post } + end + + context 'and _method has wrong content' do + let(:env) do + EnvGenerator.post('/foo', { + :input => '_method=foobar', + 'CONTENT_TYPE' => 'multipart/form-data' + }) + end + its(:method) { should == :post } + end + + context 'and no payload' do + let(:env) do + EnvGenerator.post('/foo', { + 'CONTENT_TYPE' => 'multipart/form-data' + }) + end + its(:method) { should == :post } + end + end end |