fakesite 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/app/assets/stylesheets/fakesite/application.css +164 -164
- data/app/controllers/fakesite/fakesites_controller.rb +28 -22
- 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 +14 -14
- data/lib/fakesite/base.rb +57 -46
- data/lib/fakesite/engine.rb +6 -6
- data/lib/fakesite/registration.rb +19 -0
- data/lib/fakesite/version.rb +3 -3
- data/lib/fakesite.rb +39 -30
- metadata +8 -6
- data/lib/tasks/fakesite_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08f44d742e0b802e08b50d0424208f4a3ad37ac6
|
4
|
+
data.tar.gz: ddbad39717b60f63865067e26caba4de103ff2da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f12b46ee83323d635c8ed2c760d84f3fc753a693a620a3219b814c6c2d60310c66be2ed0c867eeb6710ad159ba9be591fd4f5e661966bf5746718d71c59439b
|
7
|
+
data.tar.gz: e5c2a6df51e96f861eebb9befc472410e8bae68f10a443a5c599e1ee25820ee1996f19a8190f33758e4a3c8381c23b928e9f520b2a85b1eb1d61809e619c3838
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Chen Yi-Cyuan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# Fakesite
|
2
|
+
|
3
|
+
[![Build Status](https://api.travis-ci.org/emn178/fakesite.png)](https://travis-ci.org/emn178/fakesite)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/emn178/fakesite/badge.svg?branch=master)](https://coveralls.io/r/emn178/fakesite?branch=master)
|
5
|
+
|
6
|
+
An rails plugin that provides a fake framework to stub 3-party redirect page such as payment or oauth login.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'fakesite', group: :development
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
bundle
|
19
|
+
|
20
|
+
### Route
|
21
|
+
Add fakesite route in your `config/route.rb`
|
22
|
+
```Ruby
|
23
|
+
mount Fakesite::Engine => "/fakesite" if Rails.env.development?
|
24
|
+
```
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
### Create Your Fakesite
|
29
|
+
|
30
|
+
Inherit `Fakesite::Base` class and implement methods:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class TestFakesite < Fakesite::Base
|
34
|
+
# specify what the parameters will return to your site
|
35
|
+
def parameters
|
36
|
+
{:test_key1 => :value1, :test_key2 => :value2}
|
37
|
+
end
|
38
|
+
|
39
|
+
# overwrite where to return, default using return_url in external_uri query string if exsit
|
40
|
+
def return_url
|
41
|
+
external_params["custom_url"]
|
42
|
+
end
|
43
|
+
|
44
|
+
# overwrite the parameters that will pass to return_url. default is params, you can do something here
|
45
|
+
# def return_parameters
|
46
|
+
# params
|
47
|
+
# end
|
48
|
+
|
49
|
+
# implement the rule to stub external page by redirect url
|
50
|
+
def self.match(external_uri)
|
51
|
+
external_uri.host == "test.com"
|
52
|
+
end
|
53
|
+
|
54
|
+
# after register event
|
55
|
+
# def self.after_register
|
56
|
+
# end
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
### Class Members
|
61
|
+
You can use following properties and methods in instance of Fakesite::Base class:
|
62
|
+
|
63
|
+
#### options
|
64
|
+
The options that you registered.
|
65
|
+
|
66
|
+
#### external_uri
|
67
|
+
The original uri of external third-party.
|
68
|
+
|
69
|
+
#### external_params
|
70
|
+
The parameters of external_uri in query string.
|
71
|
+
|
72
|
+
#### params
|
73
|
+
The post parameters in the fakesite page.
|
74
|
+
|
75
|
+
|
76
|
+
### Register Fakesite
|
77
|
+
You can register your fakesites when rails initialize.
|
78
|
+
```Ruby
|
79
|
+
if Rails.env.development?
|
80
|
+
Fakesite.register :test, TestFakesite
|
81
|
+
# You can also pass some options if needs, and using by options in your class
|
82
|
+
# Fakesite.register :test, TestFakesite, {:your => :option}
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
You can put the registration in `config/initializers/fakesite.rb`
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
91
|
+
|
92
|
+
## Contact
|
93
|
+
The project's website is located at https://github.com/emn178/fakesite
|
94
|
+
Author: emn178@gmail.com
|
@@ -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,22 +1,28 @@
|
|
1
|
-
module Fakesite
|
2
|
-
class FakesitesController < Fakesite::ApplicationController
|
3
|
-
before_action :
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
@
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
1
|
+
module Fakesite
|
2
|
+
class FakesitesController < Fakesite::ApplicationController
|
3
|
+
before_action :find_registration, :only => [:show]
|
4
|
+
before_action :deserialize, :only => [:redirect]
|
5
|
+
|
6
|
+
def show
|
7
|
+
@uri = URI.parse(params[:url])
|
8
|
+
@id = params[:id]
|
9
|
+
@fakesite = @registration.create
|
10
|
+
@fakesite.external_uri = @uri
|
11
|
+
end
|
12
|
+
|
13
|
+
def redirect
|
14
|
+
@fakesite.params = params[:p]
|
15
|
+
redirect_to @fakesite.redirect_url
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def find_registration
|
21
|
+
@registration = Fakesite.find(params[:id])
|
22
|
+
end
|
23
|
+
|
24
|
+
def deserialize
|
25
|
+
@fakesite = YAML.load(params[:serialization])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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
|
-
<% @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 :
|
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,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
|
-
orig_redirect_to Fakesite::Engine.routes.url_helpers.fakesite_path(id, :url => options)
|
9
|
-
else
|
10
|
-
orig_redirect_to(options, response_status)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
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
|
+
orig_redirect_to Fakesite::Engine.routes.url_helpers.fakesite_path(id, :url => options)
|
9
|
+
else
|
10
|
+
orig_redirect_to(options, response_status)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/fakesite/base.rb
CHANGED
@@ -1,46 +1,57 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
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 self.match(external_uri)
|
32
|
+
false
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.after_register
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def external_params
|
41
|
+
query_to_hash(external_uri)
|
42
|
+
end
|
43
|
+
|
44
|
+
def query_to_hash(uri)
|
45
|
+
uri.query ? Hash[CGI.parse(uri.query).map {|key,values| [key, values[0] || true]}] : {}
|
46
|
+
end
|
47
|
+
|
48
|
+
def append_parameters(url, params)
|
49
|
+
query_string = URI.encode_www_form(params || {})
|
50
|
+
if query_string == ""
|
51
|
+
return url
|
52
|
+
else
|
53
|
+
url + (url.include?('?') ? '&' : '?') + query_string
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
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
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fakesite
|
2
|
+
class Registration
|
3
|
+
attr_accessor :id, :fakesite, :options
|
4
|
+
|
5
|
+
def initialize(id, fakesite, options = {})
|
6
|
+
@id = id
|
7
|
+
@fakesite = fakesite
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def create
|
12
|
+
@fakesite.new(@options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def match(uri)
|
16
|
+
@fakesite.match(uri)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/fakesite/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Fakesite
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
1
|
+
module Fakesite
|
2
|
+
VERSION = "0.2.0"
|
3
|
+
end
|
data/lib/fakesite.rb
CHANGED
@@ -1,30 +1,39 @@
|
|
1
|
-
require 'uri'
|
2
|
-
|
3
|
-
require "fakesite/
|
4
|
-
require "fakesite/
|
5
|
-
|
6
|
-
module Fakesite
|
7
|
-
@@initialized = false
|
8
|
-
@@
|
9
|
-
|
10
|
-
def self.register(fakesite)
|
11
|
-
|
12
|
-
|
13
|
-
@@
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
1
|
+
require 'uri'
|
2
|
+
require "fakesite/engine"
|
3
|
+
require "fakesite/base"
|
4
|
+
require "fakesite/registration"
|
5
|
+
|
6
|
+
module Fakesite
|
7
|
+
@@initialized = false
|
8
|
+
@@registrations = {}
|
9
|
+
|
10
|
+
def self.register(id, fakesite, options = {})
|
11
|
+
Fakesite.initialize
|
12
|
+
id = id.to_sym
|
13
|
+
@@registrations[id] = Registration.new(id, fakesite, options)
|
14
|
+
fakesite.after_register
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.match(url)
|
18
|
+
return false unless url.is_a? String
|
19
|
+
begin
|
20
|
+
uri = URI.parse(url)
|
21
|
+
@@registrations.each do |id, fakesite|
|
22
|
+
return id if fakesite.match(uri)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find(id)
|
29
|
+
@@registrations[id.to_sym]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.initialize
|
35
|
+
return if @@initialized
|
36
|
+
@@initialized = true
|
37
|
+
require "fakesite/action_controller"
|
38
|
+
end
|
39
|
+
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.
|
4
|
+
version: 0.2.0
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description: An rails plugin that provides a
|
97
|
+
description: An rails plugin that provides a fake framework to stub 3-party redirect
|
98
98
|
page such as payment or oauth login.
|
99
99
|
email:
|
100
100
|
- emn178@gmail.com
|
@@ -102,6 +102,8 @@ executables: []
|
|
102
102
|
extensions: []
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.md
|
105
107
|
- Rakefile
|
106
108
|
- app/assets/javascripts/fakesite/application.js
|
107
109
|
- app/assets/stylesheets/fakesite/application.css
|
@@ -116,8 +118,8 @@ files:
|
|
116
118
|
- lib/fakesite/action_controller.rb
|
117
119
|
- lib/fakesite/base.rb
|
118
120
|
- lib/fakesite/engine.rb
|
121
|
+
- lib/fakesite/registration.rb
|
119
122
|
- lib/fakesite/version.rb
|
120
|
-
- lib/tasks/fakesite_tasks.rake
|
121
123
|
homepage: https://github.com/emn178/fakesite
|
122
124
|
licenses:
|
123
125
|
- MIT
|
@@ -138,9 +140,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
140
|
version: '0'
|
139
141
|
requirements: []
|
140
142
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.4.
|
143
|
+
rubygems_version: 2.4.8
|
142
144
|
signing_key:
|
143
145
|
specification_version: 4
|
144
|
-
summary: An rails plugin that provides a
|
146
|
+
summary: An rails plugin that provides a fake framework to stub 3-party redirect page
|
145
147
|
such as payment or oauth login.
|
146
148
|
test_files: []
|