awesome_nested_set: import git 2-1-stable branch revision 606847769 (#6579)

https://github.com/collectiveidea/awesome_nested_set/commit/606847769

git-svn-id: http://svn.redmine.org/redmine/trunk@13143 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA
2014-05-24 10:16:38 +00:00
parent 5368af4847
commit 43e84c6c10
26 changed files with 1282 additions and 922 deletions

View File

@@ -77,7 +77,10 @@ describe "Helper" do
actual = nested_set_options(Category.all) do |c|
"#{'-' * c.level} #{c.name}"
end
actual.should == expected
actual.length.should == expected.length
expected.flatten.each do |node|
actual.flatten.should include(node)
end
end
it "test_nested_set_options_with_array_as_argument_with_mover" do
@@ -90,7 +93,10 @@ describe "Helper" do
actual = nested_set_options(Category.all, categories(:child_2)) do |c|
"#{'-' * c.level} #{c.name}"
end
actual.should == expected
actual.length.should == expected.length
expected.flatten.each do |node|
actual.flatten.should include(node)
end
end
end
end

View File

@@ -81,6 +81,12 @@ describe "AwesomeNestedSet" do
Default.new.quoted_depth_column_name.should == quoted
end
it "quoted_order_column_name" do
quoted = Default.connection.quote_column_name('lft')
Default.quoted_order_column_name.should == quoted
Default.new.quoted_order_column_name.should == quoted
end
it "left_column_protected_from_assignment" do
lambda {
Category.new.lft = 1
@@ -104,7 +110,12 @@ describe "AwesomeNestedSet" do
end
it "roots_class_method" do
Category.roots.should == Category.find_all_by_parent_id(nil)
found_by_us = Category.where(:parent_id => nil).to_a
found_by_roots = Category.roots.to_a
found_by_us.length.should == found_by_roots.length
found_by_us.each do |root|
found_by_roots.should include(root)
end
end
it "root_class_method" do
@@ -131,7 +142,6 @@ describe "AwesomeNestedSet" do
end
it "leaves_class_method" do
Category.find(:all, :conditions => "#{Category.right_column_name} - #{Category.left_column_name} = 1").should == Category.leaves
Category.leaves.count.should == 4
Category.leaves.should include(categories(:child_1))
Category.leaves.should include(categories(:child_2_1))
@@ -158,7 +168,7 @@ describe "AwesomeNestedSet" do
it "self_and_ancestors" do
child = categories(:child_2_1)
self_and_ancestors = [categories(:top_level), categories(:child_2), child]
self_and_ancestors.should == child.self_and_ancestors
child.self_and_ancestors.should == self_and_ancestors
end
it "ancestors" do
@@ -433,8 +443,8 @@ describe "AwesomeNestedSet" do
categories(:child_2).parent.should be_nil
categories(:child_2).level.should == 0
categories(:child_2_1).level.should == 1
categories(:child_2).left.should == 1
categories(:child_2).right.should == 4
categories(:child_2).left.should == 7
categories(:child_2).right.should == 10
Category.valid?.should be_true
end
@@ -775,14 +785,14 @@ describe "AwesomeNestedSet" do
it "quoting_of_multi_scope_column_names" do
## Proper Array Assignment for different DBs as per their quoting column behavior
if Note.connection.adapter_name.match(/Oracle/)
if Note.connection.adapter_name.match(/oracle/i)
expected_quoted_scope_column_names = ["\"NOTABLE_ID\"", "\"NOTABLE_TYPE\""]
elsif Note.connection.adapter_name.match(/Mysql/)
elsif Note.connection.adapter_name.match(/mysql/i)
expected_quoted_scope_column_names = ["`notable_id`", "`notable_type`"]
else
expected_quoted_scope_column_names = ["\"notable_id\"", "\"notable_type\""]
end
expected_quoted_scope_column_names.should == Note.quoted_scope_column_names
Note.quoted_scope_column_names.should == expected_quoted_scope_column_names
end
it "equal_in_same_scope" do

View File

@@ -2,6 +2,7 @@ plugin_test_dir = File.dirname(__FILE__)
require 'rubygems'
require 'bundler/setup'
require 'pry'
require 'logger'
require 'active_record'
@@ -22,6 +23,7 @@ require 'support/models'
require 'action_controller'
require 'rspec/rails'
require 'database_cleaner'
RSpec.configure do |config|
config.fixture_path = "#{plugin_test_dir}/fixtures"
config.use_transactional_fixtures = true