redis_object 1.5.1 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9e5ca5eeb648940280fd12e10eadde8060bf9bd
4
- data.tar.gz: aa70d17724344acd63d808113f31449fe0da257b
3
+ metadata.gz: e29fac9ff513bd3d3f7aa116e630fe7c73f5cec7
4
+ data.tar.gz: 14d062362d8cad4c0ee0ea30de05fcf7ae21f4a2
5
5
  SHA512:
6
- metadata.gz: e24ee1ccdaa8cc5171a0d58ba3ebebad051cf361dbd719f954837427d1b9d5d69a5c7cfcc9b23103c25fe5aa57a2779035a1b2e6d78d5f956e9ce42351a2d7ce
7
- data.tar.gz: 57b3a7698aa66d95faa01f88e83dd65d75a5160b8c722160215de280ddc8ca44cf0e839afb20e2f6249ad77be48f2384cac3d7b8fa56d6da57816cfa13e92635
6
+ metadata.gz: 7ea0b819bb2181d844fbbf493d3e5cbd66a2b9511282ed200a8cc2ed2032df0fd67b1c9cbb1f43867a2d3bd349be8a369355d380ad39661855ebc734fad50786
7
+ data.tar.gz: cc1dbf34cddda5e4fadad91871d443ba038c0657f8b9566f70b3526d6bbf01e45dd94b460a7b86aa380edd08b4a03c7081104c7636080d19bb656560e46cbdff
@@ -34,11 +34,11 @@ module Seabright
34
34
  include Seabright::CachedScripts
35
35
  include Seabright::Storage
36
36
  include Seabright::Keys
37
- include Seabright::Types
38
37
  include Seabright::DefaultValues
38
+ include Seabright::Indices
39
39
  include Seabright::Collections
40
+ include Seabright::Types
40
41
  include Seabright::Triggers
41
- include Seabright::Indices
42
42
  include Seabright::Views
43
43
  include Seabright::ViewCaching
44
44
  include Seabright::Timestamps
@@ -71,7 +71,13 @@ module Seabright
71
71
  alias_method :actual, :raw
72
72
 
73
73
  def get(k)
74
- cached_hash_values[k.to_s] ||= _get(k)
74
+ filter_gotten_value(k, (cached_hash_values[k.to_s] || _get(k)))
75
+ end
76
+
77
+ def filter_gotten_value(k,v)
78
+ self.class.get_filters.inject(v) do |acc, filter|
79
+ filter.call(self, k, acc)
80
+ end
75
81
  end
76
82
 
77
83
  def _get(k)
@@ -92,6 +98,9 @@ module Seabright
92
98
  end
93
99
 
94
100
  def mset(dat)
101
+ dat = self.class.mset_filters.inject(dat) do |acc,filter|
102
+ filter.call(self, acc)
103
+ end
95
104
  store.hmset(hkey, *(dat.inject([]){|acc,(k,v)| acc << [k,v] }.flatten))
96
105
  cached_hash_values.merge!(dat)
97
106
  dat.each do |k,v|
@@ -115,6 +124,9 @@ module Seabright
115
124
  end
116
125
 
117
126
  def set(k,v)
127
+ (k,v) = self.class.set_filters.inject([k,v]) do |acc,filter|
128
+ filter.call(self,*acc) unless acc.nil? or acc[0].nil?
129
+ end
118
130
  return nil if k.nil?
119
131
  return set_ref(k,v) if v.is_a?(RedisObject)
120
132
  store.hset(hkey, k.to_s, v.to_s)
@@ -151,6 +163,9 @@ module Seabright
151
163
  end
152
164
 
153
165
  def setnx(k,v)
166
+ (k,v) = self.class.set_filters.inject([k,v]) do |acc,filter|
167
+ filter.call(self,*acc)
168
+ end
154
169
  if success = store.hsetnx(hkey, k.to_s, v.to_s)
155
170
  cached_hash_values[k.to_s] = v
156
171
  define_setter_getter(k)
@@ -216,6 +231,34 @@ module Seabright
216
231
 
217
232
  module ClassMethods
218
233
 
