mirror of
https://github.com/redmine/redmine.git
synced 2025-11-14 01:06:00 +01:00
Gemfile: use awesome_nested_set 2.1.6 gem
git-svn-id: http://svn.redmine.org/redmine/trunk@12734 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
require 'spec_helper'
|
||||
require 'awesome_nested_set/helper'
|
||||
|
||||
describe "Helper" do
|
||||
include CollectiveIdea::Acts::NestedSet::Helper
|
||||
|
||||
before(:all) do
|
||||
self.class.fixtures :categories
|
||||
end
|
||||
|
||||
describe "nested_set_options" do
|
||||
it "test_nested_set_options" do
|
||||
expected = [
|
||||
[" Top Level", 1],
|
||||
["- Child 1", 2],
|
||||
['- Child 2', 3],
|
||||
['-- Child 2.1', 4],
|
||||
['- Child 3', 5],
|
||||
[" Top Level 2", 6]
|
||||
]
|
||||
actual = nested_set_options(Category.scoped) do |c|
|
||||
"#{'-' * c.level} #{c.name}"
|
||||
end
|
||||
actual.should == expected
|
||||
end
|
||||
|
||||
it "test_nested_set_options_with_mover" do
|
||||
expected = [
|
||||
[" Top Level", 1],
|
||||
["- Child 1", 2],
|
||||
['- Child 3', 5],
|
||||
[" Top Level 2", 6]
|
||||
]
|
||||
actual = nested_set_options(Category.scoped, categories(:child_2)) do |c|
|
||||
"#{'-' * c.level} #{c.name}"
|
||||
end
|
||||
actual.should == expected
|
||||
end
|
||||
|
||||
it "test_nested_set_options_with_class_as_argument" do
|
||||
expected = [
|
||||
[" Top Level", 1],
|
||||
["- Child 1", 2],
|
||||
['- Child 2', 3],
|
||||
['-- Child 2.1', 4],
|
||||
['- Child 3', 5],
|
||||
[" Top Level 2", 6]
|
||||
]
|
||||
actual = nested_set_options(Category) do |c|
|
||||
"#{'-' * c.level} #{c.name}"
|
||||
end
|
||||
actual.should == expected
|
||||
end
|
||||
|
||||
it "test_nested_set_options_with_class_as_argument_with_mover" do
|
||||
expected = [
|
||||
[" Top Level", 1],
|
||||
["- Child 1", 2],
|
||||
['- Child 3', 5],
|
||||
[" Top Level 2", 6]
|
||||
]
|
||||
actual = nested_set_options(Category, categories(:child_2)) do |c|
|
||||
"#{'-' * c.level} #{c.name}"
|
||||
end
|
||||
actual.should == expected
|
||||
end
|
||||
|
||||
it "test_nested_set_options_with_array_as_argument_without_mover" do
|
||||
expected = [
|
||||
[" Top Level", 1],
|
||||
["- Child 1", 2],
|
||||
['- Child 2', 3],
|
||||
['-- Child 2.1', 4],
|
||||
['- Child 3', 5],
|
||||
[" Top Level 2", 6]
|
||||
]
|
||||
actual = nested_set_options(Category.all) do |c|
|
||||
"#{'-' * c.level} #{c.name}"
|
||||
end
|
||||
actual.should == expected
|
||||
end
|
||||
|
||||
it "test_nested_set_options_with_array_as_argument_with_mover" do
|
||||
expected = [
|
||||
[" Top Level", 1],
|
||||
["- Child 1", 2],
|
||||
['- Child 3', 5],
|
||||
[" Top Level 2", 6]
|
||||
]
|
||||
actual = nested_set_options(Category.all, categories(:child_2)) do |c|
|
||||
"#{'-' * c.level} #{c.name}"
|
||||
end
|
||||
actual.should == expected
|
||||
end
|
||||
end
|
||||
end
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,27 +0,0 @@
|
||||
sqlite3:
|
||||
adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3
|
||||
database: awesome_nested_set.sqlite3.db
|
||||
sqlite3mem:
|
||||
adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3
|
||||
database: ":memory:"
|
||||
postgresql:
|
||||
adapter: postgresql
|
||||
encoding: unicode
|
||||
database: awesome_nested_set_plugin_test
|
||||
pool: 5
|
||||
username: postgres
|
||||
password: postgres
|
||||
min_messages: warning
|
||||
mysql:
|
||||
adapter: mysql2
|
||||
host: localhost
|
||||
username: root
|
||||
password:
|
||||
database: awesome_nested_set_plugin_test
|
||||
## Add DB Configuration to run Oracle tests
|
||||
oracle:
|
||||
adapter: oracle_enhanced
|
||||
host: localhost
|
||||
username: awesome_nested_set_dev
|
||||
password:
|
||||
database: xe
|
||||
@@ -1,74 +0,0 @@
|
||||
ActiveRecord::Schema.define(:version => 0) do
|
||||
|
||||
create_table :categories, :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 :organization_id, :integer
|
||||
end
|
||||
|
||||
create_table :departments, :force => true do |t|
|
||||
t.column :name, :string
|
||||
end
|
||||
|
||||
create_table :notes, :force => true do |t|
|
||||
t.column :body, :text
|
||||
t.column :parent_id, :integer
|
||||
t.column :lft, :integer
|
||||
t.column :rgt, :integer
|
||||
t.column :depth, :integer
|
||||
t.column :notable_id, :integer
|
||||
t.column :notable_type, :string
|
||||
end
|
||||
|
||||
create_table :renamed_columns, :force => true do |t|
|
||||
t.column :name, :string
|
||||
t.column :mother_id, :integer
|
||||
t.column :red, :integer
|
||||
t.column :black, :integer
|
||||
t.column :pitch, :integer
|
||||
end
|
||||
|
||||
create_table :things, :force => true do |t|
|
||||
t.column :body, :text
|
||||
t.column :parent_id, :integer
|
||||
t.column :lft, :integer
|
||||
t.column :rgt, :integer
|
||||
t.column :depth, :integer
|
||||
t.column :children_count, :integer
|
||||
end
|
||||
|
||||
create_table :brokens, :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
|
||||
end
|
||||
|
||||
create_table :orders, :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
|
||||
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|
|
||||
t.column :name, :string
|
||||
t.column :parent_id, :integer
|
||||
t.column :lft, :integer
|
||||
t.column :rgt, :integer
|
||||
end
|
||||
end
|
||||
@@ -1,3 +0,0 @@
|
||||
one:
|
||||
id: 1
|
||||
name: One
|
||||
@@ -1,34 +0,0 @@
|
||||
top_level:
|
||||
id: 1
|
||||
name: Top Level
|
||||
lft: 1
|
||||
rgt: 10
|
||||
child_1:
|
||||
id: 2
|
||||
name: Child 1
|
||||
parent_id: 1
|
||||
lft: 2
|
||||
rgt: 3
|
||||
child_2:
|
||||
id: 3
|
||||
name: Child 2
|
||||
parent_id: 1
|
||||
lft: 4
|
||||
rgt: 7
|
||||
child_2_1:
|
||||
id: 4
|
||||
name: Child 2.1
|
||||
parent_id: 3
|
||||
lft: 5
|
||||
rgt: 6
|
||||
child_3:
|
||||
id: 5
|
||||
name: Child 3
|
||||
parent_id: 1
|
||||
lft: 8
|
||||
rgt: 9
|
||||
top_level_2:
|
||||
id: 6
|
||||
name: Top Level 2
|
||||
lft: 11
|
||||
rgt: 12
|
||||
@@ -1,3 +0,0 @@
|
||||
top:
|
||||
id: 1
|
||||
name: Top
|
||||
@@ -1,38 +0,0 @@
|
||||
scope1:
|
||||
id: 1
|
||||
body: Top Level
|
||||
lft: 1
|
||||
rgt: 10
|
||||
notable_id: 1
|
||||
notable_type: Category
|
||||
child_1:
|
||||
id: 2
|
||||
body: Child 1
|
||||
parent_id: 1
|
||||
lft: 2
|
||||
rgt: 3
|
||||
notable_id: 1
|
||||
notable_type: Category
|
||||
child_2:
|
||||
id: 3
|
||||
body: Child 2
|
||||
parent_id: 1
|
||||
lft: 4
|
||||
rgt: 7
|
||||
notable_id: 1
|
||||
notable_type: Category
|
||||
child_3:
|
||||
id: 4
|
||||
body: Child 3
|
||||
parent_id: 1
|
||||
lft: 8
|
||||
rgt: 9
|
||||
notable_id: 1
|
||||
notable_type: Category
|
||||
scope2:
|
||||
id: 5
|
||||
body: Top Level 2
|
||||
lft: 1
|
||||
rgt: 2
|
||||
notable_id: 1
|
||||
notable_type: Departments
|
||||
@@ -1,27 +0,0 @@
|
||||
parent1:
|
||||
id: 1
|
||||
body: Top Level
|
||||
lft: 1
|
||||
rgt: 10
|
||||
children_count: 2
|
||||
child_1:
|
||||
id: 2
|
||||
body: Child 1
|
||||
parent_id: 1
|
||||
lft: 2
|
||||
rgt: 3
|
||||
children_count: 0
|
||||
child_2:
|
||||
id: 3
|
||||
body: Child 2
|
||||
parent_id: 1
|
||||
lft: 4
|
||||
rgt: 7
|
||||
children_count: 0
|
||||
child_2_1:
|
||||
id: 4
|
||||
body: Child 2.1
|
||||
parent_id: 3
|
||||
lft: 8
|
||||
rgt: 9
|
||||
children_count: 0
|
||||
@@ -1,33 +0,0 @@
|
||||
plugin_test_dir = File.dirname(__FILE__)
|
||||
|
||||
require 'rubygems'
|
||||
require 'bundler/setup'
|
||||
|
||||
require 'logger'
|
||||
require 'active_record'
|
||||
ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")
|
||||
|
||||
require 'yaml'
|
||||
require 'erb'
|
||||
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result)
|
||||
ActiveRecord::Base.establish_connection(ENV["DB"] ||= "sqlite3mem")
|
||||
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"))
|
||||
|
||||
require 'awesome_nested_set'
|
||||
require 'support/models'
|
||||
|
||||
require 'action_controller'
|
||||
require 'rspec/rails'
|
||||
RSpec.configure do |config|
|
||||
config.fixture_path = "#{plugin_test_dir}/fixtures"
|
||||
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
|
||||
@@ -1,96 +0,0 @@
|
||||
class Note < ActiveRecord::Base
|
||||
acts_as_nested_set :scope => [:notable_id, :notable_type]
|
||||
end
|
||||
|
||||
class Default < ActiveRecord::Base
|
||||
self.table_name = 'categories'
|
||||
acts_as_nested_set
|
||||
end
|
||||
|
||||
class ScopedCategory < ActiveRecord::Base
|
||||
self.table_name = 'categories'
|
||||
acts_as_nested_set :scope => :organization
|
||||
end
|
||||
|
||||
class OrderedCategory < ActiveRecord::Base
|
||||
self.table_name = 'categories'
|
||||
acts_as_nested_set :order_column => 'name'
|
||||
end
|
||||
|
||||
class RenamedColumns < ActiveRecord::Base
|
||||
acts_as_nested_set :parent_column => 'mother_id',
|
||||
:left_column => 'red',
|
||||
:right_column => 'black',
|
||||
:depth_column => 'pitch'
|
||||
end
|
||||
|
||||
class Category < ActiveRecord::Base
|
||||
acts_as_nested_set
|
||||
|
||||
validates_presence_of :name
|
||||
|
||||
# Setup a callback that we can switch to true or false per-test
|
||||
set_callback :move, :before, :custom_before_move
|
||||
cattr_accessor :test_allows_move
|
||||
@@test_allows_move = true
|
||||
def custom_before_move
|
||||
@@test_allows_move
|
||||
end
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
|
||||
def recurse &block
|
||||
block.call self, lambda{
|
||||
self.children.each do |child|
|
||||
child.recurse &block
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
class Thing < ActiveRecord::Base
|
||||
acts_as_nested_set :counter_cache => 'children_count'
|
||||
end
|
||||
|
||||
class DefaultWithCallbacks < ActiveRecord::Base
|
||||
|
||||
self.table_name = 'categories'
|
||||
|
||||
attr_accessor :before_add, :after_add, :before_remove, :after_remove
|
||||
|
||||
acts_as_nested_set :before_add => :do_before_add_stuff,
|
||||
:after_add => :do_after_add_stuff,
|
||||
:before_remove => :do_before_remove_stuff,
|
||||
:after_remove => :do_after_remove_stuff
|
||||
|
||||
private
|
||||
|
||||
[ :before_add, :after_add, :before_remove, :after_remove ].each do |hook_name|
|
||||
define_method "do_#{hook_name}_stuff" do |child_node|
|
||||
self.send("#{hook_name}=", child_node)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Broken < ActiveRecord::Base
|
||||
acts_as_nested_set
|
||||
end
|
||||
|
||||
class Order < ActiveRecord::Base
|
||||
acts_as_nested_set
|
||||
|
||||
default_scope order(:name)
|
||||
end
|
||||
|
||||
class Position < ActiveRecord::Base
|
||||
acts_as_nested_set
|
||||
|
||||
default_scope order(:position)
|
||||
end
|
||||
|
||||
class NoDepth < ActiveRecord::Base
|
||||
acts_as_nested_set
|
||||
end
|
||||
Reference in New Issue
Block a user