pg_ltree 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af73780dad2653e9068d80d56ad53a1cac86f88968cbe9f697bc832e42aedcf6
4
- data.tar.gz: a4bea89ea088fe18ce1a5d5ce9606bceecb1833a36b9ec4ce7b252bcde5e7f83
3
+ metadata.gz: ba0cf379067eb0d7c24ff36828795d78b6cbbdc5b6738c45427868164940516d
4
+ data.tar.gz: c63501e14473075c2916567fdee20d974c09fe77d93c0553b9d16c185af436a1
5
5
  SHA512:
6
- metadata.gz: '086bcf6439fdfd185d738ab1c120c41192567f8d3e9c1ee456c0ef82bf28d0e6c921d9c9a397ff5cacd7735dfc21605c078ade8927266e6685ef7fefbc1d0b58'
7
- data.tar.gz: 9317b961bd9ae4f6ff781c3aa72bf2b5ee0c5136bb6b2a28482853a8c0262278f5a00daf6d8b4dfd71302d4e2b52975abc8e4f2b0629fffdb03037d95ca51ced
6
+ metadata.gz: 8c8545986852ec4d61a2b9623a2142d4f79e2a3613d75fb7efff6511e70699531831527a625b89693b4b9d21c8bc7e4937f432bb14315ea82c01cc4a6eb34079
7
+ data.tar.gz: 1be5c7b2a06dc1228ba07ab50284f5d6af6147a27bbec92fb6768b92d7f718399dacf6150532ea2c1939a5660cd62e7f650463d7f534301df5cde8b29d7e9fb6
data/Rakefile CHANGED
@@ -20,32 +20,3 @@ Rake::TestTask.new(:test) do |t|
20
20
  t.verbose = false
21
21
  end
22
22
 
23
- desc 'Default: run unit tests.'
24
- task default: 'test:all'
25
-
26
- namespace :test do
27
- AVAILABLE_CASES = %w(
28
- activerecord_40_pg_017 activerecord_40_pg_018
29
- activerecord_41_pg_017 activerecord_41_pg_018
30
- activerecord_42_pg_017 activerecord_42_pg_018
31
- activerecord_50_pg_018 activerecord_51_pg_020
32
- activerecord_51_pg_021 activerecord_52_pg_100
33
- activerecord_60_pg_021 activerecord_60_pg_100
34
- activerecord_60_pg_110
35
- ).freeze
36
-
37
- AVAILABLE_CASES.each do |version|
38
- desc "Test pg_ltree against #{version}"
39
- task version do
40
- sh "bundle install --gemfile=gemfiles/#{version}.gemfile --quiet"
41
- sh "BUNDLE_GEMFILE='gemfiles/#{version}.gemfile' bundle exec rake -t test"
42
- end
43
- end
44
-
45
- desc 'Run all tests for pg_ltree'
46
- task :all do
47
- AVAILABLE_CASES.each do |version|
48
- sh "rake test:#{version}"
49
- end
50
- end
51
- end
@@ -3,18 +3,16 @@ module PgLtree
3
3
  #
4
4
  # @see [ActiveRecord::Base]
5
5
  # @see http://www.postgresql.org/docs/current/static/ltree.html
6
- #
7
- # @author a.ponomarenko
8
6
  module Ltree
9
7
  # Initialzie ltree for active model
10
8
  #
11
9
  # @param column [String] ltree column name
12
- def ltree(column = :path, options: { cascade: true })
10
+ def ltree(column = :path, cascade: true)
13
11
  cattr_accessor :ltree_path_column
14
12
 
15
13
  self.ltree_path_column = column
16
14
 
17
- if options[:cascade]
15
+ if cascade
18
16
  after_update :cascade_update
19
17
  after_destroy :cascade_destroy
20
18
  end
@@ -245,7 +243,7 @@ module PgLtree
245
243
  #
246
244
  # @return [ActiveRecord::Relation]
247
245
  def cascade_destroy
248
- ltree_scope.where("#{ltree_scope.table_name}.#{ltree_path_column} <@ ?", ltree_path_in_database).delete_all
246
+ ltree_scope.where("#{ltree_scope.table_name}.#{ltree_path_column} <@ ?", ltree_path_in_database).destroy_all
249
247
  end
250
248
  end
251
249
  end
@@ -1,8 +1,6 @@
1
1
  module PgLtree
2
2
  # Narrowing the Scope for ActiveRecord Model
3
3
  # @note When model have composite uniq key (for example: state + path), you should use this module for narrowing the scope
4
- #
5
- # @author a.ponomarenko
6
4
  module ScopedFor
7
5
  # Define base instance scope for model by columns
8
6
  #
@@ -21,7 +19,7 @@ module PgLtree
21
19
  #
22
20
  # @return current class
23
21
  def ltree_scope
24
- self.class.where *(ltree_scoped_for.map { |column| { column => public_send(column) } })
22
+ self.class.where(*(ltree_scoped_for.map { |column| { column => public_send(column) } }))
25
23
  end
26
24
  end
27
25
  end
@@ -1,7 +1,4 @@
1
1
  # Organize ActiveRecord model into a tree structure with PostgreSQL LTree
