mongoid-ancestry 0.2.3 → 0.3.0.rc

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,32 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-ancestry (0.2.3)
5
- bson_ext (>= 1.3)
6
- mongoid (>= 2.0)
4
+ mongoid-ancestry (0.3.0.rc)
5
+ mongoid (= 3.0.0.rc)
7
6
 
8
7
  GEM
9
8
  remote: http://rubygems.org/
10
9
  specs:
11
- activemodel (3.2.5)
12
- activesupport (= 3.2.5)
10
+ activemodel (3.2.3)
11
+ activesupport (= 3.2.3)
13
12
  builder (~> 3.0.0)
14
- activesupport (3.2.5)
13
+ activesupport (3.2.3)
15
14
  i18n (~> 0.6)
16
15
  multi_json (~> 1.0)
17
- bson (1.6.4)
18
- bson_ext (1.6.4)
19
- bson (~> 1.6.4)
20
16
  builder (3.0.0)
21
17
  diff-lcs (1.1.2)
22
18
  i18n (0.6.0)
23
- mongo (1.6.2)
24
- bson (~> 1.6.2)
25
- mongoid (2.4.7)
19
+ mongoid (3.0.0.rc)
26
20
  activemodel (~> 3.1)
27
- mongo (~> 1.3)
21
+ moped (~> 1.0.0.rc)
22
+ origin (~> 1.0.0.rc)
28
23
  tzinfo (~> 0.3.22)
24
+ moped (1.0.0.rc)
29
25
  multi_json (1.3.6)
26
+ origin (1.0.0.rc)
30
27
  rake (0.9.2.2)
31
28
  rspec (2.5.0)
32
29
  rspec-core (~> 2.5.0)
data/README.md CHANGED
@@ -23,6 +23,12 @@ To apply Mongoid-ancestry to any Mongoid model, follow these simple steps:
23
23
 
24
24
  Your model is now a tree!
25
25
 
26
+ ## Mongoid compatibility
27
+
28
+ This gem only supports Mongoid 3.x starting with version 0.3.0.
29
+
30
+ If you want to use Mongoid version 2.x, you should either use this gem in a 0.2.x version or checkout the "mongoid-2.4-stable" branch. You can ask bundler to stick with 0.2.x versions of this gem by adding this to your Gemfile: `gem 'mongoid-ancestry', '~> 0.2.2'`
31
+
26
32
  ## Organising records into a tree
27
33
  You can use the parent attribute to organise your records into a tree. If you have the id of the record you want
28
34
  to use as a parent and don't want to fetch it, you can also use `parent_id`. Like any virtual model attributes,
@@ -220,7 +226,7 @@ The materialised path pattern requires Mongoid-ancestry to use a `regexp` condit
220
226
 
221
227
  ## Contact and copyright
222
228
 
223
- It's a fork of [original ancestry](https://github.com/stefankroes/ancestry) gem but adopted to work with Mongoid.
229
+ It's a fork of [original ancestry](https://github.com/stefankroes/ancestry) gem but adapted to work with Mongoid.
224
230
 
225
231
  All thanks should goes to Stefan Kroes for his great work.
226
232
 
@@ -23,7 +23,7 @@ module Mongoid
23
23
  self.ancestry_field = opts[:ancestry_field]
24
24
 
25
25
  self.field ancestry_field, :type => String
26
- self.index ancestry_field
26
+ self.index({ ancestry_field => 1 })
27
27
 
28
28
  # Create orphan strategy accessor and set to option or default (writer comes from DynamicClassMethods)
29
29
  cattr_reader :orphan_strategy
@@ -167,7 +167,7 @@ module Mongoid
167
167
  end
168
168
  end
169
169
  # ... save parent of this node in parents array if it exists
170
- parents[node.id] = node.parent_id if exists? node.parent_id
170
+ parents[node.id] = node.parent_id if where(:_id => node.parent_id).first
171
171
 
172
172
  # Reset parent id in array to nil if it introduces a cycle
173
173
  parent = parents[node.id]
@@ -229,7 +229,7 @@ module Mongoid
229
229
  if primary_key_type == Integer
230
230
  key.to_i
231
231
  elsif primary_key_type == BSON::ObjectId && key =~ /[a-z0-9]{24}/
232
- BSON::ObjectId.convert(self, key)
232
+ BSON::ObjectId.from_string(key)
233
233
  else
234
234
  key
235
235
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Ancestry
3
- VERSION = '0.2.3'
3
+ VERSION = '0.3.0.rc'
4
4
  end
5
5
  end
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  "README.md"
24
24
  ]
25
25
 
26
- s.add_dependency('mongoid', ">= 2.0")
27
- s.add_dependency('bson_ext', ">= 1.3")
26
+ s.add_dependency('mongoid', "= 3.0.0.rc")
28
27
  end
29
28
 
@@ -80,7 +80,7 @@ describe MongoidAncestry do
80
80
  end
81
81
 
82
82
  it "should have STI support" do
83
- subject.with_model :extra_columns => {:type => :string} do |model|
83
+ subject.with_model :extra_columns => {:type => 'String'} do |model|
84
84
  subclass1 = Object.const_set 'Subclass1', Class.new(model)
85
85
  (class << subclass1; self; end).send(:define_method, :model_name) do
86
86
  Struct.new(:human, :underscore).new 'Subclass1', 'subclass1'
@@ -232,7 +232,7 @@ describe MongoidAncestry do
232
232
  end
233
233
 
234
234
  it "should build ancestry from parent ids" do
