warden-redirect 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in warden-redirect.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jon Rowe
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Warden::Redirect
2
+
3
+ Simple gem for throwing redirects in warden.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'warden-redirect'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install warden-redirect
18
+
19
+ ## Usage
20
+
21
+ To use with a specific location:
22
+
23
+ throw :warden, Warden::Redirect.new('/location')
24
+
25
+ To use with a specific location and status:
26
+
27
+ throw :warden, Warden::Redirect.new('/location',301)
28
+
29
+ To use with a specific location, status and extra headers:
30
+
31
+ throw :warden, Warden::Redirect.new('/location',301, "X-SHALL-NOT-PASS" => true)
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec'
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new :spec
8
+
9
+ task :default => [:spec]
@@ -0,0 +1,2 @@
1
+ require "warden/redirect/version"
2
+ require "warden/redirect"
@@ -0,0 +1,13 @@
1
+ module Warden
2
+ class Redirect < Array
3
+ def initialize(location,status=302,headers={})
4
+ redirect_headers = headers.merge({ "Content-Type" => "text/html", "Location" => location })
5
+ body = "<html><body>You are being redirected to <a href='#{location}'>#{location}</a></body></html>"
6
+ super [status,redirect_headers,[body]]
7
+ end
8
+
9
+ def status; self[0]; end
10
+ def headers; self[1]; end
11
+ def body; self[2]; end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Warden
2
+ class Redirect < Array
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,64 @@
1
+ require 'warden/redirect'
2
+
3
+ shared_examples_for 'warden redirect' do |opts|
4
+
5
+ #rack status
6
+ its([0]) { should == opts[:status] }
7
+ its(:status) { should == opts[:status] }
8
+ its(:first) { should == opts[:status] }
9
+
10
+ #rack headers
11
+ its([1]) { should == opts[:headers] }
12
+ its(:headers) { should == opts[:headers] }
13
+
14
+ #rack body
15
+ specify { subject[2].first.should include 'You are being redirected' }
16
+
17
+ #warden compat
18
+ it { should be_a Array }
19
+ specify do
20
+ status, headers, body = subject
21
+ status.should == opts[:status]
22
+ headers.should == opts[:headers]
23
+ body.should == subject[2]
24
+ end
25
+ end
26
+
27
+ describe 'redirecting to a specific location' do
28
+ subject { Warden::Redirect.new '/location' }
29
+
30
+ it_should_behave_like 'warden redirect',
31
+ :status => 302,
32
+ :headers => { "Location" => "/location", "Content-Type" => "text/html" }
33
+ end
34
+
35
+ describe 'redirecting to a specific location with a status' do
36
+ subject { Warden::Redirect.new '/location', 301 }
37
+
38
+ it_should_behave_like 'warden redirect',
39
+ :status => 301,
40
+ :headers => { "Location" => "/location", "Content-Type" => "text/html" }
41
+ end
42
+
43
+ describe 'redirecting to a specific location with a status and headers' do
44
+ subject { Warden::Redirect.new '/location', 301, "X-SHALL-NOT-PASS" => true }
45
+
46
+ it_should_behave_like 'warden redirect',
47
+ :status => 301,
48
+ :headers => { "Location" => "/location", "Content-Type" => "text/html", "X-SHALL-NOT-PASS" => true }
49
+ end
50
+
51
+ describe 'warden compatilbity' do
52
+ subject { throw :warden, Warden::Redirect.new('/location') }
53
+ let(:result) { catch(:warden) { subject } }
54
+
55
+ specify do
56
+ case result
57
+ when Array
58
+ true
59
+ else
60
+ fail
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'warden/redirect/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "warden-redirect"
8
+ gem.version = Warden::Redirect::VERSION
9
+ gem.authors = ["Jon Rowe"]
10
+ gem.email = ["hello@jonrowe.co.uk"]
11
+ gem.description = %q{Simple gem for throwing redirects in warden.}
12
+ gem.summary = %q{Simple gem for throwing redirects in warden.}
13
+ gem.homepage = "https://github.com/JonRowe/warden-redirect.git"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency 'warden'
21
+
22
+ gem.add_development_dependency 'rspec'
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: warden-redirect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jon Rowe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: warden
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Simple gem for throwing redirects in warden.
47
+ email:
48
+ - hello@jonrowe.co.uk
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/warden-redirect.rb
59
+ - lib/warden/redirect.rb
60
+ - lib/warden/redirect/version.rb
61
+ - spec/warden/redirect_spec.rb
62
+ - warden-redirect.gemspec
63
+ homepage: https://github.com/JonRowe/warden-redirect.git
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Simple gem for throwing redirects in warden.
87
+ test_files:
88
+ - spec/warden/redirect_spec.rb