2
- #
3
- # @author a.ponomarenko
4
2
  module PgLtree
5
- # Gem Version
6
- VERSION = '1.1.8'.freeze
3
+ VERSION = '1.1.9'.freeze
7
4
  end
@@ -1,5 +1,5 @@
1
1
  adapter: postgresql
2
2
  host: localhost
3
3
  username: postgres
4
- password:
4
+ password: postgres
5
5
  database: pg_ltree_test
@@ -17,6 +17,9 @@ class PgLtree::LtreeTest < BaseTest
17
17
  Top.Collections.Pictures.Astronomy.Stars
18
18
  Top.Collections.Pictures.Astronomy.Galaxies
19
19
  Top.Collections.Pictures.Astronomy.Astronauts
20
+ Top.Collections.Videos
21
+ Top.Collections.Videos.Vacation
22
+ Top.Collections.Videos.NewYear
20
23
  ).each do |path|
21
24
  TreeNode.create! path: path
22
25
  end
@@ -50,6 +53,8 @@ class PgLtree::LtreeTest < BaseTest
50
53
  Top.Collections.Pictures.Astronomy.Stars
51
54
  Top.Collections.Pictures.Astronomy.Galaxies
52
55
  Top.Collections.Pictures.Astronomy.Astronauts
56
+ Top.Collections.Videos.Vacation
57
+ Top.Collections.Videos.NewYear
53
58
  )
54
59
  end
55
60
 
@@ -60,6 +65,8 @@ class PgLtree::LtreeTest < BaseTest
60
65
  Top.Hobbies.Amateurs_Astronomy
61
66
  Top.Collections.Pictures.Astronomy.Galaxies
62
67
  Top.Collections.Pictures.Astronomy.Astronauts
68
+ Top.Collections.Videos.Vacation
69
+ Top.Collections.Videos.NewYear
63
70
  )
64
71
  end
65
72
 
@@ -191,8 +198,52 @@ class PgLtree::LtreeTest < BaseTest
191
198
  end
192
199
 
193
200
  test '.cascade_destroy' do
194
- TreeNode.find_by(path: 'Top.Collections').destroy
201
+ assert_equal TreeNode.where("path <@ 'Top.Collections'").pluck(:path), %w(
202
+ Top.Collections
203
+ Top.Collections.Pictures
204
+ Top.Collections.Pictures.Astronomy
205
+ Top.Collections.Pictures.Astronomy.Stars
206
+ Top.Collections.Pictures.Astronomy.Galaxies
207
+ Top.Collections.Pictures.Astronomy.Astronauts
208
+ Top.Collections.Videos
209
+ Top.Collections.Videos.Vacation
210
+ Top.Collections.Videos.NewYear
211
+ )
195
212
 
196
- assert_equal TreeNode.where("path ~ 'Top.Collections'").pluck(:path), %w()
213
+ TreeNode.find_by(path: 'Top.Collections.Pictures').destroy
214
+
215
+ assert_equal TreeNode.where("path <@ 'Top.Collections'").pluck(:path), %w(
216
+ Top.Collections
217
+ Top.Collections.Videos
218
+ Top.Collections.Videos.Vacation
219
+ Top.Collections.Videos.NewYear
220
+ )
221
+ end
222
+
223
+ test '.destroy' do
224
+ assert_equal TreeWithoutCascadeNode.where("path <@ 'Top.Collections'").pluck(:path), %w(
225
+ Top.Collections
226
+ Top.Collections.Pictures
227
+ Top.Collections.Pictures.Astronomy
228
+ Top.Collections.Pictures.Astronomy.Stars
229
+ Top.Collections.Pictures.Astronomy.Galaxies
230
+ Top.Collections.Pictures.Astronomy.Astronauts
231
+ Top.Collections.Videos
232
+ Top.Collections.Videos.Vacation
233
+ Top.Collections.Videos.NewYear
234
+ )
235
+
236
+ TreeWithoutCascadeNode.find_by(path: 'Top.Collections.Pictures').destroy
237
+
238
+ assert_equal TreeWithoutCascadeNode.where("path <@ 'Top.Collections'").pluck(:path), %w(
239
+ Top.Collections
240
+ Top.Collections.Pictures.Astronomy
241
+ Top.Collections.Pictures.Astronomy.Stars
242
+ Top.Collections.Pictures.Astronomy.Galaxies
243
+ Top.Collections.Pictures.Astronomy.Astronauts
244
+ Top.Collections.Videos
245
+ Top.Collections.Videos.Vacation
246
+ Top.Collections.Videos.NewYear
247
+ )
197
248
  end
198
249
  end
@@ -17,6 +17,9 @@ class PgLtree::ScopedForTest < BaseTest
17
17
  Top.Collections.Pictures.Astronomy.Stars
18
18
  Top.Collections.Pictures.Astronomy.Galaxies
19
19
  Top.Collections.Pictures.Astronomy.Astronauts
20
+ Top.Collections.Videos
21
+ Top.Collections.Videos.Vacation
22
+ Top.Collections.Videos.NewYear
20
23
  ).each do |path|
