spec/hash_spec.rb in restruct-0.0.3 vs spec/hash_spec.rb in restruct-0.1.0
- old
+ new
@@ -6,11 +6,11 @@
let(:hash) { klass.new }
def fill(data)
data.each { |k,v| data[k] = hash.send(:serialize, v) }
- redis.call 'HMSET', hash.id, *data.flatten
+ connection.call 'HMSET', hash.id, *data.flatten
end
describe 'Getters' do
it '[]' do
@@ -18,11 +18,11 @@
hash[:a].must_equal 'x'
hash[:b].must_equal 'y'
hash[:c].must_be_nil
end
-
+
it 'fetch' do
fill a: 'x', b: 'y'
hash.fetch(:a).must_equal 'x'
hash.fetch(:b).must_equal 'y'
@@ -30,11 +30,11 @@
hash.fetch(:c) { |k| k.to_s }.must_equal 'c'
error = proc { hash.fetch(:c) }.must_raise KeyError
error.message.must_equal 'key not found: c'
end
-
+
it 'key' do
fill a: 'x', b: 'y', c: 'y'
hash.key('x').must_equal 'a'
hash.key('y').must_equal 'b'
@@ -233,9 +233,23 @@
other = klass.new
other.restore dump
other.id.wont_equal hash.id
other.to_primitive.must_equal hash.to_primitive
+ end
+
+ it 'Batch' do
+ fill a: 'x', b: 'y', c: 'z'
+
+ hash.connection.batch do
+ hash[:d] = 'w'
+ hash.delete :a
+ hash.merge! b: 'x', e: 'v'
+
+ hash.to_h.must_equal 'a' => 'x', 'b' => 'y', 'c' => 'z'
+ end
+
+ hash.to_h.must_equal 'b' => 'x', 'c' => 'z', 'd' => 'w', 'e' => 'v'
end
end
end
\ No newline at end of file