mongo_delegate 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/mongo_delegate/composite_cursor.rb +4 -1
- data/lib/mongo_delegate/delegating_collection.rb +2 -1
- data/spec/delegating_collection_spec.rb +25 -8
- metadata +1 -1
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -19,6 +19,7 @@ class CompositeCursor
|
|
19
19
|
attr_accessor :colls, :selector, :options
|
20
20
|
include FromHash
|
21
21
|
include Enumerable
|
22
|
+
def to_af; rows; end
|
22
23
|
fattr(:rows) do
|
23
24
|
cursors.map { |x| x.to_af }.flatten
|
24
25
|
end
|
@@ -26,7 +27,9 @@ class CompositeCursor
|
|
26
27
|
rows.each(&b)
|
27
28
|
end
|
28
29
|
def count
|
29
|
-
|
30
|
+
colls.map do |coll|
|
31
|
+
coll.scope_ne('_duplicate' => true).find(selector).count
|
32
|
+
end.sum
|
30
33
|
end
|
31
34
|
def first
|
32
35
|
rows.first
|
@@ -15,7 +15,7 @@ context Mongo::DelegatingCollection do
|
|
15
15
|
@d.find.count.should == @all.size
|
16
16
|
end
|
17
17
|
it 'find doesnt return dups' do
|
18
|
-
@d.
|
18
|
+
@d.save(@d.remote.find_one(:name => 'Randy'))
|
19
19
|
@d.find.count.should == @all.size
|
20
20
|
@d.find.unpruned_rows.size.should == @all.size + 1
|
21
21
|
end
|
@@ -30,7 +30,7 @@ context Mongo::DelegatingCollection do
|
|
30
30
|
@d.find_one(:name => 'Randy')['age'].should == 'old'
|
31
31
|
end
|
32
32
|
it 'respects limit' do
|
33
|
-
@d.find({},:limit => 4).
|
33
|
+
@d.find({},:limit => 4).to_af.size.should == 4
|
34
34
|
expected_names = @d.find.map { |x| x['name'] }[0...4].sort
|
35
35
|
@d.find({},:limit => 4).map { |x| x['name'] }.sort.should == expected_names
|
36
36
|
end
|
@@ -39,21 +39,26 @@ context Mongo::DelegatingCollection do
|
|
39
39
|
@d.find({},:limit => 2).rows
|
40
40
|
end
|
41
41
|
it 'respects skip' do
|
42
|
-
@d.find({},:skip => 1).
|
42
|
+
@d.find({},:skip => 1).to_af.size.should == 5
|
43
43
|
@d.find({},:skip => 1).map { |x| x['name'] }.sort.should == @all.reject { |x| x == 'Mike' }.sort
|
44
44
|
end
|
45
45
|
it 'respects skip whole collection' do
|
46
|
-
@d.find({},:skip => 4).
|
46
|
+
@d.find({},:skip => 4).to_af.size.should == 2
|
47
47
|
end
|
48
48
|
it 'wont return remote records that were skipped locally' do
|
49
49
|
@d.local.save(@d.remote.find_one(:name => 'Randy'))
|
50
|
-
@d.find({},:skip => 5).
|
50
|
+
@d.find({},:skip => 5).to_af.size.should == 1
|
51
51
|
end
|
52
52
|
it 'respects skip and limit' do
|
53
|
-
@d.find({},:skip => 1, :limit => 4).
|
53
|
+
@d.find({},:skip => 1, :limit => 4).to_af.size.should == 4
|
54
|
+
end
|
55
|
+
it 'count doesnt fetch records' do
|
56
|
+
mock.instance_of(Mongo::Cursor).to_a.times(0)
|
57
|
+
@d.count.should == 6
|
54
58
|
end
|
55
|
-
# it 'count
|
56
|
-
#
|
59
|
+
# it 'count honors remote deletes' do
|
60
|
+
# @d.remote.find.each { |x| @d.save(x) }
|
61
|
+
# @d.remote.remove
|
57
62
|
# @d.count.should == 6
|
58
63
|
# end
|
59
64
|
end
|
@@ -65,5 +70,17 @@ context Mongo::DelegatingCollection do
|
|
65
70
|
@d.remote.count.should == @remotes.size
|
66
71
|
@d.local.count.should == @locals.size + 1
|
67
72
|
end
|
73
|
+
it 'updating a non-dup shouldnt mark it as a dup' do
|
74
|
+
r = @d.local.find_one(:name => 'Mike').merge(:foo => :bar)
|
75
|
+
@d.save(r)
|
76
|
+
@d.count.should == 6
|
77
|
+
@d.local.find_one(:name => 'Mike')['_duplicate'].should be_nil
|
78
|
+
end
|
79
|
+
it 'saving a dup for first time should mark it as a dup' do
|
80
|
+
r = @d.remote.find_one(:name => 'Randy')
|
81
|
+
@d.save(r)
|
82
|
+
@d.count.should == 6
|
83
|
+
@d.local.find_one(:name => 'Randy')['_duplicate'].should == true
|
84
|
+
end
|
68
85
|
end
|
69
86
|
end
|