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.
data/spec/user_spec.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe "empty db" do
4
+
5
+ before :each do
6
+ User.delete_all
7
+ ReferralHierarchy.delete_all
8
+ end
9
+
10
+ context "empty db" do
11
+ it "should return no entities" do
12
+ User.roots.should be_empty
13
+ User.leaves.should be_empty
14
+ end
15
+ end
16
+
17
+ context "1 user db" do
18
+ it "should return the only entity as a root and leaf" do
19
+ a = User.create!(:email => "me@domain.com")
20
+ User.roots.should == [a]
21
+ User.leaves.should == [a]
22
+ end
23
+ end
24
+
25
+ context "2 user db" do
26
+ it "should return a simple root and leaf" do
27
+ root = User.create!(:email => "first@t.co")
28
+ leaf = root.children.create!(:email => "second@t.co")
29
+ User.roots.should == [root]
30
+ User.leaves.should == [leaf]
31
+ end
32
+ end
33
+
34
+
35
+ context "3 User collection.create db" do
36
+ before :each do
37
+ @root = User.create! :email => "poppy@t.co"
38
+ @mid = @root.children.create! :email => "matt@t.co"
39
+ @leaf = @mid.children.create! :email => "james@t.co"
40
+ end
41
+
42
+ it "should create all Users" do
43
+ User.all.should =~ [@root, @mid, @leaf]
44
+ end
45
+
46
+ it "should return a root and leaf without middle User" do
47
+ User.roots.should == [@root]
48
+ User.leaves.should == [@leaf]
49
+ end
50
+
51
+ it "should delete leaves" do
52
+ User.leaves.destroy_all
53
+ User.roots.should == [@root] # untouched
54
+ User.leaves.should == [@mid]
55
+ end
56
+
57
+ it "should delete roots and maintain hierarchies" do
58
+ User.roots.destroy_all
59
+ assert_mid_and_leaf_remain
60
+ end
61
+
62
+ it "should root all children" do
63
+ @root.destroy
64
+ assert_mid_and_leaf_remain
65
+ end
66
+ end
67
+ end
68
+
69
+ def assert_mid_and_leaf_remain
70
+ @mid.ancestry_path.should == %w{matt@t.co}
71
+ @leaf.ancestry_path.should == %w{matt@t.co james@t.co}
72
+ @mid.self_and_descendants.should =~ [@mid, @leaf]
73
+ User.roots.should == [@mid]
74
+ User.leaves.should == [@leaf]
75
+ end
metadata CHANGED
@@ -1,36 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: closure_tree
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 62196449
5
+ prerelease: 6
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ - beta
11
+ - 1
12
+ version: 2.0.0.beta1
6
13
  platform: ruby
7
- authors:
8
- - matthew-github@mceachen.org
14
+ authors:
15
+ - Matthew McEachen
9
16
  autorequire:
10
17
  bindir: bin
11
18
  cert_chain: []
12
- date: 2011-07-02 00:00:00.000000000 -07:00
13
- default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: activerecord
17
- requirement: &2154383840 !ruby/object:Gem::Requirement
19
+
20
+ date: 2011-10-27 00:00:00 Z
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
18
24
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 0
22
33
  version: 3.0.0
34
+ requirement: *id001
23
35
  type: :runtime
24
36
  prerelease: false
25
- version_requirements: *2154383840
26
- description: ! " A mostly-API-compatible replacement for the acts_as_tree and awesome_nested_set
27
- gems,\n but with much better mutation performance thanks to the Closure Tree storage
28
- algorithm\n"
37
+ name: activerecord
38
+ description: " A mostly-API-compatible replacement for the acts_as_tree and awesome_nested_set gems,\n but with much better mutation performance thanks to the Closure Tree storage algorithm\n"
29
39
  email:
40
+ - matthew-github@mceachen.org
30
41
  executables: []
42
+
31
43
  extensions: []
44
+
32
45
  extra_rdoc_files: []
33
- files:
46
+
47
+ files:
34
48
  - lib/closure_tree/acts_as_tree.rb
35
49
  - lib/closure_tree/version.rb
36
50
  - lib/closure_tree.rb
@@ -38,70 +52,54 @@ files:
38
52
  - MIT-LICENSE
39
53
  - Rakefile
40
54
  - README.md
