svn propset svn:eol-style LF lib/plugins/awesome_nested_set/spec/*

git-svn-id: http://svn.redmine.org/redmine/trunk@12676 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2014-01-20 02:19:08 +00:00
parent df9da6750d
commit 77f29deb29
11 changed files with 1176 additions and 1176 deletions

View File

@ -1,67 +1,67 @@
require 'spec_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) 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, 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
require 'spec_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) 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, 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

View File

@ -1,18 +1,18 @@
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
username: postgres
password: postgres
database: awesome_nested_set_plugin_test
min_messages: ERROR
mysql:
adapter: mysql2
host: localhost
username: root
password:
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
username: postgres
password: postgres
database: awesome_nested_set_plugin_test
min_messages: ERROR
mysql:
adapter: mysql2
host: localhost
username: root
password:
database: awesome_nested_set_plugin_test

View File

@ -1,45 +1,45 @@
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 :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 :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
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 :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
end
end
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 :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 :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
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 :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
end
end

View File

@ -1,3 +1,3 @@
one:
id: 1
one:
id: 1
name: One

View File

@ -1,34 +1,34 @@
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
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

View File

@ -1,3 +1,3 @@
top:
id: 1
top:
id: 1
name: Top

View File

@ -1,38 +1,38 @@
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
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

View File

@ -1,27 +1,27 @@
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
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

View File

@ -1,32 +1,32 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')
plugin_test_dir = File.dirname(__FILE__)
require 'rubygems'
require 'bundler/setup'
require 'rspec'
require 'logger'
require 'active_support'
require 'active_model'
require 'active_record'
require 'action_controller'
require 'awesome_nested_set'
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
load(File.join(plugin_test_dir, "db", "schema.rb"))
require 'support/models'
require 'rspec/rails'
RSpec.configure do |config|
config.fixture_path = "#{plugin_test_dir}/fixtures"
config.use_transactional_fixtures = true
end
$:.unshift(File.dirname(__FILE__) + '/../lib')
plugin_test_dir = File.dirname(__FILE__)
require 'rubygems'
require 'bundler/setup'
require 'rspec'
require 'logger'
require 'active_support'
require 'active_model'
require 'active_record'
require 'action_controller'
require 'awesome_nested_set'
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
load(File.join(plugin_test_dir, "db", "schema.rb"))
require 'support/models'
require 'rspec/rails'
RSpec.configure do |config|
config.fixture_path = "#{plugin_test_dir}/fixtures"
config.use_transactional_fixtures = true
end

View File

@ -1,72 +1,72 @@
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 RenamedColumns < ActiveRecord::Base
acts_as_nested_set :parent_column => 'mother_id', :left_column => 'red', :right_column => 'black'
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
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 RenamedColumns < ActiveRecord::Base
acts_as_nested_set :parent_column => 'mother_id', :left_column => 'red', :right_column => 'black'
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