acts_as_nested_interval 0.2.0 → 0.3.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -4
  3. data/lib/acts_as_nested_interval.rb +3 -30
  4. data/lib/acts_as_nested_interval/associations.rb +41 -0
  5. data/lib/acts_as_nested_interval/callbacks.rb +18 -8
  6. data/lib/acts_as_nested_interval/configuration.rb +9 -2
  7. data/lib/acts_as_nested_interval/core_ext/rational.rb +7 -0
  8. data/lib/acts_as_nested_interval/instance_methods.rb +49 -106
  9. data/lib/acts_as_nested_interval/version.rb +1 -1
  10. data/test/acts_as_nested_interval_test.rb +64 -160
  11. metadata +35 -87
  12. data/test/dummy/README.rdoc +0 -28
  13. data/test/dummy/Rakefile +0 -6
  14. data/test/dummy/app/assets/javascripts/application.js +0 -13
  15. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  16. data/test/dummy/app/controllers/application_controller.rb +0 -5
  17. data/test/dummy/app/helpers/application_helper.rb +0 -2
  18. data/test/dummy/app/models/region.rb +0 -5
  19. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  20. data/test/dummy/bin/bundle +0 -3
  21. data/test/dummy/bin/rails +0 -4
  22. data/test/dummy/bin/rake +0 -4
  23. data/test/dummy/config.ru +0 -4
  24. data/test/dummy/config/application.rb +0 -23
  25. data/test/dummy/config/boot.rb +0 -5
  26. data/test/dummy/config/database.yml +0 -31
  27. data/test/dummy/config/environment.rb +0 -5
  28. data/test/dummy/config/environments/development.rb +0 -37
  29. data/test/dummy/config/environments/production.rb +0 -83
  30. data/test/dummy/config/environments/test.rb +0 -39
  31. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  32. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  33. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  34. data/test/dummy/config/initializers/inflections.rb +0 -16
  35. data/test/dummy/config/initializers/mime_types.rb +0 -4
  36. data/test/dummy/config/initializers/session_store.rb +0 -3
  37. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  38. data/test/dummy/config/locales/en.yml +0 -23
  39. data/test/dummy/config/routes.rb +0 -56
  40. data/test/dummy/config/secrets.yml +0 -22
  41. data/test/dummy/db/migrate/20120302143528_create_regions.rb +0 -15
  42. data/test/dummy/db/migrate/20121004204252_change_interval_precision.rb +0 -6
  43. data/test/dummy/db/schema.rb +0 -31
  44. data/test/dummy/log/development.log +0 -140
  45. data/test/dummy/log/test.log +0 -7048
  46. data/test/dummy/public/404.html +0 -67
  47. data/test/dummy/public/422.html +0 -67
  48. data/test/dummy/public/500.html +0 -66
  49. data/test/dummy/public/favicon.ico +0 -0
@@ -1,3 +1,3 @@
1
1
  module ActsAsNestedInterval
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0.pre"
3
3
  end
@@ -9,92 +9,6 @@ class ActsAsNestedIntervalTest < ActiveSupport::TestCase
9
9
  assert_equal [nil, 1, 5, nil, 7, 2, nil, 4, 8], (0...9).map { |k| k.inverse(9) }
10
10
  end
11
11
 