234
+ def action_filters
235
+ @@action_filters ||= {}
236
+ end
237
+
238
+ def set_filters
239
+ action_filters[:set] ||= []
240
+ end
241
+
242
+ def filter_sets(&block)
243
+ set_filters << block
244
+ end
245
+
246
+ def mset_filters
247
+ action_filters[:mset] ||= []
248
+ end
249
+
250
+ def filter_msets(&block)
251
+ mset_filters << block
252
+ end
253
+
254
+ def get_filters
255
+ action_filters[:get] ||= []
256
+ end
257
+
258
+ def filter_gets(&block)
259
+ get_filters << block
260
+ end
261
+
219
262
  def clean_id(i)
220
263
  i.to_s.gsub(/.*:/,'').gsub(/_h$/,'')
221
264
  end
@@ -6,20 +6,6 @@ module Seabright
6
6
  "#{hkey}:collections"
7
7
  end
8
8
 
9
- def load(o_id)
10
- super(o_id)
11
- store.smembers(hkey_col).each do |name|
12
- collections[name] = Seabright::Collection.load(name,self)
13
- define_access(name) do
14
- get_collection(name)
15
- end
16
- define_access(name.to_s.singularize) do
17
- get_collection(name).latest
18
- end
19
- end
20
- true
21
- end
22
-
23
9
  def delete_child(obj)
24
10
  if col = get_collection(obj.collection_name)
25
11
  col.delete obj
@@ -78,14 +64,18 @@ module Seabright
78
64
  end
79
65
  end
80
66
 
81
- def get(k)
82
- if has_collection?(k)
83
- get_collection(k)
84
- elsif has_collection?(pk = k.to_s.pluralize)
85
- get_collection(pk).first
86
- else
87
- super(k)
67
+ def load(o_id)
68
+ super(o_id)
69
+ store.smembers(hkey_col).each do |name|
70
+ collections[name] = Seabright::Collection.load(name,self)
71
+ define_access(name) do
72
+ get_collection(name)
73
+ end
74
+ define_access(name.to_s.singularize) do
75
+ get_collection(name).latest
76
+ end
88
77
  end
78
+ true
89
79
  end
90
80
 
91
81
  def has_collection?(name)
@@ -97,13 +87,13 @@ module Seabright
97
87
  collections[name.to_s] ||= Collection.load(name,self)
98
88
  else
99
89
  store.sadd hkey_col, name
100
- @collection_names << name.to_s
90
+ collection_names << name.to_s
101
91
  collections[name.to_s] ||= Collection.load(name,self)
102
92
  define_access(name.to_s.pluralize) do
103
93
  get_collection(name)
104
94
  end
105
95
  define_access(name.to_s.singularize) do
106
- get_collection(name).latest
96
+ get_collection(name).first
107
97
  end
108
98
  end
109
99
  collections[name.to_s]
@@ -117,16 +107,6 @@ module Seabright
117
107
  @collection_names ||= store.smembers(hkey_col)
118
108
  end
119
109
 
120
- def mset(dat)
121
- dat.select! {|k,v| !collections[k.to_s] }
122
- super(dat)
123
- end
124
-
125
- def set(k,v)
126
- @data ? super(k,v) : has_collection?(k) ? get_collection(k.to_s).replace(v) : super(k,v)
127
- v
128
- end
129
-
130
110
  def collect_type_by_key(col,*keys)
131
111
  collect = get_collection(col)
132
112
  keys.each do |k|
@@ -136,6 +116,37 @@ module Seabright
136
116
 
137
117
  module ClassMethods
138
118
 
119
+ def intercept_sets_for_collecting!
120
+ return if @intercepted_sets_for_collecting
121
+ self.class_eval do
122
+
123
+ filter_gets do |obj, k, v|
124
+ if obj.has_collection?(k)
125
+ obj.get_collection(k)
126
+ elsif obj.has_collection?(pk = k.to_s.pluralize)
127
+ obj.get_collection(pk).first
128
+ else
129
+ v
130
+ end
131
+ end
132
+
133
+ filter_sets do |obj, k, v|
134
+ if obj.has_collection?(k)
135
+ obj.get_collection(k.to_s).replace(v)
136
+ return [nil,nil]
137
+ else
138
+ [k,v]
139
+ end
140
+ end
141
+
142
+ filter_msets do |obj, dat|
143
+ dat.select {|k,v| !obj.collections[k.to_s] }
144
+ end
145
+
146
+ end
147
+ @intercepted_sets_for_collecting = true
148
+ end
149
+
139
150
  def hkey_col(ident = nil)