21
24
  %i( active deactive ).each do |status|
22
25
  NotUniqTreeNode.create! new_path: path, status: status
@@ -47,6 +50,8 @@ class PgLtree::ScopedForTest < BaseTest
47
50
  Top.Collections.Pictures.Astronomy.Stars
48
51
  Top.Collections.Pictures.Astronomy.Galaxies
49
52
  Top.Collections.Pictures.Astronomy.Astronauts
53
+ Top.Collections.Videos.Vacation
54
+ Top.Collections.Videos.NewYear
50
55
  )
51
56
  end
52
57
 
@@ -161,32 +166,25 @@ class PgLtree::ScopedForTest < BaseTest
161
166
  end
162
167
 
163
168
  test '.cascade_destroy' do
164
- assert_equal NotUniqTreeNode.where("new_path <@ 'Top.Collections'").pluck(:new_path), %w(
169
+ assert_equal NotUniqTreeNode.where("new_path <@ 'Top.Collections'").where(status: :active).pluck(:new_path), %w(
165
170
  Top.Collections
166
- Top.Collections
167
- Top.Collections.Pictures
168
171
  Top.Collections.Pictures
169
172
  Top.Collections.Pictures.Astronomy
170
- Top.Collections.Pictures.Astronomy
171
173
  Top.Collections.Pictures.Astronomy.Stars
172
- Top.Collections.Pictures.Astronomy.Stars
173
- Top.Collections.Pictures.Astronomy.Galaxies
174
174
  Top.Collections.Pictures.Astronomy.Galaxies
175
175
  Top.Collections.Pictures.Astronomy.Astronauts
176
- Top.Collections.Pictures.Astronomy.Astronauts
176
+ Top.Collections.Videos
177
+ Top.Collections.Videos.Vacation
178
+ Top.Collections.Videos.NewYear
177
179
  )
178
180
 
179
- NotUniqTreeNode.find_by(new_path: 'Top.Collections', status: :active).destroy
181
+ NotUniqTreeNode.find_by(new_path: 'Top.Collections.Pictures', status: :active).destroy
180
182
 
181
- assert_equal NotUniqTreeNode.where("new_path <@ 'Top.Collections'").where(status: :active).pluck(:new_path), %w()
182
-
183
- assert_equal NotUniqTreeNode.where("new_path <@ 'Top.Collections'").where(status: :deactive).pluck(:new_path), %w(
183
+ assert_equal NotUniqTreeNode.where("new_path <@ 'Top.Collections'").where(status: :active).pluck(:new_path), %w(
184
184
  Top.Collections
185
- Top.Collections.Pictures
186
- Top.Collections.Pictures.Astronomy
187
- Top.Collections.Pictures.Astronomy.Stars
188
- Top.Collections.Pictures.Astronomy.Galaxies
189
- Top.Collections.Pictures.Astronomy.Astronauts
185
+ Top.Collections.Videos
186
+ Top.Collections.Videos.Vacation
187
+ Top.Collections.Videos.NewYear
190
188
  )
191
189
  end
192
190
  end
data/test/test_helper.rb CHANGED
@@ -7,6 +7,8 @@ rescue Bundler::BundlerError => e
7
7
  exit e.status_code
8
8
  end
9
9
 
10
+ $VERBOSE=nil
11
+
10
12
  require 'pg'
11
13
  require 'pg_ltree'
12
14
  require 'minitest/autorun'
@@ -76,3 +78,8 @@ end
76
78
  class TreeNode < ActiveRecord::Base
77
79
  ltree
78
80
  end
81
+
82
+ class TreeWithoutCascadeNode < ActiveRecord::Base
83
+ self.table_name = 'tree_nodes'
84
+ ltree :path, cascade: false
85
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_ltree
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Panamarenka
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-13 00:00:00.000000000 Z
11
+ date: 2022-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.0
20
- - - "<="
19
+ version: '5.2'
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 7.0.0.rc1
22
+ version: '8.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 4.0.0
30
- - - "<="
29
+ version: '5.2'
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 7.0.0.rc1
32
+ version: '8.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: pg
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -120,6 +120,20 @@ dependencies:
120
120
  - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: appraisal
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
123
137
  description: Organise ActiveRecord model into a tree structure with PostgreSQL LTree
124
138
  email:
125
139
  - andrei.panamarenka@gmail.com
@@ -144,7 +158,7 @@ homepage: https://github.com/sjke/pg_ltree
144
158
  licenses:
145
159
  - MIT
146
160
  metadata: {}
147
- post_install_message:
161
+ post_install_message:
148
162
  rdoc_options: []
149
163
  require_paths:
150
164
  - lib
@@ -159,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
173
  - !ruby/object:Gem::Version
160
174
  version: '0'
161
175
  requirements: []
162
- rubygems_version: 3.1.0.pre2
163
- signing_key:
176
+ rubygems_version: 3.1.6
177
+ signing_key:
164
178
  specification_version: 4
165
179
  summary: Organise ActiveRecord model into a tree structure with PostgreSQL LTree
166
180
  test_files: