redis_fixtures 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +15 -0
- data/Appraisals +7 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +197 -0
- data/Rakefile +15 -0
- data/gemfiles/redis_3_0_0.gemfile +7 -0
- data/gemfiles/redis_3_0_0.gemfile.lock +94 -0
- data/gemfiles/redis_3_2_1.gemfile +7 -0
- data/gemfiles/redis_3_2_1.gemfile.lock +94 -0
- data/lib/redis_fixtures.rb +10 -0
- data/lib/redis_fixtures/config.rb +71 -0
- data/lib/redis_fixtures/connection.rb +23 -0
- data/lib/redis_fixtures/dump_fixtures.rb +94 -0
- data/lib/redis_fixtures/load_fixtures.rb +15 -0
- data/lib/redis_fixtures/minitest.rb +13 -0
- data/lib/redis_fixtures/version.rb +3 -0
- data/redis_fixtures.gemspec +43 -0
- data/test/connection_test.rb +63 -0
- data/test/dump_fixtures_test.rb +56 -0
- data/test/load_fixtures_test.rb +32 -0
- data/test/minitest_hook_test.rb +12 -0
- data/test/test_helper.rb +67 -0
- metadata +249 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f27c2a5df49bdb562d141a61695a64b0940c5bd0
|
4
|
+
data.tar.gz: 6a08100879c24423f7c071efe924acbace93d4da
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 15700b8aeac3b9b3caa9287bfbbf7a672c44e23f8d4d510ad80a466fe148735e8d66ef12f154c43d42f9193c42d8f1c31b99d4c63cade46c1acb5857bb21b2e2
|
7
|
+
data.tar.gz: 7e5d0257945e4e13e07ac275af34da9e7edf812854e92450c1b146bca20d80f67108587b3133183c68a3f68848805b412f92619a44d4d078803077ce47870991
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Daniel Magliola
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# redis_fixtures
|
2
|
+
|
3
|
+
[](https://travis-ci.org/dmagliola/redis_fixtures)
|
4
|
+
[](https://coveralls.io/github/dmagliola/redis_fixtures?branch=master)
|
5
|
+
[](https://codeclimate.com/github/dmagliola/redis_fixtures)
|
6
|
+
[](http://inch-ci.org/github/dmagliola/redis_fixtures)
|
7
|
+
[](http://badge.fury.io/rb/redis_fixtures)
|
8
|
+
[](https://gemnasium.com/dmagliola/redis_fixtures)
|
9
|
+
|
10
|
+
Add fixtures to your Redis database, to test the parts of your code that need Redis to be more than a cache.
|
11
|
+
|
12
|
+
If you are using Redis for anything more interesting than a cache (and if you're not, get on it, Redis is awesome!),
|
13
|
+
RedisFixtures will help you test by guaranteeing a clean, well-known state of your Redis Database at the
|
14
|
+
start of each test.
|
15
|
+
|
16
|
+
RedisFixtures is designed to integrate seamlessly with gems like [FixtureBuilder](https://github.com/rdy/fixture_builder),
|
17
|
+
which take a snapshot of your database and dumps the data into fixture files. RedisFixtures will run at the end
|
18
|
+
of the fixture generation phase and do exactly the same with your Redis database, dumping all the keys into a
|
19
|
+
single fixture file. It will then reset your Redis DB to the state specified in that fixture.
|
20
|
+
|
21
|
+
If you are building your fixtures manually, you can also do that, more on that below, but that sounds like a lot of
|
22
|
+
work, I can't recommend FixtureBuilder enough to save you time, and most importantly, speed up your test suite if you're
|
23
|
+
using tools like FactoryGirl.
|
24
|
+
|
25
|
+
## Sample Use Cases / What is this good for?
|
26
|
+
|
27
|
+
Here are a few situations where we're using RedisFixtures to help our tests:
|
28
|
+
|
29
|
+
1. We do geo-location based on a user's IP using a Redis Sorted Set (populated with the IP ranges).
|
30
|
+
Testing that requires having some ranges in Redis.
|
31
|
+
|
32
|
+
2. We have a phone line rotation module (to be released soon) to send SMS doing a round-robin of multiple
|
33
|
+
phone lines. That module uses Redis very heavily for performance, and we need some sample phone lines in there
|
34
|
+
to test it.
|
35
|
+
|
36
|
+
3. Our localization feature stores dynamic string translations in Redis. Again, testing this requires
|
37
|
+
some sample translations in there.
|
38
|
+
|
39
|
+
It's much more convenient to have all these as the initial well-known state of every test case, rather than
|
40
|
+
having to set these up, particularly for our integration tests.
|
41
|
+
|
42
|
+
|
43
|
+
## Download
|
44
|
+
|
45
|
+
Gem:
|
46
|
+
|
47
|
+
`gem install redis_fixtures`
|
48
|
+
|
49
|
+
## Installation
|
50
|
+
|
51
|
+
Load the gem in the test environment in your GemFile.
|
52
|
+
|
53
|
+
`gem "redis_fixtures", group: :test`
|
54
|
+
|
55
|
+
|
56
|
+
## Configuration
|
57
|
+
|
58
|
+
In your `test_helper.rb` file, call RedisFixtures.configure (after the setup of your Redis connection has run),
|
59
|
+
and set how RedisFixtures should connect to Redis:
|
60
|
+
|
61
|
+
```
|
62
|
+
RedisFixtures.configure do |config|
|
63
|
+
# set one of :connection_pool, :connection_block, :connection_settings or :connection properties
|
64
|
+
config.connection_pool = $RedisPool
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
You have 4 options to configure how RedisFixtures connects to your Redis database:
|
69
|
+
|
70
|
+
- If you are using the [connection_pool](https://github.com/mperham/connection_pool) gem, simply set
|
71
|
+
`config.connection_pool = your_connection_pool`, and RedisFixtures will checkout connections from
|
72
|
+
the pool as needed. If you're not using connection_pool, I really recommend it, it's awesome.
|
73
|
+
- If you already have a connection that you are reusing in your project, you can set
|
74
|
+
`config.connection = your_connection` and RedisFixtures will use that.
|
75
|
+
- If you would like RedisFixtures to connect as needed, and you need some special magic to connect
|
76
|
+
to redis, you can use `connection_proc` to specify how to connect. For example:
|
77
|
+
`config.connection_proc = Proc.new{ your_magic_code_here }`. This proc should return a Redis object.
|
78
|
+
- Or, you can simply set `connection_settings` with the connection details, like:
|
79
|
+
`config.connection_settings = {host: 'localhost', port: 1234}`, and RedisFixtures will connect on demand
|
80
|
+
by passing that object to `Redis.new`.
|
81
|
+
- Finally, if you have a default Redis running in localhost in the default port, you don't need to set
|
82
|
+
anything, RedisFixtures will connect to it automatically.
|
83
|
+
|
84
|
+
You can also configure the name of the fixture file generated (don't give it a .yml extension, it may get cleared
|
85
|
+
by tools like FixtureBuilder), and the path to your app's root, if you're not using Rails.
|
86
|
+
|
87
|
+
### Separate database for test
|
88
|
+
|
89
|
+
It's very convenient to use a separate DB for your dev environment and your test env. For example, we use db0 for
|
90
|
+
dev, and db1 for test. That way, running tests can reset the DB without ruining our work, if we're in the middle
|
91
|
+
of testing something manually.
|
92
|
+
|
93
|
+
Sample redis initializer to do this:
|
94
|
+
|
95
|
+
```
|
96
|
+
redis_connection = (ENV["REDISCLOUD_URL"] ? {url: ENV["REDISCLOUD_URL"]} : {host: 'localhost', port: 6379})
|
97
|
+
redis_connection[:driver] = :hiredis
|
98
|
+
redis_connection[:db] = 1 if Rails.env.test?
|
99
|
+
$RedisPool = ConnectionPool.new(size: redis_pool_size, timeout: 2) do
|
100
|
+
Redis.new(redis_connection)
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
## Generating the Fixture File
|
105
|
+
|
106
|
+
There are two ways to generate the fixture file: Automagic or Manual.
|
107
|
+
|
108
|
+
If you are using a tool that automatically snapshots your database into fixture files, you want to call RedisFixtures
|
109
|
+
from it. Simply call `RedisFixtures.before_fixture_data_generation` before you generate your data into Redis, and
|
110
|
+
`RedisFixtures.save_fixtures` afterwards, and that's it! Every time fixtures get generated, a new Redis one will
|
111
|
+
show up.
|
112
|
+
|
113
|
+
For example, you can set FixtureBuilder like this:
|
114
|
+
|
115
|
+
```
|
116
|
+
FixtureBuilder.configure do |fbuilder|
|
117
|
+
fbuilder.factory do
|
118
|
+
RedisFixtures.before_fixture_data_generation
|
119
|
+
SampleData.generate_test_data
|
120
|
+
RedisFixtures.save_fixtures
|
121
|
+
end
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
Other fixture building tools will be similar. If you're using one of them, I'd love to see a bit of sample code
|
126
|
+
to add here!
|
127
|
+
|
128
|
+
|
129
|
+
### Manual Fixture Generation
|
130
|
+
|
131
|
+
You can generate your Fixture manually in 2 ways:
|
132
|
+
|
133
|
+
1. Actually generate the YAML file manually. The YAML file contains an array with one entry per Redis key. Each
|
134
|
+
of those entries is an array that has several entries: The first one is the Redis command to create the key (:set, :zadd, etc),
|
135
|
+
the second one is the key, and the rest are whatever parameters you'd pass to the Redis client to populate that key.
|
136
|
+
|
137
|
+
2. A much more reasonable way is to use whatever tool you want to get Redis into the state you'd like to have it
|
138
|
+
(I really like [RDM](http://redisdesktop.com/) for fiddling with Redis), and then call RedisFixtures.save_fixtures from
|
139
|
+
the Rails Console (or irb, etc).
|
140
|
+
|
141
|
+
But really, try to use the automagic way, it's much more convenient.
|
142
|
+
|
143
|
+
|
144
|
+
## Running tests
|
145
|
+
|
146
|
+
If you are using Minitest, you're done! RedisFixtures will automatically reset your Redis DB to a known state before
|
147
|
+
each test.
|
148
|
+
|
149
|
+
If you are using RSpec... This is a great opportunity for you to submit a Pull Request! No, in all seriousness, I have plans
|
150
|
+
to add RSpec integration, but it may be easier for someone more experienced with RSpec.
|
151
|
+
|
152
|
+
|
153
|
+
## Version Compatibility and Continuous Integration
|
154
|
+
|
155
|
+
Tested with [Travis](https://travis-ci.org/dmagliola/redis_fixtures) using Ruby 1.9.3, 2.0, 2.1.1 and 2.1.5,
|
156
|
+
and against redis 3.0.0 and 3.2.1.
|
157
|
+
|
158
|
+
To locally run tests do:
|
159
|
+
|
160
|
+
```
|
161
|
+
appraisal rake test
|
162
|
+
```
|
163
|
+
|
164
|
+
## Copyright
|
165
|
+
|
166
|
+
Copyright (c) 2015, Daniel Magliola
|
167
|
+
|
168
|
+
See LICENSE for details.
|
169
|
+
|
170
|
+
|
171
|
+
## Users
|
172
|
+
|
173
|
+
This gem is being used by:
|
174
|
+
|
175
|
+
- [MSTY](https://www.msty.com)
|
176
|
+
- You? please, let us know if you are using this gem.
|
177
|
+
|
178
|
+
|
179
|
+
## Changelog
|
180
|
+
|
181
|
+
### Version 1.0.0 (Oct 8th, 2015)
|
182
|
+
- Newly released gem
|
183
|
+
|
184
|
+
## Contributing
|
185
|
+
|
186
|
+
1. Fork it
|
187
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
188
|
+
1. Code your thing
|
189
|
+
1. Write and run tests:
|
190
|
+
bundle install
|
191
|
+
appraisal
|
192
|
+
appraisal rake test
|
193
|
+
1. Write documentation and make sure it looks good: yard server --reload
|
194
|
+
1. Add items to the changelog, in README.
|
195
|
+
1. Commit your changes (`git commit -am "Add some feature"`)
|
196
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
197
|
+
1. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
require "rake/testtask"
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << "lib"
|
8
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => :test
|
12
|
+
|
13
|
+
require 'coveralls/rake/task'
|
14
|
+
Coveralls::RakeTask.new
|
15
|
+
task :test_with_coveralls => ["test", "coveralls:push"]
|
@@ -0,0 +1,94 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
redis_fixtures (1.0.0)
|
5
|
+
redis (>= 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (4.2.4)
|
11
|
+
i18n (~> 0.7)
|
12
|
+
json (~> 1.7, >= 1.7.7)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
ansi (1.5.0)
|
17
|
+
appraisal (2.1.0)
|
18
|
+
bundler
|
19
|
+
rake
|
20
|
+
thor (>= 0.14.0)
|
21
|
+
builder (3.2.2)
|
22
|
+
codeclimate-test-reporter (0.4.8)
|
23
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
24
|
+
connection_pool (2.2.0)
|
25
|
+
coveralls (0.8.3)
|
26
|
+
json (~> 1.8)
|
27
|
+
rest-client (>= 1.6.8, < 2)
|
28
|
+
simplecov (~> 0.10.0)
|
29
|
+
term-ansicolor (~> 1.3)
|
30
|
+
thor (~> 0.19.1)
|
31
|
+
docile (1.1.5)
|
32
|
+
domain_name (0.5.24)
|
33
|
+
unf (>= 0.0.5, < 1.0.0)
|
34
|
+
http-cookie (1.0.2)
|
35
|
+
domain_name (~> 0.5)
|
36
|
+
i18n (0.7.0)
|
37
|
+
json (1.8.3)
|
38
|
+
metaclass (0.0.4)
|
39
|
+
mime-types (2.6.2)
|
40
|
+
minitest (5.8.1)
|
41
|
+
minitest-reporters (1.1.2)
|
42
|
+
ansi
|
43
|
+
builder
|
44
|
+
minitest (>= 5.0)
|
45
|
+
ruby-progressbar
|
46
|
+
mocha (1.1.0)
|
47
|
+
metaclass (~> 0.0.1)
|
48
|
+
netrc (0.10.3)
|
49
|
+
rake (10.4.2)
|
50
|
+
redis (3.0.0)
|
51
|
+
rest-client (1.8.0)
|
52
|
+
http-cookie (>= 1.0.2, < 2.0)
|
53
|
+
mime-types (>= 1.16, < 3.0)
|
54
|
+
netrc (~> 0.7)
|
55
|
+
ruby-progressbar (1.7.5)
|
56
|
+
shoulda (3.5.0)
|
57
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
58
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
59
|
+
shoulda-context (1.2.1)
|
60
|
+
shoulda-matchers (2.8.0)
|
61
|
+
activesupport (>= 3.0.0)
|
62
|
+
simplecov (0.10.0)
|
63
|
+
docile (~> 1.1.0)
|
64
|
+
json (~> 1.8)
|
65
|
+
simplecov-html (~> 0.10.0)
|
66
|
+
simplecov-html (0.10.0)
|
67
|
+
term-ansicolor (1.3.2)
|
68
|
+
tins (~> 1.0)
|
69
|
+
thor (0.19.1)
|
70
|
+
thread_safe (0.3.5)
|
71
|
+
tins (1.6.0)
|
72
|
+
tzinfo (1.2.2)
|
73
|
+
thread_safe (~> 0.1)
|
74
|
+
unf (0.1.4)
|
75
|
+
unf_ext
|
76
|
+
unf_ext (0.0.7.1)
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
appraisal
|
83
|
+
bundler
|
84
|
+
codeclimate-test-reporter
|
85
|
+
connection_pool
|
86
|
+
coveralls
|
87
|
+
minitest
|
88
|
+
minitest-reporters
|
89
|
+
mocha
|
90
|
+
rake
|
91
|
+
redis (= 3.0.0)
|
92
|
+
redis_fixtures!
|
93
|
+
shoulda
|
94
|
+
simplecov
|
@@ -0,0 +1,94 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
redis_fixtures (1.0.0)
|
5
|
+
redis (>= 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (4.2.4)
|
11
|
+
i18n (~> 0.7)
|
12
|
+
json (~> 1.7, >= 1.7.7)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
ansi (1.5.0)
|
17
|
+
appraisal (2.1.0)
|
18
|
+
bundler
|
19
|
+
rake
|
20
|
+
thor (>= 0.14.0)
|
21
|
+
builder (3.2.2)
|
22
|
+
codeclimate-test-reporter (0.4.8)
|
23
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
24
|
+
connection_pool (2.2.0)
|
25
|
+
coveralls (0.8.2)
|
26
|
+
json (~> 1.8)
|
27
|
+
rest-client (>= 1.6.8, < 2)
|
28
|
+
simplecov (~> 0.10.0)
|
29
|
+
term-ansicolor (~> 1.3)
|
30
|
+
thor (~> 0.19.1)
|
31
|
+
docile (1.1.5)
|
32
|
+
domain_name (0.5.24)
|
33
|
+
unf (>= 0.0.5, < 1.0.0)
|
34
|
+
http-cookie (1.0.2)
|
35
|
+
domain_name (~> 0.5)
|
36
|
+
i18n (0.7.0)
|
37
|
+
json (1.8.3)
|
38
|
+
metaclass (0.0.4)
|
39
|
+
mime-types (2.6.2)
|
40
|
+
minitest (5.8.1)
|
41
|
+
minitest-reporters (1.1.2)
|
42
|
+
ansi
|
43
|
+
builder
|
44
|
+
minitest (>= 5.0)
|
45
|
+
ruby-progressbar
|
46
|
+
mocha (1.1.0)
|
47
|
+
metaclass (~> 0.0.1)
|
48
|
+
netrc (0.10.3)
|
49
|
+
rake (10.4.2)
|
50
|
+
redis (3.2.1)
|
51
|
+
rest-client (1.8.0)
|
52
|
+
http-cookie (>= 1.0.2, < 2.0)
|
53
|
+
mime-types (>= 1.16, < 3.0)
|
54
|
+
netrc (~> 0.7)
|
55
|
+
ruby-progressbar (1.7.5)
|
56
|
+
shoulda (3.5.0)
|
57
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
58
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
59
|
+
shoulda-context (1.2.1)
|
60
|
+
shoulda-matchers (2.8.0)
|
61
|
+
activesupport (>= 3.0.0)
|
62
|
+
simplecov (0.10.0)
|
63
|
+
docile (~> 1.1.0)
|
64
|
+
json (~> 1.8)
|
65
|
+
simplecov-html (~> 0.10.0)
|
66
|
+
simplecov-html (0.10.0)
|
67
|
+
term-ansicolor (1.3.2)
|
68
|
+
tins (~> 1.0)
|
69
|
+
thor (0.19.1)
|
70
|
+
thread_safe (0.3.5)
|
71
|
+
tins (1.6.0)
|
72
|
+
tzinfo (1.2.2)
|
73
|
+
thread_safe (~> 0.1)
|
74
|
+
unf (0.1.4)
|
75
|
+
unf_ext
|
76
|
+
unf_ext (0.0.7.1)
|
77
|
+
|
78
|
+
PLATFORMS
|
79
|
+
ruby
|
80
|
+
|
81
|
+
DEPENDENCIES
|
82
|
+
appraisal
|
83
|
+
bundler
|
84
|
+
codeclimate-test-reporter
|
85
|
+
connection_pool
|
86
|
+
coveralls
|
87
|
+
minitest
|
88
|
+
minitest-reporters
|
89
|
+
mocha
|
90
|
+
rake
|
91
|
+
redis (= 3.2.1)
|
92
|
+
redis_fixtures!
|
93
|
+
shoulda
|
94
|
+
simplecov
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'redis_fixtures/config'
|
2
|
+
require 'redis_fixtures/connection'
|
3
|
+
require 'redis_fixtures/dump_fixtures'
|
4
|
+
require 'redis_fixtures/load_fixtures'
|
5
|
+
require 'redis_fixtures/minitest'
|
6
|
+
require 'redis_fixtures/version'
|
7
|
+
|
8
|
+
# Add fixtures to your Redis database, to test the parts of your code that need Redis to be more than a cache.
|
9
|
+
module RedisFixtures
|
10
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module RedisFixtures
|
2
|
+
# Thrown when a config setting is invalid
|
3
|
+
class InvalidConfigSettingError < StandardError; end
|
4
|
+
|
5
|
+
# Holds the configuration
|
6
|
+
class Configuration
|
7
|
+
# Root directory of the app (where the test or spec directory exists)
|
8
|
+
# Defaults to Rails.root or `pwd`, use only if using this gem in a non-Rails environment
|
9
|
+
attr_accessor :app_root
|
10
|
+
|
11
|
+
# Filename where to store the Redis fixtures. (Will be stored in regular fixtures path)
|
12
|
+
# Defaults to 'redis.fixture'
|
13
|
+
# Do not set a .yml extension, or it may get cleared out by other tools
|
14
|
+
attr_accessor :fixture_filename
|
15
|
+
|
16
|
+
# Connection Pool used to get a new Redis connection
|
17
|
+
# One of :connection_pool, :connection_block, :connection_settings or :connection must be set
|
18
|
+
attr_accessor :connection_pool
|
19
|
+
|
20
|
+
# Proc that yields a connection object when needed
|
21
|
+
# One of :connection_pool, :connection_block, :connection_settings or :connection must be set
|
22
|
+
attr_accessor :connection_proc
|
23
|
+
|
24
|
+
# Hash specifying the settings to connect to Redis. Gets passed to `Redis.new`
|
25
|
+
# One of :connection_pool, :connection_block, :connection_settings or :connection must be set
|
26
|
+
# Defaults to localhost:6379
|
27
|
+
attr_accessor :connection_settings
|
28
|
+
|
29
|
+
# Already established connection to Redis for the library to use
|
30
|
+
# One of :connection_pool, :connection_block, :connection_settings or :connection must be set
|
31
|
+
attr_accessor :connection
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@connection_settings = {host: 'localhost', port: 6379}
|
35
|
+
@fixture_filename = "redis.fixture"
|
36
|
+
@app_root = defined?(::Rails) ? ::Rails.root : Dir.pwd
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns the current configuration
|
41
|
+
# @return [Configuration] the configuration class
|
42
|
+
def self.configuration
|
43
|
+
@configuration ||= Configuration.new
|
44
|
+
end
|
45
|
+
|
46
|
+
# Yields the current configuration, allowing the caller to modify it in a block
|
47
|
+
def self.configure
|
48
|
+
yield(configuration) if block_given?
|
49
|
+
end
|
50
|
+
|
51
|
+
# Path to the file where we'll store Redis fixtures
|
52
|
+
# @return [String]
|
53
|
+
def self.fixture_file_path
|
54
|
+
fixtures_dir(RedisFixtures.configuration.fixture_filename)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# Full path to where Fixtures are stored, or to a file inside the fixtures directory
|
60
|
+
# @param path [Symbol] path to resolve inside of the fixtures directory
|
61
|
+
# @return [String] "{your_app}/(spec|test)/fixtures/{path}"
|
62
|
+
def self.fixtures_dir(path = '')
|
63
|
+
File.expand_path(File.join(RedisFixtures.configuration.app_root, spec_or_test_dir, 'fixtures', path))
|
64
|
+
end
|
65
|
+
|
66
|
+
# Directory where specs or tests are stored
|
67
|
+
# @return [String] 'spec' or 'test'
|
68
|
+
def self.spec_or_test_dir
|
69
|
+
File.exists?(File.join(RedisFixtures.configuration.app_root, 'spec')) ? 'spec' : 'test'
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RedisFixtures
|
2
|
+
# Gets a connection to Redis using whatever method was configured,
|
3
|
+
# and yields it to the block passed in
|
4
|
+
# @return [Object] Whatever your block returned
|
5
|
+
def self.with_redis_connection
|
6
|
+
result = nil
|
7
|
+
conf = RedisFixtures.configuration
|
8
|
+
if conf.connection_pool.present?
|
9
|
+
conf.connection_pool.with do |redis|
|
10
|
+
result = yield(redis)
|
11
|
+
end
|
12
|
+
elsif conf.connection.present?
|
13
|
+
result = yield(conf.connection)
|
14
|
+
elsif conf.connection_proc.present? || conf.connection_settings.present?
|
15
|
+
redis = conf.connection_proc.present? ?
|
16
|
+
conf.connection_proc.call :
|
17
|
+
Redis.new(conf.connection_settings)
|
18
|
+
result = yield(redis)
|
19
|
+
redis.disconnect! if redis.respond_to?(:disconnect!)
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module RedisFixtures
|
2
|
+
# Cleans up the Redis DB. Call this before starting your sample data generation
|
3
|
+
# to start with a clean slate
|
4
|
+
def self.before_fixture_data_generation
|
5
|
+
with_redis_connection do |redis|
|
6
|
+
redis.flushdb
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
# Dumps the contents of the Redis DB into a fixture file.
|
11
|
+
# Call this after generating all your sample data in Redis.
|
12
|
+
def self.save_fixtures
|
13
|
+
redis_dump = with_redis_connection do |redis|
|
14
|
+
dump_keys(redis)
|
15
|
+
end
|
16
|
+
FileUtils.mkdir_p(fixtures_dir) unless File.directory?(fixtures_dir)
|
17
|
+
File.open(fixture_file_path, 'w') { |file| file.write(redis_dump.to_yaml) }
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# Finds all the keys in the Redis Database and dumps them into an array of arrays
|
23
|
+
# that can then be used to easily reconstruct the data
|
24
|
+
#
|
25
|
+
# @param redis [Redis] Redis connection
|
26
|
+
# @return [Array of `commands`] an array of arrays, one entry per key, each of which
|
27
|
+
# can be used to execute a redis call that will create and populate the key in Redis.
|
28
|
+
def self.dump_keys(redis)
|
29
|
+
keys = redis.keys("*")
|
30
|
+
keys.map do |key|
|
31
|
+
key_type = redis.type(key)
|
32
|
+
case key_type
|
33
|
+
when "hash"
|
34
|
+
dump_hash(redis, key)
|
35
|
+
when "zset"
|
36
|
+
dump_zset(redis, key)
|
37
|
+
when "list"
|
38
|
+
dump_list(redis, key)
|
39
|
+
when "set"
|
40
|
+
dump_set(redis, key)
|
41
|
+
when "string" # HLL's are stored internally as strings
|
42
|
+
dump_string(redis, key)
|
43
|
+
else
|
44
|
+
raise "Don't know how to dump a fixture for Redis type: #{key_type} (key: #{key})" # Should never happen, these are all the types Redis can return
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Dump a Redis Hash into a `command` that will allows us to regenerate it
|
50
|
+
# @param redis [Redis] Redis connection
|
51
|
+
# @param key [String] the key to dump
|
52
|
+
# @return [Array] an array specifying a `mapped_hmset` command, the key, and the hash to store in Redis
|
53
|
+
def self.dump_hash(redis, key)
|
54
|
+
hash = redis.hgetall(key)
|
55
|
+
[:mapped_hmset, key, hash]
|
56
|
+
end
|
57
|
+
|
58
|
+
# Dump a Redis Sorted Set into a `command` that will allows us to regenerate it
|
59
|
+
# @param redis [Redis] Redis connection
|
60
|
+
# @param key [String] the key to dump
|
61
|
+
# @return [Array] an array specifying a `zadd` command, the key, and the values and scores to store in Redis
|
62
|
+
def self.dump_zset(redis, key)
|
63
|
+
zset = redis.zrange key, 0, -1, with_scores: true
|
64
|
+
zset = zset.map{|entry| entry.reverse} # Zrange returns [["a", 32.0], ["b", 64.0]]. Zadd wants [[32.0, "a"], [64.0, "b"]]
|
65
|
+
[:zadd, key, zset]
|
66
|
+
end
|
67
|
+
|
68
|
+
# Dump a Redis List into a `command` that will allows us to regenerate it
|
69
|
+
# @param redis [Redis] Redis connection
|
70
|
+
# @param key [String] the key to dump
|
71
|
+
# @return [Array] an array specifying a `rpush` command, the key, and the values and scores to store in Redis
|
72
|
+
def self.dump_list(redis, key)
|
73
|
+
list = redis.lrange key, 0, -1
|
74
|
+
[:rpush, key, list]
|
75
|
+
end
|
76
|
+
|
77
|
+
# Dump a Redis Set into a `command` that will allows us to regenerate it
|
78
|
+
# @param redis [Redis] Redis connection
|
79
|
+
# @param key [String] the key to dump
|
80
|
+
# @return [Array] an array specifying a `sadd` command, the key, and the values and scores to store in Redis
|
81
|
+
def self.dump_set(redis, key)
|
82
|
+
set = redis.smembers key
|
83
|
+
[:sadd, key, set]
|
84
|
+
end
|
85
|
+
|
86
|
+
# Dump a Redis String into a `command` that will allows us to regenerate it
|
87
|
+
# This also covers HyperLogLogs and Bitmaps.
|
88
|
+
# @param redis [Redis] Redis connection
|
89
|
+
# @param key [String] the key to dump
|
90
|
+
# @return [Array] an array specifying a `set` command, the key, and the string to store in Redis
|
91
|
+
def self.dump_string(redis, key)
|
92
|
+
[:set, key, redis.get(key)]
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RedisFixtures
|
2
|
+
# Load the Redis fixture YAML file, into Redis, flushing the DB first
|
3
|
+
def self.load_fixtures
|
4
|
+
return unless File.exists?(fixture_file_path)
|
5
|
+
commands = YAML.load_file(fixture_file_path)
|
6
|
+
with_redis_connection do |redis|
|
7
|
+
redis.pipelined do |predis|
|
8
|
+
predis.flushdb
|
9
|
+
commands.each do |command|
|
10
|
+
predis.send(*command)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Module to set a before_setup Minitest hook, to reset Redis to the state specified by the fixture
|
2
|
+
# before each test runs
|
3
|
+
module MinitestRedisFixtures
|
4
|
+
# Clear Redis DB and load the fixture before the setup step of each test
|
5
|
+
def before_setup
|
6
|
+
super
|
7
|
+
RedisFixtures.load_fixtures
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class MiniTest::Test
|
12
|
+
include MinitestRedisFixtures
|
13
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "redis_fixtures/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'redis_fixtures'
|
7
|
+
s.version = RedisFixtures::VERSION
|
8
|
+
s.summary = "Add fixtures to your Redis database, to test the parts of your code that need Redis to be more than a cache."
|
9
|
+
s.description = %q{RedisFixtures allows you to have fixtures for Redis, in addition to the ones for your database.
|
10
|
+
If you are using Redis as more than just a cache (and I hope you are), you probably need to have
|
11
|
+
some data there to test your application. RedisFixtures will reset your (test) Redis database
|
12
|
+
at the beginning of every test to the fixture you set.
|
13
|
+
And if you use FixtureBuilder (or any other fixture-generating library), you can automatically
|
14
|
+
generate your Redis fixture from the contents of your test Redis database.
|
15
|
+
}
|
16
|
+
s.authors = ["Daniel Magliola"]
|
17
|
+
s.email = 'dmagliola@crystalgears.com'
|
18
|
+
s.homepage = 'https://github.com/dmagliola/redis_fixtures'
|
19
|
+
s.license = 'MIT'
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split($/)
|
22
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
23
|
+
s.test_files = s.files.grep(%r{^(test|s.features)/})
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
|
26
|
+
s.required_ruby_version = ">= 1.9.3"
|
27
|
+
|
28
|
+
s.add_runtime_dependency "redis", '>= 3.0'
|
29
|
+
|
30
|
+
s.add_development_dependency "bundler"
|
31
|
+
s.add_development_dependency "rake"
|
32
|
+
|
33
|
+
s.add_development_dependency "minitest"
|
34
|
+
s.add_development_dependency "minitest-reporters"
|
35
|
+
s.add_development_dependency "shoulda"
|
36
|
+
s.add_development_dependency "mocha"
|
37
|
+
s.add_development_dependency "simplecov"
|
38
|
+
|
39
|
+
s.add_development_dependency "appraisal"
|
40
|
+
s.add_development_dependency "coveralls"
|
41
|
+
s.add_development_dependency "codeclimate-test-reporter"
|
42
|
+
s.add_development_dependency "connection_pool"
|
43
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class ConnectionTest < MiniTest::Test
|
4
|
+
context "with resetting of configuration" do
|
5
|
+
setup do
|
6
|
+
TestResetHelper.reset_configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
TestResetHelper.reset_configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
should "connect using a connection pool" do
|
14
|
+
redis_pool = ::ConnectionPool.new(size: 2, timeout: 2) do
|
15
|
+
Redis.new($RedisConnectionSettings)
|
16
|
+
end
|
17
|
+
|
18
|
+
RedisFixtures.configure do |config|
|
19
|
+
config.connection_pool = redis_pool
|
20
|
+
config.connection_settings = {host: 'localhost', port: 1111} # Just to make sure it's not using this
|
21
|
+
end
|
22
|
+
|
23
|
+
test_connection
|
24
|
+
end
|
25
|
+
|
26
|
+
should "connect using a connection proc" do
|
27
|
+
RedisFixtures.configure do |config|
|
28
|
+
config.connection_proc = Proc.new{ Redis.new($RedisConnectionSettings) }
|
29
|
+
config.connection_settings = {host: 'localhost', port: 1111} # Just to make sure it's not using this
|
30
|
+
end
|
31
|
+
|
32
|
+
test_connection
|
33
|
+
end
|
34
|
+
|
35
|
+
should "connect using an existing connection" do
|
36
|
+
conn = Redis.new($RedisConnectionSettings)
|
37
|
+
|
38
|
+
RedisFixtures.configure do |config|
|
39
|
+
config.connection = conn
|
40
|
+
config.connection_settings = {host: 'localhost', port: 1111} # Just to make sure it's not using this
|
41
|
+
end
|
42
|
+
|
43
|
+
test_connection
|
44
|
+
end
|
45
|
+
|
46
|
+
should "connect using default connection settings" do
|
47
|
+
RedisFixtures.configure do |config|
|
48
|
+
config.connection_settings = {host: 'localhost', port: 6379} # Just to make sure it's not using this
|
49
|
+
end
|
50
|
+
|
51
|
+
test_connection
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def test_connection
|
58
|
+
RedisFixtures.with_redis_connection do |redis|
|
59
|
+
redis.set "aaa", "bbb"
|
60
|
+
assert_equal "bbb", redis.get("aaa")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class DumpFixturesTest < MiniTest::Test
|
4
|
+
should "dump fixtures" do
|
5
|
+
begin
|
6
|
+
# Check that we start with the normal keys
|
7
|
+
RedisFixtures.with_redis_connection do |redis|
|
8
|
+
assert_equal ["string_key"], redis.keys("*")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Set some new data in Redis
|
12
|
+
commands = [
|
13
|
+
[:mapped_hmset, "hash1", {"a" => "1", "b" => "2", "c" => "3"}],
|
14
|
+
[:zadd, "zset1", [[32.0, "a"], [64.0, "b"]]],
|
15
|
+
[:rpush, "list1", ["3", "4", "5", "6"]],
|
16
|
+
[:sadd, "set1", ["3", "4", "5", "6"]],
|
17
|
+
[:set, "string1", "thestring!"],
|
18
|
+
]
|
19
|
+
keys = commands.map{|cmd| cmd[1]}
|
20
|
+
|
21
|
+
RedisFixtures.with_redis_connection do |redis|
|
22
|
+
redis.flushdb
|
23
|
+
commands.each do |cmd|
|
24
|
+
redis.send(*cmd)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Check that the keys are there
|
28
|
+
assert_equal keys.sort, redis.keys("*").sort
|
29
|
+
end
|
30
|
+
|
31
|
+
RedisFixtures.save_fixtures
|
32
|
+
|
33
|
+
# Check the YAML file
|
34
|
+
serialized_commands = YAML.load_file(RedisFixtures.fixture_file_path)
|
35
|
+
assert_equal commands.sort_by{|cmd| cmd[1]}, serialized_commands.sort_by{|cmd| cmd[1]}
|
36
|
+
rescue
|
37
|
+
ensure
|
38
|
+
TestResetHelper.reset_fixtures_file_and_db
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
should "clear DB before fixture generation" do
|
43
|
+
RedisFixtures.before_fixture_data_generation
|
44
|
+
RedisFixtures.with_redis_connection do |redis|
|
45
|
+
assert_equal [], redis.keys("*")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
should "raise an exception if it finds a strange key type in Redis" do
|
50
|
+
# This can't actually happen, but it's future proofing. Thus, we need to mock.
|
51
|
+
Redis.any_instance.expects(:type).returns("unknown_type")
|
52
|
+
assert_raises RuntimeError do
|
53
|
+
RedisFixtures.save_fixtures
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class LoadFixturesTest < MiniTest::Test
|
4
|
+
should "load fixtures" do
|
5
|
+
begin
|
6
|
+
# Generate a new fixtures file
|
7
|
+
commands = [
|
8
|
+
[:zadd, "zset1", [[32.0, "a"], [64.0, "b"]]],
|
9
|
+
[:rpush, "list1", ["3", "4", "5", "6"]],
|
10
|
+
[:set, "string1", "thestring!"],
|
11
|
+
]
|
12
|
+
File.open(RedisFixtures.fixture_file_path, 'w') { |file| file.write(commands.to_yaml) }
|
13
|
+
|
14
|
+
# Check that we start with the normal keys
|
15
|
+
RedisFixtures.with_redis_connection do |redis|
|
16
|
+
assert_equal ["string_key"], redis.keys("*")
|
17
|
+
end
|
18
|
+
|
19
|
+
RedisFixtures.load_fixtures
|
20
|
+
|
21
|
+
# Check that we have these new keys in the DB
|
22
|
+
RedisFixtures.with_redis_connection do |redis|
|
23
|
+
assert_equal ["zset1", "list1", "string1"].sort, redis.keys("*").sort
|
24
|
+
assert_equal ["3", "4", "5", "6"], redis.lrange("list1", 0, -1)
|
25
|
+
assert_equal ["a", "b"], redis.zrange("zset1", 0, -1)
|
26
|
+
end
|
27
|
+
rescue
|
28
|
+
ensure
|
29
|
+
TestResetHelper.reset_fixtures_file_and_db
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative "test_helper"
|
2
|
+
|
3
|
+
class MinitestHookTest < MiniTest::Test
|
4
|
+
should "have cleaned the database and loaded the fixtures" do
|
5
|
+
# Test helper left the DB with one key called "delete_me", and the fixture says there's one string called "string_key"
|
6
|
+
# When the test runs, the DB should reflect the fixture
|
7
|
+
RedisFixtures.with_redis_connection do |redis|
|
8
|
+
keys = redis.keys("*")
|
9
|
+
assert_equal ["string_key"], keys
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
|
3
|
+
require "simplecov"
|
4
|
+
require "coveralls"
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter "/test/"
|
11
|
+
add_filter "/gemfiles/vendor"
|
12
|
+
end
|
13
|
+
|
14
|
+
require "codeclimate-test-reporter"
|
15
|
+
CodeClimate::TestReporter.start
|
16
|
+
|
17
|
+
require "minitest/autorun"
|
18
|
+
require "minitest/reporters"
|
19
|
+
MiniTest::Reporters.use!
|
20
|
+
|
21
|
+
require "shoulda"
|
22
|
+
require "shoulda-context"
|
23
|
+
require "shoulda-matchers"
|
24
|
+
require "mocha/setup"
|
25
|
+
|
26
|
+
# Make the code to be tested easy to load.
|
27
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
28
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
29
|
+
|
30
|
+
require 'active_support/testing/assertions'
|
31
|
+
include ActiveSupport::Testing::Assertions
|
32
|
+
|
33
|
+
require "benchmark"
|
34
|
+
|
35
|
+
require "redis_fixtures"
|
36
|
+
require "redis"
|
37
|
+
require "connection_pool"
|
38
|
+
|
39
|
+
|
40
|
+
# Add helper methods to use in the tests
|
41
|
+
$RedisConnectionSettings = {host: 'localhost', port: 6379, db: 2}
|
42
|
+
|
43
|
+
class TestResetHelper
|
44
|
+
def self.reset_configuration
|
45
|
+
RedisFixtures.instance_variable_set(:@configuration, RedisFixtures::Configuration.new)
|
46
|
+
RedisFixtures.configure do |config|
|
47
|
+
config.connection_settings = $RedisConnectionSettings
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.reset_fixtures_file_and_db
|
52
|
+
reset_configuration
|
53
|
+
RedisFixtures.with_redis_connection do |redis|
|
54
|
+
redis.flushdb
|
55
|
+
redis.set("string_key", "blah")
|
56
|
+
RedisFixtures.save_fixtures
|
57
|
+
redis.flushdb
|
58
|
+
redis.set("delete_me", "aa")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
# Prepare some test data, before tests run, since we're testing a "before_setup" hook
|
65
|
+
TestResetHelper.reset_configuration
|
66
|
+
TestResetHelper.reset_fixtures_file_and_db
|
67
|
+
|
metadata
ADDED
@@ -0,0 +1,249 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis_fixtures
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Magliola
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest-reporters
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: shoulda
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mocha
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: appraisal
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: coveralls
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: codeclimate-test-reporter
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: connection_pool
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: "RedisFixtures allows you to have fixtures for Redis, in addition to
|
182
|
+
the ones for your database.\n If you are using Redis as more
|
183
|
+
than just a cache (and I hope you are), you probably need to have\n some
|
184
|
+
data there to test your application. RedisFixtures will reset your (test) Redis
|
185
|
+
database\n at the beginning of every test to the fixture you
|
186
|
+
set.\n And if you use FixtureBuilder (or any other fixture-generating
|
187
|
+
library), you can automatically\n generate your Redis fixture
|
188
|
+
from the contents of your test Redis database.\n "
|
189
|
+
email: dmagliola@crystalgears.com
|
190
|
+
executables: []
|
191
|
+
extensions: []
|
192
|
+
extra_rdoc_files: []
|
193
|
+
files:
|
194
|
+
- ".gitignore"
|
195
|
+
- ".travis.yml"
|
196
|
+
- Appraisals
|
197
|
+
- Gemfile
|
198
|
+
- LICENSE
|
199
|
+
- README.md
|
200
|
+
- Rakefile
|
201
|
+
- gemfiles/redis_3_0_0.gemfile
|
202
|
+
- gemfiles/redis_3_0_0.gemfile.lock
|
203
|
+
- gemfiles/redis_3_2_1.gemfile
|
204
|
+
- gemfiles/redis_3_2_1.gemfile.lock
|
205
|
+
- lib/redis_fixtures.rb
|
206
|
+
- lib/redis_fixtures/config.rb
|
207
|
+
- lib/redis_fixtures/connection.rb
|
208
|
+
- lib/redis_fixtures/dump_fixtures.rb
|
209
|
+
- lib/redis_fixtures/load_fixtures.rb
|
210
|
+
- lib/redis_fixtures/minitest.rb
|
211
|
+
- lib/redis_fixtures/version.rb
|
212
|
+
- redis_fixtures.gemspec
|
213
|
+
- test/connection_test.rb
|
214
|
+
- test/dump_fixtures_test.rb
|
215
|
+
- test/load_fixtures_test.rb
|
216
|
+
- test/minitest_hook_test.rb
|
217
|
+
- test/test_helper.rb
|
218
|
+
homepage: https://github.com/dmagliola/redis_fixtures
|
219
|
+
licenses:
|
220
|
+
- MIT
|
221
|
+
metadata: {}
|
222
|
+
post_install_message:
|
223
|
+
rdoc_options: []
|
224
|
+
require_paths:
|
225
|
+
- lib
|
226
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
version: 1.9.3
|
231
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
|
+
requirements:
|
233
|
+
- - ">="
|
234
|
+
- !ruby/object:Gem::Version
|
235
|
+
version: '0'
|
236
|
+
requirements: []
|
237
|
+
rubyforge_project:
|
238
|
+
rubygems_version: 2.4.5
|
239
|
+
signing_key:
|
240
|
+
specification_version: 4
|
241
|
+
summary: Add fixtures to your Redis database, to test the parts of your code that
|
242
|
+
need Redis to be more than a cache.
|
243
|
+
test_files:
|
244
|
+
- test/connection_test.rb
|
245
|
+
- test/dump_fixtures_test.rb
|
246
|
+
- test/load_fixtures_test.rb
|
247
|
+
- test/minitest_hook_test.rb
|
248
|
+
- test/test_helper.rb
|
249
|
+
has_rdoc:
|