Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Fixed it for Rails 3.2 and broke it for 2.x, changed version …

…1.2.6 and activerecord dependency to >= 3.0.0", as it is an incomplete commit. Rails 3-specific code has been moved to the rails3 branch.

This reverts commit b5fd912.
  • Loading branch information...
commit 91bc017192701fe90c39956817e29495c4494985 1 parent b5fd912
Gerjan Stokkink authored
View
7 Gemfile
@@ -1,7 +0,0 @@
-source 'http://rubygems.org'
-
-gemspec
-
-group :test do
- gem 'sqlite3'
-end
View
33 Gemfile.lock
@@ -1,33 +0,0 @@
-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,6 +1,7 @@
require 'rake'
require 'rake/testtask'
-require 'rdoc/task'
+require 'rake/rdoctask'
+require 'rcov/rcovtask'
desc 'Default: run unit tests.'
task :default => :test
@@ -12,6 +13,15 @@ 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.6'
+ s.version = '1.2.5'
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', '>= 3.0.0'
+ s.add_dependency 'activerecord', '>= 2.2.2'
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, 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}") }
+ 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}"} }
# Update descendants with new ancestry before save
before_save :update_descendants_with_new_ancestry
View
26 test/environment.rb
@@ -1,11 +1,5 @@
require 'rubygems'
-
-if ENV['ar'].nil?
- gem 'activerecord'
-else
- gem 'activerecord', ENV['ar']
-end
-
+Gem.activate 'activerecord', ENV['ar'] || '3.0.0'
require 'active_record'
require 'active_support/test_case'
require 'test/unit'
@@ -13,14 +7,14 @@
class AncestryTestDatabase
def self.setup
- ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new('log/test.log')
+ ActiveRecord::Base.logger
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|
@@ -38,10 +32,9 @@ def self.with_model options = {}
const_set 'TestNode', model
if primary_key_type == :string
- model.before_create { self.id = SecureRandom.hex(10) }
+ model.before_create { self.id = ActiveSupport::SecureRandom.hex(10) }
end
- model.table_name = 'test_nodes'
- model.primary_key = :id if primary_key_type == :string
+ model.send :set_table_name, 'test_nodes'
model.has_ancestry options unless options.delete(:skip_ancestry)
if depth > 0
@@ -50,9 +43,8 @@ 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
@@ -70,6 +62,6 @@ def self.create_test_nodes model, depth, width, parent = nil
puts "\nRunning Ancestry test suite:"
puts " Ruby: #{RUBY_VERSION}"
-puts " ActiveRecord: #{ActiveRecord::VERSION::STRING}"
+puts " ActiveRecord: #{ENV['ar'] || '3.0.0'}"
puts " Database: #{ActiveRecord::Base.connection.adapter_name}\n\n"
View
10 test/has_ancestry_test.rb
@@ -704,14 +704,4 @@ 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.