|
148 | 148 | end |
149 | 149 |
|
150 | 150 | it "#{meth} should set expiration when expireat option assigned" do |
151 | | - @value = Redis::Value.new('spec/value', :expireat => Time.now + 10.seconds) |
| 151 | + @value = Redis::Value.new('spec/value', :expireat => Time.now + 10) |
152 | 152 | @value.send(meth, 'monkey') |
153 | 153 | @value.ttl.should > 0 |
154 | 154 | end |
|
286 | 286 | @list.get.should == ['a','c','f','j','h','i','a'] |
287 | 287 | end |
288 | 288 |
|
289 | | - it "should support popping & shifting multiple values" do |
| 289 | + it "should support popping and shifting multiple values" do |
290 | 290 | @list.should.be.empty |
291 | 291 |
|
292 | | - @list << 'a' << 'b' << 'c' |
293 | | - @list.shift(2).should == ['a', 'b'] |
294 | | - @list.shift(2).should == ['c'] |
295 | | - @list.shift(2).should == [] |
| 292 | + @list << 'a' << 'b' << 'c' << 'd' |
| 293 | + @list.should == ['a', 'b', 'c', 'd'] |
| 294 | + @list.shift |
| 295 | + @list.should == ['b', 'c', 'd'] |
| 296 | + @list.shift(2).should == ['b', 'c'] |
| 297 | + @list.should == ['d'] |
| 298 | + @list.shift(2).should == ['d'] |
| 299 | + @list.shift(2).should == nil |
296 | 300 |
|
297 | | - @list << 'a' << 'b' << 'c' |
298 | | - @list.pop(2).should == ['b', 'c'] |
299 | | - @list.pop(2).should == ['a'] |
300 | | - @list.pop(2).should == [] |
| 301 | + @list << 'e' << 'f' << 'g' |
| 302 | + |
| 303 | + # Old behavior |
| 304 | + # @list.pop(2).should == ['f', 'g'] |
| 305 | + |
| 306 | + # New behavior |
| 307 | + @list.pop(2).should == ['g', 'f'] |
| 308 | + |
| 309 | + @list.pop(2).should == ['e'] |
| 310 | + @list.pop(2).should == nil |
301 | 311 | end |
302 | 312 |
|
303 | 313 | it "should handle rpoplpush" do |
|
412 | 422 | end |
413 | 423 |
|
414 | 424 | it "#{meth} expireat: option" do |
415 | | - @list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10.seconds) |
| 425 | + @list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10) |
416 | 426 | @list.clear |
417 | 427 | @list.send(meth, 'val') |
418 | 428 | @list.ttl.should > 0 |
|
430 | 440 | end |
431 | 441 |
|
432 | 442 | it "[]= expireat: option" do |
433 | | - @list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10.seconds) |
| 443 | + @list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10) |
434 | 444 | @list.clear |
435 | 445 | @list.redis.rpush(@list.key, 'hello') |
436 | 446 | @list[0] = 'world' |
|
448 | 458 | end |
449 | 459 |
|
450 | 460 | it "insert expireat: option" do |
451 | | - @list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10.seconds) |
| 461 | + @list = Redis::List.new('spec/list_exp', :expireat => Time.now + 10) |
452 | 462 | @list.clear |
453 | 463 | @list.redis.rpush(@list.key, 'hello') |
454 | 464 | @list.insert 'BEFORE', 'hello', 'world' |
|
586 | 596 | @counter.ttl.should <= 10 |
587 | 597 | end |
588 | 598 | it "expireat: option" do |
589 | | - @counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10.seconds) |
| 599 | + @counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10) |
590 | 600 | @counter.send(meth) |
591 | 601 | @counter.ttl.should > 0 |
592 | 602 | @counter.ttl.should <= 10 |
|
600 | 610 | [:set, :value=].each do |meth| |
601 | 611 | describe meth do |
602 | 612 | it "expiration: option" do |
603 | | - @counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10.seconds) |
| 613 | + @counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10) |
604 | 614 | @counter.send(meth, 99) |
605 | 615 | @counter.should == 99 |
606 | 616 | @counter.ttl.should > 0 |
607 | 617 | @counter.ttl.should <= 10 |
608 | 618 | end |
609 | 619 | it "expireat: option" do |
610 | | - @counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10.seconds) |
| 620 | + @counter = Redis::Counter.new('spec/counter_exp', :expireat => Time.now + 10) |
611 | 621 | @counter.send(meth, 99) |
612 | 622 | @counter.should == 99 |
613 | 623 | @counter.ttl.should > 0 |
|
805 | 815 | describe Redis::HashKey do |
806 | 816 | describe "With Marshal" do |
807 | 817 | before do |
808 | | - @hash = Redis::HashKey.new('test_hash', {:marshal_keys=>{'created_at'=>true}}) |
| 818 | + @hash = Redis::HashKey.new('test_hash', {:marshal_keys=>{'created_at' => true}}) |
809 | 819 | @hash.clear |
810 | 820 | end |
811 | 821 |
|
812 | 822 | it "should marshal specified keys" do |
813 | | - @hash['created_at'] = Time.now |
| 823 | + time = Time.now |
| 824 | + @hash['created_at'] = time |
| 825 | + @hash['created_at'].should == time |
814 | 826 | @hash['created_at'].class.should == Time |
815 | 827 | end |
816 | 828 |
|
817 | 829 | it "should not marshal unless required" do |
818 | | - @hash['updated_at'] = Time.now |
| 830 | + @hash['updated_at'] = 10 |
| 831 | + @hash['updated_at'].should == "10" |
819 | 832 | @hash['updated_at'].class.should == String |
820 | 833 | end |
821 | 834 |
|
822 | 835 | it "should marshall appropriate key with bulk set and get" do |
823 | | - @hash.bulk_set({'created_at'=>Time.now, 'updated_at'=>Time.now}) |
| 836 | + @hash.bulk_set({'created_at' => Time.now, 'updated_at' => 11}) |
824 | 837 |
|
825 | 838 | @hash['created_at'].class.should == Time |
826 | 839 | @hash['updated_at'].class.should == String |
|
849 | 862 | # no marshaling |
850 | 863 | @hash.options[:marshal] = false |
851 | 864 | v = {:json => 'data'} |
852 | | - @hash['abc'] = v |
| 865 | + @hash['abc'] = v.to_s |
853 | 866 | @hash['abc'].should == v.to_s |
854 | 867 |
|
855 | 868 | @hash.options[:marshal] = true |
|
1075 | 1088 | end |
1076 | 1089 |
|
1077 | 1090 | it "#{meth} expireat: option" do |
1078 | | - @hash = Redis::HashKey.new('spec/hash_expireat', :expireat => Time.now + 10.seconds) |
| 1091 | + @hash = Redis::HashKey.new('spec/hash_expireat', :expireat => Time.now + 10) |
1079 | 1092 | @hash.clear |
1080 | 1093 | @hash.send(meth, *args) |
1081 | 1094 | @hash.ttl.should > 0 |
|
1294 | 1307 | end |
1295 | 1308 |
|
1296 | 1309 | it "should set expiration when expireat option assigned" do |
1297 | | - @set = Redis::Set.new('spec/set', :expireat => Time.now + 10.seconds) |
| 1310 | + @set = Redis::Set.new('spec/set', :expireat => Time.now + 10) |
1298 | 1311 | @set.send(meth, 'val') |
1299 | 1312 | @set.ttl.should > 0 |
1300 | 1313 | @set.ttl.should <= 10 |
|
1558 | 1571 | end |
1559 | 1572 |
|
1560 | 1573 | it 'should set expiration when expireat option assigned' do |
1561 | | - @set = Redis::SortedSet.new('spec/zset', :expireat => Time.now + 10.seconds) |
| 1574 | + @set = Redis::SortedSet.new('spec/zset', :expireat => Time.now + 10) |
1562 | 1575 | @set['val'] = 1 |
1563 | 1576 | @set.ttl.should > 0 |
1564 | 1577 | @set.ttl.should <= 10 |
|
1590 | 1603 | @set.ttl.should <= 10 |
1591 | 1604 | end |
1592 | 1605 | it "#{meth} expireat: option" do |
1593 | | - @set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10.seconds) |
| 1606 | + @set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10) |
1594 | 1607 | @set.clear |
1595 | 1608 | @set.send(meth, 'somekey', 12) |
1596 | 1609 | @set.ttl.should > 0 |
|
1607 | 1620 | @set.ttl.should <= 10 |
1608 | 1621 | end |
1609 | 1622 | it "#{meth} expireat: option" do |
1610 | | - @set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10.seconds) |
| 1623 | + @set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10) |
1611 | 1624 | @set.clear |
1612 | 1625 | @set.send(meth, 'somekey' => 12) |
1613 | 1626 | @set.ttl.should > 0 |
|
1626 | 1639 | end |
1627 | 1640 |
|
1628 | 1641 | it "#{meth} expireat: option" do |
1629 | | - @set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10.seconds) |
| 1642 | + @set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10) |
1630 | 1643 | @set.clear |
1631 | 1644 | @set.redis.zadd(@set.key, 1, "1") |
1632 | 1645 | @set.send(meth, 'sets', Redis::SortedSet.new('other')) |
|
1646 | 1659 | end |
1647 | 1660 |
|
1648 | 1661 | it "delete expireat: option" do |
1649 | | - @set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10.seconds) |
| 1662 | + @set = Redis::SortedSet.new('spec/zset_exp', :expireat => Time.now + 10) |
1650 | 1663 | @set.clear |
1651 | 1664 | @set.redis.zadd(@set.key, 1, "1") |
1652 | 1665 | @set.redis.zadd(@set.key, 2, "2") |
|
0 commit comments