140
151
  "#{hkey(ident)}:collections"
141
152
  end
@@ -170,12 +181,11 @@ module Seabright
170
181
 
171
182
  def get(k)
172
183
  if has_collection?(k)
173
- get_collection(k)
184
+ return get_collection(k)
174
185
  elsif has_collection?(pk = k.to_s.pluralize)
175
- get_collection(pk).first
176
- else
177
- super(k)
186
+ return get_collection(pk).first
178
187
  end
188
+ nil
179
189
  end
180
190
 
181
191
  def has_collection?(name)
@@ -195,6 +205,7 @@ module Seabright
195
205
 
196
206
  def self.included(base)
197
207
  base.extend(ClassMethods)
208
+ base.intercept_sets_for_collecting!
198
209
  end
199
210
 
200
211
  end
@@ -238,12 +249,18 @@ module Seabright
238
249
  "#{key}::zintersect_temp::#{RedisObject.new_id(4)}"
239
250
  end
240
251
 
241
- RedisObject::ScriptSources::FwdScript = "redis.call('ZINTERSTORE', KEYS[1], 2, KEYS[2], KEYS[3], 'WEIGHTS', 1, 0)\nlocal keys = redis.call('ZRANGE', KEYS[1], 0, KEYS[4])\nredis.call('DEL', KEYS[1])\nreturn keys".freeze
242
- RedisObject::ScriptSources::RevScript = "redis.call('ZINTERSTORE', KEYS[1], 2, KEYS[2], KEYS[3], 'WEIGHTS', 1, 0)\nlocal keys = redis.call('ZREVRANGE', KEYS[1], 0, KEYS[4])\nredis.call('DEL', KEYS[1])\nreturn keys".freeze
252
+ RedisObject::ScriptSources::FwdScript = "redis.call('ZINTERSTORE', KEYS[1], 2, KEYS[2], KEYS[3], 'WEIGHTS', 1, 0)
253
+ local keys = redis.call('ZRANGE', KEYS[1], 0, KEYS[4])
254
+ redis.call('DEL', KEYS[1])
255
+ return keys".freeze
256
+ RedisObject::ScriptSources::RevScript = "redis.call('ZINTERSTORE', KEYS[1], 2, KEYS[2], KEYS[3], 'WEIGHTS', 1, 0)
257
+ local keys = redis.call('ZREVRANGE', KEYS[1], 0, KEYS[4])
258
+ redis.call('DEL', KEYS[1])
259
+ return keys".freeze
243
260
 
244
261
  def keys_by_index(idx,num=-1,reverse=false)
245
- keys = run_script(reverse ? :RevScript : :FwdScript, [temp_key, sort_index_key(idx), key, num])
246
- ListEnumerator.new(keys) do |y|
262
+ keys = run_script(reverse ? :RevScript : :FwdScript, [temp_key, sort_index_key(idx), key, num>0 ? num - 1 : -1])
263
+ ListEnumerator.new(keys.uniq) do |y|
247
264
  keys.each do |member|
248
265
  y << member
249
266
  end
@@ -584,6 +601,9 @@ module Seabright
584
601
  end
585
602
 
586
603
  def class_const_for(name)
604
+ if cls = RedisObject.constant_lookups[name.to_s.classify.to_sym]
605
+ return cls
606
+ end
587
607
  Object.const_get(name.to_s.classify.to_sym) rescue RedisObject
588
608
  end
589
609
 
@@ -11,12 +11,12 @@ module Seabright
11
11
  return if @intercepted_for_defaults
12
12
  self.class_eval do
13
13
 
14
- alias_method :undefaulted_get, :get unless method_defined?(:undefaulted_get)
15
- def get(k)
16
- if !is_set?(k) && (d = self.class.default_vals[k.to_sym]) && !d.nil?
17
- return d
14
+ filter_gets do |obj, k, v|
15
+ if !obj.is_set?(k) && (d = obj.class.default_vals[k.to_sym]) && !d.nil?
16
+ d
17
+ else
18
+ v
18
19
  end
19
- undefaulted_get(k)
20
20
  end
21
21
 
22
22
  end
@@ -7,41 +7,45 @@ module Seabright
7
7
  return if @intercept_for_filters
8
8
  self.class_eval do
9
9
 