12
- def test_create_root
13
- earth = Region.create name: "Earth"
14
- assert_equal [0, 1], [earth.lftp, earth.lftq]
15
- assert_equal [1, 1], [earth.rgtp, earth.rgtq]
16
- assert_equal 1.0 * 0 / 1, earth.lft
17
- assert_equal 1.0 * 1 / 1, earth.rgt
18
- assert_equal [earth], Region.roots
19
- end
20
-
21
- def test_create_first_child
22
- earth = Region.new name: "Earth"
23
- oceania = Region.new name: "Oceania", parent: earth
24
- oceania.save!
25
- assert_equal [1, 2], [oceania.lftp, oceania.lftq]
26
- assert_equal [1, 1], [oceania.rgtp, oceania.rgtq]
27
- assert_equal 1.0 * 1 / 2, oceania.lft
28
- assert_equal 1.0 * 1 / 1, oceania.rgt
29
- end
30
-
31
- def test_create_second_child
32
- earth = Region.create name: "Earth"
33
- oceania = Region.create name: "Oceania", parent: earth
34
- australia = Region.create name: "Australia", parent: oceania
35
- new_zealand = Region.create name: "New Zealand", parent: oceania
36
- assert_equal [2, 3], [australia.lftp, australia.lftq]
37
- assert_equal [1, 1], [australia.rgtp, australia.rgtq]
38
- assert_equal 1.0 * 2 / 3, australia.lft
39
- assert_equal 1.0 * 1 / 1, australia.rgt
40
- assert_equal [3, 5], [new_zealand.lftp, new_zealand.lftq]
41
- assert_equal [2, 3], [new_zealand.rgtp, new_zealand.rgtq]
42
- assert_equal 1.0 * 3 / 5, new_zealand.lft
43
- assert_equal 1.0 * 2 / 3, new_zealand.rgt
44
- end
45
-
46
- def test_append_child
47
- earth = Region.create name: "Earth"
48
- oceania = Region.new name: "Oceania"
49
- earth.children << oceania
50
- assert_equal [1, 2], [oceania.lftp, oceania.lftq]
51
- assert_equal [1, 1], [oceania.rgtp, oceania.rgtq]
52
- assert_equal 1.0 * 1 / 2, oceania.lft
53
- assert_equal 1.0 * 1 / 1, oceania.rgt
54
- end
55
-
56
- def test_ancestors
57
- earth = Region.create name: "Earth"
58
- oceania = Region.create name: "Oceania", parent: earth
59
- australia = Region.create name: "Australia", parent: oceania
60
- new_zealand = Region.create name: "New Zealand", parent: oceania
61
- assert_equal [], earth.ancestors
62
- assert_equal [earth], oceania.ancestors
63
- assert_equal [earth, oceania], australia.ancestors
64
- assert_equal [earth, oceania], new_zealand.ancestors
65
- end
66
-
67
- def test_descendants
68
- earth = Region.create name: "Earth"
69
- oceania = Region.create name: "Oceania", parent: earth
70
- australia = Region.create name: "Australia", parent: oceania
71
- new_zealand = Region.create name: "New Zealand", parent: oceania
72
- assert_equal [oceania, australia, new_zealand], earth.descendants.sort_by(&:id)
73
- assert_equal [australia, new_zealand], oceania.descendants.sort_by(&:id)
74
- assert_equal [], australia.descendants.sort_by(&:id)
75
- assert_equal [], new_zealand.descendants.sort_by(&:id)
76
- end
77
-
78
- def test_preorder
79
- earth = Region.create name: "Earth"
80
- oceania = Region.create name: "Oceania", parent: earth
81
- antarctica = Region.create name: "Antarctica", parent: earth
82
- australia = Region.create name: "Australia", parent: oceania
83
- new_zealand = Region.create name: "New Zealand", parent: oceania
84
- assert_equal [earth, oceania, australia, new_zealand, antarctica], Region.preorder
85
- end
86
-
87
- def test_depth
88
- earth = Region.create name: "Earth"
89
- oceania = Region.create name: "Oceania", parent: earth
90
- australia = Region.create name: "Australia", parent: oceania
91
- new_zealand = Region.create name: "New Zealand", parent: oceania
92
- assert_equal 0, earth.depth
93
- assert_equal 1, oceania.depth
94
- assert_equal 2, australia.depth
95
- assert_equal 2, new_zealand.depth
96
- end
97
-
98
12
  def test_move
99
13
  connection = Region.connection
100
14
  earth = Region.create name: "Earth"
@@ -157,20 +71,19 @@ class ActsAsNestedIntervalTest < ActiveSupport::TestCase
157
71
  assert_equal 5, earth.reload.descendants.count
158
72
  end
159
73
 
160
- def test_database_precision
161
- Region.all.delete_all
162
- root = Region.create name: 'root'
163
- l1=Region.create(name: 'l1', parent: root)
164
- l2=Region.create(name: 'l2', parent: l1)
165
- l3=Region.create(name: 'l3', parent: l2)
166
- l4=Region.create(name: 'l4', parent: l3)
167
- l3.parent = l1
168
- l3.save!
169
- #make sure database calculates with the same precision as ruby
170
- #l3.rgt is calculated by ruby, but l4.rgt is calculated by the database
171
- #the difference is only visible with rgt as double
172
- assert_equal 2, Region.where("abs(rgt - (select rgt from regions where id =#{l3.id})) < 1e-16").count
173
- end
74
+ #def test_database_precision
75
+ #root = Region.create name: 'root'
76
+ #l1=Region.create(name: 'l1', parent: root)
77
+ #l2=Region.create(name: 'l2', parent: l1)
78
+ #l3=Region.create(name: 'l3', parent: l2)
79
+ #l4=Region.create(name: 'l4', parent: l3)
80
+ #l3.parent = l1
81
+ #l3.save!
82
+ ##make sure database calculates with the same precision as ruby
83
+ ##l3.rgt is calculated by ruby, but l4.rgt is calculated by the database
84
+ ##the difference is only visible with rgt as double
85
+ #assert_equal 2, Region.where("abs(rgt - (select rgt from regions where id =#{l3.id})) < 1e-16").count
86
+ #end
174
87
 
175
88
  def test_destroy
176
89
  earth = Region.create name: "Earth"
@@ -190,69 +103,60 @@ class ActsAsNestedIntervalTest < ActiveSupport::TestCase
190
103
  assert_equal [], krypton.descendants
191
104
  end
192
105
 
193
- def test_limits
194
- region = Region.create name: ""
195
- 22.times do
196
- Region.create name: "", parent: region
197
- region = Region.create name: "", parent: region
198
- end
199
- region.descendants
200
- end
201
-
202
- def test_virtual_root_order
203
- set_virtual_root( true )
204
- r1 = Region.create name: "1"
205
- r2 = Region.create name: "2"
206
- r3 = Region.create name: "3"
207
- assert r3.rgt <= r2.lft
208
- assert r2.rgt <= r1.lft
209
- end
106
+ #def test_virtual_root_order
107
+ #set_virtual_root( true )
108
+ #r1 = Region.create name: "1"
109
+ #r2 = Region.create name: "2"
110
+ #r3 = Region.create name: "3"
111
+ #assert r3.rgt <= r2.lft
112
+ #assert r2.rgt <= r1.lft
113
+ #end
210
114
 
211
- def test_virtual_root_allocation
212
- set_virtual_root( true )
213
- r1 = Region.create name: "Europe"
214
- r2 = Region.create name: "Romania", :parent => r1
215
- r3 = Region.create name: "Asia"
216
- r4 = Region.create name: "America"
217
- assert_equal [["Europe", 1.0/2, 1.0], ["Romania", 2.0/3, 1.0],
218
- ["Asia", 1.0/3, 1.0/2], ["America", 1.0/4, 1.0/3]],
219
- Region.preorder.map { |r| [r.name, r.lft, r.rgt] }
220
- end
115
+ #def test_virtual_root_allocation
116
+ #set_virtual_root( true )
117
+ #r1 = Region.create name: "Europe"
118
+ #r2 = Region.create name: "Romania", :parent => r1
119
+ #r3 = Region.create name: "Asia"
120
+ #r4 = Region.create name: "America"
121
+ #assert_equal [["Europe", 1.0/2, 1.0], ["Romania", 2.0/3, 1.0],
122
+ #["Asia", 1.0/3, 1.0/2], ["America", 1.0/4, 1.0/3]],
123
+ #Region.preorder.map { |r| [r.name, r.lft, r.rgt] }
124
+ #end
221
125
 
222
- def test_rebuild_nested_interval_tree
223
- set_virtual_root( true )
224
- r1 = Region.create name: "Europe"
225
- r2 = Region.create name: "Romania", parent: r1
226
- r3 = Region.create name: "Asia"
227
- r4 = Region.create name: "America"
228
- Region.rebuild_nested_interval_tree!
229
- assert_equal [["Europe", 0.5, 1.0], ["Romania", 2.0/3, 1.0],
230
- ["Asia", 1.0/3, 1.0/2], ["America", 1.0/4, 1.0/3]],
231
- Region.preorder.map { |r| [r.name, r.lft, r.rgt] }
232
- end
126
+ #def test_rebuild_nested_interval_tree
127
+ #set_virtual_root( true )
128
+ #r1 = Region.create name: "Europe"
129
+ #r2 = Region.create name: "Romania", parent: r1
130
+ #r3 = Region.create name: "Asia"
131
+ #r4 = Region.create name: "America"
132
+ #Region.rebuild_nested_interval_tree!
133
+ #assert_equal [["Europe", 0.5, 1.0], ["Romania", 2.0/3, 1.0],
134
+ #["Asia", 1.0/3, 1.0/2], ["America", 1.0/4, 1.0/3]],
135
+ #Region.preorder.map { |r| [r.name, r.lft, r.rgt] }
136
+ #end
233
137
 