235
- subject.with_model :skip_ancestry => true, :extra_columns => {:parent_id => :integer} do |model|
235
+ subject.with_model :skip_ancestry => true, :extra_columns => {:parent_id => 'BSON::ObjectId'} do |model|
236
236
  [model.create!].each do |parent1|
237
237
  (Array.new(5) { model.create :parent_id => parent1.id }).each do |parent2|
238
238
  (Array.new(5) { model.create :parent_id => parent2.id }).each do |parent3|
@@ -133,14 +133,14 @@ describe MongoidAncestry do
133
133
  root1.parent = root2
134
134
  root1.save!
135
135
  root1.descendants.asc(:_id).map(&:to_param).should eql(descendants)
136
- }.to change(root2.descendants, 'size').by(root1.subtree.size)
136
+ }.to change(root2.descendants, 'count').by(root1.subtree.count)
137
137
 
138
138
  descendants = root2.descendants.asc(:_id).map(&:to_param)
139
139
  expect {
140
140
  root2.parent = root3
141
141
  root2.save!
142
142
  root2.descendants.asc(:_id).map(&:to_param).should eql(descendants)
143
- }.to change(root3.descendants, 'size').by(root2.subtree.size)
143
+ }.to change(root3.descendants, 'count').by(root2.subtree.count)
144
144
 
145
145
  descendants = root1.descendants.asc(:_id).map(&:to_param)
146
146
  expect {
@@ -148,8 +148,8 @@ describe MongoidAncestry do
148
148
  root1.parent = nil
149
149
  root1.save!
150
150
  root1.descendants.asc(:_id).map(&:to_param).should eql(descendants)
151
- }.to change(root3.descendants, 'size').by(-root1.subtree.size)
152
- }.to change(root2.descendants, 'size').by(-root1.subtree.size)
151
+ }.to change(root3.descendants, 'count').by(-root1.subtree.count)
152
+ }.to change(root2.descendants, 'count').by(-root1.subtree.count)
153
153
  end
154
154
  end
155
155
 
data/spec/mongoid.yml ADDED
@@ -0,0 +1,6 @@
1
+ test:
2
+ sessions:
3
+ default:
4
+ database: ancestry_test
5
+ hosts:
6
+ - localhost:27017
data/spec/spec_helper.rb CHANGED
@@ -6,17 +6,14 @@ require 'rspec'
6
6
 
7
7
  require 'mongoid-ancestry'
8
8
 
9
- Mongoid.configure do |config|
10
- logger = Logger.new('log/test.log')
11
- config.master = Mongo::Connection.new('localhost', 27017,
12
- :logger => logger).db('ancestry_test')
13
- config.logger = logger
14
- end
9
+ Mongoid.load!(File.expand_path('../mongoid.yml', __FILE__), 'test')
10
+ Mongoid.logger = Logger.new('log/test.log')
15
11
 
16
12
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
17
13
 
18
14
  RSpec.configure do |config|
19
15
  config.after :each do
20
- Mongoid.master.collections.reject { |c| c.name =~ /^system\./ }.each(&:drop)
16
+ # Drops all collections in the current environment
17
+ Mongoid::Sessions.default.drop
21
18
  end
22
19
  end
@@ -14,7 +14,7 @@ class MongoidAncestry
14
14
  TestNode.send(:include, Mongoid::Ancestry) unless skip_ancestry
15
15
 
16
16
  extra_columns.each do |name, type|
17
- TestNode.send :field, name, :type => type.to_s.capitalize.constantize
17
+ TestNode.send :field, name, :type => type.constantize
18
18
  end unless extra_columns.nil?
19
19
 
20
20
  TestNode.has_ancestry options unless skip_ancestry
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-ancestry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
5
- prerelease:
4
+ version: 0.3.0.rc
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Stefan Kroes
@@ -10,40 +10,24 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-25 00:00:00.000000000 Z
13
+ date: 2012-06-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mongoid
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
- - - ! '>='
20
+ - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: '2.0'
22
+ version: 3.0.0.rc
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
- - - ! '>='
28
+ - - '='
29
29
  - !ruby/object:Gem::Version
30
- version: '2.0'
31
- - !ruby/object:Gem::Dependency
32
- name: bson_ext
33
- requirement: !ruby/object:Gem::Requirement
34
- none: false
35
- requirements:
36
- - - ! '>='
37
- - !ruby/object:Gem::Version
38
- version: '1.3'
39
- type: :runtime
40
- prerelease: false
41
- version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '1.3'
30
+ version: 3.0.0.rc
47
31
  description: Organise Mongoid model into a tree structure
48
32
  email:
49
33
  - eagle.anton@gmail.com
@@ -72,6 +56,7 @@ files:
72
56
  - spec/lib/ancestry_spec.rb
73
57
  - spec/lib/mongoid-ancestry/class_methods_spec.rb
74
58
  - spec/lib/mongoid-ancestry/instance_methods_spec.rb
59
+ - spec/mongoid.yml
75
60
  - spec/spec_helper.rb
76
61
  - spec/support/models.rb
77
62
  homepage: http://github.com/skyeagle/mongoid-ancestry
@@ -89,16 +74,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
74
  version: '0'
90
75
  segments:
91
76
  - 0
92
- hash: -4473599239750644479
77
+ hash: -4410323303637396168
93
78
  required_rubygems_version: !ruby/object:Gem::Requirement
94
79
  none: false
95
80
  requirements:
96
- - - ! '>='
81
+ - - ! '>'
97
82
  - !ruby/object:Gem::Version
98
- version: '0'
99
- segments:
100
- - 0
101
- hash: -4473599239750644479
83
+ version: 1.3.1
102
84
  requirements: []
103
85
  rubyforge_project: mongoid-ancestry
104
86
  rubygems_version: 1.8.24