mongoid_embedded_helper 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -4,9 +4,13 @@ module Mongoid
4
4
  module EmbeddedHelper
5
5
  def in_collection stack = []
6
6
  stack.extend(ArrayExt) if stack.empty?
7
- if embedded?
7
+ if embedded?
8
8
  stack.add_collection_name self
9
- _parent.in_collection(stack)
9
+ if _parent.respond_to?(:in_collection)
10
+ _parent.in_collection(stack)
11
+ else
12
+ iterate_collection_stack stack, _parent
13
+ end
10
14
  else
11
15
  return self.class if stack.empty?
12
16
  iterate_collection_stack stack
@@ -15,8 +19,8 @@ module Mongoid
15
19
 
16
20
  private
17
21
 
18
- def iterate_collection_stack stack
19
- collection = self
22
+ def iterate_collection_stack stack, subject = nil
23
+ collection = subject || self
20
24
  stack = stack.reverse
21
25
  stack.each do |entry|
22
26
  sub_collection = collection.send entry[:collection_name]
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid_embedded_helper}
8
- s.version = "0.2.1"
8
+ s.version = "0.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 = ["Kristian Mandrup"]
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "lib/mongoid_embedded_helper.rb",
28
28
  "mongoid_embedded_helper.gemspec",
29
29
  "spec/mongoid/embedded_helper_spec.rb",
30
+ "spec/mongoid/more_embedded_helper_spec.rb",
30
31
  "spec/rspec.options",
31
32
  "spec/spec_helper.rb"
32
33
  ]
@@ -37,6 +38,7 @@ Gem::Specification.new do |s|
37
38
  s.summary = %q{Facilitates performing queries on collections in embedded Mongoid documents}
38
39
  s.test_files = [
39
40
  "spec/mongoid/embedded_helper_spec.rb",
41
+ "spec/mongoid/more_embedded_helper_spec.rb",
40
42
  "spec/spec_helper.rb"
41
43
  ]
42
44
 
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ Mongoid.configure.master = Mongo::Connection.new.db('acts_as_list-test')
4
+
5
+ class List
6
+ include Mongoid::Document
7
+ field :pos, :type => Integer
8
+ field :name, :type => String
9
+ embeds_many :items
10
+ end
11
+
12
+
13
+ class Item
14
+ include Mongoid::Document
15
+ include Mongoid::EmbeddedHelper
16
+ field :pos, :type => Integer
17
+ field :number, :type => Integer
18
+ field :name, :type => String
19
+ field :assoc, :type => Symbol
20
+ embedded_in :list, :inverse_of => :items
21
+ end
22
+
23
+ describe 'Mongoid Embedded Helper' do
24
+ before :each do
25
+ @list = List.create! :pos => 1, :name => 'My list'
26
+ item_names = ('A'..'C').to_a
27
+ (1..3).each do |counter|
28
+ item = Item.new :pos => counter, :number => counter, :name => item_names[counter-1]
29
+ @list.items << item
30
+ end
31
+ @list.save!
32
+ end
33
+
34
+ after :each do
35
+ Mongoid.database.collections.each do |coll|
36
+ coll.remove
37
+ end
38
+ end
39
+
40
+ describe '#in_collection' do
41
+ it "should handle query from mid level node without List including Embedded::Helper" do
42
+ result = @list.items[0].in_collection.where(:pos => 2).to_a.first
43
+ result.pos.should == 2
44
+ result.number.should == 2
45
+ result.name.should == 'B'
46
+ end
47
+ end
48
+ end
49
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -84,6 +84,7 @@ files:
84
84
  - lib/mongoid_embedded_helper.rb
85
85
  - mongoid_embedded_helper.gemspec
86
86
  - spec/mongoid/embedded_helper_spec.rb
87
+ - spec/mongoid/more_embedded_helper_spec.rb
87
88
  - spec/rspec.options
88
89
  - spec/spec_helper.rb
89
90
  has_rdoc: true
@@ -120,4 +121,5 @@ specification_version: 3
120
121
  summary: Facilitates performing queries on collections in embedded Mongoid documents
121
122
  test_files:
122
123
  - spec/mongoid/embedded_helper_spec.rb
124
+ - spec/mongoid/more_embedded_helper_spec.rb
123
125
  - spec/spec_helper.rb