234
- def test_root_update_keeps_interval
235
- set_virtual_root( true )
236
- r1 = Region.create name: "Europe"
237
- r2 = Region.create name: "Romania", parent: r1
238
- r3 = Region.create name: "Asia"
239
- r4 = Region.create name: "America"
240
- lftq = r4.lftq
241
- r4.name = 'USA'
242
- r4.save
243
- assert_equal lftq, r4.lftq
244
- end
138
+ #def test_root_update_keeps_interval
139
+ #set_virtual_root( true )
140
+ #r1 = Region.create name: "Europe"
141
+ #r2 = Region.create name: "Romania", parent: r1
142
+ #r3 = Region.create name: "Asia"
143
+ #r4 = Region.create name: "America"
144
+ #lftq = r4.lftq
145
+ #r4.name = 'USA'
146
+ #r4.save
147
+ #assert_equal lftq, r4.lftq
148
+ #end
245
149
 
246
- def test_move_to_root_recomputes_interval
247
- set_virtual_root( true )
248
- r1 = Region.create name: "Europe"
249
- r2 = Region.create name: "Romania", parent: r1
250
- r3 = Region.create name: "Asia"
251
- r4 = Region.create name: "America"
252
- lftq = r2.lftq
253
- r2.parent = nil
254
- r2.save
255
- assert_not_equal lftq, r2.lftq
256
- end
150
+ #def test_move_to_root_recomputes_interval
151
+ #set_virtual_root( true )
152
+ #r1 = Region.create name: "Europe"
153
+ #r2 = Region.create name: "Romania", parent: r1
154
+ #r3 = Region.create name: "Asia"
155
+ #r4 = Region.create name: "America"
156
+ #lftq = r2.lftq
157
+ #r2.parent = nil
158
+ #r2.save
159
+ #assert_not_equal lftq, r2.lftq
160
+ #end
257
161
 
258
162
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_nested_interval
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolae Claudius
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-06-14 00:00:00.000000000 Z
13
+ date: 2014-06-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -18,20 +18,42 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.1
22
- - - "<"
23
- - !ruby/object:Gem::Version
24
- version: '5'
21
+ version: '4.0'
25
22
  type: :runtime
26
23
  prerelease: false
27
24
  version_requirements: !ruby/object:Gem::Requirement
28
25
  requirements:
29
26
  - - ">="
30
27
  - !ruby/object:Gem::Version
31
- version: 3.2.1
32
- - - "<"
28
+ version: '4.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rspec-rails
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
33
34
  - !ruby/object:Gem::Version
34
- version: '5'
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: database_cleaner
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
35
57
  description: Encode Trees in RDBMS using nested interval method for powerful querying
36
58
  and speedy inserts.
37
59
  email:
@@ -44,53 +66,17 @@ files:
44
66
  - README.md
45
67
  - Rakefile
46
68
  - lib/acts_as_nested_interval.rb
69
+ - lib/acts_as_nested_interval/associations.rb
47
70
  - lib/acts_as_nested_interval/callbacks.rb
48
71
  - lib/acts_as_nested_interval/class_methods.rb
49
72
  - lib/acts_as_nested_interval/configuration.rb
50
73
  - lib/acts_as_nested_interval/constants.rb
51
74
  - lib/acts_as_nested_interval/core_ext/integer.rb
75
+ - lib/acts_as_nested_interval/core_ext/rational.rb
52
76
  - lib/acts_as_nested_interval/instance_methods.rb
53
77
  - lib/acts_as_nested_interval/version.rb
54
78
  - lib/tasks/acts_as_nested_interval_tasks.rake
55
79
  - test/acts_as_nested_interval_test.rb
