acts_as_ordered_tree 1.1.7 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02d7e5c8d5d4f188a28d709689a5b549c34893ce
4
+ data.tar.gz: 687a430993d957a16afc33398cf8c18d0068b231
5
+ SHA512:
6
+ metadata.gz: d3694d0b00dc899e89c91e0d240b7b1cc525f5417236b2a01d4562142589e1e45f7d14311779225a250bd292c6a1f9cb8cb9e7a285a0e5d4359aef71fd8e5771
7
+ data.tar.gz: 9a5b0b6614b3119962b7e49fc60582d5f912e681f23ddfa3cb1b9ad6061b85ff3c1369fcb0f41db32addce28b7d2011b2c91a1cea3ecc6cfccf7be075cded612
@@ -5,6 +5,12 @@ require "acts_as_ordered_tree/instance_methods"
5
5
  require "acts_as_ordered_tree/validators"
6
6
 
7
7
  module ActsAsOrderedTree
8
+ PROTECTED_ATTRIBUTES_SUPPORTED = ActiveRecord::VERSION::STRING < '4.0.0' ||
9
+ defined?(ProtectedAttributes)
10
+
11
+ # can we use has_many :children, :order => :position
12
+ PLAIN_ORDER_OPTION_SUPPORTED = ActiveRecord::VERSION::STRING < '4.0.0'
13
+
8
14
  # == Usage
9
15
  # class Category < ActiveRecord::Base
10
16
  # acts_as_ordered_tree :parent_column => :parent_id,
@@ -31,7 +37,6 @@ module ActsAsOrderedTree
31
37
  has_many_children_options = {
32
38
  :class_name => "::#{base_class.name}",
33
39
  :foreign_key => options[:parent_column],
34
- :order => options[:position_column],
35
40
  :inverse_of => (:parent unless options[:polymorphic]),
36
41
  :dependent => :destroy
37
42
  }
@@ -40,15 +45,34 @@ module ActsAsOrderedTree
40
45
  has_many_children_options[callback] = options[callback] if options.key?(callback)
41
46
  end
42
47
 
43
- if scope_column_names.any?
44
- has_many_children_options[:conditions] = proc do
45
- [scope_column_names.map { |c| "#{c} = ?" }.join(' AND '),
46
- scope_column_names.map { |c| self[c] }]
48
+ if PLAIN_ORDER_OPTION_SUPPORTED
49
+ has_many_children_options[:order] = options[:position_column]
50
+
51
+ if scope_column_names.any?
52
+ has_many_children_options[:conditions] = proc do
53
+ [scope_column_names.map { |c| "#{c} = ?" }.join(' AND '),
54
+ scope_column_names.map { |c| self[c] }]
55
+ end
47
56
  end
57
+
58
+ has_many :children, has_many_children_options
59
+ else
60
+ scope = ->(parent) {
61
+ relation = order(options[:position_column])
62
+
63
+ if scope_column_names.any?
64
+ relation = relation.where(
65
+ Hash[scope_column_names.map { |c| [c, parent[c]]}]
66
+ )
67
+ end
68
+
69
+ relation
70
+ }
71
+
72
+ has_many :children, scope, has_many_children_options
48
73
  end
49
74
 
50
- # create associations
51
- has_many :children, has_many_children_options
75
+ # create parent association
52
76
  belongs_to :parent,
53
77
  :class_name => "::#{base_class.name}",
54
78
  :foreign_key => options[:parent_column],
@@ -67,7 +91,7 @@ module ActsAsOrderedTree
67
91
  extend ActiveSupport::Concern
68
92
 
69
93
  included do
70
- attr_protected depth_column, position_column
94
+ attr_protected depth_column, position_column if PROTECTED_ATTRIBUTES_SUPPORTED
71
95
  end
72
96
 
73
97
  def parent_column
@@ -5,11 +5,11 @@ module ActsAsOrderedTree
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- scope :preorder, order(arel_table[position_column].asc)
9
- scope :roots, where(arel_table[parent_column].eq(nil)).preorder
8
+ scope :preorder, -> { order(arel_table[position_column].asc) }
9
+ scope :roots, -> { where(arel_table[parent_column].eq(nil)).preorder }
10
10
 
11
11
  # add +leaves+ scope only if counter_cache column present
12
- scope :leaves, where(arel_table[children_counter_cache_column].eq(0)) if
12
+ scope :leaves, -> { where(arel_table[children_counter_cache_column].eq(0)) } if
13
13
  children_counter_cache?
14
14
 
15
15
  # when default value for counter_cache is absent we should set it manually
@@ -288,7 +288,7 @@ module ActsAsOrderedTree
288
288
  target.send(:reload_node)
289
289
  elsif pos != :root && target
290
290
  # load object if node is not an object
291
- target = self.class.find(target, :lock => true)
291
+ target = self.class.lock(true).find(target)
292
292
  elsif pos == :root
293
293
  # Obtain lock on all root nodes
294
294
  ordered_tree_scope.
@@ -308,7 +308,7 @@ module ActsAsOrderedTree
308
308
  # nothing changed - quit
309
309
  return if parent_id == parent_id_was && position == position_was
310
310
 
311
- self.class.find(self, :lock => true)
311
+ self.class.lock(true).find(self)
312
312
  self[position_column], self[parent_column] = position, parent_id
313
313
 
314
314
  move_kind = case
@@ -484,7 +484,7 @@ module ActsAsOrderedTree
484
484
 
485
485
  def ordered_tree_scope #:nodoc:
486
486
  if scope_column_names.empty?
487
- self.class.base_class.scoped
487
+ self.class.base_class
488
488
  else
489
489
  self.class.base_class.where Hash[scope_column_names.map { |column| [column, self[column]] }]
490
490
  end
@@ -1,12 +1,14 @@
1
1
  module ActsAsOrderedTree
2
2
  module Relation
3
3
  class Base < ActiveRecord::Relation
4
+ EMPTY_SCOPE_METHOD = ActiveRecord::VERSION::STRING < '4.0.0' ? :scoped : :all
5
+
4
6
  # Create from existing +relation+ or from +class+ and +table+
5
7
  def initialize(class_or_relation, table = nil)
6
8
  relation = class_or_relation
7
9
 
8
10
  if class_or_relation.is_a?(Class)
9
- relation = class_or_relation.scoped
11
+ relation = class_or_relation.send(EMPTY_SCOPE_METHOD)
10
12
  table ||= class_or_relation.arel_table
11
13
 
12
14
  super(class_or_relation, table)
@@ -12,7 +12,7 @@ module ActsAsOrderedTree
12
12
  begin
13
13
  transaction(&block)
14
14
  rescue ActiveRecord::StatementInvalid => error
15
- raise unless connection.open_transactions.zero?
15
+ raise unless self.class.connection.open_transactions.zero?
16
16
  raise unless error.message =~ DEADLOCK_MESSAGES
17
17
  raise unless retry_count < RETRY_COUNT
18
18
  retry_count += 1
@@ -1,3 +1,3 @@
1
1
  module ActsAsOrderedTree
2
- VERSION = '1.1.7'
2
+ VERSION = '1.1.8'
3
3
  end
@@ -9,11 +9,13 @@ describe ActsAsOrderedTree, :transactional do
9
9
  its(:depth_column) { should eq :depth }
10
10
  its(:children_counter_cache_column) { be_nil }
11
11
 
12
- context "instance" do
13
- subject { Default.new }
12
+ if ActsAsOrderedTree::PROTECTED_ATTRIBUTES_SUPPORTED
13
+ context "instance" do
14
+ subject { Default.new }
14
15
 
15
- it { should_not allow_mass_assignment_of(:position) }
16
- it { should_not allow_mass_assignment_of(:depth) }
16
+ it { should_not allow_mass_assignment_of(:position) }
17
+ it { should_not allow_mass_assignment_of(:depth) }
18
+ end
17
19
  end
18
20
  end
19
21
 
@@ -30,11 +32,13 @@ describe ActsAsOrderedTree, :transactional do
30
32
  its(:position_column) { should eq :red }
31
33
  its(:depth_column) { should eq :pitch }
32
34
 
33
- context "instance" do
34
- subject { RenamedColumns.new }
35
+ if ActsAsOrderedTree::PROTECTED_ATTRIBUTES_SUPPORTED
36
+ context "instance" do
37
+ subject { RenamedColumns.new }
35
38
 
36
- it { should_not allow_mass_assignment_of(:red) }
37
- it { should_not allow_mass_assignment_of(:pitch) }
39
+ it { should_not allow_mass_assignment_of(:red) }
40
+ it { should_not allow_mass_assignment_of(:pitch) }
41
+ end
38
42
  end
39
43
  end
40
44
 
@@ -422,7 +426,11 @@ describe ActsAsOrderedTree, :transactional do
422
426
 
423
427
  subject { node.send :reload_node }
424
428
 
