redis-kit 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +55 -0
- data/Guardfile +6 -0
- data/Makefile +26 -0
- data/README.md +122 -0
- data/Rakefile +10 -0
- data/lib/redis-kit/railtie.rb +16 -0
- data/lib/redis-kit/resque.rb +31 -0
- data/lib/redis-kit/version.rb +3 -0
- data/lib/redis-kit.rb +92 -0
- data/redis-kit.gemspec +28 -0
- data/test/railsapi/.gitignore +15 -0
- data/test/railsapi/Gemfile.rails_3_2 +14 -0
- data/test/railsapi/Gemfile.rails_3_2.lock +139 -0
- data/test/railsapi/Gemfile.rails_head +14 -0
- data/test/railsapi/Gemfile.rails_head.lock +143 -0
- data/test/railsapi/README.rdoc +261 -0
- data/test/railsapi/Rakefile +7 -0
- data/test/railsapi/app/controllers/application_controller.rb +2 -0
- data/test/railsapi/app/controllers/redis_controller.rb +5 -0
- data/test/railsapi/app/mailers/.gitkeep +0 -0
- data/test/railsapi/app/models/.gitkeep +0 -0
- data/test/railsapi/config/application.rb +46 -0
- data/test/railsapi/config/boot.rb +6 -0
- data/test/railsapi/config/environment.rb +5 -0
- data/test/railsapi/config/environments/development.rb +23 -0
- data/test/railsapi/config/environments/production.rb +44 -0
- data/test/railsapi/config/environments/test.rb +29 -0
- data/test/railsapi/config/initializers/wrap_parameters.rb +13 -0
- data/test/railsapi/config/locales/en.yml +5 -0
- data/test/railsapi/config/redis.mock.yml +2 -0
- data/test/railsapi/config/redis.yml +4 -0
- data/test/railsapi/config/redis_bad_syntax.yml +2 -0
- data/test/railsapi/config/routes.rb +60 -0
- data/test/railsapi/config.ru +4 -0
- data/test/railsapi/doc/README_FOR_APP +2 -0
- data/test/railsapi/lib/assets/.gitkeep +0 -0
- data/test/railsapi/lib/tasks/.gitkeep +0 -0
- data/test/railsapi/log/.gitkeep +0 -0
- data/test/railsapi/public/404.html +26 -0
- data/test/railsapi/public/422.html +26 -0
- data/test/railsapi/public/500.html +25 -0
- data/test/railsapi/public/favicon.ico +0 -0
- data/test/railsapi/public/index.html +241 -0
- data/test/railsapi/public/robots.txt +5 -0
- data/test/railsapi/script/rails +6 -0
- data/test/railsapi/test/fixtures/.gitkeep +0 -0
- data/test/railsapi/test/functional/.gitkeep +0 -0
- data/test/railsapi/test/functional/redis_controller_test.rb +9 -0
- data/test/railsapi/test/integration/.gitkeep +0 -0
- data/test/railsapi/test/test_helper.rb +63 -0
- data/test/railsapi/test/unit/.gitkeep +0 -0
- data/test/railsapi/test/unit/redis-kit_test.rb +108 -0
- data/test/redis-kit_test.rb +72 -0
- data/test/support/redis.blank.yml +0 -0
- data/test/support/redis.good.yml +7 -0
- data/test/support/redis.invalid.yml +1 -0
- data/test/test_helper.rb +33 -0
- metadata +266 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -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,25 @@
|
|
|
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
|
+
</div>
|
|
24
|
+
</body>
|
|
25
|
+
</html>
|
|
File without changes
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Ruby on Rails: Welcome aboard</title>
|
|
5
|
+
<style type="text/css" media="screen">
|
|
6
|
+
body {
|
|
7
|
+
margin: 0;
|
|
8
|
+
margin-bottom: 25px;
|
|
9
|
+
padding: 0;
|
|
10
|
+
background-color: #f0f0f0;
|
|
11
|
+
font-family: "Lucida Grande", "Bitstream Vera Sans", "Verdana";
|
|
12
|
+
font-size: 13px;
|
|
13
|
+
color: #333;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
h1 {
|
|
17
|
+
font-size: 28px;
|
|
18
|
+
color: #000;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
a {color: #03c}
|
|
22
|
+
a:hover {
|
|
23
|
+
background-color: #03c;
|
|
24
|
+
color: white;
|
|
25
|
+
text-decoration: none;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
#page {
|
|
30
|
+
background-color: #f0f0f0;
|
|
31
|
+
width: 750px;
|
|
32
|
+
margin: 0;
|
|
33
|
+
margin-left: auto;
|
|
34
|
+
margin-right: auto;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#content {
|
|
38
|
+
float: left;
|
|
39
|
+
background-color: white;
|
|
40
|
+
border: 3px solid #aaa;
|
|
41
|
+
border-top: none;
|
|
42
|
+
padding: 25px;
|
|
43
|
+
width: 500px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#sidebar {
|
|
47
|
+
float: right;
|
|
48
|
+
width: 175px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#footer {
|
|
52
|
+
clear: both;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#header, #about, #getting-started {
|
|
56
|
+
padding-left: 75px;
|
|
57
|
+
padding-right: 30px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
#header {
|
|
62
|
+
background-image: url("assets/rails.png");
|
|
63
|
+
background-repeat: no-repeat;
|
|
64
|
+
background-position: top left;
|
|
65
|
+
height: 64px;
|
|
66
|
+
}
|
|
67
|
+
#header h1, #header h2 {margin: 0}
|
|
68
|
+
#header h2 {
|
|
69
|
+
color: #888;
|
|
70
|
+
font-weight: normal;
|
|
71
|
+
font-size: 16px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
#about h3 {
|
|
76
|
+
margin: 0;
|
|
77
|
+
margin-bottom: 10px;
|
|
78
|
+
font-size: 14px;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#about-content {
|
|
82
|
+
background-color: #ffd;
|
|
83
|
+
border: 1px solid #fc0;
|
|
84
|
+
margin-left: -55px;
|
|
85
|
+
margin-right: -10px;
|
|
86
|
+
}
|
|
87
|
+
#about-content table {
|
|
88
|
+
margin-top: 10px;
|
|
89
|
+
margin-bottom: 10px;
|
|
90
|
+
font-size: 11px;
|
|
91
|
+
border-collapse: collapse;
|
|
92
|
+
}
|
|
93
|
+
#about-content td {
|
|
94
|
+
padding: 10px;
|
|
95
|
+
padding-top: 3px;
|
|
96
|
+
padding-bottom: 3px;
|
|
97
|
+
}
|
|
98
|
+
#about-content td.name {color: #555}
|
|
99
|
+
#about-content td.value {color: #000}
|
|
100
|
+
|
|
101
|
+
#about-content ul {
|
|
102
|
+
padding: 0;
|
|
103
|
+
list-style-type: none;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
#about-content.failure {
|
|
107
|
+
background-color: #fcc;
|
|
108
|
+
border: 1px solid #f00;
|
|
109
|
+
}
|
|
110
|
+
#about-content.failure p {
|
|
111
|
+
margin: 0;
|
|
112
|
+
padding: 10px;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
#getting-started {
|
|
117
|
+
border-top: 1px solid #ccc;
|
|
118
|
+
margin-top: 25px;
|
|
119
|
+
padding-top: 15px;
|
|
120
|
+
}
|
|
121
|
+
#getting-started h1 {
|
|
122
|
+
margin: 0;
|
|
123
|
+
font-size: 20px;
|
|
124
|
+
}
|
|
125
|
+
#getting-started h2 {
|
|
126
|
+
margin: 0;
|
|
127
|
+
font-size: 14px;
|
|
128
|
+
font-weight: normal;
|
|
129
|
+
color: #333;
|
|
130
|
+
margin-bottom: 25px;
|
|
131
|
+
}
|
|
132
|
+
#getting-started ol {
|
|
133
|
+
margin-left: 0;
|
|
134
|
+
padding-left: 0;
|
|
135
|
+
}
|
|
136
|
+
#getting-started li {
|
|
137
|
+
font-size: 18px;
|
|
138
|
+
color: #888;
|
|
139
|
+
margin-bottom: 25px;
|
|
140
|
+
}
|
|
141
|
+
#getting-started li h2 {
|
|
142
|
+
margin: 0;
|
|
143
|
+
font-weight: normal;
|
|
144
|
+
font-size: 18px;
|
|
145
|
+
color: #333;
|
|
146
|
+
}
|
|
147
|
+
#getting-started li p {
|
|
148
|
+
color: #555;
|
|
149
|
+
font-size: 13px;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
#sidebar ul {
|
|
154
|
+
margin-left: 0;
|
|
155
|
+
padding-left: 0;
|
|
156
|
+
}
|
|
157
|
+
#sidebar ul h3 {
|
|
158
|
+
margin-top: 25px;
|
|
159
|
+
font-size: 16px;
|
|
160
|
+
padding-bottom: 10px;
|
|
161
|
+
border-bottom: 1px solid #ccc;
|
|
162
|
+
}
|
|
163
|
+
#sidebar li {
|
|
164
|
+
list-style-type: none;
|
|
165
|
+
}
|
|
166
|
+
#sidebar ul.links li {
|
|
167
|
+
margin-bottom: 5px;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.filename {
|
|
171
|
+
font-style: italic;
|
|
172
|
+
}
|
|
173
|
+
</style>
|
|
174
|
+
<script type="text/javascript">
|
|
175
|
+
function about() {
|
|
176
|
+
info = document.getElementById('about-content');
|
|
177
|
+
if (window.XMLHttpRequest)
|
|
178
|
+
{ xhr = new XMLHttpRequest(); }
|
|
179
|
+
else
|
|
180
|
+
{ xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
|
|
181
|
+
xhr.open("GET","rails/info/properties",false);
|
|
182
|
+
xhr.send("");
|
|
183
|
+
info.innerHTML = xhr.responseText;
|
|
184
|
+
info.style.display = 'block'
|
|
185
|
+
}
|
|
186
|
+
</script>
|
|
187
|
+
</head>
|
|
188
|
+
<body>
|
|
189
|
+
<div id="page">
|
|
190
|
+
<div id="sidebar">
|
|
191
|
+
<ul id="sidebar-items">
|
|
192
|
+
<li>
|
|
193
|
+
<h3>Browse the documentation</h3>
|
|
194
|
+
<ul class="links">
|
|
195
|
+
<li><a href="http://guides.rubyonrails.org/">Rails Guides</a></li>
|
|
196
|
+
<li><a href="http://api.rubyonrails.org/">Rails API</a></li>
|
|
197
|
+
<li><a href="http://www.ruby-doc.org/core/">Ruby core</a></li>
|
|
198
|
+
<li><a href="http://www.ruby-doc.org/stdlib/">Ruby standard library</a></li>
|
|
199
|
+
</ul>
|
|
200
|
+
</li>
|
|
201
|
+
</ul>
|
|
202
|
+
</div>
|
|
203
|
+
|
|
204
|
+
<div id="content">
|
|
205
|
+
<div id="header">
|
|
206
|
+
<h1>Welcome aboard</h1>
|
|
207
|
+
<h2>You’re riding Ruby on Rails!</h2>
|
|
208
|
+
</div>
|
|
209
|
+
|
|
210
|
+
<div id="about">
|
|
211
|
+
<h3><a href="rails/info/properties" onclick="about(); return false">About your application’s environment</a></h3>
|
|
212
|
+
<div id="about-content" style="display: none"></div>
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<div id="getting-started">
|
|
216
|
+
<h1>Getting started</h1>
|
|
217
|
+
<h2>Here’s how to get rolling:</h2>
|
|
218
|
+
|
|
219
|
+
<ol>
|
|
220
|
+
<li>
|
|
221
|
+
<h2>Use <code>rails generate</code> to create your models and controllers</h2>
|
|
222
|
+
<p>To see all available options, run it without parameters.</p>
|
|
223
|
+
</li>
|
|
224
|
+
|
|
225
|
+
<li>
|
|
226
|
+
<h2>Set up a default route and remove <span class="filename">public/index.html</span></h2>
|
|
227
|
+
<p>Routes are set up in <span class="filename">config/routes.rb</span>.</p>
|
|
228
|
+
</li>
|
|
229
|
+
|
|
230
|
+
<li>
|
|
231
|
+
<h2>Create your database</h2>
|
|
232
|
+
<p>Run <code>rake db:create</code> to create your database. If you're not using SQLite (the default), edit <span class="filename">config/database.yml</span> with your username and password.</p>
|
|
233
|
+
</li>
|
|
234
|
+
</ol>
|
|
235
|
+
</div>
|
|
236
|
+
</div>
|
|
237
|
+
|
|
238
|
+
<div id="footer"> </div>
|
|
239
|
+
</div>
|
|
240
|
+
</body>
|
|
241
|
+
</html>
|
|
@@ -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'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
|
3
|
+
require 'rails/test_help'
|
|
4
|
+
require 'minitest/autorun'
|
|
5
|
+
|
|
6
|
+
module TestHelpers
|
|
7
|
+
def jruby?
|
|
8
|
+
RUBY_ENGINE == "jruby"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def initialize_redis_kit
|
|
12
|
+
Rails.application.initializers.select do |initializer|
|
|
13
|
+
initializer.name =~ /redis-kit/
|
|
14
|
+
end.each do |initializer|
|
|
15
|
+
initializer.run( Rails.application )
|
|
16
|
+
end
|
|
17
|
+
$redis.client.connect if $redis.client.respond_to?( :connect )
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get_socket( redis )
|
|
21
|
+
case connection = redis.client.connection
|
|
22
|
+
when Redis::Connection::Ruby
|
|
23
|
+
connection.instance_variable_get( "@sock" )
|
|
24
|
+
when Redis::Connection::Hiredis
|
|
25
|
+
connection.instance_variable_get("@connection").sock
|
|
26
|
+
else
|
|
27
|
+
raise "#{connection} isn't a known connection type."
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def initialize_resque
|
|
32
|
+
Resque.redis = $redis
|
|
33
|
+
Resque.redis.client.connect if Resque.redis.client.respond_to?( :connect )
|
|
34
|
+
Resque.after_fork = nil
|
|
35
|
+
RedisKit::Resque.setup
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def resque_worker
|
|
39
|
+
worker = Resque::Worker.new( :test )
|
|
40
|
+
worker.term_child = "1"
|
|
41
|
+
worker
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class ActiveSupport::TestCase
|
|
46
|
+
include TestHelpers
|
|
47
|
+
class << self
|
|
48
|
+
include TestHelpers
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class TestResqueJob
|
|
53
|
+
@queue = :test
|
|
54
|
+
|
|
55
|
+
class << self
|
|
56
|
+
include TestHelpers
|
|
57
|
+
|
|
58
|
+
def perform
|
|
59
|
+
$redis.ping
|
|
60
|
+
$redis.set("socket", get_socket($redis).to_s)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class TestRailsKit < ActiveSupport::TestCase
|
|
4
|
+
def setup
|
|
5
|
+
Rails.application.paths["config/redis"] = "config/redis.yml"
|
|
6
|
+
ENV["REDIS_URL"] = nil
|
|
7
|
+
$redis.flushall
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
#
|
|
11
|
+
# Configuration
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
def test_load_from_config_redis_yml
|
|
15
|
+
initialize_redis_kit
|
|
16
|
+
$redis.class.must_equal Redis
|
|
17
|
+
$redis.client.id.must_equal "redis://localhost:6379/0"
|
|
18
|
+
if jruby?
|
|
19
|
+
$redis.client.connection.class.must_equal Redis::Connection::Ruby
|
|
20
|
+
else
|
|
21
|
+
$redis.client.connection.class.must_equal Redis::Connection::Hiredis
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_load_url_from_env_variable
|
|
26
|
+
ENV["REDIS_URL"] = "redis://127.0.0.1:6379"
|
|
27
|
+
initialize_redis_kit
|
|
28
|
+
$redis.class.must_equal Redis
|
|
29
|
+
$redis.client.id.must_equal "redis://127.0.0.1:6379/0"
|
|
30
|
+
if jruby?
|
|
31
|
+
$redis.client.connection.class.must_equal Redis::Connection::Ruby
|
|
32
|
+
else
|
|
33
|
+
$redis.client.connection.class.must_equal Redis::Connection::Hiredis
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_load_bad_config_file
|
|
38
|
+
Rails.application.paths["config/redis"] = "/tmp/this_doesnt_exist.yml"
|
|
39
|
+
error = nil
|
|
40
|
+
begin
|
|
41
|
+
initialize_redis_kit
|
|
42
|
+
rescue => e
|
|
43
|
+
error = e
|
|
44
|
+
end
|
|
45
|
+
error.must_be_kind_of RedisKit::MissingConfigError
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_mock_redis_config
|
|
49
|
+
Rails.application.paths["config/redis"] = "config/redis.mock.yml"
|
|
50
|
+
initialize_redis_kit
|
|
51
|
+
$redis.must_be_kind_of MockRedis
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
#
|
|
55
|
+
# Resque
|
|
56
|
+
#
|
|
57
|
+
|
|
58
|
+
unless jruby?
|
|
59
|
+
def test_not_clobbering_resque_hooks
|
|
60
|
+
initialize_redis_kit
|
|
61
|
+
initialize_resque
|
|
62
|
+
Resque.after_fork do |*args|
|
|
63
|
+
$redis.set( "called", true )
|
|
64
|
+
end
|
|
65
|
+
RedisKit::Resque.setup
|
|
66
|
+
Resque.enqueue(TestResqueJob)
|
|
67
|
+
resque_worker.work(0)
|
|
68
|
+
$redis.get( "called" ).must_equal "true"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_resque_using_same_connection
|
|
72
|
+
initialize_redis_kit
|
|
73
|
+
initialize_resque
|
|
74
|
+
|
|
75
|
+
original_socket = get_socket( $redis ).to_s
|
|
76
|
+
Resque.enqueue(TestResqueJob)
|
|
77
|
+
resque_worker.work(0)
|
|
78
|
+
Resque.redis.redis.must_equal $redis
|
|
79
|
+
forked_socket = $redis.get("socket")
|
|
80
|
+
forked_socket.must_match( /Socket:/ )
|
|
81
|
+
|
|
82
|
+
# Resque reconnected to redis
|
|
83
|
+
forked_socket.wont_equal original_socket
|
|
84
|
+
# Still sharing the same connection
|
|
85
|
+
get_socket( Resque.redis ).must_equal get_socket( $redis )
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_resque_using_different_connection
|
|
89
|
+
initialize_redis_kit
|
|
90
|
+
initialize_resque
|
|
91
|
+
initialize_redis_kit # New connection for $redis
|
|
92
|
+
|
|
93
|
+
# Using 2 different connections
|
|
94
|
+
$redis.wont_equal Resque.redis.redis
|
|
95
|
+
|
|
96
|
+
original_socket = get_socket( $redis ).to_s
|
|
97
|
+
Resque.enqueue(TestResqueJob)
|
|
98
|
+
resque_worker.work(0)
|
|
99
|
+
forked_socket = $redis.get("socket")
|
|
100
|
+
forked_socket.must_match( /Socket:/ )
|
|
101
|
+
|
|
102
|
+
# Resque reconnected to redis
|
|
103
|
+
forked_socket.wont_equal original_socket
|
|
104
|
+
# And we still have two different connections
|
|
105
|
+
get_socket( Resque.redis ).wont_equal get_socket( $redis )
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
require_relative "test_helper"
|
|
2
|
+
|
|
3
|
+
describe "RedisKit.load_config" do
|
|
4
|
+
after do
|
|
5
|
+
ENV["REDIS_URL"] = nil
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "loads config from an environment variable" do
|
|
9
|
+
ENV["REDIS_URL"] = "redis://cool.dude:12345"
|
|
10
|
+
config = RedisKit.load_config( good_config_path, "test" )
|
|
11
|
+
if jruby?
|
|
12
|
+
config.must_equal url: "redis://cool.dude:12345"
|
|
13
|
+
else
|
|
14
|
+
config.must_equal driver: :hiredis, url: "redis://cool.dude:12345"
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "loads config from a config file" do
|
|
19
|
+
config = RedisKit.load_config( good_config_path, "test" )
|
|
20
|
+
if jruby?
|
|
21
|
+
config.must_equal url: "redis://good:1234", mock: false
|
|
22
|
+
else
|
|
23
|
+
config.must_equal driver: :hiredis, url: "redis://good:1234", mock: false
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "supports ERB in the config file" do
|
|
28
|
+
config = RedisKit.load_config( good_config_path, "test_erb" )
|
|
29
|
+
if jruby?
|
|
30
|
+
config.must_equal url: "redis://good:1234"
|
|
31
|
+
else
|
|
32
|
+
config.must_equal driver: :hiredis, url: "redis://good:1234"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "returns an error if the config file doesn't have a config for the environment" do
|
|
37
|
+
catch_error do
|
|
38
|
+
RedisKit.load_config( good_config_path, "whoops" )
|
|
39
|
+
end.must_be_kind_of RedisKit::MissingConfigError
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "returns an error if the config file doesn't exist" do
|
|
43
|
+
catch_error do
|
|
44
|
+
RedisKit.load_config( missing_config_path, "test" )
|
|
45
|
+
end.must_be_kind_of RedisKit::MissingConfigError
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "returns an error if the config file is blank" do
|
|
49
|
+
catch_error do
|
|
50
|
+
RedisKit.load_config( blank_config_path, "test" )
|
|
51
|
+
end.must_be_kind_of RedisKit::MissingConfigError
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "returns an error if the config file is invalid" do
|
|
55
|
+
catch_error do
|
|
56
|
+
RedisKit.load_config( invalid_config_path, "test" )
|
|
57
|
+
end.must_be_kind_of RedisKit::InvalidConfigSyntaxError
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe "RedisKit.new_redis" do
|
|
62
|
+
it "builds a regular redis connection" do
|
|
63
|
+
redis = RedisKit.new_redis( good_config_path, "test" )
|
|
64
|
+
redis.must_be_kind_of Redis
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "builds a mock redis connection" do
|
|
68
|
+
redis = RedisKit.new_redis( good_config_path, "test_mock" )
|
|
69
|
+
redis.must_be_kind_of MockRedis
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@#%%$$%@#%
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require_relative "../lib/redis-kit"
|
|
2
|
+
require 'minitest/spec'
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
|
|
5
|
+
def jruby?
|
|
6
|
+
RUBY_ENGINE == "jruby"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def good_config_path
|
|
10
|
+
"test/support/redis.good.yml"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def missing_config_path
|
|
14
|
+
"test/support/whoops.yml"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def invalid_config_path
|
|
18
|
+
"test/support/redis.invalid.yml"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def blank_config_path
|
|
22
|
+
"test/support/redis.blank.yml"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def catch_error
|
|
26
|
+
begin
|
|
27
|
+
yield
|
|
28
|
+
nil
|
|
29
|
+
rescue => e
|
|
30
|
+
return e
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|