take the root Query class rather than active records. also re-allow passing an order to acts_as_nested_set. all to make the tests happy

pull/1186/head
Martin Linkhorst 12 years ago
parent 085a44a7ff
commit b6aac286d4
  1. 2
      app/models/issue.rb
  2. 2
      app/models/project.rb
  3. 2
      app/models/query/statement_invalid.rb
  4. 4
      app/models/user.rb
  5. 47
      config/initializers/10-patches.rb
  6. 9
      test/unit/project_test.rb

@ -87,7 +87,7 @@ class Issue < ActiveRecord::Base
scope :with_query, lambda {|query|
{
:conditions => Query.merge_conditions(query.statement)
:conditions => ::Query.merge_conditions(query.statement)
}
}

@ -809,7 +809,7 @@ class Project < ActiveRecord::Base
# Copies queries from +project+
def copy_queries(project)
project.queries.each do |query|
new_query = Query.new
new_query = ::Query.new
new_query.attributes = query.attributes.dup.except("id", "project_id", "sort_criteria")
new_query.sort_criteria = query.sort_criteria if query.sort_criteria
new_query.project = self

@ -1,2 +1,2 @@
class Query::StatementInvalid < ActiveRecord::StatementInvalid
class ::Query::StatementInvalid < ActiveRecord::StatementInvalid
end

@ -641,7 +641,7 @@ class User < Principal
klass.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
end
[TimeEntry, Journal, Query].each do |klass|
[TimeEntry, Journal, ::Query].each do |klass|
klass.update_all ['user_id = ?', substitute.id], ['user_id = ?', id]
end
@ -671,7 +671,7 @@ class User < Principal
end
def delete_associated_public_queries
Query.delete_all ['user_id = ? AND is_public = ?', id, false]
::Query.delete_all ['user_id = ? AND is_public = ?', id, false]
end
end

@ -14,7 +14,7 @@
require 'active_record'
ActiveSupport::Deprecation.silenced = true
module ActiveRecord
class Base
include Redmine::I18n
@ -286,3 +286,48 @@ module CollectiveIdea
end
end
end
module CollectiveIdea #:nodoc:
module Acts #:nodoc:
module NestedSet #:nodoc:
module Model
module ClassMethods
# Rebuilds the left & rights if unset or invalid.
# Also very useful for converting from acts_as_tree.
def rebuild!(validate_nodes = true)
# Don't rebuild a valid tree.
return true if valid?
scope = lambda{|node|}
if acts_as_nested_set_options[:scope]
scope = lambda{|node|
scope_column_names.inject(""){|str, column_name|
str << "AND #{connection.quote_column_name(column_name)} = #{connection.quote(node.send(column_name.to_sym))} "
}
}
end
indices = {}
set_left_and_rights = lambda do |node|
# set left
node[left_column_name] = indices[scope.call(node)] += 1
# find
where(["#{quoted_parent_column_name} = ? #{scope.call(node)}", node]).order("#{quoted_left_column_name}, #{quoted_right_column_name}, #{acts_as_nested_set_options[:order] || 'id'}").each{|n| set_left_and_rights.call(n) }
# set right
node[right_column_name] = indices[scope.call(node)] += 1
node.save!(:validate => validate_nodes)
end
# Find root node(s)
root_nodes = where("#{quoted_parent_column_name} IS NULL").order("#{quoted_left_column_name}, #{quoted_right_column_name}, #{acts_as_nested_set_options[:order] || 'id'}").each do |root_node|
# setup index for this scope
indices[scope.call(root_node)] ||= 0
set_left_and_rights.call(root_node)
end
end
end
end
end
end
end

@ -424,16 +424,21 @@ class ProjectTest < ActiveSupport::TestCase
context "description" do
setup do
@project = Project.generate!
@project.description = ("Abcd " * 5 + "\n") * 11
# this block unfortunately isn't run
# move first two lines of next to specs up here
# when you know that it will work
end
def test_short_description_returns_shortened_description
@project = Project.generate!
@project.description = ("Abcd " * 5 + "\n") * 11
@project.summary = ""
assert_equal (("Abcd " * 5 + "\n") * 10)[0..-2] + "...", @project.short_description
end
def test_short_description_returns_summary
@project = Project.generate!
@project.description = ("Abcd " * 5 + "\n") * 11
@project.summary = "In short"
assert_equal "In short", @project.short_description
end

Loading…
Cancel
Save