import awesome_nested_set 2.1.6
64cc8bc8cf
git-svn-id: http://svn.redmine.org/redmine/trunk@12687 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
bdfcfb35a3
commit
3f6a676622
|
@ -1,16 +1,21 @@
|
||||||
before_install: gem install bundler --pre
|
language: ruby
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
- parndt@gmail.com
|
- parndt@gmail.com
|
||||||
|
script: bundle exec rspec spec
|
||||||
env:
|
env:
|
||||||
- DB=sqlite3
|
- DB=sqlite3
|
||||||
- DB=sqlite3mem
|
- DB=sqlite3mem
|
||||||
|
- DB=postgresql
|
||||||
|
- DB=mysql
|
||||||
rvm:
|
rvm:
|
||||||
- 1.8.7
|
- 2.0.0
|
||||||
- 1.9.2
|
|
||||||
- 1.9.3
|
- 1.9.3
|
||||||
- rbx
|
- 1.8.7
|
||||||
- jruby
|
- rbx-19mode
|
||||||
|
- jruby-19mode
|
||||||
|
- rbx-18mode
|
||||||
|
- jruby-18mode
|
||||||
gemfile:
|
gemfile:
|
||||||
- gemfiles/Gemfile.rails-3.0.rb
|
- gemfiles/Gemfile.rails-3.0.rb
|
||||||
- gemfiles/Gemfile.rails-3.1.rb
|
- gemfiles/Gemfile.rails-3.1.rb
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
2.1.6
|
||||||
|
* Fixed rebuild! when there is a default_scope with order [Adrian Serafin]
|
||||||
|
* Testing with stable bundler, ruby 2.0, MySQL and PostgreSQL [Philip Arndt]
|
||||||
|
* Optimized move_to for large trees [ericsmith66]
|
||||||
|
|
||||||
2.1.5
|
2.1.5
|
||||||
* Worked around issues where AR#association wasn't present on Rails 3.0.x. [Philip Arndt]
|
* Worked around issues where AR#association wasn't present on Rails 3.0.x. [Philip Arndt]
|
||||||
* Adds option 'order_column' which defaults to 'left_column_name'. [gudata]
|
* Adds option 'order_column' which defaults to 'left_column_name'. [gudata]
|
||||||
|
|
|
@ -4,11 +4,15 @@ require 'rubygems'
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
require 'awesome_nested_set/version'
|
require 'awesome_nested_set/version'
|
||||||
|
|
||||||
require "rspec/core/rake_task"
|
|
||||||
RSpec::Core::RakeTask.new(:spec)
|
|
||||||
|
|
||||||
task :default => :spec
|
task :default => :spec
|
||||||
|
|
||||||
|
task :spec do
|
||||||
|
%w(3.0 3.1 3.2).each do |rails_version|
|
||||||
|
puts "\n" + (cmd = "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}.rb' bundle exec rspec spec")
|
||||||
|
system cmd
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
task :build do
|
task :build do
|
||||||
system "gem build awesome_nested_set.gemspec"
|
system "gem build awesome_nested_set.gemspec"
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
lib = File.expand_path('../lib/', __FILE__)
|
require File.expand_path('../lib/awesome_nested_set/version', __FILE__)
|
||||||
$:.unshift lib unless $:.include?(lib)
|
|
||||||
require 'awesome_nested_set/version'
|
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{awesome_nested_set}
|
s.name = %q{awesome_nested_set}
|
||||||
|
@ -9,15 +7,18 @@ Gem::Specification.new do |s|
|
||||||
s.authors = ["Brandon Keepers", "Daniel Morrison", "Philip Arndt"]
|
s.authors = ["Brandon Keepers", "Daniel Morrison", "Philip Arndt"]
|
||||||
s.description = %q{An awesome nested set implementation for Active Record}
|
s.description = %q{An awesome nested set implementation for Active Record}
|
||||||
s.email = %q{info@collectiveidea.com}
|
s.email = %q{info@collectiveidea.com}
|
||||||
s.extra_rdoc_files = [
|
s.extra_rdoc_files = %w[README.rdoc]
|
||||||
"README.rdoc"
|
|
||||||
]
|
|
||||||
s.files = Dir.glob("lib/**/*") + %w(MIT-LICENSE README.rdoc CHANGELOG)
|
s.files = Dir.glob("lib/**/*") + %w(MIT-LICENSE README.rdoc CHANGELOG)
|
||||||
s.homepage = %q{http://github.com/collectiveidea/awesome_nested_set}
|
s.homepage = %q{http://github.com/collectiveidea/awesome_nested_set}
|
||||||
s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
|
s.rdoc_options = ["--main", "README.rdoc", "--inline-source", "--line-numbers"]
|
||||||
s.require_paths = ["lib"]
|
s.require_paths = ["lib"]
|
||||||
s.rubygems_version = %q{1.3.6}
|
s.rubygems_version = %q{1.3.6}
|
||||||
s.summary = %q{An awesome nested set implementation for Active Record}
|
s.summary = %q{An awesome nested set implementation for Active Record}
|
||||||
|
s.license = %q{MIT}
|
||||||
|
|
||||||
s.add_runtime_dependency 'activerecord', '>= 3.0.0'
|
s.add_runtime_dependency 'activerecord', '>= 3.0.0'
|
||||||
s.add_development_dependency 'rspec-rails', '~> 2.8'
|
|
||||||
|
s.add_development_dependency 'rspec-rails', '~> 2.12'
|
||||||
|
s.add_development_dependency 'rake', '~> 10'
|
||||||
|
s.add_development_dependency 'combustion', '>= 0.3.3'
|
||||||
end
|
end
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
require File.dirname(__FILE__) + '/lib/awesome_nested_set'
|
|
|
@ -181,6 +181,8 @@ module CollectiveIdea #:nodoc:
|
||||||
# Rebuilds the left & rights if unset or invalid.
|
# Rebuilds the left & rights if unset or invalid.
|
||||||
# Also very useful for converting from acts_as_tree.
|
# Also very useful for converting from acts_as_tree.
|
||||||
def rebuild!(validate_nodes = true)
|
def rebuild!(validate_nodes = true)
|
||||||
|
# default_scope with order may break database queries so we do all operation without scope
|
||||||
|
unscoped do
|
||||||
# Don't rebuild a valid tree.
|
# Don't rebuild a valid tree.
|
||||||
return true if valid?
|
return true if valid?
|
||||||
|
|
||||||
|
@ -211,6 +213,7 @@ module CollectiveIdea #:nodoc:
|
||||||
set_left_and_rights.call(root_node)
|
set_left_and_rights.call(root_node)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Iterates over tree elements and determines the current level in the tree.
|
# Iterates over tree elements and determines the current level in the tree.
|
||||||
# Only accepts default ordering, odering by an other column than lft
|
# Only accepts default ordering, odering by an other column than lft
|
||||||
|
@ -590,8 +593,6 @@ module CollectiveIdea #:nodoc:
|
||||||
["#{quoted_right_column_name} = (#{quoted_right_column_name} - ?)", diff]
|
["#{quoted_right_column_name} = (#{quoted_right_column_name} - ?)", diff]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Reload is needed because children may have updated their parent (self) during deletion.
|
|
||||||
reload
|
|
||||||
# Don't allow multiple calls to destroy to corrupt the set
|
# Don't allow multiple calls to destroy to corrupt the set
|
||||||
self.skip_before_destroy = true
|
self.skip_before_destroy = true
|
||||||
end
|
end
|
||||||
|
@ -654,7 +655,27 @@ module CollectiveIdea #:nodoc:
|
||||||
else target[parent_column_name]
|
else target[parent_column_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
self.nested_set_scope.update_all([
|
where_statement = ["not (#{quoted_left_column_name} = CASE " +
|
||||||
|
"WHEN #{quoted_left_column_name} BETWEEN :a AND :b " +
|
||||||
|
"THEN #{quoted_left_column_name} + :d - :b " +
|
||||||
|
"WHEN #{quoted_left_column_name} BETWEEN :c AND :d " +
|
||||||
|
"THEN #{quoted_left_column_name} + :a - :c " +
|
||||||
|
"ELSE #{quoted_left_column_name} END AND " +
|
||||||
|
"#{quoted_right_column_name} = CASE " +
|
||||||
|
"WHEN #{quoted_right_column_name} BETWEEN :a AND :b " +
|
||||||
|
"THEN #{quoted_right_column_name} + :d - :b " +
|
||||||
|
"WHEN #{quoted_right_column_name} BETWEEN :c AND :d " +
|
||||||
|
"THEN #{quoted_right_column_name} + :a - :c " +
|
||||||
|
"ELSE #{quoted_right_column_name} END AND " +
|
||||||
|
"#{quoted_parent_column_name} = CASE " +
|
||||||
|
"WHEN #{self.class.base_class.primary_key} = :id THEN :new_parent " +
|
||||||
|
"ELSE #{quoted_parent_column_name} END)" ,
|
||||||
|
{:a => a, :b => b, :c => c, :d => d, :id => self.id, :new_parent => new_parent} ]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.nested_set_scope.where(*where_statement).update_all([
|
||||||
"#{quoted_left_column_name} = CASE " +
|
"#{quoted_left_column_name} = CASE " +
|
||||||
"WHEN #{quoted_left_column_name} BETWEEN :a AND :b " +
|
"WHEN #{quoted_left_column_name} BETWEEN :a AND :b " +
|
||||||
"THEN #{quoted_left_column_name} + :d - :b " +
|
"THEN #{quoted_left_column_name} + :d - :b " +
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
module AwesomeNestedSet
|
module AwesomeNestedSet
|
||||||
VERSION = '2.1.5' unless defined?(::AwesomeNestedSet::VERSION)
|
VERSION = '2.1.6' unless defined?(::AwesomeNestedSet::VERSION)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
require 'awesome_nested_set/helper'
|
||||||
|
|
||||||
describe "Helper" do
|
describe "Helper" do
|
||||||
include CollectiveIdea::Acts::NestedSet::Helper
|
include CollectiveIdea::Acts::NestedSet::Helper
|
||||||
|
|
|
@ -1006,6 +1006,12 @@ describe "AwesomeNestedSet" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'rebuilding tree with a default scope ordering' do
|
||||||
|
it "doesn't throw exception" do
|
||||||
|
expect { Position.rebuild! }.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'creating roots with a default scope ordering' do
|
describe 'creating roots with a default scope ordering' do
|
||||||
it "assigns rgt and lft correctly" do
|
it "assigns rgt and lft correctly" do
|
||||||
alpha = Order.create(:name => 'Alpha')
|
alpha = Order.create(:name => 'Alpha')
|
||||||
|
|
|
@ -6,10 +6,12 @@ sqlite3mem:
|
||||||
database: ":memory:"
|
database: ":memory:"
|
||||||
postgresql:
|
postgresql:
|
||||||
adapter: postgresql
|
adapter: postgresql
|
||||||
|
encoding: unicode
|
||||||
|
database: awesome_nested_set_plugin_test
|
||||||
|
pool: 5
|
||||||
username: postgres
|
username: postgres
|
||||||
password: postgres
|
password: postgres
|
||||||
database: awesome_nested_set_plugin_test
|
min_messages: warning
|
||||||
min_messages: ERROR
|
|
||||||
mysql:
|
mysql:
|
||||||
adapter: mysql2
|
adapter: mysql2
|
||||||
host: localhost
|
host: localhost
|
||||||
|
|
|
@ -56,6 +56,15 @@ ActiveRecord::Schema.define(:version => 0) do
|
||||||
t.column :depth, :integer
|
t.column :depth, :integer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table :positions, :force => true do |t|
|
||||||
|
t.column :name, :string
|
||||||
|
t.column :parent_id, :integer
|
||||||
|
t.column :lft, :integer
|
||||||
|
t.column :rgt, :integer
|
||||||
|
t.column :depth, :integer
|
||||||
|
t.column :position, :integer
|
||||||
|
end
|
||||||
|
|
||||||
create_table :no_depths, :force => true do |t|
|
create_table :no_depths, :force => true do |t|
|
||||||
t.column :name, :string
|
t.column :name, :string
|
||||||
t.column :parent_id, :integer
|
t.column :parent_id, :integer
|
||||||
|
|
|
@ -1,32 +1,33 @@
|
||||||
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
|
||||||
plugin_test_dir = File.dirname(__FILE__)
|
plugin_test_dir = File.dirname(__FILE__)
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
require 'bundler/setup'
|
require 'bundler/setup'
|
||||||
|
|
||||||
require 'rspec'
|
|
||||||
require 'logger'
|
require 'logger'
|
||||||
|
|
||||||
require 'active_support'
|
|
||||||
require 'active_model'
|
|
||||||
require 'active_record'
|
require 'active_record'
|
||||||
require 'action_controller'
|
|
||||||
|
|
||||||
require 'awesome_nested_set'
|
|
||||||
|
|
||||||
ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")
|
ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")
|
||||||
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
require 'erb'
|
require 'erb'
|
||||||
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result)
|
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result)
|
||||||
ActiveRecord::Base.establish_connection(ENV["DB"] || "sqlite3mem")
|
ActiveRecord::Base.establish_connection(ENV["DB"] ||= "sqlite3mem")
|
||||||
ActiveRecord::Migration.verbose = false
|
ActiveRecord::Migration.verbose = false
|
||||||
|
|
||||||
|
require 'combustion/database'
|
||||||
|
Combustion::Database.create_database(ActiveRecord::Base.configurations[ENV["DB"]])
|
||||||
load(File.join(plugin_test_dir, "db", "schema.rb"))
|
load(File.join(plugin_test_dir, "db", "schema.rb"))
|
||||||
|
|
||||||
|
require 'awesome_nested_set'
|
||||||
require 'support/models'
|
require 'support/models'
|
||||||
|
|
||||||
|
require 'action_controller'
|
||||||
require 'rspec/rails'
|
require 'rspec/rails'
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.fixture_path = "#{plugin_test_dir}/fixtures"
|
config.fixture_path = "#{plugin_test_dir}/fixtures"
|
||||||
config.use_transactional_fixtures = true
|
config.use_transactional_fixtures = true
|
||||||
|
config.after(:suite) do
|
||||||
|
unless /sqlite/ === ENV['DB']
|
||||||
|
Combustion::Database.drop_database(ActiveRecord::Base.configurations[ENV['DB']])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -85,6 +85,12 @@ class Order < ActiveRecord::Base
|
||||||
default_scope order(:name)
|
default_scope order(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Position < ActiveRecord::Base
|
||||||
|
acts_as_nested_set
|
||||||
|
|
||||||
|
default_scope order(:position)
|
||||||
|
end
|
||||||
|
|
||||||
class NoDepth < ActiveRecord::Base
|
class NoDepth < ActiveRecord::Base
|
||||||
acts_as_nested_set
|
acts_as_nested_set
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue