fakesite 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/Rakefile +25 -6
- data/app/assets/stylesheets/fakesite/application.css +164 -164
- data/app/controllers/fakesite/fakesites_controller.rb +31 -28
- data/app/views/fakesite/fakesites/show.html.erb +55 -55
- data/config/routes.rb +7 -7
- data/config/spring.rb +1 -1
- data/lib/fakesite/action_controller.rb +18 -14
- data/lib/fakesite/base.rb +65 -57
- data/lib/fakesite/engine.rb +6 -6
- data/lib/fakesite/registration.rb +20 -19
- data/lib/fakesite/version.rb +3 -3
- data/lib/fakesite.rb +45 -39
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed01cfab014f5c03eae99b94cc2b9f923e27ca3d
|
4
|
+
data.tar.gz: d76f37ae83521989ad734a05aee6a9e2f79752a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e965244a24792f39df467f7ea7c0056f64905ae0969ebe903370a67d9cf5d83aa1177d7d5cb8fbd91da1fa852180efc815b7ef6ce9c5d89ea0d857a050459f37
|
7
|
+
data.tar.gz: de9c46dd58b591b7e50874f28649888b412b222531f4bf56045947267bb0853961af32291fcb5145d53a720fde784e8d0bb91e24490f02682fec45e1ffb29832
|
data/README.md
CHANGED
@@ -72,6 +72,9 @@ The parameters of external_uri in query string.
|
|
72
72
|
#### params
|
73
73
|
The post parameters in the fakesite page.
|
74
74
|
|
75
|
+
#### user
|
76
|
+
`current_user` instance from devise if exists.
|
77
|
+
|
75
78
|
|
76
79
|
### Register Fakesite
|
77
80
|
You can register your fakesites when rails initialize.
|
data/Rakefile
CHANGED
@@ -1,6 +1,25 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'fakesite'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bundler::GemHelper.install_tasks
|
@@ -1,165 +1,165 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
-
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
-
* file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
16
|
-
|
17
|
-
/* http://meyerweb.com/eric/tools/css/reset/
|
18
|
-
v2.0 | 20110126
|
19
|
-
License: none (public domain)
|
20
|
-
*/
|
21
|
-
|
22
|
-
html, body, div, span, applet, object, iframe,
|
23
|
-
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
24
|
-
a, abbr, acronym, address, big, cite, code,
|
25
|
-
del, dfn, em, img, ins, kbd, q, s, samp,
|
26
|
-
small, strike, strong, sub, sup, tt, var,
|
27
|
-
b, u, i, center,
|
28
|
-
dl, dt, dd, ol, ul, li,
|
29
|
-
fieldset, form, label, legend,
|
30
|
-
table, caption, tbody, tfoot, thead, tr, th, td,
|
31
|
-
article, aside, canvas, details, embed,
|
32
|
-
figure, figcaption, footer, header, hgroup,
|
33
|
-
menu, nav, output, ruby, section, summary,
|
34
|
-
time, mark, audio, video {
|
35
|
-
margin: 0;
|
36
|
-
padding: 0;
|
37
|
-
border: 0;
|
38
|
-
font-size: 100%;
|
39
|
-
font: inherit;
|
40
|
-
vertical-align: baseline;
|
41
|
-
}
|
42
|
-
/* HTML5 display-role reset for older browsers */
|
43
|
-
article, aside, details, figcaption, figure,
|
44
|
-
footer, header, hgroup, menu, nav, section {
|
45
|
-
display: block;
|
46
|
-
}
|
47
|
-
body {
|
48
|
-
line-height: 1;
|
49
|
-
}
|
50
|
-
ol, ul {
|
51
|
-
list-style: none;
|
52
|
-
}
|
53
|
-
blockquote, q {
|
54
|
-
quotes: none;
|
55
|
-
}
|
56
|
-
blockquote:before, blockquote:after,
|
57
|
-
q:before, q:after {
|
58
|
-
content: '';
|
59
|
-
content: none;
|
60
|
-
}
|
61
|
-
table {
|
62
|
-
border-collapse: collapse;
|
63
|
-
border-spacing: 0;
|
64
|
-
}
|
65
|
-
|
66
|
-
body {
|
67
|
-
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
|
68
|
-
font-size: 14px;
|
69
|
-
line-height: 1.42857143;
|
70
|
-
color: #333;
|
71
|
-
margin: 0 20px;
|
72
|
-
}
|
73
|
-
|
74
|
-
h2 {
|
75
|
-
font-size: 30px;
|
76
|
-
margin-top: 20px;
|
77
|
-
margin-bottom: 10px;
|
78
|
-
font-family: inherit;
|
79
|
-
font-weight: 500;
|
80
|
-
line-height: 1.1;
|
81
|
-
}
|
82
|
-
|
83
|
-
h3 {
|
84
|
-
font-size: 24px;
|
85
|
-
margin-top: 20px;
|
86
|
-
margin-bottom: 10px;
|
87
|
-
font-family: inherit;
|
88
|
-
font-weight: 500;
|
89
|
-
line-height: 1.1;
|
90
|
-
}
|
91
|
-
|
92
|
-
table {
|
93
|
-
border: 1px solid #ddd;
|
94
|
-
width: 100%;
|
95
|
-
max-width: 100%;
|
96
|
-
border-spacing: 0;
|
97
|
-
border-collapse: collapse;
|
98
|
-
}
|
99
|
-
|
100
|
-
tr:nth-of-type(odd) {
|
101
|
-
background-color: #f9f9f9;
|
102
|
-
}
|
103
|
-
|
104
|
-
tr:first-child>th {
|
105
|
-
border-top: 0;
|
106
|
-
}
|
107
|
-
|
108
|
-
th, td {
|
109
|
-
border-bottom-width: 2px;
|
110
|
-
border: 1px solid #ddd;
|
111
|
-
vertical-align: bottom;
|
112
|
-
border-bottom: 2px solid #ddd;
|
113
|
-
padding: 8px;
|
114
|
-
line-height: 1.42857143;
|
115
|
-
vertical-align: top;
|
116
|
-
border-top: 1px solid #ddd;
|
117
|
-
}
|
118
|
-
|
119
|
-
a {
|
120
|
-
text-decoration: none;
|
121
|
-
color: #007CFF;
|
122
|
-
}
|
123
|
-
|
124
|
-
.btn {
|
125
|
-
display: inline-block;
|
126
|
-
padding: 6px 12px;
|
127
|
-
margin-bottom: 0;
|
128
|
-
font-size: 14px;
|
129
|
-
font-weight: 400;
|
130
|
-
line-height: 1.42857143;
|
131
|
-
text-align: center;
|
132
|
-
white-space: nowrap;
|
133
|
-
vertical-align: middle;
|
134
|
-
-ms-touch-action: manipulation;
|
135
|
-
touch-action: manipulation;
|
136
|
-
cursor: pointer;
|
137
|
-
-webkit-user-select: none;
|
138
|
-
-moz-user-select: none;
|
139
|
-
-ms-user-select: none;
|
140
|
-
user-select: none;
|
141
|
-
background-image: none;
|
142
|
-
border: 1px solid transparent;
|
143
|
-
border-radius: 4px;
|
144
|
-
}
|
145
|
-
|
146
|
-
.btn-default:hover {
|
147
|
-
color: #333;
|
148
|
-
background-color: #e6e6e6;
|
149
|
-
border-color: #adadad;
|
150
|
-
}
|
151
|
-
|
152
|
-
.btn.focus, .btn:focus, .btn:hover {
|
153
|
-
color: #333;
|
154
|
-
text-decoration: none;
|
155
|
-
}
|
156
|
-
|
157
|
-
.btn-default {
|
158
|
-
color: #333;
|
159
|
-
background-color: #fff;
|
160
|
-
border-color: #ccc;
|
161
|
-
}
|
162
|
-
|
163
|
-
.center {
|
164
|
-
text-align: center;
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
16
|
+
|
17
|
+
/* http://meyerweb.com/eric/tools/css/reset/
|
18
|
+
v2.0 | 20110126
|
19
|
+
License: none (public domain)
|
20
|
+
*/
|
21
|
+
|
22
|
+
html, body, div, span, applet, object, iframe,
|
23
|
+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
24
|
+
a, abbr, acronym, address, big, cite, code,
|
25
|
+
del, dfn, em, img, ins, kbd, q, s, samp,
|
26
|
+
small, strike, strong, sub, sup, tt, var,
|
27
|
+
b, u, i, center,
|
28
|
+
dl, dt, dd, ol, ul, li,
|
29
|
+
fieldset, form, label, legend,
|
30
|
+
table, caption, tbody, tfoot, thead, tr, th, td,
|
31
|
+
article, aside, canvas, details, embed,
|
32
|
+
figure, figcaption, footer, header, hgroup,
|
33
|
+
menu, nav, output, ruby, section, summary,
|
34
|
+
time, mark, audio, video {
|
35
|
+
margin: 0;
|
36
|
+
padding: 0;
|
37
|
+
border: 0;
|
38
|
+
font-size: 100%;
|
39
|
+
font: inherit;
|
40
|
+
vertical-align: baseline;
|
41
|
+
}
|
42
|
+
/* HTML5 display-role reset for older browsers */
|
43
|
+
article, aside, details, figcaption, figure,
|
44
|
+
footer, header, hgroup, menu, nav, section {
|
45
|
+
display: block;
|
46
|
+
}
|
47
|
+
body {
|
48
|
+
line-height: 1;
|
49
|
+
}
|
50
|
+
ol, ul {
|
51
|
+
list-style: none;
|
52
|
+
}
|
53
|
+
blockquote, q {
|
54
|
+
quotes: none;
|
55
|
+
}
|
56
|
+
blockquote:before, blockquote:after,
|
57
|
+
q:before, q:after {
|
58
|
+
content: '';
|
59
|
+
content: none;
|
60
|
+
}
|
61
|
+
table {
|
62
|
+
border-collapse: collapse;
|
63
|
+
border-spacing: 0;
|
64
|
+
}
|
65
|
+
|
66
|
+
body {
|
67
|
+
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
|
68
|
+
font-size: 14px;
|
69
|
+
line-height: 1.42857143;
|
70
|
+
color: #333;
|
71
|
+
margin: 0 20px;
|
72
|
+
}
|
73
|
+
|
74
|
+
h2 {
|
75
|
+
font-size: 30px;
|
76
|
+
margin-top: 20px;
|
77
|
+
margin-bottom: 10px;
|
78
|
+
font-family: inherit;
|
79
|
+
font-weight: 500;
|
80
|
+
line-height: 1.1;
|
81
|
+
}
|
82
|
+
|
83
|
+
h3 {
|
84
|
+
font-size: 24px;
|
85
|
+
margin-top: 20px;
|
86
|
+
margin-bottom: 10px;
|
87
|
+
font-family: inherit;
|
88
|
+
font-weight: 500;
|
89
|
+
line-height: 1.1;
|
90
|
+
}
|
91
|
+
|
92
|
+
table {
|
93
|
+
border: 1px solid #ddd;
|
94
|
+
width: 100%;
|
95
|
+
max-width: 100%;
|
96
|
+
border-spacing: 0;
|
97
|
+
border-collapse: collapse;
|
98
|
+
}
|
99
|
+
|
100
|
+
tr:nth-of-type(odd) {
|
101
|
+
background-color: #f9f9f9;
|
102
|
+
}
|
103
|
+
|
104
|
+
tr:first-child>th {
|
105
|
+
border-top: 0;
|
106
|
+
}
|
107
|
+
|
108
|
+
th, td {
|
109
|
+
border-bottom-width: 2px;
|
110
|
+
border: 1px solid #ddd;
|
111
|
+
vertical-align: bottom;
|
112
|
+
border-bottom: 2px solid #ddd;
|
113
|
+
padding: 8px;
|
114
|
+
line-height: 1.42857143;
|
115
|
+
vertical-align: top;
|
116
|
+
border-top: 1px solid #ddd;
|
117
|
+
}
|
118
|
+
|
119
|
+
a {
|
120
|
+
text-decoration: none;
|
121
|
+
color: #007CFF;
|
122
|
+
}
|
123
|
+
|
124
|
+
.btn {
|
125
|
+
display: inline-block;
|
126
|
+
padding: 6px 12px;
|
127
|
+
margin-bottom: 0;
|
128
|
+
font-size: 14px;
|
129
|
+
font-weight: 400;
|
130
|
+
line-height: 1.42857143;
|
131
|
+
text-align: center;
|
132
|
+
white-space: nowrap;
|
133
|
+
vertical-align: middle;
|
134
|
+
-ms-touch-action: manipulation;
|
135
|
+
touch-action: manipulation;
|
136
|
+
cursor: pointer;
|
137
|
+
-webkit-user-select: none;
|
138
|
+
-moz-user-select: none;
|
139
|
+
-ms-user-select: none;
|
140
|
+
user-select: none;
|
141
|
+
background-image: none;
|
142
|
+
border: 1px solid transparent;
|
143
|
+
border-radius: 4px;
|
144
|
+
}
|
145
|
+
|
146
|
+
.btn-default:hover {
|
147
|
+
color: #333;
|
148
|
+
background-color: #e6e6e6;
|
149
|
+
border-color: #adadad;
|
150
|
+
}
|
151
|
+
|
152
|
+
.btn.focus, .btn:focus, .btn:hover {
|
153
|
+
color: #333;
|
154
|
+
text-decoration: none;
|
155
|
+
}
|
156
|
+
|
157
|
+
.btn-default {
|
158
|
+
color: #333;
|
159
|
+
background-color: #fff;
|
160
|
+
border-color: #ccc;
|
161
|
+
}
|
162
|
+
|
163
|
+
.center {
|
164
|
+
text-align: center;
|
165
165
|
}
|
@@ -1,28 +1,31 @@
|
|
1
|
-
module Fakesite
|
2
|
-
class FakesitesController < Fakesite::ApplicationController
|
3
|
-
before_action :find_registration
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@fakesite = @
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
1
|
+
module Fakesite
|
2
|
+
class FakesitesController < Fakesite::ApplicationController
|
3
|
+
before_action :find_registration
|
4
|
+
|
5
|
+
def show
|
6
|
+
@uri = URI.parse(params[:url])
|
7
|
+
@id = params[:id]
|
8
|
+
@fakesite = @registration.create
|
9
|
+
@fakesite.external_uri = @uri
|
10
|
+
key = params[:key]
|
11
|
+
if key
|
12
|
+
@fakesite.user = Rails.cache.fetch(key)
|
13
|
+
Rails.cache.delete(key)
|
14
|
+
@fakesite.reload_user
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def redirect
|
19
|
+
@fakesite = @registration.deserialize(params[:serialization])
|
20
|
+
@fakesite.reload_user
|
21
|
+
@fakesite.params = params[:p]
|
22
|
+
redirect_to @fakesite.redirect_url
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def find_registration
|
28
|
+
@registration = Fakesite.find(params[:id])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
<h2>
|
2
|
-
Fakesite - <%=@id %>
|
3
|
-
</h2>
|
4
|
-
<h3>Request Host</h3>
|
5
|
-
<p><%= @uri.to_s.split('?')[0] %></p>
|
6
|
-
<h3>Request Parameters</h3>
|
7
|
-
<table>
|
8
|
-
<colgroup>
|
9
|
-
<col width="200px"></col>
|
10
|
-
<col></col>
|
11
|
-
</colgroup>
|
12
|
-
<tr>
|
13
|
-
<th>Key</th>
|
14
|
-
<th>Value</th>
|
15
|
-
</tr>
|
16
|
-
<% Rack::Utils.parse_nested_query(@uri.query).each do |key, value| %>
|
17
|
-
<tr>
|
18
|
-
<td>
|
19
|
-
<%= key %>
|
20
|
-
</td>
|
21
|
-
<td>
|
22
|
-
<%= value %>
|
23
|
-
</td>
|
24
|
-
</tr>
|
25
|
-
<% end %>
|
26
|
-
</table>
|
27
|
-
<h3>Return Parameters</h3>
|
28
|
-
<%= form_tag redirect_fakesite_path(@id), :method => :post do %>
|
29
|
-
<table>
|
30
|
-
<colgroup>
|
31
|
-
<col width="200px"></col>
|
32
|
-
<col></col>
|
33
|
-
</colgroup>
|
34
|
-
<tr>
|
35
|
-
<th>Key</th>
|
36
|
-
<th>Value</th>
|
37
|
-
</tr>
|
38
|
-
<% @fakesite.parameters.each do |key, value| %>
|
39
|
-
<tr>
|
40
|
-
<td>
|
41
|
-
<%= label_tag "p[#{key}]", key %>
|
42
|
-
</td>
|
43
|
-
<td>
|
44
|
-
<%= text_field_tag "p[#{key}]", value %>
|
45
|
-
</td>
|
46
|
-
</tr>
|
47
|
-
<% end %>
|
48
|
-
<tr>
|
49
|
-
<td colspan="2" class="center">
|
50
|
-
<%= hidden_field_tag :serialization, @fakesite.serialize %>
|
51
|
-
<button type="submit" class="btn btn-default">Return</button>
|
52
|
-
</td>
|
53
|
-
</tr>
|
54
|
-
</table>
|
55
|
-
<% end %>
|
1
|
+
<h2>
|
2
|
+
Fakesite - <%=@id %>
|
3
|
+
</h2>
|
4
|
+
<h3>Request Host</h3>
|
5
|
+
<p><%= @uri.to_s.split('?')[0] %></p>
|
6
|
+
<h3>Request Parameters</h3>
|
7
|
+
<table>
|
8
|
+
<colgroup>
|
9
|
+
<col width="200px"></col>
|
10
|
+
<col></col>
|
11
|
+
</colgroup>
|
12
|
+
<tr>
|
13
|
+
<th>Key</th>
|
14
|
+
<th>Value</th>
|
15
|
+
</tr>
|
16
|
+
<% Rack::Utils.parse_nested_query(@uri.query).each do |key, value| %>
|
17
|
+
<tr>
|
18
|
+
<td>
|
19
|
+
<%= key %>
|
20
|
+
</td>
|
21
|
+
<td>
|
22
|
+
<%= value %>
|
23
|
+
</td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
</table>
|
27
|
+
<h3>Return Parameters</h3>
|
28
|
+
<%= form_tag redirect_fakesite_path(@id), :method => :post do %>
|
29
|
+
<table>
|
30
|
+
<colgroup>
|
31
|
+
<col width="200px"></col>
|
32
|
+
<col></col>
|
33
|
+
</colgroup>
|
34
|
+
<tr>
|
35
|
+
<th>Key</th>
|
36
|
+
<th>Value</th>
|
37
|
+
</tr>
|
38
|
+
<% @fakesite.parameters.each do |key, value| %>
|
39
|
+
<tr>
|
40
|
+
<td>
|
41
|
+
<%= label_tag "p[#{key}]", key %>
|
42
|
+
</td>
|
43
|
+
<td>
|
44
|
+
<%= text_field_tag "p[#{key}]", value %>
|
45
|
+
</td>
|
46
|
+
</tr>
|
47
|
+
<% end %>
|
48
|
+
<tr>
|
49
|
+
<td colspan="2" class="center">
|
50
|
+
<%= hidden_field_tag :serialization, @fakesite.serialize %>
|
51
|
+
<button type="submit" class="btn btn-default">Return</button>
|
52
|
+
</td>
|
53
|
+
</tr>
|
54
|
+
</table>
|
55
|
+
<% end %>
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
Fakesite::Engine.routes.draw do
|
2
|
-
resources :fakesites, :path => '/', :only => [:show] do
|
3
|
-
member do
|
4
|
-
post 'redirect'
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
1
|
+
Fakesite::Engine.routes.draw do
|
2
|
+
resources :fakesites, :path => '/', :only => [:show] do
|
3
|
+
member do
|
4
|
+
post 'redirect'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
data/config/spring.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Spring.application_root = './spec/dummy'
|
1
|
+
Spring.application_root = './spec/dummy'
|
@@ -1,14 +1,18 @@
|
|
1
|
-
if defined?(::Rails::Engine)
|
2
|
-
class ActionController::Base
|
3
|
-
alias_method :orig_redirect_to, :redirect_to
|
4
|
-
|
5
|
-
def redirect_to(options = {}, response_status = {})
|
6
|
-
id = Fakesite.match(options)
|
7
|
-
if id
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
if defined?(::Rails::Engine)
|
2
|
+
class ActionController::Base
|
3
|
+
alias_method :orig_redirect_to, :redirect_to
|
4
|
+
|
5
|
+
def redirect_to(options = {}, response_status = {})
|
6
|
+
id = Fakesite.match(options)
|
7
|
+
if id
|
8
|
+
if respond_to? :current_user
|
9
|
+
key = Fakesite.generate_cache_key
|
10
|
+
Rails.cache.write(key, current_user)
|
11
|
+
end
|
12
|
+
orig_redirect_to Fakesite::Engine.routes.url_helpers.fakesite_path(id, :url => options, :key => key)
|
13
|
+
else
|
14
|
+
orig_redirect_to(options, response_status)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/fakesite/base.rb
CHANGED
@@ -1,57 +1,65 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Fakesite
|
4
|
-
class Base
|
5
|
-
attr_accessor :external_uri, :options, :params
|
6
|
-
|
7
|
-
def initialize(options = {})
|
8
|
-
self.options = options
|
9
|
-
end
|
10
|
-
|
11
|
-
def parameters
|
12
|
-
{}
|
13
|
-
end
|
14
|
-
|
15
|
-
def return_parameters
|
16
|
-
params
|
17
|
-
end
|
18
|
-
|
19
|
-
def return_url
|
20
|
-
external_params["return_url"] || '/'
|
21
|
-
end
|
22
|
-
|
23
|
-
def redirect_url
|
24
|
-
append_parameters(return_url, return_parameters)
|
25
|
-
end
|
26
|
-
|
27
|
-
def serialize
|
28
|
-
YAML.dump(self)
|
29
|
-
end
|
30
|
-
|
31
|
-
def
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Fakesite
|
4
|
+
class Base
|
5
|
+
attr_accessor :external_uri, :options, :params, :user
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
self.options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def parameters
|
12
|
+
{}
|
13
|
+
end
|
14
|
+
|
15
|
+
def return_parameters
|
16
|
+
params
|
17
|
+
end
|
18
|
+
|
19
|
+
def return_url
|
20
|
+
external_params["return_url"] || '/'
|
21
|
+
end
|
22
|
+
|
23
|
+
def redirect_url
|
24
|
+
append_parameters(return_url, return_parameters)
|
25
|
+
end
|
26
|
+
|
27
|
+
def serialize
|
28
|
+
YAML.dump(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
def reload_user
|
32
|
+
user.reload if !user.nil? && user.respond_to?(:reload)
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.match(external_uri)
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.deserialize(source)
|
40
|
+
YAML.load(source)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.after_register
|
44
|
+
end
|
45
|
+
|
46
|
+
protected
|
47
|
+
|
48
|
+
def external_params
|
49
|
+
query_to_hash(external_uri)
|
50
|
+
end
|
51
|
+
|
52
|
+
def query_to_hash(uri)
|
53
|
+
uri.query ? Hash[CGI.parse(uri.query).map {|key,values| [key, values[0] || true]}] : {}
|
54
|
+
end
|
55
|
+
|
56
|
+
def append_parameters(url, params)
|
57
|
+
query_string = URI.encode_www_form(params || {})
|
58
|
+
if query_string == ""
|
59
|
+
return url
|
60
|
+
else
|
61
|
+
url + (url.include?('?') ? '&' : '?') + query_string
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/fakesite/engine.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
if defined?(::Rails::Engine)
|
2
|
-
module Fakesite
|
3
|
-
class Engine < ::Rails::Engine
|
4
|
-
isolate_namespace Fakesite
|
5
|
-
end
|
6
|
-
end
|
1
|
+
if defined?(::Rails::Engine)
|
2
|
+
module Fakesite
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
isolate_namespace Fakesite
|
5
|
+
end
|
6
|
+
end
|
7
7
|
end
|
@@ -1,19 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Fakesite
|
4
|
+
class Registration
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
attr_accessor :id, :fakesite, :options
|
8
|
+
def_delegators :fakesite, :match, :deserialize
|
9
|
+
|
10
|
+
def initialize(id, fakesite, options = {})
|
11
|
+
self.id = id
|
12
|
+
self.fakesite = fakesite
|
13
|
+
self.options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
fakesite.new(options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/fakesite/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Fakesite
|
2
|
-
VERSION = "0.2.
|
3
|
-
end
|
1
|
+
module Fakesite
|
2
|
+
VERSION = "0.2.1"
|
3
|
+
end
|
data/lib/fakesite.rb
CHANGED
@@ -1,39 +1,45 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require "fakesite/engine"
|
3
|
-
require "fakesite/base"
|
4
|
-
require "fakesite/registration"
|
5
|
-
|
6
|
-
module Fakesite
|
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
|
-
def self.
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
1
|
+
require 'uri'
|
2
|
+
require "fakesite/engine"
|
3
|
+
require "fakesite/base"
|
4
|
+
require "fakesite/registration"
|
5
|
+
|
6
|
+
module Fakesite
|
7
|
+
CacheKey = "fakesite"
|
8
|
+
|
9
|
+
@@initialized = false
|
10
|
+
@@registrations = {}
|
11
|
+
|
12
|
+
def self.register(id, fakesite, options = {})
|
13
|
+
Fakesite.initialize
|
14
|
+
id = id.to_sym
|
15
|
+
@@registrations[id] = Registration.new(id, fakesite, options)
|
16
|
+
fakesite.after_register
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.match(url)
|
20
|
+
return false unless url.is_a? String
|
21
|
+
begin
|
22
|
+
uri = URI.parse(url)
|
23
|
+
@@registrations.each do |id, fakesite|
|
24
|
+
return id if fakesite.match(uri)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.find(id)
|
31
|
+
@@registrations[id.to_sym]
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.generate_cache_key
|
35
|
+
"#{CacheKey}:#{Time.now.to_i}"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def self.initialize
|
41
|
+
return if @@initialized
|
42
|
+
@@initialized = true
|
43
|
+
require "fakesite/action_controller"
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fakesite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chen Yi-Cyuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|