56
- - test/dummy/README.rdoc
57
- - test/dummy/Rakefile
58
- - test/dummy/app/assets/javascripts/application.js
59
- - test/dummy/app/assets/stylesheets/application.css
60
- - test/dummy/app/controllers/application_controller.rb
61
- - test/dummy/app/helpers/application_helper.rb
62
- - test/dummy/app/models/region.rb
63
- - test/dummy/app/views/layouts/application.html.erb
64
- - test/dummy/bin/bundle
65
- - test/dummy/bin/rails
66
- - test/dummy/bin/rake
67
- - test/dummy/config.ru
68
- - test/dummy/config/application.rb
69
- - test/dummy/config/boot.rb
70
- - test/dummy/config/database.yml
71
- - test/dummy/config/environment.rb
72
- - test/dummy/config/environments/development.rb
73
- - test/dummy/config/environments/production.rb
74
- - test/dummy/config/environments/test.rb
75
- - test/dummy/config/initializers/backtrace_silencers.rb
76
- - test/dummy/config/initializers/cookies_serializer.rb
77
- - test/dummy/config/initializers/filter_parameter_logging.rb
78
- - test/dummy/config/initializers/inflections.rb
79
- - test/dummy/config/initializers/mime_types.rb
80
- - test/dummy/config/initializers/session_store.rb
81
- - test/dummy/config/initializers/wrap_parameters.rb
82
- - test/dummy/config/locales/en.yml
83
- - test/dummy/config/routes.rb
84
- - test/dummy/config/secrets.yml
85
- - test/dummy/db/migrate/20120302143528_create_regions.rb
86
- - test/dummy/db/migrate/20121004204252_change_interval_precision.rb
87
- - test/dummy/db/schema.rb
88
- - test/dummy/log/development.log
89
- - test/dummy/log/test.log
90
- - test/dummy/public/404.html
91
- - test/dummy/public/422.html
92
- - test/dummy/public/500.html
93
- - test/dummy/public/favicon.ico
94
80
  - test/test_helper.rb
95
81
  homepage: https://github.com/grzlus/acts_as_nested_interval
96
82
  licenses: []
@@ -113,9 +99,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
99
  version: '2.0'
114
100
  required_rubygems_version: !ruby/object:Gem::Requirement
115
101
  requirements:
116
- - - ">="
102
+ - - ">"
117
103
  - !ruby/object:Gem::Version
118
- version: '0'
104
+ version: 1.3.1
119
105
  requirements: []
120
106
  rubyforge_project:
121
107
  rubygems_version: 2.2.2
@@ -125,41 +111,3 @@ summary: Encode Trees in RDBMS using nested interval method.
125
111
  test_files:
126
112
  - test/test_helper.rb
127
113
  - test/acts_as_nested_interval_test.rb
128
- - test/dummy/public/404.html
129
- - test/dummy/public/favicon.ico
130
- - test/dummy/public/422.html
131
- - test/dummy/public/500.html
132
- - test/dummy/db/schema.rb
133
- - test/dummy/db/migrate/20120302143528_create_regions.rb
134
- - test/dummy/db/migrate/20121004204252_change_interval_precision.rb
135
- - test/dummy/bin/bundle
136
- - test/dummy/bin/rails
137
- - test/dummy/bin/rake
138
- - test/dummy/config.ru
139
- - test/dummy/Rakefile
140
- - test/dummy/log/development.log
141
- - test/dummy/log/test.log
142
- - test/dummy/README.rdoc
143
- - test/dummy/config/environment.rb
144
- - test/dummy/config/locales/en.yml
145
- - test/dummy/config/routes.rb
146
- - test/dummy/config/environments/test.rb
147
- - test/dummy/config/environments/production.rb
148
- - test/dummy/config/environments/development.rb
149
- - test/dummy/config/secrets.yml
150
- - test/dummy/config/database.yml
151
- - test/dummy/config/application.rb
152
- - test/dummy/config/initializers/session_store.rb
153
- - test/dummy/config/initializers/inflections.rb
154
- - test/dummy/config/initializers/wrap_parameters.rb
155
- - test/dummy/config/initializers/filter_parameter_logging.rb
156
- - test/dummy/config/initializers/backtrace_silencers.rb
157
- - test/dummy/config/initializers/mime_types.rb
158
- - test/dummy/config/initializers/cookies_serializer.rb
159
- - test/dummy/config/boot.rb
160
- - test/dummy/app/helpers/application_helper.rb
161
- - test/dummy/app/assets/stylesheets/application.css
162
- - test/dummy/app/assets/javascripts/application.js
163
- - test/dummy/app/views/layouts/application.html.erb
164
- - test/dummy/app/models/region.rb
165
- - test/dummy/app/controllers/application_controller.rb
@@ -1,28 +0,0 @@
1
- == README
2
-
3
- This README would normally document whatever steps are necessary to get the
4
- application up and running.
5
-
6
- Things you may want to cover:
7
-
8
- * Ruby version
9
-
10
- * System dependencies
11
-
12
- * Configuration
13
-
14
- * Database creation
15
-
16
- * Database initialization
17
-
18
- * How to run the test suite
19
-
20
- * Services (job queues, cache servers, search engines, etc.)
21
-
22
- * Deployment instructions
23
-
24
- * ...
25
-
26
-
27
- Please feel free to use a different markup language if you do not plan to run
28
- <tt>rake doc:app</tt>.