Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order option with arel nodes #79

Merged
merged 3 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acts_as_tree.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.add_dependency "activerecord", ">= 3.0.0"

# Dependencies (installed via 'bundle install')...
s.add_development_dependency "sqlite3"
s.add_development_dependency "sqlite3", "~> 1.3.6"
s.add_development_dependency "rdoc"
s.add_development_dependency "minitest", ">= 4.7.5"
end
23 changes: 10 additions & 13 deletions lib/acts_as_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,19 @@ def acts_as_tree(options = {})
inverse_of: :parent
end

class_eval <<-EOV
include ActsAsTree::InstanceMethods
include ActsAsTree::InstanceMethods

def self.default_tree_order
order_option = #{configuration[:order].inspect}
order(order_option)
end
define_singleton_method :default_tree_order do
order(configuration[:order])
end

def self.root
self.roots.first
end
define_singleton_method :root do
self.roots.first
end

def self.roots
where(:#{configuration[:foreign_key]} => nil).default_tree_order
end
EOV
define_singleton_method :roots do
where(configuration[:foreign_key] => nil).default_tree_order
end

# Returns a hash of all nodes grouped by their level in the tree structure.
#
Expand Down
2 changes: 1 addition & 1 deletion test/acts_as_tree_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setup_db(options = {})
# AR keeps printing annoying schema statements
capture_stdout do
ActiveRecord::Base.logger
ActiveRecord::Schema.define(version: 1) do
ActiveRecord::Schema.define do
create_table :mixins, force: true do |t|
t.column :type, :string
t.column :parent_id, :integer
Expand Down