Skip to content

Commit

Permalink
Added RCOV, minor change to primary_key_format
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankroes committed Oct 26, 2010
1 parent c410dcf commit bb6d920
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,5 @@ doc
*.gem
**/*.log
**/*.db
test/database.yml
test/database.yml
coverage
10 changes: 10 additions & 0 deletions Rakefile
@@ -1,6 +1,7 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rcov/rcovtask'

desc 'Default: run unit tests.'
task :default => :test
Expand All @@ -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'
Expand Down
5 changes: 2 additions & 3 deletions lib/ancestry/has_ancestry.rb
Expand Up @@ -31,8 +31,8 @@ def has_ancestry options = {}
self.base_class = self

# Validate format of ancestry column value
key_format = options[:primary_key_format] || /[0-9]+/
validates_format_of ancestry_column, :with => /\A#{key_format.source}(\/#{key_format.source})*\Z/, :allow_nil => true
primary_key_format = options[:primary_key_format] || /[0-9]+/
validates_format_of ancestry_column, :with => /\A#{primary_key_format.source}(\/#{primary_key_format.source})*\Z/, :allow_nil => true

# Validate that the ancestor ids don't include own id
validate :ancestry_exclude_self
Expand All @@ -44,7 +44,6 @@ def has_ancestry options = {}
# Workaround to support Rails 2
scope_method = if rails_3 then :scope else :named_scope end


# Named scopes
send scope_method, :roots, :conditions => {ancestry_column => nil}
send scope_method, :ancestors_of, lambda { |object| {:conditions => to_node(object).ancestor_conditions} }
Expand Down

0 comments on commit bb6d920

Please sign in to comment.