aboutsummaryrefslogtreecommitdiff
path: root/spec/unit/request/parameter/element_reference_spec.rb
blob: 1136eae5ff1bb1782c5ef586495f378e1a418390 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'spec_helper'

describe Zero::Request::Parameter, '#[]' do
  subject { Zero::Request::Parameter.new(env) }

  context 'without parameters' do
    let(:env) { EnvGenerator.get('/foo') }

    it 'returns the custom parameter' do
      subject['foo'] = 'bar'
      expect(subject['foo']).to eq('bar')
    end
  end

  context 'with query parameters' do
    let(:env) { EnvGenerator.get('/foo?foo=bar') }

    it 'returns the query parameter' do
      expect(subject['foo']).to eq('bar')
    end

    it 'returns the custom parameter' do
      subject['foo'] = 'baz'
      expect(subject['foo']).to eq('baz')
    end
  end

  context 'with payload parameters' do
    let(:env) do
      EnvGenerator.post('/foo', {
        :input => 'foo=bar', 'CONTENT_TYPE' => 'multipart/form-data'
      })
    end

    it 'returns the payload value' do
      expect(subject['foo']).to eq('bar')
    end

    it 'returns the custom parameter' do
      subject['foo'] = 'baz'
      expect(subject['foo']).to eq('baz')
    end
  end

  context 'with query and payload parameters' do
    let(:env) do
      EnvGenerator.post('/foo?foo=baz', {
        :input => 'foo=bar', 'CONTENT_TYPE' => 'multipart/form-data'
      })
    end

    it 'returns the payload parameter' do
      expect(subject['foo']).to eq('bar')
    end
  end
end