boomerang-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Rakefile +10 -0
- data/boomerang.gemspec +21 -0
- data/lib/boomerang.rb +5 -0
- data/lib/boomerang/controller_support.rb +17 -0
- data/lib/boomerang/version.rb +3 -0
- data/spec/controllers/controller_support_spec.rb +62 -0
- data/spec/spec_helper.rb +21 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/boomerang.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/boomerang/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Tom Ward']
|
6
|
+
gem.email = ['tom@popdog.net']
|
7
|
+
gem.summary = %q{Redirection helpers for rails}
|
8
|
+
gem.description = %q{Redirect away from an action and come back later}
|
9
|
+
gem.homepage = ''
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = 'boomerang-rails'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = Boomerang::VERSION
|
17
|
+
gem.add_dependency 'rails', '~>3.0'
|
18
|
+
gem.add_development_dependency 'rake', '~>0.9.2.2'
|
19
|
+
gem.add_development_dependency 'rspec-rails', '~>2.7.0'
|
20
|
+
gem.add_development_dependency 'mocha'
|
21
|
+
end
|
data/lib/boomerang.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Boomerang::ControllerSupport
|
2
|
+
def redirect_away(*args)
|
3
|
+
session[:boomerang_return_path] = request.fullpath
|
4
|
+
redirect_to *args
|
5
|
+
end
|
6
|
+
|
7
|
+
def redirect_back(*args)
|
8
|
+
if return_uri = session[:boomerang_return_path]
|
9
|
+
redirect_to return_uri
|
10
|
+
session[:boomerang_return_path] = nil
|
11
|
+
elsif args.empty?
|
12
|
+
redirect_to '/'
|
13
|
+
else
|
14
|
+
redirect_to *args
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Boomerang::ControllerSupport do
|
4
|
+
describe '#redirect_away' do
|
5
|
+
controller do
|
6
|
+
def index
|
7
|
+
redirect_away '/another/path'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'redirects to the given path' do
|
12
|
+
get :index
|
13
|
+
response.should redirect_to('/another/path')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'stores current request path in the session' do
|
17
|
+
request.stubs(:fullpath).returns('/full/request/path')
|
18
|
+
get :index
|
19
|
+
session[:boomerang_return_path].should eql('/full/request/path')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#redirect_back' do
|
24
|
+
describe '(in general)' do
|
25
|
+
controller do
|
26
|
+
def index
|
27
|
+
redirect_back '/fallback/path'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'redirects to the stored return path' do
|
32
|
+
session[:boomerang_return_path] = '/stored/request/path'
|
33
|
+
get :index
|
34
|
+
response.should redirect_to('/stored/request/path')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'redirects to the fallback path if no stored path found' do
|
38
|
+
get :index
|
39
|
+
response.should redirect_to('/fallback/path')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'removes return path from the session' do
|
43
|
+
session[:boomerang_return_path] = '/stored/request/path'
|
44
|
+
get :index
|
45
|
+
session[:boomerang_return_path].should be_nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '(when no fallback path given)' do
|
50
|
+
controller do
|
51
|
+
def index
|
52
|
+
redirect_back
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'redirects to the root path' do
|
57
|
+
get :index
|
58
|
+
response.should redirect_to('/')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'action_controller/railtie'
|
3
|
+
require 'rails/test_unit/railtie'
|
4
|
+
|
5
|
+
module Boomerang
|
6
|
+
class Application < Rails::Application
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'boomerang'
|
11
|
+
|
12
|
+
class ApplicationController < ActionController::Base
|
13
|
+
include Boomerang::ControllerSupport
|
14
|
+
include Rails.application.routes.url_helpers
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'rspec/rails'
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.mock_with :mocha
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: boomerang-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tom Ward
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &70364739589920 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70364739589920
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70364739588800 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.2.2
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70364739588800
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec-rails
|
38
|
+
requirement: &70364739587300 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.7.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70364739587300
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: mocha
|
49
|
+
requirement: &70364739586020 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70364739586020
|
58
|
+
description: Redirect away from an action and come back later
|
59
|
+
email:
|
60
|
+
- tom@popdog.net
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- Gemfile
|
67
|
+
- Rakefile
|
68
|
+
- boomerang.gemspec
|
69
|
+
- lib/boomerang.rb
|
70
|
+
- lib/boomerang/controller_support.rb
|
71
|
+
- lib/boomerang/version.rb
|
72
|
+
- spec/controllers/controller_support_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: ''
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
hash: 2214935989642829388
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
hash: 2214935989642829388
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.11
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Redirection helpers for rails
|
104
|
+
test_files:
|
105
|
+
- spec/controllers/controller_support_spec.rb
|
106
|
+
- spec/spec_helper.rb
|