mongoid 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.1
1
+ 1.2.2
@@ -69,8 +69,7 @@ module Mongoid #:nodoc:
69
69
  when Criteria
70
70
  self.selector == other.selector && self.options == other.options
71
71
  when Enumerable
72
- @collection ||= execute
73
- return (@collection.entries == other)
72
+ return (execute.entries == other)
74
73
  else
75
74
  return false
76
75
  end
@@ -119,9 +118,8 @@ module Mongoid #:nodoc:
119
118
  #
120
119
  # <tt>criteria.each { |doc| p doc }</tt>
121
120
  def each(&block)
122
- @collection ||= execute
123
121
  if block_given?
124
- @collection.each { |doc| yield doc }
122
+ execute.each { |doc| yield doc }
125
123
  end
126
124
  self
127
125
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "1.2.1"
8
+ s.version = "1.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Durran Jordan"]
@@ -2,6 +2,14 @@ require "spec_helper"
2
2
 
3
3
  describe Mongoid::Criteria do
4
4
 
5
+ before do
6
+ Person.delete_all
7
+ end
8
+
9
+ after do
10
+ Person.delete_all
11
+ end
12
+
5
13
  describe "#excludes" do
6
14
 
7
15
  before do
@@ -30,6 +38,26 @@ describe Mongoid::Criteria do
30
38
 
31
39
  end
32
40
 
41
+ describe "#execute" do
42
+
43
+ context "when reiterating" do
44
+
45
+ before do
46
+ @person = Person.create(:title => "Sir", :age => 100, :aliases => ["D", "Durran"], :ssn => "666666666")
47
+ end
48
+
49
+ after do
50
+ Person.delete_all
51
+ end
52
+
53
+ it "executes the query again" do
54
+ criteria = Person.all
55
+ criteria.size.should == 1
56
+ criteria.should_not be_empty
57
+ end
58
+ end
59
+ end
60
+
33
61
  describe "#max" do
34
62
 
35
63
  before do
@@ -19,9 +19,9 @@ describe Mongoid::Criteria do
19
19
  before do
20
20
  @collection = mock
21
21
  @cursor = stub(:count => 1)
22
- @cursor.expects(:each).yields(@sir)
23
- Person.expects(:collection).returns(@collection)
24
- @collection.expects(:find).returns(@cursor)
22
+ @cursor.expects(:each).at_least_once.yields(@sir)
23
+ Person.expects(:collection).at_least_once.returns(@collection)
24
+ @collection.expects(:find).at_least_once.returns(@cursor)
25
25
  end
26
26
 
27
27
  it "executes the criteria and concats the results" do
@@ -31,29 +31,24 @@ describe Mongoid::Criteria do
31
31
 
32
32
  end
33
33
 
34
- context "when the criteria has been executed" do
35
-
36
- before do
37
- @criteria.instance_variable_set(:@collection, [ @sir, @madam ])
38
- end
39
-
40
- it "concats the results" do
41
- results = @criteria + [ @canvas ]
42
- results.should == [ @sir, @madam, @canvas ]
43
- end
44
-
45
- end
46
-
47
34
  context "when the other is a criteria" do
48
35
 
49
36
  before do
50
- @criteria.instance_variable_set(:@collection, [ @sir, @madam ])
51
- @canvas_criteria.instance_variable_set(:@collection, [ @canvas ])
37
+ @collection = mock
38
+ @canvas_collection = mock
39
+ @cursor = stub(:count => 1)
40
+ @canvas_cursor = stub(:count => 1)
41
+ @cursor.expects(:each).at_least_once.yields(@sir)
42
+ @canvas_cursor.expects(:each).at_least_once.yields(@canvas)
43
+ Person.expects(:collection).at_least_once.returns(@collection)
44
+ @collection.expects(:find).at_least_once.returns(@cursor)
45
+ Canvas.expects(:collection).at_least_once.returns(@canvas_collection)
46
+ @canvas_collection.expects(:find).at_least_once.returns(@canvas_cursor)
52
47
  end
53
48
 
54
49
  it "concats the results" do
55
50
  results = @criteria + @canvas_criteria
56
- results.should == [ @sir, @madam, @canvas ]
51
+ results.should == [ @sir, @canvas ]
57
52
  end
58
53
 
59
54
  end
@@ -84,33 +79,6 @@ describe Mongoid::Criteria do
84
79
 
85
80
  end
86
81
 
87
- context "when the criteria has been executed" do
88
-
89
- before do
90
- @criteria.instance_variable_set(:@collection, [@sir, @sir, @madam])
91
- end
92
-
93
- it "returns the difference" do
94
- results = @criteria - [ @sir ]
95
- results.should == [ @madam ]
96
- end
97
-
98
- end
99
-
100
- context "when the other is a criteria" do
101
-
102
- before do
103
- @criteria.instance_variable_set(:@collection, [@sir, @sir, @madam])
104
- @canvas_criteria.instance_variable_set(:@collection, [@sir])
105
- end
106
-
107
- it "returns the difference" do
108
- results = @criteria - @canvas_criteria
109
- results.should == [ @madam ]
110
- end
111
-
112
- end
113
-
114
82
  end
115
83
 
116
84
  describe "#[]" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan