closure_tree 1.0.0 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,39 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
6
- # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
8
- config.cache_classes = true
9
-
10
- # Configure static asset server for tests with Cache-Control for performance
11
- config.serve_static_assets = true
12
- config.static_cache_control = "public, max-age=3600"
13
-
14
- # Log error messages when you accidentally call methods on nil
15
- config.whiny_nils = true
16
-
17
- # Show full error reports and disable caching
18
- config.consider_all_requests_local = true
19
- config.action_controller.perform_caching = false
20
-
21
- # Raise exceptions instead of rendering exception templates
22
- config.action_dispatch.show_exceptions = false
23
-
24
- # Disable request forgery protection in test environment
25
- config.action_controller.allow_forgery_protection = false
26
-
27
- # Tell Action Mailer not to deliver emails to the real world.
28
- # The :test delivery method accumulates sent emails in the
29
- # ActionMailer::Base.deliveries array.
30
- config.action_mailer.delivery_method = :test
31
-
32
- # Use SQL instead of Active Record's schema dumper when creating the test database.
33
- # This is necessary if your schema can't be completely dumped by the schema dumper,
34
- # like if you have constraints or database-specific column types
35
- # config.active_record.schema_format = :sql
36
-
37
- # Print deprecation notices to the stderr
38
- config.active_support.deprecation = :stderr
39
- end
@@ -1,3 +0,0 @@
1
- Dummy::Application.routes.draw do
2
-
3
- end
@@ -1,24 +0,0 @@
1
- class CreateTags < ActiveRecord::Migration
2
- def change
3
-
4
- create_table :tags do |t|
5
- t.string :name
6
- t.string :title
7
- t.integer :parent_id
8
- t.timestamps
9
- end
10
-
11
- create_table :tags_hierarchies, :id => false do |t|
12
- t.integer :ancestor_id, :null => false # ID of the parent/grandparent/great-grandparent/... tag
13
- t.integer :descendant_id, :null => false # ID of the target tag
14
- t.integer :generations, :null => false # Number of generations between the ancestor and the descendant. Parent/child = 1, for example.
15
- end
16
-
17
- # For "all progeny of..." selects:
18
- add_index :tags_hierarchies, [:ancestor_id, :descendant_id], :unique => true
19
-
20
- # For "all ancestors of..." selects
21
- add_index :tags_hierarchies, :descendant_id
22
-
23
- end
24
- end
@@ -1,32 +0,0 @@
1
- # This file is auto-generated from the current state of the database. Instead
2
- # of editing this file, please use the migrations feature of Active Record to
3
- # incrementally modify your database, and then regenerate this schema definition.
4
- #
5
- # Note that this schema.rb definition is the authoritative source for your
6
- # database schema. If you need to create the application database on another
7
- # system, you should be using db:schema:load, not running all the migrations
8
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
- # you'll amass, the slower it'll run and the greater likelihood for issues).
10
- #
11
- # It's strongly recommended to check this file into your version control system.
12
-
13
- ActiveRecord::Schema.define(:version => 20110522004834) do
14
-
15
- create_table "tags", :force => true do |t|
16
- t.string "name"
17
- t.string "title"
18
- t.integer "parent_id"
19
- t.datetime "created_at"
20
- t.datetime "updated_at"
21
- end
22
-
23
- create_table "tags_hierarchies", :id => false, :force => true do |t|
24
- t.integer "ancestor_id", :null => false
25
- t.integer "descendant_id", :null => false
26
- t.integer "generations", :null => false
27
- end
28
-
29
- add_index "tags_hierarchies", ["ancestor_id", "descendant_id"], :name => "index_tags_hierarchies_on_ancestor_id_and_descendant_id", :unique => true
30
- add_index "tags_hierarchies", ["descendant_id"], :name => "index_tags_hierarchies_on_descendant_id"
31
-
32
- end
File without changes
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
-
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
6
- require 'rails/commands'
@@ -1,118 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TagTest < ActiveSupport::TestCase
4
-
5
- fixtures :tags
6
-
7
- def setup
8
- Tag.rebuild!
9
- end
10
-
11
- def test_roots
12
- roots = Tag.roots.to_a
13
- assert roots.include?(tags(:people))
14
- assert roots.include?(tags(:events))
15
- assert !roots.include?(tags(:child))
16
- assert tags(:people).root?
17
- assert !tags(:child).root?
18
- end
19
-
20
- def test_add_child
21
- sb = Tag.create!(:name => "Santa Barbara")
22
- assert sb.leaf?
23
- tags(:california).add_child sb
24
- assert sb.leaf?
25
- validate_city_tag sb
26
- end
27
-
28
- def test_add_through_children
29
- eg = Tag.create!(:name => "El Granada")
30
- assert eg.leaf?
31
- tags(:california).children << eg
32
- assert eg.leaf?
33
- validate_city_tag eg
34
- end
35
-
36
- def test_level
37
- assert_equal 0, tags(:grandparent).level
38
- assert_equal 1, tags(:parent).level
39
- assert_equal 2, tags(:child).level
40
- end
41
-
42
- def test_parent
43
- assert_equal nil, tags(:grandparent).parent
44
- assert_equal tags(:grandparent), tags(:parent).parent
45
- assert_equal tags(:parent), tags(:child).parent
46
- end
47
-
48
- def test_children
49
- assert tags(:grandparent).children.include? tags(:parent)
50
- assert tags(:parent).children.include? tags(:child)
51
- assert tags(:child).children.empty?
52
- end
53
-
54
- def test_ancestors
55
- assert_equal [tags(:parent), tags(:grandparent)], tags(:child).ancestors
56
- assert_equal [tags(:child), tags(:parent), tags(:grandparent)], tags(:child).self_and_ancestors
57
- end
58
-
59
- def test_ancestry_path
60
- assert_equal %w{grandparent parent child}, tags(:child).ancestry_path
61
- assert_equal %w{grandparent parent child}, tags(:child).ancestry_path(:name)
62
- assert_equal %w{Nonnie Mom Kid}, tags(:child).ancestry_path(:title)
63
- end
64
-
65
- def test_find_by_path
66
- # class method:
67
- assert_equal tags(:child), Tag.find_by_path(%w{grandparent parent child})
68
- assert_equal tags(:child), Tag.find_by_path(:title, %w{Nonnie Mom Kid})
69
- # instance method:
70
- assert_equal tags(:child), tags(:parent).find_by_path(%w{child})
71
- assert_equal tags(:child), tags(:parent).find_by_path(:title, %w{Kid})
72
- assert_equal tags(:child), tags(:grandparent).find_by_path(%w{parent child})
73
- assert_equal tags(:child), tags(:grandparent).find_by_path(:title, %w{Mom Kid})
74
- assert_nil tags(:parent).find_by_path(%w{child larvae})
75
- end
76
-
77
- def test_find_or_create_by_path
78
- # class method:
79
- assert_equal tags(:child), Tag.find_or_create_by_path(%w{grandparent parent child})
80
- assert_equal tags(:child), Tag.find_or_create_by_path(:title, %w{Nonnie Mom Kid})
81
- assert_equal %w{events anniversary}, Tag.find_or_create_by_path(%w{events anniversary}).ancestry_path
82
- a = Tag.find_or_create_by_path(%w{a})
83
- assert_equal %w{a}, a.ancestry_path
84
- # instance method:
85
- assert_equal %w{a b c}, a.find_or_create_by_path(%w{b c}).ancestry_path
86
- end
87
-
88
- def test_descendants
89
- assert_equal [tags(:child)], tags(:parent).descendants
90
- assert_equal [tags(:parent), tags(:child)], tags(:parent).self_and_descendants
91
-
92
- assert_equal [tags(:parent), tags(:child)], tags(:grandparent).descendants
93
- assert_equal [tags(:grandparent), tags(:parent), tags(:child)], tags(:grandparent).self_and_descendants
94
-
95
- assert_equal "grandparent > parent > child", tags(:grandparent).self_and_descendants.collect { |t| t.name }.join(" > ")
96
- end
97
-
98
- def validate_city_tag city
99
- assert tags(:california).children.include?(city)
100
- assert_equal [tags(:california), tags(:united_states), tags(:places)], city.ancestors
101
- assert_equal [city, tags(:california), tags(:united_states), tags(:places)], city.self_and_ancestors
102
- end
103
-
104
- def test_root
105
- assert_equal tags(:grandparent), tags(:grandparent).root
106
- assert_equal tags(:grandparent), tags(:parent).root
107
- assert_equal tags(:grandparent), tags(:child).root
108
- end
109
-
110
- def test_leaves
111
- assert Tag.leaves.include? tags(:child)
112
- assert Tag.leaves.select{|t|!t.leaf?}.empty?
113
- assert_equal [tags(:child)], tags(:grandparent).leaves
114
- assert_equal [tags(:child)], tags(:parent).leaves
115
- assert_equal [tags(:child)], tags(:child).leaves
116
- end
117
- end
118
-
data/test/test_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
3
-
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
- require "rails/test_help"
6
-
7
- Rails.backtrace_cleaner.remove_silencers!
8
-
9
- # Load support files
10
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }