mongoid 1.2.10 → 1.2.11

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.10
1
+ 1.2.11
@@ -64,10 +64,27 @@ module Mongoid #:nodoc:
64
64
  def initialize(document, options, target = nil)
65
65
  @parent, @klass = document, options.klass
66
66
  @foreign_key = options.foreign_key
67
- @target = target || @klass.all(:conditions => { @foreign_key => document.id })
67
+ @base = lambda { @klass.all(:conditions => { @foreign_key => document.id }) }
68
+ @target = target || @base.call
68
69
  extends(options)
69
70
  end
70
71
 
72
+ # Override the default behavior to allow the criteria to get reset on
73
+ # each call into the association.
74
+ #
75
+ # Example:
76
+ #
77
+ # person.posts.where(:title => "New")
78
+ # person.posts # resets the criteria
79
+ #
80
+ # Returns:
81
+ #
82
+ # A Criteria object or Array.
83
+ def method_missing(name, *args, &block)
84
+ @target = @base.call unless @target.is_a?(Array)
85
+ @target.send(name, *args, &block)
86
+ end
87
+
71
88
  # Delegates to <<
72
89
  def push(*objects)
73
90
  self << objects
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "1.2.10"
8
+ s.version = "1.2.11"
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"]
@@ -216,10 +216,33 @@ describe Mongoid::Associations do
216
216
 
217
217
  end
218
218
 
219
- end
219
+ context "calling criteria methods" do
220
220
 
221
- end
221
+ before do
222
+ @post.title = "New Title"
223
+ @post.save
224
+ end
225
+
226
+ it "returns the proper object for the criteria" do
227
+ posts = @from_db.posts.where(:title => "New Title")
228
+ posts.size.should == 1
229
+ end
230
+
231
+ context "when calling with a new criteria" do
222
232
 
233
+ before do
234
+ @from_db.posts.create(:title => "Other Title")
235
+ end
236
+
237
+ it "does not retain the old criteria" do
238
+ @from_db.posts.where(:title => "New Title").size.should == 1
239
+ @from_db.posts.size.should == 2
240
+ @from_db.posts.where(:title => "Other Title").size.should == 1
241
+ end
242
+ end
243
+ end
244
+ end
245
+ end
223
246
  end
224
247
 
225
248
  context "nested embedded associations" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 2
8
- - 10
9
- version: 1.2.10
8
+ - 11
9
+ version: 1.2.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Durran Jordan