10
- def filtered_method_call(method,*args)
11
- if filters = self.class.filters_for(method)
12
- filters.each do |f|
13
- next unless args.is_a?(Array) and !args[0].nil?
14
- args = send(f,*args)
10
+ filter_gets do |obj, k, v|
11
+ if filters = obj.class.filters_for(:get)
12
+ return filters.inject(v) do |acc,f|
13
+ obj.send(f,acc)
15
14
  end
15
+ else
16
+ v
16
17
  end
17
- unless args.is_a?(Array)
18
- args = [nil,nil]
19
- end
20
- send("unfiltered_#{method.to_s}".to_sym,*args)
21
- end
22
-
23
- alias_method :unfiltered_get, :get unless method_defined?(:unfiltered_get)
24
- def get(k)
25
- filtered_method_call(:get,k)
26
18
  end
27
19
 
28
- alias_method :unfiltered_set, :set unless method_defined?(:unfiltered_set)
29
- def set(k,v)
30
- filtered_method_call(:set,k,v)
31
- end
32
-
33
- alias_method :unfiltered_setnx, :setnx unless method_defined?(:unfiltered_setnx)
34
- def setnx(k,v)
35
- filtered_method_call(:setnx,k,v)
20
+ filter_sets do |obj, k, v|
21
+ if filters = obj.class.filters_for(:set)
22
+ filters.inject([k,v]) do |acc,f|
23
+ obj.send(f,*acc)
24
+ end
25
+ else
26
+ [k,v]
27
+ end
36
28
  end
37
29
 
30
+ # filter_msets do |dat|
31
+ # if filters = self.class.filters_for(method)
32
+ # filters.each do |f|
33
+ # next unless args.is_a?(Array) and !args[0].nil?
34
+ # args = send(f,*args)
35
+ # end
36
+ # end
37
+ # unless args.is_a?(Array)
38
+ # args = [nil,nil]
39
+ # end
40
+ # args
41
+ # end
42
+ #
38
43
  end
39
44
  @intercept_for_filters = true
40
45
  end
41
46
 
42
47
  def set_filter(filter)
43
48
  filter_method(:set,filter)
44
- filter_method(:setnx,filter)
45
49
  end
46
50
 
47
51
  def get_filter(filter)
@@ -22,17 +22,6 @@ module Seabright
22
22
  return if @intercepted_sets_for_indices
23
23
  self.class_eval do
24
24
 
25
- def indexed_set_method(meth,k,v)
26
- ret = send("unindexed_#{meth}".to_sym,k,v)
27
- if self.class.has_index?(k)
28
- set_index k, v, hkey
29
- end
30
- if self.class.has_sort_index?(k)
31
- set_sort_index k, v, hkey
32
- end
33
- ret
34
- end
35
-
36
25
  def set_index(k,v,hkey)
37
26
  if cur = get(k)
38
27
  store.srem(self.class.index_key(k,cur), hkey)
@@ -45,25 +34,24 @@ module Seabright
45
34
  store.zadd(self.class.sort_index_key(k), score_format(k,v), hkey)
46
35
  end
47
36
 
48
- alias_method :unindexed_set, :set unless method_defined?(:unindexed_set)
49
- def set(k,v)
50
- indexed_set_method(:set,k,v)
51
- end
52
-
53
- alias_method :unindexed_setnx, :setnx unless method_defined?(:unindexed_setnx)
54
- def setnx(k,v)
55
- indexed_set_method(:setnx,k,v)
37
+ filter_sets do |obj, k, v|
38
+ if obj.class.has_index?(k)
39
+ obj.set_index k, v, obj.hkey
40
+ end
41
+ if obj.class.has_sort_index?(k)
42
+ obj.set_sort_index k, v, obj.hkey
43
+ end
44
+ [k, v]
56
45
  end
57
46
 
58
- alias_method :unindexed_mset, :mset unless method_defined?(:unindexed_mset)
59
- def mset(dat)
60
- dat.select {|k,v| self.class.has_index?(k) }.each do |k,v|
61
- set_index k, v, hkey
47
+ filter_msets do |obj, dat|
48
+ dat.each do |k,v|
49
+ obj.set_index(k, v, obj.hkey) if obj.class.has_index?(k)
62
50
  end
