Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed it for Rails 3.2 and broke it for 2.x, changed version 1.2.6 an…

…d activerecord dependency to >= 3.0.0
  • Loading branch information...
commit b5fd912e58339c728d714f4bb3d17dc96cec2b41 1 parent f99359f
Stefan Kroes authored
View
7 Gemfile
@@ -0,0 +1,7 @@
+source 'http://rubygems.org'
+
+gemspec
+
+group :test do
+ gem 'sqlite3'
+end
View
33 Gemfile.lock
@@ -0,0 +1,33 @@
+PATH
+ remote: .
+ specs:
+ ancestry (1.2.5)
+ activerecord (>= 2.2.2)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activemodel (3.2.2)
+ activesupport (= 3.2.2)
+ builder (~> 3.0.0)
+ activerecord (3.2.2)
+ activemodel (= 3.2.2)
+ activesupport (= 3.2.2)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activesupport (3.2.2)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.0)
+ i18n (0.6.0)
+ multi_json (1.2.0)
+ sqlite3 (1.3.5)
+ tzinfo (0.3.32)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ ancestry!
+ sqlite3
View
12 Rakefile
@@ -1,7 +1,6 @@
require 'rake'
require 'rake/testtask'
-require 'rake/rdoctask'
-require 'rcov/rcovtask'
+require 'rdoc/task'
desc 'Default: run unit tests.'
task :default => :test
@@ -13,15 +12,6 @@ Rake::TestTask.new(:test) do |t|
t.verbose = true
end
-desc 'Determine test code coverage for the ancestry plugin.'
-Rcov::RcovTask.new(:coverage) do |t|
- t.libs << 'lib'
- t.test_files = FileList['test/**/*_test.rb']
- t.verbose = true
- t.output_dir = "test/coverage"
- t.rcov_opts << "-x /gems/,/library/"
-end
-
desc 'Generate documentation for the ancestry plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'doc'
View
4 ancestry.gemspec
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
s.description = 'Organise ActiveRecord model into a tree structure'
s.summary = 'Ancestry allows the records of a ActiveRecord model to be organised in a tree structure, using a single, intuitively formatted database column. It exposes all the standard tree structure relations (ancestors, parent, root, children, siblings, descendants) and all of them can be fetched in a single sql query. Additional features are named_scopes, integrity checking, integrity restoration, arrangement of (sub)tree into hashes and different strategies for dealing with orphaned records.'
- s.version = '1.2.5'
+ s.version = '1.2.6'
s.author = 'Stefan Kroes'
s.email = 's.a.kroes@gmail.com'
@@ -22,5 +22,5 @@ Gem::Specification.new do |s|
'README.rdoc'
]
- s.add_dependency 'activerecord', '>= 2.2.2'
+ s.add_dependency 'activerecord', '>= 3.0.0'
end
View
4 lib/ancestry/has_ancestry.rb
@@ -51,8 +51,8 @@ def has_ancestry options = {}
send scope_method, :descendants_of, lambda { |object| {:conditions => to_node(object).descendant_conditions} }
send scope_method, :subtree_of, lambda { |object| {:conditions => to_node(object).subtree_conditions} }
send scope_method, :siblings_of, lambda { |object| {:conditions => to_node(object).sibling_conditions} }
- send scope_method, :ordered_by_ancestry, :order => "(case when #{table_name}.#{ancestry_column} is null then 0 else 1 end), #{table_name}.#{ancestry_column}"
- send scope_method, :ordered_by_ancestry_and, lambda { |order| {:order => "(case when #{table_name}.#{ancestry_column} is null then 0 else 1 end), #{table_name}.#{ancestry_column}, #{order}"} }
+ send scope_method, :ordered_by_ancestry, reorder("(case when #{table_name}.#{ancestry_column} is null then 0 else 1 end), #{table_name}.#{ancestry_column}")
+ send scope_method, :ordered_by_ancestry_and, lambda { |order| reorder("(case when #{table_name}.#{ancestry_column} is null then 0 else 1 end), #{table_name}.#{ancestry_column}, #{order}") }
# Update descendants with new ancestry before save
before_save :update_descendants_with_new_ancestry
View
26 test/environment.rb
@@ -1,5 +1,11 @@
require 'rubygems'
-Gem.activate 'activerecord', ENV['ar'] || '3.0.0'
+
+if ENV['ar'].nil?
+ gem 'activerecord'
+else
+ gem 'activerecord', ENV['ar']
+end
+
require 'active_record'
require 'active_support/test_case'
require 'test/unit'
@@ -7,14 +13,14 @@
class AncestryTestDatabase
def self.setup
- ActiveRecord::Base.logger
+ ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new('log/test.log')
ActiveRecord::Base.establish_connection YAML.load(File.open(File.join(File.dirname(__FILE__), 'database.yml')).read)[ENV['db'] || 'sqlite3']
end
def self.with_model options = {}
- depth = options.delete(:depth) || 0
- width = options.delete(:width) || 0
- extra_columns = options.delete(:extra_columns)
+ depth = options.delete(:depth) || 0
+ width = options.delete(:width) || 0
+ extra_columns = options.delete(:extra_columns)
primary_key_type = options.delete(:primary_key_type) || :default
ActiveRecord::Base.connection.create_table 'test_nodes', :id => (primary_key_type == :default) do |table|
@@ -32,9 +38,10 @@ def self.with_model options = {}
const_set 'TestNode', model
if primary_key_type == :string
- model.before_create { self.id = ActiveSupport::SecureRandom.hex(10) }
+ model.before_create { self.id = SecureRandom.hex(10) }
end
- model.send :set_table_name, 'test_nodes'
+ model.table_name = 'test_nodes'
+ model.primary_key = :id if primary_key_type == :string
model.has_ancestry options unless options.delete(:skip_ancestry)
if depth > 0
@@ -43,8 +50,9 @@ def self.with_model options = {}
yield model
end
ensure
+ model.reset_column_information
ActiveRecord::Base.connection.drop_table 'test_nodes'
- remove_const "TestNode"
+ remove_const 'TestNode'
end
end
@@ -62,6 +70,6 @@ def self.create_test_nodes model, depth, width, parent = nil
puts "\nRunning Ancestry test suite:"
puts " Ruby: #{RUBY_VERSION}"
-puts " ActiveRecord: #{ENV['ar'] || '3.0.0'}"
+puts " ActiveRecord: #{ActiveRecord::VERSION::STRING}"
puts " Database: #{ActiveRecord::Base.connection.adapter_name}\n\n"
View
10 test/has_ancestry_test.rb
@@ -704,4 +704,14 @@ def test_sort_by_ancestry
assert_equal [n1, n2, n4, n3, n5].map(&:id), arranged.map(&:id)
end
end
+
+ def test_arrangement_nesting
+ AncestryTestDatabase.with_model :extra_columns => {:name => :string} do |model|
+ model.send :default_scope, model.order('name')
+
+ model.create!(:name => 'Linux').children.create! :name => 'Debian'
+
+ assert_equal 1, model.arrange.count
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.