jump_back 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jump_back/engine.rb +1 -1
- data/lib/jump_back/options_parser.rb +19 -0
- data/lib/jump_back/redirect_back.rb +6 -16
- data/lib/jump_back/redirection_determiner.rb +2 -1
- data/lib/jump_back/referer_interpreter.rb +5 -5
- data/lib/jump_back/return_to_referer.rb +16 -11
- data/lib/jump_back/version.rb +1 -1
- data/spec/controller/application_controller_spec.rb +31 -13
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/environments/development.rb +1 -1
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +2 -2
- data/spec/dummy/log/development.log +91 -0
- data/spec/dummy/log/test.log +5793 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13b46750e5e152338c99ca95598a07da26f2520c
|
4
|
+
data.tar.gz: bcfc2c6ff049737adca0d7d039ec284e76caae0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae36bde7619da211b1d0277079188c376734124f926ebb65ccce53e5251c742a26ffd37e03651e67e9baea4292f2078ff41be724724fe3ee16c15f35ebc844b0
|
7
|
+
data.tar.gz: 44ec9bd6e00a0fa7f45c9f43ffe603386ae9b8d4cf2978d5a538613831100c013fc9ce1d255f40db3f9d682fdf3c1778520a15a0a323e6f7c258d5f16c500a8a
|
data/lib/jump_back/engine.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module JumpBack
|
2
|
+
|
3
|
+
class OptionsParser
|
4
|
+
|
5
|
+
def self.parse(path, options, default)
|
6
|
+
if path.is_a? Hash
|
7
|
+
options = path
|
8
|
+
path = default
|
9
|
+
end
|
10
|
+
|
11
|
+
jump_back_options = { offsite: options.delete(:offsite) }
|
12
|
+
{
|
13
|
+
redirect_options: options,
|
14
|
+
jump_back_options: jump_back_options,
|
15
|
+
path: path
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,24 +1,14 @@
|
|
1
1
|
require 'jump_back/referer_interpreter'
|
2
2
|
require 'jump_back/redirection_determiner'
|
3
|
+
require 'jump_back/options_parser'
|
3
4
|
|
4
5
|
module JumpBack
|
5
6
|
|
6
|
-
|
7
|
-
parsed_args = parse_jump_back_arguments(path, options)
|
8
|
-
redirect_to RedirectionDeterminer.new(request, parsed_args[:path], parsed_args[:jump_back_options]).path, parsed_args[:redirect_options]
|
9
|
-
end
|
10
|
-
|
11
|
-
def parse_jump_back_arguments(path, options)
|
12
|
-
if path.is_a? Hash
|
13
|
-
options = path
|
14
|
-
path = root_path
|
15
|
-
end
|
7
|
+
module Redirection
|
16
8
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
path: path
|
22
|
-
}
|
9
|
+
def redirect_back(path=root_path, options={})
|
10
|
+
parsed_args = OptionsParser.parse(path, options, root_path)
|
11
|
+
redirect_to RedirectionDeterminer.new(request, parsed_args[:path], parsed_args[:jump_back_options]).path, parsed_args[:redirect_options]
|
12
|
+
end
|
23
13
|
end
|
24
14
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module JumpBack
|
2
|
+
|
2
3
|
class RedirectionDeterminer
|
3
4
|
attr_reader :path
|
4
5
|
|
@@ -7,7 +8,7 @@ module JumpBack
|
|
7
8
|
end
|
8
9
|
|
9
10
|
def path_determiner(request, path, options)
|
10
|
-
RefererInterpreter.
|
11
|
+
RefererInterpreter.back?(request, options) ? :back : path
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -2,15 +2,15 @@ module JumpBack
|
|
2
2
|
|
3
3
|
class RefererInterpreter
|
4
4
|
|
5
|
-
def back?(request, options)
|
5
|
+
def self.back?(request, options)
|
6
6
|
has_referer?(request) ? is_local?(request, options) ? true : false : false
|
7
7
|
end
|
8
8
|
|
9
|
-
def has_referer?(request)
|
9
|
+
def self.has_referer?(request)
|
10
10
|
!request.env["HTTP_REFERER"].blank? and request.env["HTTP_REFERER"] != request.env["REQUEST_URI"]
|
11
11
|
end
|
12
12
|
|
13
|
-
def is_local?(request, options)
|
13
|
+
def self.is_local?(request, options)
|
14
14
|
return true if options[:offsite]
|
15
15
|
host = host(request.env["HTTP_REFERER"])
|
16
16
|
!(host && host != request.host)
|
@@ -18,11 +18,11 @@ module JumpBack
|
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
def host(string)
|
21
|
+
def self.host(string)
|
22
22
|
return URI.parse(string).host if uri? string
|
23
23
|
end
|
24
24
|
|
25
|
-
def uri?(string)
|
25
|
+
def self.uri?(string)
|
26
26
|
uri = URI.parse(string)
|
27
27
|
%w( http https ).include?(uri.scheme)
|
28
28
|
rescue URI::BadURIError
|
@@ -1,15 +1,20 @@
|
|
1
|
+
require 'jump_back/options_parser'
|
2
|
+
|
1
3
|
module JumpBack
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
module Redirection
|
6
|
+
|
7
|
+
def save_referer
|
8
|
+
session[:jump_back_stored_referer] ||= request.referer
|
9
|
+
end
|
10
|
+
|
11
|
+
def return_to_referer(path=root_path, options={})
|
12
|
+
parsed_args = OptionsParser.parse(path, options, root_path)
|
13
|
+
session[:jump_back_stored_referer] ? redirect_to(clear_referer, parsed_args[:redirect_options]) : redirect_to(parsed_args[:path], parsed_args[:redirect_options])
|
14
|
+
end
|
15
|
+
|
16
|
+
def clear_referer
|
17
|
+
session.delete(:jump_back_stored_referer)
|
18
|
+
end
|
14
19
|
end
|
15
20
|
end
|
data/lib/jump_back/version.rb
CHANGED
@@ -1,18 +1,36 @@
|
|
1
1
|
describe ApplicationController do
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
describe 'jump_back methods' do
|
4
|
+
|
5
|
+
it 'should have the redirect_back method' do
|
6
|
+
expect(ApplicationController.new).to respond_to :redirect_back
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should have the save_referer method' do
|
10
|
+
expect(ApplicationController.new).to respond_to :save_referer
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have the return_to_referer method' do
|
14
|
+
expect(ApplicationController.new).to respond_to :return_to_referer
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should have the clear_referer method' do
|
18
|
+
expect(ApplicationController.new).to respond_to :clear_referer
|
19
|
+
end
|
13
20
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
21
|
+
|
22
|
+
describe 'private jump_back classes' do
|
23
|
+
|
24
|
+
it 'should not have the OptionsParser class' do
|
25
|
+
expect { ApplicationController::OptionsParser.new }.to raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should not have the RefererInterpreter class' do
|
29
|
+
expect { ApplicationController::RefererInterpreter.new }.to raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not have the RedirectionDeterminer class' do
|
33
|
+
expect { ApplicationController::RedirectionDeterminer.new }.to raise_error
|
34
|
+
end
|
17
35
|
end
|
18
36
|
end
|
@@ -13,6 +13,7 @@ require "jump_back"
|
|
13
13
|
|
14
14
|
module Dummy
|
15
15
|
class Application < Rails::Application
|
16
|
+
config.secret_key_base = '19af9ac3d6f4fdbae6dc48cb0dfb99a825f38c144ce34f456e81da6f87fbf24571f3a79c9999419fe9f26a340b2b4fac202bd3b0cb907146992d6e80bc94309f'
|
16
17
|
# Settings in config/environments/* take precedence over those specified here.
|
17
18
|
# Application configuration should go into files in config/initializers
|
18
19
|
# -- all .rb files in that directory are automatically loaded.
|
@@ -20,7 +20,7 @@ Rails.application.configure do
|
|
20
20
|
# config.action_dispatch.rack_cache = true
|
21
21
|
|
22
22
|
# Disable Rails's static asset server (Apache or nginx will already do this).
|
23
|
-
config.serve_static_assets = false
|
23
|
+
# config.serve_static_assets = false
|
24
24
|
|
25
25
|
# Compress JavaScripts and CSS.
|
26
26
|
config.assets.js_compressor = :uglifier
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Dummy::Application.configure do
|
2
2
|
# Settings specified here will take precedence over those in config/application.rb.
|
3
3
|
|
4
4
|
# The test environment is used exclusively to run your application's
|
@@ -13,7 +13,7 @@ Rails.application.configure do
|
|
13
13
|
config.eager_load = false
|
14
14
|
|
15
15
|
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
-
config.serve_static_assets = true
|
16
|
+
# config.serve_static_assets = true
|
17
17
|
config.static_cache_control = 'public, max-age=3600'
|
18
18
|
|
19
19
|
# Show full error reports and disable caching.
|
@@ -12,3 +12,94 @@
|
|
12
12
|
[1m[36m (1.7ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
13
13
|
[1m[35m (0.2ms)[0m SELECT version FROM "schema_migrations"
|
14
14
|
[1m[36m (1.0ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
15
|
+
[1m[36m (1.6ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
16
|
+
[1m[35m (0.6ms)[0m select sqlite_version(*)
|
17
|
+
[1m[36m (1.7ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
18
|
+
[1m[35m (0.2ms)[0m SELECT version FROM "schema_migrations"
|
19
|
+
[1m[36m (1.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
20
|
+
[1m[36m (8.5ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
21
|
+
[1m[35m (0.3ms)[0m select sqlite_version(*)
|
22
|
+
[1m[36m (1.6ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
23
|
+
[1m[35m (0.2ms)[0m SELECT version FROM "schema_migrations"
|
24
|
+
[1m[36m (1.0ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
25
|
+
[1m[36m (1.4ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
26
|
+
[1m[35m (1.2ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
27
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
28
|
+
[1m[35m (1.2ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
29
|
+
[1m[36m (1.2ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
30
|
+
[1m[35m (1.1ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
31
|
+
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
32
|
+
[1m[35m (0.9ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
33
|
+
[1m[36m (9.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
34
|
+
[1m[35m (1.2ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
35
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
36
|
+
[1m[35m (1.1ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
37
|
+
[1m[36m (9.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
38
|
+
[1m[35m (1.3ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
39
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
40
|
+
[1m[35m (1.1ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
41
|
+
[1m[36m (1.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
42
|
+
[1m[35m (1.2ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
43
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
44
|
+
[1m[35m (1.1ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
45
|
+
[1m[36m (1.8ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
46
|
+
[1m[35m (1.5ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
47
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
48
|
+
[1m[35m (1.1ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
49
|
+
[1m[36m (1.7ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
50
|
+
[1m[35m (1.6ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
51
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
52
|
+
[1m[35m (1.1ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
53
|
+
[1m[36m (3.4ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
54
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
55
|
+
[1m[36m (2.2ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
56
|
+
[1m[35m (0.2ms)[0m SELECT version FROM "schema_migrations"
|
57
|
+
[1m[36m (1.2ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
58
|
+
[1m[36m (1.4ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
59
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
60
|
+
[1m[36m (1.2ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
61
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
62
|
+
[1m[36m (1.2ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
63
|
+
[1m[36m (1.7ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
64
|
+
[1m[35m (1.9ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
65
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
66
|
+
[1m[35m (1.1ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
67
|
+
[1m[36m (1.5ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
68
|
+
[1m[35m (1.3ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
69
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
70
|
+
[1m[35m (1.0ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
71
|
+
[1m[36m (1.2ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
72
|
+
[1m[35m (1.2ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
73
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
74
|
+
[1m[35m (1.3ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
75
|
+
[1m[36m (1.1ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
76
|
+
[1m[35m (1.0ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
77
|
+
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
78
|
+
[1m[35m (1.1ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
79
|
+
[1m[36m (9.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
80
|
+
[1m[35m (0.6ms)[0m select sqlite_version(*)
|
81
|
+
[1m[36m (1.4ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
82
|
+
[1m[35m (0.2ms)[0m SELECT version FROM "schema_migrations"
|
83
|
+
[1m[36m (1.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
84
|
+
[1m[36m (9.6ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
85
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
86
|
+
[1m[36m (1.5ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
87
|
+
[1m[35m (0.2ms)[0m SELECT version FROM "schema_migrations"
|
88
|
+
[1m[36m (1.2ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
89
|
+
[1m[36m (8.5ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
90
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
91
|
+
[1m[36m (1.3ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
92
|
+
[1m[35m (0.2ms)[0m SELECT version FROM "schema_migrations"
|
93
|
+
[1m[36m (1.2ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
94
|
+
[1m[36m (1.5ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
95
|
+
[1m[35m (1.3ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
96
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
97
|
+
[1m[35m (1.1ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
98
|
+
[1m[36m (1.1ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
99
|
+
[1m[35m (1.1ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
100
|
+
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
101
|
+
[1m[35m (0.9ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|
102
|
+
[1m[36m (3.0ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
103
|
+
[1m[35m (1.7ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
104
|
+
[1m[36m (0.2ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
105
|
+
[1m[35m (1.2ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('0')
|