63
- dat.select {|k,v| self.class.has_sort_index?(k) }.each do |k,v|
64
- set_sort_index k, v, hkey
51
+ dat.each do |k,v|
52
+ obj.set_sort_index(k, v, obj.hkey) if obj.class.has_sort_index?(k)
65
53
  end
66
- unindexed_mset(dat)
54
+ dat
67
55
  end
68
56
 
69
57
  end
@@ -147,6 +135,7 @@ module Seabright
147
135
 
148
136
  def self.included(base)
149
137
  base.extend(ClassMethods)
138
+ base.intercept_sets_for_indices!
150
139
  end
151
140
 
152
141
  end
@@ -1,8 +1,15 @@
1
1
  module Seabright
2
+
3
+ def RedisObject.constant_lookups
4
+ @constant_lookups ||= {}
5
+ end
6
+
2
7
  module InheritanceTracking
3
8
 
4
9
  module ClassMethods
10
+
5
11
  def inherited(child_class)
12
+ RedisObject.constant_lookups[child_class.name.to_s.split("::").last.to_sym] ||= child_class
6
13
  child_classes_set.add(child_class)
7
14
  end
8
15
 
@@ -3,7 +3,9 @@ module Seabright
3
3
 
4
4
  def update_timestamps
5
5
  # return unless self.class.time_matters?
6
- set(:created_at, Time.now) if !is_set?(:created_at)
6
+ if !is_set?(:created_at)
7
+ set(:created_at, Time.now)
8
+ end
7
9
  set(:updated_at, Time.now)
8
10
  end
9
11
 
@@ -136,30 +136,19 @@ module Seabright
136
136
 
137
137
  def intercept_for_typing!
138
138
  return if @intercepted_for_typing
139
- self.class_eval do
140
-
141
- alias_method :untyped_get, :get unless method_defined?(:untyped_get)
142
- def get(k)
143
- enforce_format(k,untyped_get(k))
144
- end
145
-
146
- alias_method :untyped_mset, :mset unless method_defined?(:untyped_mset)
147
- def mset(dat)
148
- dat.merge!(dat) {|k,v1,v2| save_format(k,v1) }
149
- untyped_mset(dat)
150
- end
151
-
152
- alias_method :untyped_set, :set unless method_defined?(:untyped_set)
153
- def set(k,v)
154
- untyped_set(k,save_format(k,v))
155
- end
156
-
157
- alias_method :untyped_setnx, :setnx unless method_defined?(:untyped_setnx)
158
- def setnx(k,v)
159
- untyped_setnx(k,save_format(k,v))
160
- end
161
-
139
+
140
+ filter_gets do |obj, k, v|
141
+ obj.enforce_format(k, v)
142
+ end
143
+
144
+ filter_sets do |obj, k, v|
145
+ [k, obj.save_format(k,v)]
146
+ end
147
+
148
+ filter_msets do |obj, dat|
149
+ dat.merge!(dat) {|k,v1,v2| obj.save_format(k, v1) }
162
150
  end
151
+
163
152
  @intercepted_for_typing = true
164
153
  end
165
154
 
@@ -3,10 +3,12 @@ module Seabright
3
3
  module ArrayType
4
4
 
5
5
  def format_array(val)
6
+ return val if val.is_a?(Array)
6
7
  val ? Yajl::Parser.new(:symbolize_keys => true).parse(val) : []
7
8
  end
8
9
 
9
10
  def save_array(val)
11
+ return val if val.is_a?(String)
10
12
  Yajl::Encoder.encode(val)
11
13
  end
12
14
 
@@ -3,11 +3,11 @@ module Seabright
3
3
  module BooleanType
4
4
 
5
5
  def format_boolean(val)
6
- val=="true"
6
+ (val === true or val === "true") ? true : false
7
7
  end
8
8
 
9
9
  def save_boolean(val)
10
- val === true ? "true" : "false"
10
+ (val === true or val === "true") ? "true" : "false"
11
11
  end
12
12
 
13
13
  def score_boolean(val)
@@ -3,10 +3,12 @@ module Seabright
3
3
  module JsonType
4
4
 
5
5
  def format_json(val)
6
+ return val unless val.is_a?(String)
6
7
  val ? Yajl::Parser.new(:symbolize_keys => true).parse(val) : nil
7
8
  end
8
9
 
9
10
  def save_json(val)
11
+ return val if val.is_a?(String)
10
12
  Yajl::Encoder.encode(val)
11
13
  end
12
14
 
@@ -1,5 +1,5 @@
1
1
  module Seabright
2
2
  class RedisObject
3
- VERSION = "1.5.1"
3
+ VERSION = "1.5.3"
4
4
  end
5
5
  end
@@ -22,7 +22,7 @@ describe RedisObject do
22
22
  it "can dump to a file" do
23
23
  obj = ObjectTests::User.create("test")
24
24
  RedisObject.dump_stores_to_files("/tmp")
25
- RedisObject.store.flushdb
25
+ SpecHelper.flushdb
26
26
  end
27
27
 
28
28
  it "can restore from a file" do
@@ -30,7 +30,7 @@ module BenchmarkSpec
30
30
 
31
31
  describe Seabright::Benchmark do
32
32
  before do
33
- RedisObject.store.flushdb
33
+ SpecHelper.flushdb
34
34
  end
35
35
 
36
36
  it "benchmarks a call" do
@@ -10,7 +10,7 @@ module CollectionSpec
10
10
  describe Seabright::Collections do
11
11
  before do
12
12
 
13
- RedisObject.store.flushdb
13
+ SpecHelper.flushdb
14
14
  @granddad = GrandDad.create("gramps")
15
15
  @dad = Daddy.create("dad")
16
16
  @son = Son.create("sun")
@@ -140,7 +140,7 @@ module CollectionSpec
140
140
  @dad << Son.create
141
141
  end
142
142
 
143
- # @dad.sons.indexed(:created_at,3,true).count.should eq(3)
143
+ @dad.sons.indexed(:created_at,3,true).count.should eq(3)
144
144
 
145
145
  Son.indexed(:created_at,3,true).count.should eq(3)
146
146
 
@@ -28,7 +28,7 @@ module DefaultSpec
28
28
 
29
29
  describe Seabright::DefaultValues do
30
30
  before do
31
- RedisObject.store.flushdb
31
+ SpecHelper.flushdb
32
32
  end
33
33
 
34
34
  it "returns default value" do
@@ -16,9 +16,9 @@ module DumpingSpec
16
16
 
17
17
  end
18
18
 
19
- describe Seabright::Triggers do
19
+ describe Seabright::Dumping do
20
20
  before do
21
- RedisObject.store.flushdb
21
+ SpecHelper.flushdb
22
22
  5.times do
23
23
  d = DumpableObject.create(phone: Random.rand(100)*555, mailed: true, canceled_at: Time.now)
24
24
  d << GenericObject.create(complex: {woot: true, ohnoes: false})
@@ -64,13 +64,13 @@ module DumpingSpec
64
64
 
65
65
  r = RedisObject.dump_everything(:yml)
66
66
  r.size.should > 100
67
- RedisObject.store.flushdb
67
+ SpecHelper.flushdb
68
68
  RedisObject.load_dump r, :yml
69
69
  DumpableObject.latest.generic_objects.count.should eq(1)
70
70
 
71
71
  # r = RedisObject.dump_everything(:json)
72
72
  # r.size.should > 100
73
- # RedisObject.store.flushdb
73
+ # SpecHelper.flushdb
74
74
  # RedisObject.load_dump r, :json
75
75
  # DumpableObject.latest.generic_objects.count.should eq(1)
76
76
 
@@ -8,7 +8,7 @@ module FieldRefSpec
8
8
  describe RedisObject do
9
9
 
10
10
  before do
11
- RedisObject.store.flushdb
11
+ SpecHelper.flushdb
12
12
  @dad = Dad.create("daddy")
13
13
  @son = Son.create("sonny")
14
14
  @dad.stepson = @son
@@ -13,7 +13,7 @@ module FilterSpec
13
13
 
14
14
  describe Seabright::Filters do
15
15
  before do
16
- RedisObject.store.flushdb
16
+ SpecHelper.flushdb
17
17
  end
18
18
 
19
19
  it "modifies set and gets correctly" do
@@ -35,7 +35,7 @@ module IndexSpec
35
35
  describe Seabright::Indices do
36
36
 
37
37
  before do
38
- RedisObject.store.flushdb
38
+ SpecHelper.flushdb
39
39
  end
40
40
 
41
41
  it "sorts on integer field" do
@@ -10,7 +10,7 @@ module RenameClassSpec
10
10
 
11
11
  describe Seabright::Storage::Redis, "#rename_class" do
