mongoid_shortener 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.markdown +118 -0
- data/Rakefile +37 -0
- data/app/controllers/mongoid_shortener/application_controller.rb +4 -0
- data/app/controllers/mongoid_shortener/shortened_urls_controller.rb +19 -0
- data/app/helpers/mongoid_shortener/shortened_urls_helper.rb +10 -0
- data/app/models/mongoid_shortener/shortened_url.rb +78 -0
- data/lib/mongoid_shortener.rb +12 -0
- data/lib/mongoid_shortener/engine.rb +5 -0
- data/lib/mongoid_shortener/version.rb +3 -0
- data/lib/tasks/mongoid_shortener_tasks.rake +4 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +51 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +30 -0
- data/test/dummy/config/environments/production.rb +60 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +10 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/mongoid.yml +20 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/log/development.log +6 -0
- data/test/dummy/log/test.log +3498 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/functional/mongoid_shortener/shortened_urls_controller_test.rb +32 -0
- data/test/mongoid_shortener_test.rb +7 -0
- data/test/test_helper.rb +18 -0
- data/test/unit/helpers/mongoid_shortener/shortened_urls_helper_test.rb +18 -0
- data/test/unit/mongoid_shortener/shortened_url_test.rb +33 -0
- metadata +154 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/404.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
23
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/422.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>The change you wanted was rejected.</h1>
|
23
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<style type="text/css">
|
6
|
+
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
7
|
+
div.dialog {
|
8
|
+
width: 25em;
|
9
|
+
padding: 0 4em;
|
10
|
+
margin: 4em auto 0 auto;
|
11
|
+
border: 1px solid #ccc;
|
12
|
+
border-right-color: #999;
|
13
|
+
border-bottom-color: #999;
|
14
|
+
}
|
15
|
+
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
16
|
+
</style>
|
17
|
+
</head>
|
18
|
+
|
19
|
+
<body>
|
20
|
+
<!-- This file lives in public/500.html -->
|
21
|
+
<div class="dialog">
|
22
|
+
<h1>We're sorry, but something went wrong.</h1>
|
23
|
+
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
24
|
+
</div>
|
25
|
+
</body>
|
26
|
+
</html>
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module MongoidShortener
|
4
|
+
class ShortenedUrlsControllerTest < ActionController::TestCase
|
5
|
+
test "get non-existence unique key" do
|
6
|
+
get :translate, {unique_key: "~123"}
|
7
|
+
assert_response :redirect
|
8
|
+
assert_redirected_to "http://localhost:3000"
|
9
|
+
end
|
10
|
+
|
11
|
+
test "get valid unique key" do
|
12
|
+
short_url = MongoidShortener.generate("http://google.com")
|
13
|
+
unique_key = short_url[short_url.index("~")..-1]
|
14
|
+
get :translate, {unique_key: unique_key}
|
15
|
+
assert_response :redirect
|
16
|
+
assert_redirected_to "http://google.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
test "changing redirect root_url" do
|
20
|
+
MongoidShortener.root_url = "http://google.com"
|
21
|
+
get :translate, {unique_key: "~123"}
|
22
|
+
assert_response :redirect
|
23
|
+
assert_redirected_to "http://google.com"
|
24
|
+
end
|
25
|
+
|
26
|
+
test "redirect to non-valid key should raise exception" do
|
27
|
+
assert_raise(ActionController::RoutingError) {
|
28
|
+
get :translate, {unique_key: "123"}
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
|
4
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
|
+
require "rails/test_help"
|
6
|
+
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
8
|
+
|
9
|
+
class ActiveSupport::TestCase
|
10
|
+
setup do
|
11
|
+
MongoidShortener::ShortenedUrl.delete_all
|
12
|
+
MongoidShortener.root_url = "http://localhost:3000"
|
13
|
+
MongoidShortener.prefix_url = "http://localhost:3000/~"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Load support files
|
18
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module MongoidShortener
|
4
|
+
class ShortenedUrlsHelperTest < ActionView::TestCase
|
5
|
+
test "shortened invalid url" do
|
6
|
+
assert_nil shortened_url("haha")
|
7
|
+
end
|
8
|
+
|
9
|
+
test "shorten valid url" do
|
10
|
+
assert_equal("http://localhost:3000/~0", shortened_url("http://google.com"))
|
11
|
+
end
|
12
|
+
|
13
|
+
test "shorten two same url" do
|
14
|
+
assert_equal("http://localhost:3000/~0", shortened_url("http://google.com"))
|
15
|
+
assert_equal("http://localhost:3000/~0", shortened_url("http://google.com"))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module MongoidShortener
|
4
|
+
class ShortenedUrlTest < ActiveSupport::TestCase
|
5
|
+
test "shorten invalid url" do
|
6
|
+
assert_nil MongoidShortener.generate "ahha"
|
7
|
+
end
|
8
|
+
|
9
|
+
test "shorten valid url with http" do
|
10
|
+
assert_equal("http://localhost:3000/~0", MongoidShortener.generate("http://google.com"))
|
11
|
+
end
|
12
|
+
|
13
|
+
test "shorten valid url without http" do
|
14
|
+
assert_equal("http://localhost:3000/~0", MongoidShortener.generate("yahoo.com"))
|
15
|
+
end
|
16
|
+
|
17
|
+
test "reshorten the same valid url" do
|
18
|
+
assert_equal("http://localhost:3000/~0", MongoidShortener.generate("http://google.com"))
|
19
|
+
assert_equal("http://localhost:3000/~0", MongoidShortener.generate("google.com"))
|
20
|
+
end
|
21
|
+
|
22
|
+
test "shorten two valid url" do
|
23
|
+
assert_equal("http://localhost:3000/~0", MongoidShortener.generate("google.com"))
|
24
|
+
assert_equal("http://localhost:3000/~1", MongoidShortener.generate("yahoo.com"))
|
25
|
+
end
|
26
|
+
|
27
|
+
test "set prefix_url" do
|
28
|
+
MongoidShortener.prefix_url = "http://dailymus.es/~"
|
29
|
+
assert_equal("http://dailymus.es/~", MongoidShortener.prefix_url)
|
30
|
+
assert_equal("http://dailymus.es/~0", MongoidShortener.generate("yahoo.com"))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_shortener
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Teng Siong Ong
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-11-29 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &70323348204560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70323348204560
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: yab62
|
27
|
+
requirement: &70323348204000 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70323348204000
|
36
|
+
description: MongoidShortener is a simple Rails 3.1 engine that shortens URL based
|
37
|
+
on Mongoid.
|
38
|
+
email:
|
39
|
+
- siong1987@gmail.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- app/controllers/mongoid_shortener/application_controller.rb
|
45
|
+
- app/controllers/mongoid_shortener/shortened_urls_controller.rb
|
46
|
+
- app/helpers/mongoid_shortener/shortened_urls_helper.rb
|
47
|
+
- app/models/mongoid_shortener/shortened_url.rb
|
48
|
+
- lib/mongoid_shortener/engine.rb
|
49
|
+
- lib/mongoid_shortener/version.rb
|
50
|
+
- lib/mongoid_shortener.rb
|
51
|
+
- lib/tasks/mongoid_shortener_tasks.rake
|
52
|
+
- MIT-LICENSE
|
53
|
+
- Rakefile
|
54
|
+
- README.markdown
|
55
|
+
- test/dummy/app/assets/javascripts/application.js
|
56
|
+
- test/dummy/app/assets/stylesheets/application.css
|
57
|
+
- test/dummy/app/controllers/application_controller.rb
|
58
|
+
- test/dummy/app/helpers/application_helper.rb
|
59
|
+
- test/dummy/app/views/layouts/application.html.erb
|
60
|
+
- test/dummy/config/application.rb
|
61
|
+
- test/dummy/config/boot.rb
|
62
|
+
- test/dummy/config/environment.rb
|
63
|
+
- test/dummy/config/environments/development.rb
|
64
|
+
- test/dummy/config/environments/production.rb
|
65
|
+
- test/dummy/config/environments/test.rb
|
66
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
67
|
+
- test/dummy/config/initializers/inflections.rb
|
68
|
+
- test/dummy/config/initializers/mime_types.rb
|
69
|
+
- test/dummy/config/initializers/secret_token.rb
|
70
|
+
- test/dummy/config/initializers/session_store.rb
|
71
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
72
|
+
- test/dummy/config/locales/en.yml
|
73
|
+
- test/dummy/config/mongoid.yml
|
74
|
+
- test/dummy/config/routes.rb
|
75
|
+
- test/dummy/config.ru
|
76
|
+
- test/dummy/log/development.log
|
77
|
+
- test/dummy/log/test.log
|
78
|
+
- test/dummy/public/404.html
|
79
|
+
- test/dummy/public/422.html
|
80
|
+
- test/dummy/public/500.html
|
81
|
+
- test/dummy/public/favicon.ico
|
82
|
+
- test/dummy/Rakefile
|
83
|
+
- test/dummy/script/rails
|
84
|
+
- test/functional/mongoid_shortener/shortened_urls_controller_test.rb
|
85
|
+
- test/mongoid_shortener_test.rb
|
86
|
+
- test/test_helper.rb
|
87
|
+
- test/unit/helpers/mongoid_shortener/shortened_urls_helper_test.rb
|
88
|
+
- test/unit/mongoid_shortener/shortened_url_test.rb
|
89
|
+
homepage: https://github.com/siong1987/mongoid_shortener
|
90
|
+
licenses: []
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: -4195420191726620944
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: -4195420191726620944
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.8.10
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: MongoidShortener is a simple Rails 3.1 engine that shortens URL based on
|
119
|
+
Mongoid.
|
120
|
+
test_files:
|
121
|
+
- test/dummy/app/assets/javascripts/application.js
|
122
|
+
- test/dummy/app/assets/stylesheets/application.css
|
123
|
+
- test/dummy/app/controllers/application_controller.rb
|
124
|
+
- test/dummy/app/helpers/application_helper.rb
|
125
|
+
- test/dummy/app/views/layouts/application.html.erb
|
126
|
+
- test/dummy/config/application.rb
|
127
|
+
- test/dummy/config/boot.rb
|
128
|
+
- test/dummy/config/environment.rb
|
129
|
+
- test/dummy/config/environments/development.rb
|
130
|
+
- test/dummy/config/environments/production.rb
|
131
|
+
- test/dummy/config/environments/test.rb
|
132
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
133
|
+
- test/dummy/config/initializers/inflections.rb
|
134
|
+
- test/dummy/config/initializers/mime_types.rb
|
135
|
+
- test/dummy/config/initializers/secret_token.rb
|
136
|
+
- test/dummy/config/initializers/session_store.rb
|
137
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
138
|
+
- test/dummy/config/locales/en.yml
|
139
|
+
- test/dummy/config/mongoid.yml
|
140
|
+
- test/dummy/config/routes.rb
|
141
|
+
- test/dummy/config.ru
|
142
|
+
- test/dummy/log/development.log
|
143
|
+
- test/dummy/log/test.log
|
144
|
+
- test/dummy/public/404.html
|
145
|
+
- test/dummy/public/422.html
|
146
|
+
- test/dummy/public/500.html
|
147
|
+
- test/dummy/public/favicon.ico
|
148
|
+
- test/dummy/Rakefile
|
149
|
+
- test/dummy/script/rails
|
150
|
+
- test/functional/mongoid_shortener/shortened_urls_controller_test.rb
|
151
|
+
- test/mongoid_shortener_test.rb
|
152
|
+
- test/test_helper.rb
|
153
|
+
- test/unit/helpers/mongoid_shortener/shortened_urls_helper_test.rb
|
154
|
+
- test/unit/mongoid_shortener/shortened_url_test.rb
|