diff options
| author | Gibheer <gibheer@gmail.com> | 2013-07-26 14:46:33 +0200 | 
|---|---|---|
| committer | Gibheer <gibheer@gmail.com> | 2013-07-26 14:46:33 +0200 | 
| commit | e2f3e29a341945bb6a2ee3a9dc31cce71de3a58b (patch) | |
| tree | 46e265d6f790a7630b6ce06dd04665cac4065665 /spec | |
| parent | 89e2efeffaf46874c9ead2c63a49bdf3684626fe (diff) | |
extend server with protocol information
This extends the server class with the information, if it is serving
http or https. This can then be used to generate a root uri to the web
application.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/unit/zero/request/server/hostname_spec.rb | 1 | ||||
| -rw-r--r-- | spec/unit/zero/request/server/is_http_spec.rb | 20 | ||||
| -rw-r--r-- | spec/unit/zero/request/server/is_https_spec.rb | 20 | ||||
| -rw-r--r-- | spec/unit/zero/request/server/uri_spec.rb | 23 | 
4 files changed, 63 insertions, 1 deletions
| diff --git a/spec/unit/zero/request/server/hostname_spec.rb b/spec/unit/zero/request/server/hostname_spec.rb index b2275b4..2f9af13 100644 --- a/spec/unit/zero/request/server/hostname_spec.rb +++ b/spec/unit/zero/request/server/hostname_spec.rb @@ -6,4 +6,3 @@ describe Zero::Request::Server, '#hostname' do    let(:env) { EnvGenerator.get('/foo', {'SERVER_NAME' => hostname}) }    its(:hostname) { should be(hostname) }  end - diff --git a/spec/unit/zero/request/server/is_http_spec.rb b/spec/unit/zero/request/server/is_http_spec.rb new file mode 100644 index 0000000..6e41393 --- /dev/null +++ b/spec/unit/zero/request/server/is_http_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Zero::Request::Server, '#is_http?' do +  subject { Zero::Request::Server.new(env) } +  let(:hostname) { 'FooName' } + +  context 'with http' do +    let(:env) { EnvGenerator.get('/foo', {'SERVER_NAME' => hostname}) } +    its(:is_http?) { should be(true) } +  end + +  context 'with https' do +    let(:env) { EnvGenerator.get('/foo', { +      'SERVER_NAME' => hostname, +      'HTTPS' => 'on' +    }) } +    its(:is_http?) { should be(false) } +  end +end + diff --git a/spec/unit/zero/request/server/is_https_spec.rb b/spec/unit/zero/request/server/is_https_spec.rb new file mode 100644 index 0000000..340e489 --- /dev/null +++ b/spec/unit/zero/request/server/is_https_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Zero::Request::Server, '#is_https?' do +  subject { Zero::Request::Server.new(env) } +  let(:hostname) { 'FooName' } + +  context 'with http' do +    let(:env) { EnvGenerator.get('/foo', {'SERVER_NAME' => hostname}) } +    its(:is_https?) { should be(false) } +  end + +  context 'with https' do +    let(:env) { EnvGenerator.get('/foo', { +      'SERVER_NAME' => hostname, +      'HTTPS' => 'on' +    }) } +    its(:is_https?) { should be(true) } +  end +end + diff --git a/spec/unit/zero/request/server/uri_spec.rb b/spec/unit/zero/request/server/uri_spec.rb new file mode 100644 index 0000000..c9bd9ec --- /dev/null +++ b/spec/unit/zero/request/server/uri_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Zero::Request::Server, '#uri' do +  subject { Zero::Request::Server.new(env) } +  let(:hostname) { 'FooName' } +  let(:port) { '80' } +  let(:protocol) { 'http' } +  let(:env) { EnvGenerator.get('/foo', { +    'SERVER_NAME' => hostname, +    'SERVER_PORT' => port +  }) } + +  context 'with standard port' do +    let(:result) { "#{protocol}://#{hostname}" } +    its(:uri) { should eq(result) } +  end + +  context 'with different port' do +    let(:port) { '9292' } +    let(:result) { "#{protocol}://#{hostname}:#{port}" } +    its(:uri) { should eq(result) } +  end +end | 