12
12
  before do
13
- RedisObject.store.flushdb
13
+ SpecHelper.flushdb
14
14
 
15
15
  mozzarella = Topping.create(:mozzarella)
16
16
  basil = Topping.create(:basil)
@@ -16,26 +16,29 @@ module TriggerSpec
16
16
  end
17
17
 
18
18
  describe Seabright::Triggers do
19
- before do
20
- RedisObject.store.flushdb
21
- @secret = SensitiveObject.create(test: Time.now, yay: true, stuff: {test: "1"}, worthless: "yup", sup: "dawg")
19
+ before(:each) do
20
+ SpecHelper.flushdb
21
+ end
22
+
23
+ let(:secret) do
24
+ SensitiveObject.create(test: Time.now, yay: true, stuff: {test: "1"}, worthless: "yup", sup: "dawg")
22
25
  end
23
26
 
24
27
  it "can sanitize a field or two willy nilly" do
25
28
 
26
- @secret.stuff.should be_a(Hash)
27
- @secret.sanitize! :stuff, :sup
28
- @secret.stuff.should eq(nil)
29
+ secret.stuff.should be_a(Hash)
30
+ secret.sanitize! :stuff, :sup
31
+ secret.stuff.should eq(nil)
29
32
 
30
33
  end
31
34
 
32
35
  it "can sanitize by name" do
33
36
 
34
- @secret.test.should_not eq(nil)
35
- @secret.yay.should eq(true)
36
- @secret.sanitize_by_name! :burn
37
- @secret.test.should eq(nil)
38
- @secret.yay.should eq(false)
37
+ secret.test.should_not eq(nil)
38
+ secret.yay.should eq(true)
39
+ secret.sanitize_by_name! :burn
40
+ secret.test.should eq(nil)
41
+ secret.yay.should eq(false)
39
42
 
40
43
  end
41
44
 
@@ -7,7 +7,7 @@ module ScriptCacheSpec
7
7
  describe Seabright::CachedScripts do
8
8
  before do
9
9
 
10
- RedisObject.store.flushdb
10
+ SpecHelper.flushdb
11
11
 
12
12
  (1..5).each do |n|
13
13
  GenericObject.create(n.to_s)
@@ -35,5 +35,13 @@ Debug = if ENV['DEBUG']
35
35
  DebugMode.new
36
36
  end
37
37
 
38
+ module SpecHelper
39
+
40
+ def self.flushdb
41
+ RedisObject.store.flushdb
42
+ end
43
+
44
+ end
45
+
38
46
  raise 'must specify TEST_DB' unless ENV['TEST_DB']
39
47
  RedisObject.configure_store({adapter:'Redis', db:ENV['TEST_DB']},:global,:alias)
@@ -6,7 +6,7 @@ module TriggerSpec
6
6
 
7
7
  describe Seabright::Triggers do
8
8
  before do
9
- RedisObject.store.flushdb
9
+ SpecHelper.flushdb
10
10
  end
11
11
 
12
12
  it "should get recently created object" do
@@ -30,7 +30,7 @@ module TriggerSpec
30
30
 
31
31
  describe Seabright::Triggers do
32
32
  before do
33
- RedisObject.store.flushdb
33
+ SpecHelper.flushdb
34
34
  end
35
35
 
36
36
  it "triggers on a call" do
@@ -26,7 +26,7 @@ module TypeSpec
26
26
 
27
27
  describe Seabright::Types do
28
28
  before do
29
- RedisObject.store.flushdb
29
+ SpecHelper.flushdb
30
30
  end
31
31
 
32
32
  it "can be created via data packet" do
@@ -53,7 +53,7 @@ module ViewCachingSpec
53
53
  describe Seabright::ViewCaching do
54
54
 
55
55
  before do
56
- RedisObject.store.flushdb
56
+ SpecHelper.flushdb
57
57
  @obj = TypedObject.create(TestData)
58
58
  @dad = Container.create("daddy")
59
59
  @dad << @obj
@@ -33,7 +33,7 @@ module ViewSpec
33
33
  describe Seabright::Views do
34
34
 
35
35
  before do
36
- RedisObject.store.flushdb
36
+ SpecHelper.flushdb
37
37
  @obj = ViewedObject.create(TestData)
38
38
  end
39
39
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Bragg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-25 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: utf8_utils