41
- - test/dummy/Rakefile
42
- - test/dummy/app/models/.gitkeep
43
- - test/dummy/app/models/tag.rb
44
- - test/dummy/config.ru
45
- - test/dummy/config/application.rb
46
- - test/dummy/config/boot.rb
47
- - test/dummy/config/database.yml
48
- - test/dummy/config/environment.rb
49
- - test/dummy/config/environments/development.rb
50
- - test/dummy/config/environments/production.rb
51
- - test/dummy/config/environments/test.rb
52
- - test/dummy/config/routes.rb
53
- - test/dummy/db/migrate/20110522004834_create_tags.rb
54
- - test/dummy/db/schema.rb
55
- - test/dummy/log/.gitkeep
56
- - test/dummy/script/rails
57
- - test/dummy/test/fixtures/tags.yml
58
- - test/dummy/test/unit/tag_test.rb
59
- - test/test_helper.rb
60
- has_rdoc: true
61
- homepage:
55
+ - spec/db/database.yml
56
+ - spec/db/schema.rb
57
+ - spec/fixtures/tags.yml
58
+ - spec/spec_helper.rb
59
+ - spec/support/models.rb
60
+ - spec/tag_spec.rb
61
+ - spec/user_spec.rb
62
+ homepage: http://matthew.mceachen.us/closure_tree
62
63
  licenses: []
64
+
63
65
  post_install_message:
64
66
  rdoc_options: []
65
- require_paths:
67
+
68
+ require_paths:
66
69
  - lib
67
- required_ruby_version: !ruby/object:Gem::Requirement
70
+ required_ruby_version: !ruby/object:Gem::Requirement
68
71
  none: false
69
- requirements:
70
- - - ! '>='
71
- - !ruby/object:Gem::Version
72
- version: '0'
73
- segments:
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
74
77
  - 0
75
- hash: -1776514194989324524
76
- required_rubygems_version: !ruby/object:Gem::Requirement
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
80
  none: false
78
- requirements:
79
- - - ! '>='
80
- - !ruby/object:Gem::Version
81
- version: '0'
81
+ requirements:
82
+ - - ">"
83
+ - !ruby/object:Gem::Version
84
+ hash: 25
85
+ segments:
86
+ - 1
87
+ - 3
88
+ - 1
89
+ version: 1.3.1
82
90
  requirements: []
91
+
83
92
  rubyforge_project:
84
- rubygems_version: 1.6.2
93
+ rubygems_version: 1.8.10
85
94
  signing_key:
86
95
  specification_version: 3
87
96
  summary: Hierarchies for ActiveRecord models using a Closure Tree storage algorithm
88
- test_files:
89
- - test/dummy/Rakefile
90
- - test/dummy/app/models/.gitkeep
91
- - test/dummy/app/models/tag.rb
92
- - test/dummy/config.ru
93
- - test/dummy/config/application.rb
94
- - test/dummy/config/boot.rb
95
- - test/dummy/config/database.yml
96
- - test/dummy/config/environment.rb
97
- - test/dummy/config/environments/development.rb
98
- - test/dummy/config/environments/production.rb
99
- - test/dummy/config/environments/test.rb
100
- - test/dummy/config/routes.rb
101
- - test/dummy/db/migrate/20110522004834_create_tags.rb
102
- - test/dummy/db/schema.rb
103
- - test/dummy/log/.gitkeep
104
- - test/dummy/script/rails
105
- - test/dummy/test/fixtures/tags.yml
106
- - test/dummy/test/unit/tag_test.rb
107
- - test/test_helper.rb
97
+ test_files:
98
+ - spec/db/database.yml
99
+ - spec/db/schema.rb
100
+ - spec/fixtures/tags.yml
101
+ - spec/spec_helper.rb
102
+ - spec/support/models.rb
103
+ - spec/tag_spec.rb
104
+ - spec/user_spec.rb
105
+ has_rdoc:
data/test/dummy/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env rake
2
- # Add your own tasks in files placed in lib/tasks ending in .rake,
3
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
-
5
- require File.expand_path('../config/application', __FILE__)
6
-
7
- Dummy::Application.load_tasks
File without changes
@@ -1,3 +0,0 @@
1
- class Tag < ActiveRecord::Base
2
- acts_as_tree
3
- end
data/test/dummy/config.ru DELETED
@@ -1,4 +0,0 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
- require ::File.expand_path('../config/environment', __FILE__)
4
- run Dummy::Application
@@ -1,53 +0,0 @@
1
- require File.expand_path('../boot', __FILE__)
2
-
3
- require 'rails/all'
4
-
5
- Bundler.require
6
- require "closure_tree"
7
-
8
- module Dummy
9
- class Application < Rails::Application
10
- # Settings in config/environments/* take precedence over those specified here.
11
- # Application configuration should go into files in config/initializers
12
- # -- all .rb files in that directory are automatically loaded.
13
-
14
- # Custom directories with classes and modules you want to be autoloadable.
15
- # config.autoload_paths += %W(#{config.root}/extras)
16
-
17
- # Only load the plugins named here, in the order given (default is alphabetical).
18
- # :all can be used as a placeholder for all plugins not explicitly named.
19
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
-
21
- # Activate observers that should always be running.
22
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
-
24
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
- # config.time_zone = 'Central Time (US & Canada)'
27
-
28
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
- # config.i18n.default_locale = :de
31
-
32
- # Please note that JavaScript expansions are *ignored altogether* if the asset
33
- # pipeline is enabled (see config.assets.enabled below). Put your defaults in
34
- # app/assets/javascripts/application.js in that case.
35
- #
36
- # JavaScript files you want as :defaults (application.js is always included).
37
- # config.action_view.javascript_expansions[:defaults] = %w(prototype prototype_ujs)
38
-
39
-
40
- # Configure the default encoding used in templates for Ruby 1.9.
41
- config.encoding = "utf-8"
42
-
43
- # Configure sensitive parameters which will be filtered from the log file.
44
- config.filter_parameters += [:password]
45
-
46
- # Enable IdentityMap for Active Record, to disable set to false or remove the line below.
47
- config.active_record.identity_map = true
48
-
49
- # Enable the asset pipeline
50
- config.assets.enabled = true
51
- end
52
- end
53
-
@@ -1,10 +0,0 @@
1
- require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
-
4
- if File.exist?(gemfile)
5
- ENV['BUNDLE_GEMFILE'] = gemfile
6
- require 'bundler'
7
- Bundler.setup
8
- end
9
-
10
- $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -1,45 +0,0 @@
1
- # MySQL. Versions 4.1 and 5.0 are recommended.
2
- #
3
- # Install the MySQL driver:
4
- # gem install mysql2
5
- #
6
- # And be sure to use new-style password hashing:
7
- # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
8
- development:
9
- adapter: mysql2
10
- encoding: utf8
11
- reconnect: false
12
- database: dummy_development
13
- pool: 5
14
- username: root
15
- password:
16
- socket: /tmp/mysql.sock
17
-
18
- # Warning: The database defined as "test" will be erased and
19
- # re-generated from your development database when you run "rake".
20
- # Do not set this db to the same as development or production.
21
- test:
22
- adapter: mysql2
23
- encoding: utf8
24
- reconnect: false
25
- database: dummy_test
26
- pool: 5
27
- username: root
28
- password:
29
- socket: /tmp/mysql.sock
30
-
31
- test_sqlite:
32
- adapter: sqlite3
33
- database: db/test.sqlite3
34
- pool: 5
35
- timeout: 5000
36
-
37
- production:
38
- adapter: mysql2
39
- encoding: utf8
40
- reconnect: false
41
- database: dummy_production
42
- pool: 5
43
- username: root
44
- password:
45
- socket: /tmp/mysql.sock
@@ -1,5 +0,0 @@
1
- # Load the rails application
2
- require File.expand_path('../application', __FILE__)
3
-
4
- # Initialize the rails application
5
- Dummy::Application.initialize!
@@ -1,25 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the web server when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
15
-
16
- # Don't care if the mailer can't send
17
- config.action_mailer.raise_delivery_errors = false
18
-
19
- # Print deprecation notices to the Rails logger
20
- config.active_support.deprecation = :log
21
-
22
- # Only use best-standards-support built into browsers
23
- config.action_dispatch.best_standards_support = :builtin
24
- end
25
-
@@ -1,52 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # Code is not reloaded between requests
5
- config.cache_classes = true
6
-
7
- # Full error reports are disabled and caching is turned on
8
- config.consider_all_requests_local = false
9
- config.action_controller.perform_caching = true
10
-
11
- # Disable Rails's static asset server (Apache or nginx will already do this)
12
- config.serve_static_assets = false
13
-
14
- # Compress both stylesheets and JavaScripts
15
- config.assets.js_compressor = :uglifier
16
- config.assets.css_compressor = :scss
17
-
18
- # Specifies the header that your server uses for sending files
19
- # (comment out if your front-end server doesn't support this)
20
- config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx
21
-
22
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
23
- # config.force_ssl = true
24
-
25
- # See everything in the log (default is :info)
26
- # config.log_level = :debug
27
-
28
- # Use a different logger for distributed setups
29
- # config.logger = SyslogLogger.new
30
-
31
- # Use a different cache store in production
32
- # config.cache_store = :mem_cache_store
33
-
34
- # Enable serving of images, stylesheets, and javascripts from an asset server
35
- # config.action_controller.asset_host = "http://assets.example.com"
36
-
37
- # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
38
- # config.assets.precompile += %w( search.js )
39
-
40
- # Disable delivery errors, bad email addresses will be ignored
41
- # config.action_mailer.raise_delivery_errors = false
42
-
43
- # Enable threaded mode
44
- # config.threadsafe!
45
-
46
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
47
- # the I18n.default_locale when a translation can not be found)
48
- config.i18n.fallbacks = true
49
-
50
- # Send deprecation notices to registered listeners
51
- config.active_support.deprecation = :notify
52
- end