redis-objects-legacy 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +16 -0
- data/ATOMICITY.rdoc +154 -0
- data/CHANGELOG.rdoc +362 -0
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/README.md +600 -0
- data/Rakefile +14 -0
- data/lib/redis/base_object.rb +62 -0
- data/lib/redis/counter.rb +145 -0
- data/lib/redis/enumerable_object.rb +28 -0
- data/lib/redis/hash_key.rb +163 -0
- data/lib/redis/helpers/core_commands.rb +89 -0
- data/lib/redis/list.rb +160 -0
- data/lib/redis/lock.rb +89 -0
- data/lib/redis/objects/connection_pool_proxy.rb +31 -0
- data/lib/redis/objects/counters.rb +155 -0
- data/lib/redis/objects/hashes.rb +60 -0
- data/lib/redis/objects/lists.rb +58 -0
- data/lib/redis/objects/locks.rb +73 -0
- data/lib/redis/objects/sets.rb +58 -0
- data/lib/redis/objects/sorted_sets.rb +49 -0
- data/lib/redis/objects/values.rb +64 -0
- data/lib/redis/objects/version.rb +5 -0
- data/lib/redis/objects.rb +199 -0
- data/lib/redis/set.rb +182 -0
- data/lib/redis/sorted_set.rb +325 -0
- data/lib/redis/value.rb +65 -0
- data/lib/redis-objects-legacy.rb +1 -0
- data/spec/redis_autoload_objects_spec.rb +46 -0
- data/spec/redis_namespace_compat_spec.rb +24 -0
- data/spec/redis_objects_active_record_spec.rb +162 -0
- data/spec/redis_objects_conn_spec.rb +276 -0
- data/spec/redis_objects_custom_serializer.rb +198 -0
- data/spec/redis_objects_instance_spec.rb +1666 -0
- data/spec/redis_objects_model_spec.rb +1097 -0
- data/spec/spec_helper.rb +92 -0
- metadata +214 -0
@@ -0,0 +1,198 @@
|
|
1
|
+
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
+
|
4
|
+
require 'redis/objects'
|
5
|
+
|
6
|
+
class CustomSerializer
|
7
|
+
class << self
|
8
|
+
attr_accessor :dump_called, :load_called, :dump_args, :load_args
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.dump(value, *args, **kargs)
|
12
|
+
@dump_called = true
|
13
|
+
@dump_args = [args, kargs]
|
14
|
+
Marshal.dump(value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.load(value, *args, **kargs)
|
18
|
+
@load_called = true
|
19
|
+
@load_args = [args, kargs]
|
20
|
+
Marshal.load(value)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.reset!
|
24
|
+
@dump_called = nil
|
25
|
+
@load_called = nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'with custom serialization' do
|
30
|
+
before do
|
31
|
+
CustomSerializer.reset!
|
32
|
+
end
|
33
|
+
|
34
|
+
describe Redis::Value do
|
35
|
+
before do
|
36
|
+
@value = Redis::Value.new(
|
37
|
+
'spec/value_custom_serializer',
|
38
|
+
marshal: true,
|
39
|
+
serializer: CustomSerializer
|
40
|
+
)
|
41
|
+
@value.clear
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'uses custom serializer' do
|
45
|
+
@value.value = { json: 'data' }
|
46
|
+
CustomSerializer.dump_called.should == true
|
47
|
+
CustomSerializer.load_called.should == nil
|
48
|
+
@value.value.should == { json: 'data' }
|
49
|
+
CustomSerializer.dump_called.should == true
|
50
|
+
CustomSerializer.load_called.should == true
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'passes extra arguments to dump' do
|
54
|
+
@value.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
|
55
|
+
@value.value = 1
|
56
|
+
CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'passes extra arguments to load' do
|
60
|
+
@value.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
|
61
|
+
@value.value = 1
|
62
|
+
@value.value.should == 1
|
63
|
+
CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe Redis::List do
|
68
|
+
before do
|
69
|
+
@list = Redis::List.new(
|
70
|
+
'spec/list_custom_serializer',
|
71
|
+
marshal: true,
|
72
|
+
serializer: CustomSerializer
|
73
|
+
)
|
74
|
+
@list.clear
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'uses custom serializer' do
|
78
|
+
@list << { json: 'data' }
|
79
|
+
CustomSerializer.dump_called.should == true
|
80
|
+
CustomSerializer.load_called.should == nil
|
81
|
+
@list.should == [{ json: 'data' }]
|
82
|
+
CustomSerializer.dump_called.should == true
|
83
|
+
CustomSerializer.load_called.should == true
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'passes extra arguments to dump' do
|
87
|
+
@list.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
|
88
|
+
@list << 1
|
89
|
+
CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'passes extra arguments to load' do
|
93
|
+
@list.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
|
94
|
+
@list << 1
|
95
|
+
@list.values.should == [1]
|
96
|
+
CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe Redis::HashKey do
|
101
|
+
before do
|
102
|
+
@hash = Redis::HashKey.new(
|
103
|
+
'spec/hash_custom_serializer',
|
104
|
+
marshal: true,
|
105
|
+
serializer: CustomSerializer
|
106
|
+
)
|
107
|
+
@hash.clear
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'uses custom serializer' do
|
111
|
+
@hash['a'] = 1
|
112
|
+
CustomSerializer.dump_called.should == true
|
113
|
+
CustomSerializer.load_called.should == nil
|
114
|
+
@hash.value.should == { 'a' => 1 }
|
115
|
+
CustomSerializer.dump_called.should == true
|
116
|
+
CustomSerializer.load_called.should == true
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'passes extra arguments to dump' do
|
120
|
+
@hash.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
|
121
|
+
@hash['a'] = 1
|
122
|
+
CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'passes extra arguments to load' do
|
126
|
+
@hash.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
|
127
|
+
@hash['a'] = 1
|
128
|
+
@hash.value.should == { 'a' => 1 }
|
129
|
+
CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe Redis::Set do
|
134
|
+
before do
|
135
|
+
@set = Redis::Set.new(
|
136
|
+
'spec/set_custom_serializer',
|
137
|
+
marshal: true,
|
138
|
+
serializer: CustomSerializer
|
139
|
+
)
|
140
|
+
@set.clear
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'uses custom serializer' do
|
144
|
+
@set << 'a'
|
145
|
+
CustomSerializer.dump_called.should == true
|
146
|
+
CustomSerializer.load_called.should == nil
|
147
|
+
@set.members.should == ['a']
|
148
|
+
CustomSerializer.dump_called.should == true
|
149
|
+
CustomSerializer.load_called.should == true
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'passes extra arguments to dump' do
|
153
|
+
@set.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
|
154
|
+
@set << 'a'
|
155
|
+
CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'passes extra arguments to load' do
|
159
|
+
@set.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
|
160
|
+
@set << 'a'
|
161
|
+
@set.members.should == ['a']
|
162
|
+
CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe Redis::SortedSet do
|
167
|
+
before do
|
168
|
+
@set = Redis::SortedSet.new(
|
169
|
+
'spec/zset_custom_serializer',
|
170
|
+
marshal: true,
|
171
|
+
serializer: CustomSerializer
|
172
|
+
)
|
173
|
+
@set.clear
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'uses custom serializer' do
|
177
|
+
@set['a'] = 1
|
178
|
+
CustomSerializer.dump_called.should == true
|
179
|
+
CustomSerializer.load_called.should == nil
|
180
|
+
@set.members.should == ['a']
|
181
|
+
CustomSerializer.dump_called.should == true
|
182
|
+
CustomSerializer.load_called.should == true
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'passes extra arguments to dump' do
|
186
|
+
@set.options[:marshal_dump_args] = ['some', { extra: 'arguments' }]
|
187
|
+
@set['a'] = 1
|
188
|
+
CustomSerializer.dump_args.should == [['some'], { extra: 'arguments' }]
|
189
|
+
end
|
190
|
+
|
191
|
+
it 'passes extra arguments to load' do
|
192
|
+
@set.options[:marshal_load_args] = ['some', { extra: 'arguments' }]
|
193
|
+
@set['a'] = 1
|
194
|
+
@set.members.should == ['a']
|
195
|
+
CustomSerializer.load_args.should == [['some'], { extra: 'arguments' }]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|