Skip to content
Permalink
Browse files

changed config -> tree_config to avoid method name clashing

  • Loading branch information...
dhoss committed Nov 2, 2014
1 parent a691003 commit d76dc47c5091b9924a955e6186bf91325c0deb4e
Showing with 10 additions and 8 deletions.
  1. +5 −4 lib/treeify.rb
  2. +1 −1 spec/spec_helper.rb
  3. +4 −3 spec/treeify_spec.rb
@@ -13,17 +13,18 @@ module Treeify
belongs_to :parent,
class_name: self,
foreign_key: "parent_id"

class_attribute :cols
scope :roots, -> { where(parent_id: nil) }
scope :tree_for, ->(instance) { where("#{table_name}.id IN (#{tree_sql_for(instance)})").order("#{table_name}.id") }
scope :tree_for_ancestors, ->(instance) { where("#{table_name}.id IN (#{tree_sql_for_ancestors(instance)})").order("#{table_name}.id") }

end

module ClassMethods

def config(hash = {})
# apparently columns is a reserved word in rails
self.cols = hash[:cols]

def tree_config(hash = {})
self.cols = hash[:cols]
end

def tree_sql(instance)
@@ -18,7 +18,7 @@

class Node < ActiveRecord::Base
include Treeify
config({cols: [:name]})
tree_config({cols: [:name]})

validates_uniqueness_of :name
validates_uniqueness_of :parent_id, :scope=> :id
@@ -2,6 +2,10 @@

describe Treeify do
describe "Initialization" do
it "has the correct config values" do
expect(Node.cols).to eq([:name])
end

it "is set up correctly" do
expect(Node.table_name).to eq("nodes")
expect(Node.cols).to eq([:name])
@@ -118,9 +122,6 @@
}
])
end



end
end

0 comments on commit d76dc47

Please sign in to comment.
You can’t perform that action at this time.