dm-is-nested_set 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
data/lib/dm-is-nested_set.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'pathname'
|
3
3
|
|
4
|
-
gem 'dm-core', '
|
4
|
+
gem 'dm-core', '~>0.9.7'
|
5
5
|
require 'dm-core'
|
6
6
|
|
7
|
-
gem 'dm-adjust', '
|
7
|
+
gem 'dm-adjust', '~>0.9.7'
|
8
8
|
require 'dm-adjust'
|
9
9
|
|
10
10
|
require Pathname(__FILE__).dirname.expand_path / 'dm-is-nested_set' / 'is' / 'nested_set.rb'
|
@@ -163,8 +163,7 @@ module DataMapper
|
|
163
163
|
# @raise <UnableToPositionError> if node is unable to calculate a new position for the element
|
164
164
|
# @see move_without_saving
|
165
165
|
def move(vector)
|
166
|
-
move_without_saving(vector)
|
167
|
-
save
|
166
|
+
move_without_saving(vector) && save
|
168
167
|
end
|
169
168
|
|
170
169
|
##
|
@@ -3,56 +3,6 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
|
3
3
|
|
4
4
|
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
5
5
|
|
6
|
-
class User
|
7
|
-
include DataMapper::Resource
|
8
|
-
|
9
|
-
property :id, Serial
|
10
|
-
property :name, String
|
11
|
-
|
12
|
-
has n, :categories
|
13
|
-
end
|
14
|
-
|
15
|
-
class Category
|
16
|
-
include DataMapper::Resource
|
17
|
-
|
18
|
-
property :id, Integer, :serial => true
|
19
|
-
property :name, String
|
20
|
-
property :class_name, Discriminator
|
21
|
-
|
22
|
-
belongs_to :user
|
23
|
-
|
24
|
-
is :nested_set, :scope => [:user_id]
|
25
|
-
|
26
|
-
def pos; [lft,rgt] end # convenience method only for speccing.
|
27
|
-
end
|
28
|
-
|
29
|
-
class CustomCategory < Category
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def setup
|
34
|
-
repository(:default) do
|
35
|
-
|
36
|
-
User.auto_migrate!
|
37
|
-
@paul = User.create!(:name => "paul")
|
38
|
-
@john = User.create!(:name => "john")
|
39
|
-
|
40
|
-
Category.auto_migrate!
|
41
|
-
Category.create!(:id => 1, :name => "Electronics")
|
42
|
-
Category.create!(:id => 2, :parent_id => 1, :name => "Televisions")
|
43
|
-
Category.create!(:id => 3, :parent_id => 2, :name => "Tube")
|
44
|
-
Category.create!(:id => 4, :parent_id => 2, :name => "LCD")
|
45
|
-
Category.create!(:id => 5, :parent_id => 2, :name => "Plasma")
|
46
|
-
Category.create!(:id => 6, :parent_id => 1, :name => "Portable Electronics")
|
47
|
-
Category.create!(:id => 7, :parent_id => 6, :name => "MP3 Players")
|
48
|
-
Category.create!(:id => 8, :parent_id => 7, :name => "Flash")
|
49
|
-
Category.create!(:id => 9, :parent_id => 6, :name => "CD Players")
|
50
|
-
Category.create!(:id => 10,:parent_id => 6, :name => "2 Way Radios")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
setup
|
55
|
-
|
56
6
|
# id | lft| rgt| title
|
57
7
|
#========================================
|
58
8
|
# 1 | 1 | 20 | - Electronics
|
@@ -77,7 +27,54 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
77
27
|
# | Electronics |
|
78
28
|
# |____________________________________________________________________________________________________|
|
79
29
|
|
80
|
-
describe
|
30
|
+
describe DataMapper::Is::NestedSet do
|
31
|
+
before do
|
32
|
+
Object.send(:remove_const, :User) if defined?(User)
|
33
|
+
class User
|
34
|
+
include DataMapper::Resource
|
35
|
+
|
36
|
+
property :id, Serial
|
37
|
+
property :name, String
|
38
|
+
|
39
|
+
has n, :categories
|
40
|
+
end
|
41
|
+
|
42
|
+
Object.send(:remove_const, :Category) if defined?(Category)
|
43
|
+
class Category
|
44
|
+
include DataMapper::Resource
|
45
|
+
|
46
|
+
property :id, Integer, :serial => true
|
47
|
+
property :name, String
|
48
|
+
property :class_name, Discriminator
|
49
|
+
|
50
|
+
belongs_to :user
|
51
|
+
|
52
|
+
is :nested_set, :scope => [:user_id]
|
53
|
+
|
54
|
+
def pos; [lft,rgt] end # convenience method only for speccing.
|
55
|
+
end
|
56
|
+
|
57
|
+
Object.send(:remove_const, :CustomCategory) if defined?(CustomCategory)
|
58
|
+
class CustomCategory < Category; end
|
59
|
+
|
60
|
+
DataMapper.auto_migrate!
|
61
|
+
|
62
|
+
repository(:default) do
|
63
|
+
@paul = User.create(:name => "paul")
|
64
|
+
@john = User.create(:name => "john")
|
65
|
+
|
66
|
+
Category.create(:id => 1, :name => "Electronics")
|
67
|
+
Category.create(:id => 2, :parent_id => 1, :name => "Televisions")
|
68
|
+
Category.create(:id => 3, :parent_id => 2, :name => "Tube")
|
69
|
+
Category.create(:id => 4, :parent_id => 2, :name => "LCD")
|
70
|
+
Category.create(:id => 5, :parent_id => 2, :name => "Plasma")
|
71
|
+
Category.create(:id => 6, :parent_id => 1, :name => "Portable Electronics")
|
72
|
+
Category.create(:id => 7, :parent_id => 6, :name => "MP3 Players")
|
73
|
+
Category.create(:id => 8, :parent_id => 7, :name => "Flash")
|
74
|
+
Category.create(:id => 9, :parent_id => 6, :name => "CD Players")
|
75
|
+
Category.create(:id => 10,:parent_id => 6, :name => "2 Way Radios")
|
76
|
+
end
|
77
|
+
end
|
81
78
|
|
82
79
|
describe 'Class#rebuild_tree_from_set' do
|
83
80
|
it 'should reset all parent_ids correctly' do
|
@@ -138,8 +135,6 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
138
135
|
end
|
139
136
|
end
|
140
137
|
|
141
|
-
Category.get(1).children
|
142
|
-
|
143
138
|
describe '#descendants and #self_and_descendants' do
|
144
139
|
it 'should return all subnodes of node' do
|
145
140
|
repository(:default) do
|
@@ -248,9 +243,9 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
248
243
|
repository(:default) do |repos|
|
249
244
|
Category.auto_migrate!
|
250
245
|
|
251
|
-
c1 = Category.create
|
246
|
+
c1 = Category.create(:name => "New Electronics")
|
252
247
|
|
253
|
-
c2 = Category.create
|
248
|
+
c2 = Category.create(:name => "OLED TVs")
|
254
249
|
|
255
250
|
c1.pos.should == [1,4]
|
256
251
|
c1.root.should == c1
|
@@ -299,7 +294,6 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
299
294
|
describe 'scoping' do
|
300
295
|
it 'should detach from list when changing scope' do
|
301
296
|
repository(:default) do |repos|
|
302
|
-
setup
|
303
297
|
plasma = Category.get(5)
|
304
298
|
plasma.pos.should == [7,8]
|
305
299
|
plasma.user_id = 1
|
@@ -312,7 +306,6 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
|
|
312
306
|
describe 'integrity' do
|
313
307
|
it 'should detach object from list when deleted' do
|
314
308
|
repository(:default) do |repos|
|
315
|
-
setup
|
316
309
|
lcd = Category.get(4)
|
317
310
|
lcd.pos.should == [5,6]
|
318
311
|
Category.get(3).destroy
|
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,7 @@ def load_driver(name, default_uri)
|
|
10
10
|
lib = "do_#{name}"
|
11
11
|
|
12
12
|
begin
|
13
|
-
gem lib, '
|
13
|
+
gem lib, '~>0.9.7'
|
14
14
|
require lib
|
15
15
|
DataMapper.setup(name, ENV["#{name.to_s.upcase}_SPEC_URI"] || default_uri)
|
16
16
|
DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[name]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-is-nested_set
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sindre Aarsaether
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-18 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.7
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.8.2
|
34
34
|
version:
|
35
35
|
description: DataMapper plugin allowing the creation of nested sets from data models
|
36
36
|
email:
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements: []
|
80
80
|
|
81
81
|
rubyforge_project: datamapper
|
82
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.3.1
|
83
83
|
signing_key:
|
84
84
|
specification_version: 2
|
85
85
|
summary: DataMapper plugin allowing the creation of nested sets from data models
|