425
- its(:name) { should eq 'changed' }
429
+ if ActiveRecord::VERSION::STRING >= '4.0.0'
430
+ xit 'ActiveRecord::Persistence#reload method ignores :select option since rails-4.0.0'
431
+ else
432
+ its(:name) { should eq 'changed' }
433
+ end
426
434
  its(:parent_id) { should be_nil }
427
435
  its(:position) { should eq 1 }
428
436
  end
@@ -802,7 +810,7 @@ describe ActsAsOrderedTree, :transactional do
802
810
  let!(:child1) { create :scoped, :parent => root1 }
803
811
  let!(:orphan) do
804
812
  record = create :scoped, :parent => root1
805
- record.class.update_all({:scope_type => "t0", :position => 1}, {:id => record.id})
813
+ record.class.where(:id => record.id).update_all(:scope_type => "t0", :position => 1)
806
814
  record
807
815
  end
808
816
 
@@ -0,0 +1,13 @@
1
+ pg:
2
+ adapter: postgresql
3
+ username: postgres
4
+ database: acts_as_ordered_tree_test
5
+ min_messages: ERROR
6
+ mysql:
7
+ adapter: mysql2
8
+ database: acts_as_ordered_tree_test
9
+ username: travis
10
+ encoding: utf8
11
+ sqlite3:
12
+ adapter: sqlite3
13
+ database: acts_as_ordered_tree.sqlite3.db
@@ -1,9 +1,6 @@
1
1
  pg:
2
2
  adapter: postgresql
3
- username: postgres
4
3
  database: acts_as_ordered_tree_test
5
- host: 127.0.0.1
6
- encoding: unicode
7
4
  min_messages: ERROR
8
5
  mysql:
9
6
  adapter: mysql2
@@ -20,7 +20,9 @@ require "acts_as_ordered_tree"
20
20
  require "logger"
21
21
  require "yaml"
22
22
 
23
- ActiveRecord::Base.configurations = YAML::load(IO.read(test_dir + "/db/config.yml"))
23
+ config_file = ENV['DBCONF'] || 'config.yml'
24
+
25
+ ActiveRecord::Base.configurations = YAML::load(IO.read(File.join(test_dir, 'db', config_file)))
24
26
  ActiveRecord::Base.establish_connection(ENV['DB'] || "pg")
25
27
  ActiveRecord::Base.logger = Logger.new(ENV['DEBUG'] ? $stderr : '/dev/null')
26
28
  ActiveRecord::Migration.verbose = false
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_ordered_tree
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.1.7
4
+ version: 1.1.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alexei Mikhailov
@@ -10,120 +9,106 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-07-02 00:00:00.000000000 Z
12
+ date: 2013-12-01 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- version_requirements: !ruby/object:Gem::Requirement
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - '>='
19
19
  - !ruby/object:Gem::Version
20
20
  version: 3.0.0
21
- none: false
22
- prerelease: false
23
- name: activerecord
24
21
  type: :runtime
25
- requirement: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
26
24
  requirements:
27
- - - ! '>='
25
+ - - '>='
28
26
  - !ruby/object:Gem::Version
29
27
  version: 3.0.0
30
- none: false
31
28
  - !ruby/object:Gem::Dependency
32
- version_requirements: !ruby/object:Gem::Requirement
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
33
31
  requirements:
34
- - - ! '>='
32
+ - - '>='
35
33
  - !ruby/object:Gem::Version
36
34
  version: 0.9.2
37
- none: false
38
- prerelease: false
39
- name: rake
40
35
  type: :development
41
- requirement: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
42
38
  requirements:
43
- - - ! '>='
39
+ - - '>='
44
40
  - !ruby/object:Gem::Version
45
41
  version: 0.9.2
46
- none: false
47
42
  - !ruby/object:Gem::Dependency
48
- version_requirements: !ruby/object:Gem::Requirement
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
49
45
  requirements:
50
- - - ! '>='
46
+ - - '>='
51
47
  - !ruby/object:Gem::Version
52
48
  version: '1.0'
53
- none: false
54
- prerelease: false
55
- name: bundler
56
49
  type: :development
57
- requirement: !ruby/object:Gem::Requirement
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
58
52
  requirements:
59
- - - ! '>='
53
+ - - '>='
60
54
  - !ruby/object:Gem::Version
61
55
  version: '1.0'
62
- none: false
63
56
  - !ruby/object:Gem::Dependency
64
- version_requirements: !ruby/object:Gem::Requirement
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
65
59
  requirements:
66
- - - ! '>='
60
+ - - '>='
67
61
  - !ruby/object:Gem::Version
68
62
  version: '2.11'
69
- none: false
70
- prerelease: false
71
- name: rspec
72
63
  type: :development
73
- requirement: !ruby/object:Gem::Requirement
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
74
66
  requirements:
75
- - - ! '>='
67
+ - - '>='
76
68
  - !ruby/object:Gem::Version
77
69
  version: '2.11'
78
- none: false
79
70
  - !ruby/object:Gem::Dependency
80
- version_requirements: !ruby/object:Gem::Requirement
71
+ name: shoulda-matchers
72
+ requirement: !ruby/object:Gem::Requirement
81
73
  requirements:
82
- - - ! '>='
74
+ - - '>='
83
75
  - !ruby/object:Gem::Version
84
76
  version: 1.2.0
85
- none: false
86
- prerelease: false
87
- name: shoulda-matchers
88
77
  type: :development
89
- requirement: !ruby/object:Gem::Requirement
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
90
80
  requirements:
91
- - - ! '>='
81
+ - - '>='
92
82
  - !ruby/object:Gem::Version
93
83
  version: 1.2.0
94
- none: false
95
84
  - !ruby/object:Gem::Dependency
96
- version_requirements: !ruby/object:Gem::Requirement
85
+ name: factory_girl
86
+ requirement: !ruby/object:Gem::Requirement
97
87
  requirements:
98
88
  - - <
99
89
  - !ruby/object:Gem::Version
100
90
  version: '3'
101
- none: false
102
- prerelease: false
103
- name: factory_girl
104
91
  type: :development
105
- requirement: !ruby/object:Gem::Requirement
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
106
94
  requirements:
107
95
  - - <
108
96
  - !ruby/object:Gem::Version
109
97
  version: '3'
110
- none: false
111
98
  - !ruby/object:Gem::Dependency
112
- version_requirements: !ruby/object:Gem::Requirement
99
+ name: appraisal
100
+ requirement: !ruby/object:Gem::Requirement
113
101
  requirements:
114
- - - ! '>='
102
+ - - '>='
115
103
  - !ruby/object:Gem::Version
116
104
  version: 0.4.0
117
- none: false
118
- prerelease: false
119
- name: appraisal
120
105
  type: :development
121
- requirement: !ruby/object:Gem::Requirement
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
122
108
  requirements:
123
- - - ! '>='
109
+ - - '>='
124
110
  - !ruby/object:Gem::Version
125
111
  version: 0.4.0
126
- none: false
127
112
  description:
128
113
  email:
129
114
  - amikhailov83@gmail.com
@@ -144,6 +129,7 @@ files:
144
129
  - lib/acts_as_ordered_tree/version.rb
145
130
  - spec/acts_as_ordered_tree_spec.rb
146
131
  - spec/concurrency_support_spec.rb
132
+ - spec/db/config.travis.yml
147
133
  - spec/db/config.yml
148
134
  - spec/db/schema.rb
149
135
  - spec/spec_helper.rb
@@ -152,37 +138,31 @@ files:
152
138
  - spec/support/models.rb
153
139
  homepage: https://github.com/take-five/acts_as_ordered_tree
154
140
  licenses: []
141
+ metadata: {}
155
142
  post_install_message:
156
143
  rdoc_options: []
157
144
  require_paths:
158
145
  - lib
159
146
  required_ruby_version: !ruby/object:Gem::Requirement
160
147
  requirements:
161
- - - ! '>='
148
+ - - '>='
162
149
  - !ruby/object:Gem::Version
163
- segments:
164
- - 0
165
- hash: -154648787
166
150
  version: '0'
167
- none: false
168
151
  required_rubygems_version: !ruby/object:Gem::Requirement
169
152
  requirements:
170
- - - ! '>='
153
+ - - '>='
171
154
  - !ruby/object:Gem::Version
172
- segments:
173
- - 0
174
- hash: -154648787
175
155
  version: '0'
176
- none: false
177
156
  requirements: []
178
157
  rubyforge_project: acts_as_ordered_tree
179
- rubygems_version: 1.8.25
158
+ rubygems_version: 2.1.11
180
159
  signing_key:
181
- specification_version: 3
160
+ specification_version: 4
182
161
  summary: ActiveRecord extension for sorted adjacency lists support
183
162
  test_files:
184
163
  - spec/acts_as_ordered_tree_spec.rb
185
164
  - spec/concurrency_support_spec.rb
165
+ - spec/db/config.travis.yml
186
166
  - spec/db/config.yml
187
167
  - spec/db/schema.rb
188
168
  - spec/spec_helper.rb