summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb6
-rw-r--r--lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb5
-rw-r--r--lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb7
-rw-r--r--lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb15
-rw-r--r--lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb2
-rw-r--r--lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb2
-rw-r--r--lib/plugins/awesome_nested_set/.autotest13
-rw-r--r--lib/plugins/awesome_nested_set/.gitignore8
-rw-r--r--lib/plugins/awesome_nested_set/.travis.yml18
-rw-r--r--lib/plugins/awesome_nested_set/CHANGELOG57
-rw-r--r--lib/plugins/awesome_nested_set/CONTRIBUTING.md14
-rw-r--r--lib/plugins/awesome_nested_set/Gemfile38
-rw-r--r--lib/plugins/awesome_nested_set/MIT-LICENSE20
-rw-r--r--lib/plugins/awesome_nested_set/README.md163
-rw-r--r--lib/plugins/awesome_nested_set/Rakefile32
-rw-r--r--lib/plugins/awesome_nested_set/awesome_nested_set.gemspec24
-rw-r--r--lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.0.rb4
-rw-r--r--lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.1.rb4
-rw-r--r--lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.2.rb4
-rw-r--r--lib/plugins/awesome_nested_set/init.rb1
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set.rb8
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb135
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/columns.rb72
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/helper.rb44
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/iterator.rb29
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb204
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/movable.rb137
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb61
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/rebuildable.rb43
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/relatable.rb121
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/transactable.rb27
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb69
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/move.rb130
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/set_validator.rb63
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/tree.rb63
-rw-r--r--lib/plugins/awesome_nested_set/lib/awesome_nested_set/version.rb3
-rw-r--r--lib/plugins/awesome_nested_set/spec/awesome_nested_set/helper_spec.rb102
-rw-r--r--lib/plugins/awesome_nested_set/spec/awesome_nested_set_spec.rb1098
-rw-r--r--lib/plugins/awesome_nested_set/spec/db/database.yml27
-rw-r--r--lib/plugins/awesome_nested_set/spec/db/schema.rb74
-rw-r--r--lib/plugins/awesome_nested_set/spec/fixtures/brokens.yml3
-rw-r--r--lib/plugins/awesome_nested_set/spec/fixtures/categories.yml34
-rw-r--r--lib/plugins/awesome_nested_set/spec/fixtures/departments.yml3
-rw-r--r--lib/plugins/awesome_nested_set/spec/fixtures/notes.yml38
-rw-r--r--lib/plugins/awesome_nested_set/spec/fixtures/things.yml27
-rw-r--r--lib/plugins/awesome_nested_set/spec/spec_helper.rb35
-rw-r--r--lib/plugins/awesome_nested_set/spec/support/models.rb96
-rw-r--r--lib/redmine.rb7
-rw-r--r--lib/redmine/access_control.rb4
-rw-r--r--lib/redmine/codeset_util.rb147
-rw-r--r--lib/redmine/core_ext/active_record.rb25
-rw-r--r--lib/redmine/core_ext/string/conversions.rb7
-rw-r--r--lib/redmine/export/pdf.rb4
-rw-r--r--lib/redmine/field_format.rb7
-rw-r--r--lib/redmine/helpers/gantt.rb2
-rw-r--r--lib/redmine/menu_manager.rb2
-rw-r--r--lib/redmine/scm/adapters/abstract_adapter.rb27
-rw-r--r--lib/redmine/scm/adapters/bazaar_adapter.rb7
-rw-r--r--lib/redmine/scm/adapters/cvs_adapter.rb8
-rw-r--r--lib/redmine/scm/adapters/darcs_adapter.rb5
-rw-r--r--lib/redmine/scm/adapters/git_adapter.rb10
-rw-r--r--lib/redmine/scm/adapters/mercurial_adapter.rb22
-rw-r--r--lib/redmine/scm/adapters/subversion_adapter.rb25
-rw-r--r--lib/redmine/unified_diff.rb20
-rw-r--r--lib/tasks/ci.rake4
-rw-r--r--lib/tasks/locales.rake3
-rw-r--r--lib/tasks/migrate_from_mantis.rake8
-rw-r--r--lib/tasks/migrate_from_trac.rake10
68 files changed, 88 insertions, 3449 deletions
diff --git a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb
index fd5e2a6a6..8e29700a7 100644
--- a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb
+++ b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb
@@ -29,7 +29,7 @@ module Redmine
send :include, Redmine::Acts::ActivityProvider::InstanceMethods
end
- options.assert_valid_keys(:type, :permission, :timestamp, :author_key, :find_options)
+ options.assert_valid_keys(:type, :permission, :timestamp, :author_key, :find_options, :scope)
self.activity_provider_options ||= {}
# One model can provide different event types
@@ -54,7 +54,7 @@ module Redmine
provider_options = activity_provider_options[event_type]
raise "#{self.name} can not provide #{event_type} events." if provider_options.nil?
- scope = self
+ scope = (provider_options[:scope] || self)
if from && to
scope = scope.where("#{provider_options[:timestamp]} BETWEEN ? AND ?", from, to)
@@ -79,7 +79,7 @@ module Redmine
scope = scope.where(Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options))
end
- scope.all(provider_options[:find_options].dup)
+ scope.to_a
end
end
end
diff --git a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
index a816490cc..e65c68c6f 100644
--- a/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
+++ b/lib/plugins/acts_as_attachable/lib/acts_as_attachable.rb
@@ -29,9 +29,8 @@ module Redmine
attachable_options[:view_permission] = options.delete(:view_permission) || "view_#{self.name.pluralize.underscore}".to_sym
attachable_options[:delete_permission] = options.delete(:delete_permission) || "edit_#{self.name.pluralize.underscore}".to_sym
- has_many :attachments, options.merge(:as => :container,
- :order => "#{Attachment.table_name}.created_on ASC, #{Attachment.table_name}.id ASC",
- :dependent => :destroy)
+ has_many :attachments, lambda {order("#{Attachment.table_name}.created_on ASC, #{Attachment.table_name}.id ASC")},
+ options.merge(:as => :container, :dependent => :destroy)
send :include, Redmine::Acts::Attachable::InstanceMethods
before_save :attach_saved_attachments
end
diff --git a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
index 928e98872..f4a8b2b51 100644
--- a/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
+++ b/lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
@@ -27,9 +27,8 @@ module Redmine
return if self.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)
cattr_accessor :customizable_options
self.customizable_options = options
- has_many :custom_values, :as => :customized,
- :include => :custom_field,
- :order => "#{CustomField.table_name}.position",
+ has_many :custom_values, lambda {includes(:custom_field).order("#{CustomField.table_name}.position")},
+ :as => :customized,
:dependent => :delete_all,
:validate => false
@@ -46,7 +45,7 @@ module Redmine
end
def available_custom_fields
- CustomField.where("type = '#{self.class.name}CustomField'").sorted.all
+ CustomField.where("type = '#{self.class.name}CustomField'").sorted.to_a
end
# Sets the values of the object's custom fields
diff --git a/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb b/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
index 0d4b3cc0f..8cd907b49 100644
--- a/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
+++ b/lib/plugins/acts_as_searchable/lib/acts_as_searchable.rb
@@ -31,6 +31,7 @@ module Redmine
# * :permission - permission required to search the model (default to :view_"objects")
def acts_as_searchable(options = {})
return if self.included_modules.include?(Redmine::Acts::Searchable::InstanceMethods)
+ options.assert_valid_keys(:columns, :project_key, :date_column, :order_column, :search_custom_fields, :permission, :scope)
cattr_accessor :searchable_options
self.searchable_options = options
@@ -70,7 +71,7 @@ module Redmine
# TODO: make user an argument
user = User.current
tokens = [] << tokens unless tokens.is_a?(Array)
- projects = [] << projects unless projects.nil? || projects.is_a?(Array)
+ projects = [] << projects if projects.is_a?(Project)
limit_options = {}
limit_options[:limit] = options[:limit] if options[:limit]
@@ -100,7 +101,10 @@ module Redmine
tokens_conditions = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort]
- scope = self.scoped
+ scope = (searchable_options[:scope] || self)
+ if scope.is_a? Proc
+ scope = scope.call
+ end
project_conditions = []
if searchable_options.has_key?(:permission)
project_conditions << Project.allowed_to_condition(user, searchable_options[:permission] || :view_project)
@@ -118,10 +122,11 @@ module Redmine
results_count = 0
scope = scope.
- includes(searchable_options[:include]).
+ joins(searchable_options[:include]).
order("#{searchable_options[:order_column]} " + (options[:before] ? 'DESC' : 'ASC')).
where(project_conditions).
- where(tokens_conditions)
+ where(tokens_conditions).
+ uniq
results_count = scope.count
@@ -129,7 +134,7 @@ module Redmine
if options[:offset]
scope_with_limit = scope_with_limit.where("#{searchable_options[:date_column]} #{options[:before] ? '<' : '>'} ?", options[:offset])
end
- results = scope_with_limit.all
+ results = scope_with_limit.to_a
[results, results_count]
end
diff --git a/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb b/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb
index 34fa34560..c078e7edb 100644
--- a/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb
+++ b/lib/plugins/acts_as_tree/lib/active_record/acts/tree.rb
@@ -44,7 +44,7 @@ module ActiveRecord
configuration.update(options) if options.is_a?(Hash)
belongs_to :parent, :class_name => name, :foreign_key => configuration[:foreign_key], :counter_cache => configuration[:counter_cache]
- has_many :children, :class_name => name, :foreign_key => configuration[:foreign_key], :order => configuration[:order], :dependent => configuration[:dependent]
+ has_many :children, lambda {order(configuration[:order])}, :class_name => name, :foreign_key => configuration[:foreign_key], :dependent => configuration[:dependent]
scope :roots, lambda {
where("#{configuration[:foreign_key]} IS NULL").
diff --git a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
index e31026dcb..19af8e56c 100644
--- a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
+++ b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
@@ -68,7 +68,7 @@ module Redmine
end
def notified_watchers
- notified = watcher_users.active
+ notified = watcher_users.active.to_a
notified.reject! {|user| user.mail.blank? || user.mail_notification == 'none'}
if respond_to?(:visible?)
notified.reject! {|user| !visible?(user)}
diff --git a/lib/plugins/awesome_nested_set/.autotest b/lib/plugins/awesome_nested_set/.autotest
deleted file mode 100644
index 54518a40a..000000000
--- a/lib/plugins/awesome_nested_set/.autotest
+++ /dev/null
@@ -1,13 +0,0 @@
-Autotest.add_hook :initialize do |at|
- at.clear_mappings
-
- at.add_mapping %r%^lib/(.*)\.rb$% do |_, m|
- at.files_matching %r%^test/#{m[1]}_test.rb$%
- end
-
- at.add_mapping(%r%^test/.*\.rb$%) {|filename, _| filename }
-
- at.add_mapping %r%^test/fixtures/(.*)s.yml% do |_, _|
- at.files_matching %r%^test/.*\.rb$%
- end
-end \ No newline at end of file
diff --git a/lib/plugins/awesome_nested_set/.gitignore b/lib/plugins/awesome_nested_set/.gitignore
deleted file mode 100644
index 373690149..000000000
--- a/lib/plugins/awesome_nested_set/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-awesome_nested_set.sqlite3.db
-spec/debug.log
-rdoc
-coverage
-pkg
-*.gem
-Gemfile.lock
-gemfiles/Gemfile*.lock \ No newline at end of file
diff --git a/lib/plugins/awesome_nested_set/.travis.yml b/lib/plugins/awesome_nested_set/.travis.yml
deleted file mode 100644
index ad9e670a3..000000000
--- a/lib/plugins/awesome_nested_set/.travis.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-language: ruby
-script: bundle exec rspec spec
-env:
- - DB=sqlite3
- - DB=sqlite3mem
- - DB=postgresql
- - DB=mysql
-rvm:
- - 2.0.0
- - 1.9.3
- - rbx
- - jruby-19mode
- - 1.8.7
- - jruby-18mode
-gemfile:
- - gemfiles/Gemfile.rails-3.0.rb
- - gemfiles/Gemfile.rails-3.1.rb
- - gemfiles/Gemfile.rails-3.2.rb
diff --git a/lib/plugins/awesome_nested_set/CHANGELOG b/lib/plugins/awesome_nested_set/CHANGELOG
deleted file mode 100644
index a805bfb17..000000000
--- a/lib/plugins/awesome_nested_set/CHANGELOG
+++ /dev/null
@@ -1,57 +0,0 @@
-2.1.6
-* Fixed rebuild! when there is a default_scope with order [Adrian Serafin]
-* Testing with stable bundler, ruby 2.0, MySQL and PostgreSQL [Philip Arndt]
-* Optimized move_to for large trees [ericsmith66]
-
-2.1.5
-* Worked around issues where AR#association wasn't present on Rails 3.0.x. [Philip Arndt]
-* Adds option 'order_column' which defaults to 'left_column_name'. [gudata]
-* Added moving with order functionality. [Sytse Sijbrandij]
-* Use tablename in all select queries. [Mikhail Dieterle]
-* Made sure all descendants' depths are updated when moving parent, not just immediate child. [Phil Thompson]
-* Add documentation of the callbacks. [Tobias Maier]
-
-2.1.4
-* nested_set_options accept both Class & AR Relation. [Semyon Perepelitsa]
-* Reduce the number of queries triggered by the canonical usage of `i.level` in the `nested_set` helpers. [thedarkone]
-* Specifically require active_record [Bogdan Gusiev]
-* compute_level now checks for a non nil association target. [Joel Nimety]
-
-2.1.3
-* Update child depth when parent node is moved. [Amanda Wagener]
-* Added move_to_child_with_index. [Ben Zhang]
-* Optimised self_and_descendants for when there's an index on lft. [Mark Torrance]
-* Added support for an unsaved record to return the right 'root'. [Philip Arndt]
-
-2.1.2
-* Fixed regressions introduced. [Philip Arndt]
-
-2.1.1
-* Added 'depth' which indicates how many levels deep the node is.
- This only works when you have a column called 'depth' in your table,
- otherwise it doesn't set itself. [Philip Arndt]
-* Rails 3.2 support added. [Gabriel Sobrinho]
-* Oracle compatibility added. [Pikender Sharma]
-* Adding row locking to deletion, locking source of pivot values, and adding retry on collisions. [Markus J. Q. Roberts]
-* Added method and helper for sorting children by column. [bluegod]
-* Fixed .all_roots_valid? to work with Postgres. [Joshua Clayton]
-* Made compatible with polymorphic belongs_to. [Graham Randall]
-* Added in the association callbacks to the children :has_many association. [Michael Deering]
-* Modified helper to allow using array of objects as argument. [Rahmat Budiharso]
-* Fixed cases where we were calling attr_protected. [Jacob Swanner]
-* Fixed nil cases involving lft and rgt. [Stuart Coyle] and [Patrick Morgan]
-
-2.0.2
-* Fixed deprecation warning under Rails 3.1 [Philip Arndt]
-* Converted Test::Unit matchers to RSpec. [Uģis Ozols]
-* Added inverse_of to associations to improve performance rendering trees. [Sergio Cambra]
-* Added row locking and fixed some race conditions. [Markus J. Q. Roberts]
-
-2.0.1
-* Fixed a bug with move_to not using nested_set_scope [Andreas Sekine]
-
-2.0.0.pre
-* Expect Rails 3
-* Changed how callbacks work. Returning false in a before_move action does not block save operations. Use a validation or exception in the callback if you need that.
-* Switched to RSpec
-* Remove use of Comparable
diff --git a/lib/plugins/awesome_nested_set/CONTRIBUTING.md b/lib/plugins/awesome_nested_set/CONTRIBUTING.md
deleted file mode 100644
index 112b942ef..000000000
--- a/lib/plugins/awesome_nested_set/CONTRIBUTING.md
+++ /dev/null
@@ -1,14 +0,0 @@
-# Contributing to AwesomeNestedSet
-
-If you find what you might think is a bug:
-
-1. Check the [GitHub issue tracker](https://github.com/collectiveidea/awesome_nested_set/issues/) to see if anyone else has had the same issue.
-2. If you don't see anything, create an issue with information on how to reproduce it.
-
-If you want to contribute an enhancement or a fix:
-
-1. Fork [the project on GitHub](https://github.com/collectiveidea/awesome_nested_set)
-2. Make your changes with tests.
-3. Commit the changes without making changes to the [Rakefile](Rakefile) or any other files that aren't related to your enhancement or fix.
-4. Write an entry in the [CHANGELOG](CHANGELOG)
-5. Send a pull request.
diff --git a/lib/plugins/awesome_nested_set/Gemfile b/lib/plugins/awesome_nested_set/Gemfile
deleted file mode 100644
index ca0c5f95c..000000000
--- a/lib/plugins/awesome_nested_set/Gemfile
+++ /dev/null
@@ -1,38 +0,0 @@
-gem 'combustion', :github => 'pat/combustion', :branch => 'master'
-
-source 'https://rubygems.org'
-
-gemspec :path => File.expand_path('../', __FILE__)
-
-platforms :jruby do
- gem 'activerecord-jdbcsqlite3-adapter'
- gem 'activerecord-jdbcmysql-adapter'
- gem 'jdbc-mysql'
- gem 'activerecord-jdbcpostgresql-adapter'
- gem 'jruby-openssl'
-end
-
-platforms :ruby do
- gem 'sqlite3'
- gem 'mysql2', (MYSQL2_VERSION if defined? MYSQL2_VERSION)
- gem 'pg'
-end
-
-RAILS_VERSION = nil unless defined? RAILS_VERSION
-gem 'railties', RAILS_VERSION
-gem 'activerecord', RAILS_VERSION
-gem 'actionpack', RAILS_VERSION
-
-platforms :rbx do
- gem 'rubysl', '~> 2.0'
- gem 'rubysl-test-unit'
-end
-
-
-# Add Oracle Adapters
-# gem 'ruby-oci8'
-# gem 'activerecord-oracle_enhanced-adapter'
-
-# Debuggers
-gem 'pry'
-gem 'pry-nav'
diff --git a/lib/plugins/awesome_nested_set/MIT-LICENSE b/lib/plugins/awesome_nested_set/MIT-LICENSE
deleted file mode 100644
index 7cdb82927..000000000
--- a/lib/plugins/awesome_nested_set/MIT-LICENSE
+++ /dev/null
@@ -1,20 +0,0 @@
-Copyright (c) 2007-2011 Collective Idea
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/lib/plugins/awesome_nested_set/README.md b/lib/plugins/awesome_nested_set/README.md
deleted file mode 100644
index 58bb86ee5..000000000
--- a/lib/plugins/awesome_nested_set/README.md
+++ /dev/null
@@ -1,163 +0,0 @@
-# AwesomeNestedSet
-
-Awesome Nested Set is an implementation of the nested set pattern for ActiveRecord models.
-It is a replacement for acts_as_nested_set and BetterNestedSet, but more awesome.
-
-Version 2 supports Rails 3. Gem versions prior to 2.0 support Rails 2.
-
-## What makes this so awesome?
-
-This is a new implementation of nested set based off of BetterNestedSet that fixes some bugs, removes tons of duplication, adds a few useful methods, and adds STI support.
-
-[![Code Climate](https://codeclimate.com/github/collectiveidea/awesome_nested_set.png)](https://codeclimate.com/github/collectiveidea/awesome_nested_set)
-
-## Installation
-
-Add to your Gemfile:
-
-```ruby
-gem 'awesome_nested_set'
-```
-
-## Usage
-
-To make use of `awesome_nested_set`, your model needs to have 3 fields:
-`lft`, `rgt`, and `parent_id`. The names of these fields are configurable.
-You can also have an optional field, `depth`:
-
-```ruby
-class CreateCategories < ActiveRecord::Migration
- def self.up
- create_table :categories do |t|
- t.string :name
- t.integer :parent_id
- t.integer :lft
- t.integer :rgt
- t.integer :depth # this is optional.
- end
- end
-
- def self.down
- drop_table :categories
- end
-end
-```
-
-Enable the nested set functionality by declaring `acts_as_nested_set` on your model
-
-```ruby
-class Category < ActiveRecord::Base
- acts_as_nested_set
-end
-```
-
-Run `rake rdoc` to generate the API docs and see [CollectiveIdea::Acts::NestedSet](lib/awesome_nested_set/awesome_nested_set.rb) for more information.
-
-## Callbacks
-
-There are three callbacks called when moving a node:
-`before_move`, `after_move` and `around_move`.
-
-```ruby
-class Category < ActiveRecord::Base
- acts_as_nested_set
-
- after_move :rebuild_slug
- around_move :da_fancy_things_around
-
- private
-
- def rebuild_slug
- # do whatever
- end
-
- def da_fancy_things_around
- # do something...
- yield # actually moves
- # do something else...
- end
-end
-```
-
-Beside this there are also hooks to act on the newly added or removed children.
-
-```ruby
-class Category < ActiveRecord::Base
- acts_as_nested_set :before_add => :do_before_add_stuff,
- :after_add => :do_after_add_stuff,
- :before_remove => :do_before_remove_stuff,
- :after_remove => :do_after_remove_stuff
-
- private
-
- def do_before_add_stuff(child_node)
- # do whatever with the child
- end
-
- def do_after_add_stuff(child_node)
- # do whatever with the child
- end
-
- def do_before_remove_stuff(child_node)
- # do whatever with the child
- end
-
- def do_after_remove_stuff(child_node)
- # do whatever with the child
- end
-end
-```
-
-## Protecting attributes from mass assignment
-
-It's generally best to "whitelist" the attributes that can be used in mass assignment:
-
-```ruby
-class Category < ActiveRecord::Base
- acts_as_nested_set
- attr_accessible :name, :parent_id
-end
-```
-
-If for some reason that is not possible, you will probably want to protect the `lft` and `rgt` attributes:
-
-```ruby
-class Category < ActiveRecord::Base
- acts_as_nested_set
- attr_protected :lft, :rgt
-end
-```
-
-## Conversion from other trees
-
-Coming from acts_as_tree or another system where you only have a parent_id? No problem. Simply add the lft & rgt fields as above, and then run:
-
-```ruby
-Category.rebuild!
-```
-
-Your tree will be converted to a valid nested set. Awesome!
-
-## View Helper
-
-The view helper is called #nested_set_options.
-
-Example usage:
-
-```erb
-<%= f.select :parent_id, nested_set_options(Category, @category) {|i| "#{'-' * i.level} #{i.name}" } %>
-
-<%= select_tag 'parent_id', options_for_select(nested_set_options(Category) {|i| "#{'-' * i.level} #{i.name}" } ) %>
-```
-
-See [CollectiveIdea::Acts::NestedSet::Helper](lib/awesome_nested_set/helper.rb) for more information about the helpers.
-
-## References
-
-You can learn more about nested sets at: http://threebit.net/tutorials/nestedset/tutorial1.html
-
-## How to contribute
-
-Please see the ['Contributing' document](CONTRIBUTING.md).
-
-Copyright © 2008 - 2013 Collective Idea, released under the MIT license
diff --git a/lib/plugins/awesome_nested_set/Rakefile b/lib/plugins/awesome_nested_set/Rakefile
deleted file mode 100644
index d5c79129a..000000000
--- a/lib/plugins/awesome_nested_set/Rakefile
+++ /dev/null
@@ -1,32 +0,0 @@
-# -*- encoding: utf-8 -*-
-$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
-require 'rubygems'
-require 'bundler/setup'
-require 'awesome_nested_set/version'
-
-task :default => :spec
-
-task :spec do
- %w(3.0 3.1 3.2).each do |rails_version|
- puts "\n" + (cmd = "BUNDLE_GEMFILE='gemfiles/Gemfile.rails-#{rails_version}.rb' bundle exec rspec spec")
- system cmd
- end
-end
-
-task :build do
- system "gem build awesome_nested_set.gemspec"
-end
-
-task :release => :build do
- system "gem push awesome_nested_set-#{ActsAsGeocodable::VERSION}.gem"
-end
-
-require 'rdoc/task'
-desc 'Generate documentation for the awesome_nested_set plugin.'
-Rake::RDocTask.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'AwesomeNestedSet'
- rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README.rdoc')
- rdoc.rdoc_files.include('lib/**/*.rb')
-end
diff --git a/lib/plugins/awesome_nested_set/awesome_nested_set.gemspec b/lib/plugins/awesome_nested_set/awesome_nested_set.gemspec
deleted file mode 100644
index f4f858efc..000000000
--- a/lib/plugins/awesome_nested_set/awesome_nested_set.gemspec
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../lib/awesome_nested_set/version', __FILE__)
-
-Gem::Specification.new do |s|
- s.name = %q{awesome_nested_set}
- s.version = ::AwesomeNestedSet::VERSION
- s.authors = ["Brandon Keepers", "Daniel Morrison", "Philip Arndt"]
- s.description = %q{An awesome nested set implementation for Active Record}
- s.email = %q{info@collectiveidea.com}
- s.files = Dir.glob("lib/**/*") + %w(MIT-LICENSE README.md CHANGELOG)
- s.homepage = %q{http://github.com/collectiveidea/awesome_nested_set}
- s.rdoc_options = ["--inline-source", "--line-numbers"]
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.6}
- s.summary = %q{An awesome nested set implementation for Active Record}
- s.license = %q{MIT}
-
- s.add_runtime_dependency 'activerecord', '>= 3.0.0'
-
- s.add_development_dependency 'rspec-rails', '~> 2.12'
- s.add_development_dependency 'rake', '~> 10'
- s.add_development_dependency 'combustion', '>= 0.3.3'
- s.add_development_dependency 'database_cleaner'
-end
diff --git a/lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.0.rb b/lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.0.rb
deleted file mode 100644
index 9109812e9..000000000
--- a/lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.0.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-MYSQL2_VERSION = '~> 0.2.18'
-RAILS_VERSION = '~> 3.0.17'
-
-eval File.read(File.expand_path('../../Gemfile', __FILE__))
diff --git a/lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.1.rb b/lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.1.rb
deleted file mode 100644
index fbbb15c8a..000000000
--- a/lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.1.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-MYSQL2_VERSION = '>= 0.3'
-RAILS_VERSION = '~> 3.1.0'
-
-eval File.read(File.expand_path('../../Gemfile', __FILE__))
diff --git a/lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.2.rb b/lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.2.rb
deleted file mode 100644
index 03d117309..000000000
--- a/lib/plugins/awesome_nested_set/gemfiles/Gemfile.rails-3.2.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-MYSQL2_VERSION = '>= 0.3'
-RAILS_VERSION = '~> 3.2.0'
-
-eval File.read(File.expand_path('../../Gemfile', __FILE__))
diff --git a/lib/plugins/awesome_nested_set/init.rb b/lib/plugins/awesome_nested_set/init.rb
deleted file mode 100644
index 8e2cf36ef..000000000
--- a/lib/plugins/awesome_nested_set/init.rb
+++ /dev/null
@@ -1 +0,0 @@
-require File.dirname(__FILE__) + '/lib/awesome_nested_set'
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set.rb
deleted file mode 100644
index 37ae5170d..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'awesome_nested_set/awesome_nested_set'
-require 'active_record'
-ActiveRecord::Base.send :extend, CollectiveIdea::Acts::NestedSet
-
-if defined?(ActionView)
- require 'awesome_nested_set/helper'
- ActionView::Base.send :include, CollectiveIdea::Acts::NestedSet::Helper
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb
deleted file mode 100644
index 603c177d1..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/awesome_nested_set.rb
+++ /dev/null
@@ -1,135 +0,0 @@
-require 'awesome_nested_set/columns'
-require 'awesome_nested_set/model'
-
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
-
- # This acts provides Nested Set functionality. Nested Set is a smart way to implement
- # an _ordered_ tree, with the added feature that you can select the children and all of their
- # descendants with a single query. The drawback is that insertion or move need some complex
- # sql queries. But everything is done here by this module!
- #
- # Nested sets are appropriate each time you want either an orderd tree (menus,
- # commercial categories) or an efficient way of querying big trees (threaded posts).
- #
- # == API
- #
- # Methods names are aligned with acts_as_tree as much as possible to make replacment from one
- # by another easier.
- #
- # item.children.create(:name => "child1")
- #
-
- # Configuration options are:
- #
- # * +:parent_column+ - specifies the column name to use for keeping the position integer (default: parent_id)
- # * +:left_column+ - column name for left boundry data, default "lft"
- # * +:right_column+ - column name for right boundry data, default "rgt"
- # * +:depth_column+ - column name for the depth data, default "depth"
- # * +:scope+ - restricts what is to be considered a list. Given a symbol, it'll attach "_id"
- # (if it hasn't been already) and use that as the foreign key restriction. You
- # can also pass an array to scope by multiple attributes.
- # Example: <tt>acts_as_nested_set :scope => [:notable_id, :notable_type]</tt>
- # * +:dependent+ - behavior for cascading destroy. If set to :destroy, all the
- # child objects are destroyed alongside this object by calling their destroy
- # method. If set to :delete_all (default), all the child objects are deleted
- # without calling their destroy method.
- # * +:counter_cache+ adds a counter cache for the number of children.
- # defaults to false.
- # Example: <tt>acts_as_nested_set :counter_cache => :children_count</tt>
- # * +:order_column+ on which column to do sorting, by default it is the left_column_name
- # Example: <tt>acts_as_nested_set :order_column => :position</tt>
- #
- # See CollectiveIdea::Acts::NestedSet::Model::ClassMethods for a list of class methods and
- # CollectiveIdea::Acts::NestedSet::Model for a list of instance methods added
- # to acts_as_nested_set models
- def acts_as_nested_set(options = {})
- acts_as_nested_set_parse_options! options
-
- include Model
- include Columns
- extend Columns
-
- acts_as_nested_set_relate_parent!
- acts_as_nested_set_relate_children!
-
- attr_accessor :skip_before_destroy
-
- acts_as_nested_set_prevent_assignment_to_reserved_columns!
- acts_as_nested_set_define_callbacks!
- end
-
- private
- def acts_as_nested_set_define_callbacks!
- # on creation, set automatically lft and rgt to the end of the tree
- before_create :set_default_left_and_right
- before_save :store_new_parent
- after_save :move_to_new_parent, :set_depth!
- before_destroy :destroy_descendants
-
- define_model_callbacks :move
- end
-
- def acts_as_nested_set_relate_children!
- has_many_children_options = {
- :class_name => self.base_class.to_s,
- :foreign_key => parent_column_name,
- :order => quoted_order_column_name,
- :inverse_of => (:parent unless acts_as_nested_set_options[:polymorphic]),
- }
-
- # Add callbacks, if they were supplied.. otherwise, we don't want them.
- [:before_add, :after_add, :before_remove, :after_remove].each do |ar_callback|
- has_many_children_options.update(ar_callback => acts_as_nested_set_options[ar_callback]) if acts_as_nested_set_options[ar_callback]
- end
-
- has_many :children, has_many_children_options
- end
-
- def acts_as_nested_set_relate_parent!
- belongs_to :parent, :class_name => self.base_class.to_s,
- :foreign_key => parent_column_name,
- :counter_cache => acts_as_nested_set_options[:counter_cache],
- :inverse_of => (:children unless acts_as_nested_set_options[:polymorphic]),
- :polymorphic => acts_as_nested_set_options[:polymorphic],
- :touch => acts_as_nested_set_options[:touch]
- end
-
- def acts_as_nested_set_default_options
- {
- :parent_column => 'parent_id',
- :left_column => 'lft',
- :right_column => 'rgt',
- :depth_column => 'depth',
- :dependent => :delete_all, # or :destroy
- :polymorphic => false,
- :counter_cache => false,
- :touch => false
- }.freeze
- end
-
- def acts_as_nested_set_parse_options!(options)
- options = acts_as_nested_set_default_options.merge(options)
-
- if options[:scope].is_a?(Symbol) && options[:scope].to_s !~ /_id$/
- options[:scope] = "#{options[:scope]}_id".intern
- end
-
- class_attribute :acts_as_nested_set_options
- self.acts_as_nested_set_options = options
- end
-
- def acts_as_nested_set_prevent_assignment_to_reserved_columns!
- # no assignment to structure fields
- [left_column_name, right_column_name, depth_column_name].each do |column|
- module_eval <<-"end_eval", __FILE__, __LINE__
- def #{column}=(x)
- raise ActiveRecord::ActiveRecordError, "Unauthorized assignment to #{column}: it's an internal field handled by acts_as_nested_set code, use move_to_* methods instead."
- end
- end_eval
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/columns.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/columns.rb
deleted file mode 100644
index aba32cb96..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/columns.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-# Mixed into both classes and instances to provide easy access to the column names
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
- module Columns
- def left_column_name
- acts_as_nested_set_options[:left_column]
- end
-
- def right_column_name
- acts_as_nested_set_options[:right_column]
- end
-
- def depth_column_name
- acts_as_nested_set_options[:depth_column]
- end
-
- def parent_column_name
- acts_as_nested_set_options[:parent_column]
- end
-
- def order_column
- acts_as_nested_set_options[:order_column] || left_column_name
- end
-
- def scope_column_names
- Array(acts_as_nested_set_options[:scope])
- end
-
- def quoted_left_column_name
- connection.quote_column_name(left_column_name)
- end
-
- def quoted_right_column_name
- connection.quote_column_name(right_column_name)
- end
-
- def quoted_depth_column_name
- connection.quote_column_name(depth_column_name)
- end
-
- def quoted_parent_column_name
- connection.quote_column_name(parent_column_name)
- end
-
- def quoted_scope_column_names
- scope_column_names.collect {|column_name| connection.quote_column_name(column_name) }
- end
-
- def quoted_order_column_name
- connection.quote_column_name(order_column)
- end
-
- def quoted_order_column_full_name
- "#{quoted_table_name}.#{quoted_order_column_name}"
- end
-
- def quoted_left_column_full_name
- "#{quoted_table_name}.#{quoted_left_column_name}"
- end
-
- def quoted_right_column_full_name
- "#{quoted_table_name}.#{quoted_right_column_name}"
- end
-
- def quoted_parent_column_full_name
- "#{quoted_table_name}.#{quoted_parent_column_name}"
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/helper.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/helper.rb
deleted file mode 100644
index bd8d40df1..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/helper.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-# -*- coding: utf-8 -*-
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
- # This module provides some helpers for the model classes using acts_as_nested_set.
- # It is included by default in all views.
- #
- module Helper
- # Returns options for select.
- # You can exclude some items from the tree.
- # You can pass a block receiving an item and returning the string displayed in the select.
- #
- # == Params
- # * +class_or_item+ - Class name or top level times
- # * +mover+ - The item that is being move, used to exlude impossible moves
- # * +&block+ - a block that will be used to display: { |item| ... item.name }
- #
- # == Usage
- #
- # <%= f.select :parent_id, nested_set_options(Category, @category) {|i|
- # "#{'–' * i.level} #{i.name}"
- # }) %>
- #
- def nested_set_options(class_or_item, mover = nil)
- if class_or_item.is_a? Array
- items = class_or_item.reject { |e| !e.root? }
- else
- class_or_item = class_or_item.roots if class_or_item.respond_to?(:scoped)
- items = Array(class_or_item)
- end
- result = []
- items.each do |root|
- result += root.class.associate_parents(root.self_and_descendants).map do |i|
- if mover.nil? || mover.new_record? || mover.move_possible?(i)
- [yield(i), i.id]
- end
- end.compact
- end
- result
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/iterator.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/iterator.rb
deleted file mode 100644
index 94aca41ea..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/iterator.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
- class Iterator
- attr_reader :objects
-
- def initialize(objects)
- @objects = objects
- end
-
- def each_with_level
- path = [nil]
- objects.each do |o|
- if o.parent_id != path.last
- # we are on a new level, did we descend or ascend?
- if path.include?(o.parent_id)
- # remove wrong tailing paths elements
- path.pop while path.last != o.parent_id
- else
- path << o.parent_id
- end
- end
- yield(o, path.length - 1)
- end
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb
deleted file mode 100644
index dbbf569a7..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model.rb
+++ /dev/null
@@ -1,204 +0,0 @@
-require 'awesome_nested_set/model/prunable'
-require 'awesome_nested_set/model/movable'
-require 'awesome_nested_set/model/transactable'
-require 'awesome_nested_set/model/relatable'
-require 'awesome_nested_set/model/rebuildable'
-require 'awesome_nested_set/model/validatable'
-require 'awesome_nested_set/iterator'
-
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
-
- module Model
- extend ActiveSupport::Concern
-
- included do
- delegate :quoted_table_name, :arel_table, :to => self
- extend Validatable
- extend Rebuildable
- include Movable
- include Prunable
- include Relatable
- include Transactable
- end
-
- module ClassMethods
- def associate_parents(objects)
- return objects unless objects.all? {|o| o.respond_to?(:association)}
-
- id_indexed = objects.index_by(&:id)
- objects.each do |object|
- association = object.association(:parent)
- parent = id_indexed[object.parent_id]
-
- if !association.loaded? && parent
- association.target = parent
- association.set_inverse_instance(parent)
- end
- end
- end
-
- def children_of(parent_id)
- where arel_table[parent_column_name].eq(parent_id)
- end
-
- # Iterates over tree elements and determines the current level in the tree.
- # Only accepts default ordering, odering by an other column than lft
- # does not work. This method is much more efficent than calling level
- # because it doesn't require any additional database queries.
- #
- # Example:
- # Category.each_with_level(Category.root.self_and_descendants) do |o, level|
- #
- def each_with_level(objects, &block)
- Iterator.new(objects).each_with_level(&block)
- end
-
- def leaves
- nested_set_scope.where "#{quoted_right_column_full_name} - #{quoted_left_column_full_name} = 1"
- end
-
- def left_of(node)
- where arel_table[left_column_name].lt(node)
- end
-
- def left_of_right_side(node)
- where arel_table[right_column_name].lteq(node)
- end
-
- def right_of(node)
- where arel_table[left_column_name].gteq(node)
- end
-
- def nested_set_scope(options = {})
- options = {:order => quoted_order_column_full_name}.merge(options)
-
- order(options.delete(:order)).scoped options
- end
-
- def primary_key_scope(id)
- where arel_table[primary_key].eq(id)
- end
-
- def root
- roots.first
- end
-
- def roots
- nested_set_scope.children_of nil
- end
- end # end class methods
-
- # Any instance method that returns a collection makes use of Rails 2.1's named_scope (which is bundled for Rails 2.0), so it can be treated as a finder.
- #
- # category.self_and_descendants.count
- # category.ancestors.find(:all, :conditions => "name like '%foo%'")
- # Value of the parent column
- def parent_id(target = self)
- target[parent_column_name]
- end
-
- # Value of the left column
- def left(target = self)
- target[left_column_name]
- end
-
- # Value of the right column
- def right(target = self)
- target[right_column_name]
- end
-
- # Returns true if this is a root node.
- def root?
- parent_id.nil?
- end
-
- # Returns true is this is a child node
- def child?
- !root?
- end
-
- # Returns true if this is the end of a branch.
- def leaf?
- persisted? && right.to_i - left.to_i == 1
- end
-
- # All nested set queries should use this nested_set_scope, which
- # performs finds on the base ActiveRecord class, using the :scope
- # declared in the acts_as_nested_set declaration.
- def nested_set_scope(options = {})
- if (scopes = Array(acts_as_nested_set_options[:scope])).any?
- options[:conditions] = scopes.inject({}) do |conditions,attr|
- conditions.merge attr => self[attr]
- end
- end
-
- self.class.nested_set_scope options
- end
-
- def to_text
- self_and_descendants.map do |node|
- "#{'*'*(node.level+1)} #{node.id} #{node.to_s} (#{node.parent_id}, #{node.left}, #{node.right})"
- end.join("\n")
- end
-
- protected
-
- def without_self(scope)
- return scope if new_record?
- scope.where(["#{self.class.quoted_table_name}.#{self.class.primary_key} != ?", self])
- end
-
- def store_new_parent
- @move_to_new_parent_id = send("#{parent_column_name}_changed?") ? parent_id : false
- true # force callback to return true
- end
-
- def has_depth_column?
- nested_set_scope.column_names.map(&:to_s).include?(depth_column_name.to_s)
- end
-
- def right_most_bound
- right_most_node =
- self.class.base_class.unscoped.
- order("#{quoted_right_column_full_name} desc").limit(1).lock(true).first
- right_most_node ? (right_most_node[right_column_name] || 0) : 0
- end
-
- def set_depth!
- return unless has_depth_column?
-
- in_tenacious_transaction do
- reload
- nested_set_scope.primary_key_scope(id).
- update_all(["#{quoted_depth_column_name} = ?", level])
- end
- self[depth_column_name] = self.level
- end
-
- def set_default_left_and_right
- # adds the new node to the right of all existing nodes
- self[left_column_name] = right_most_bound + 1
- self[right_column_name] = right_most_bound + 2
- end
-
- # reload left, right, and parent
- def reload_nested_set
- reload(
- :select => "#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, #{quoted_parent_column_full_name}",
- :lock => true
- )
- end
-
- def reload_target(target)
- if target.is_a? self.class.base_class
- target.reload
- else
- nested_set_scope.find(target)
- end
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/movable.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/movable.rb
deleted file mode 100644
index 7b94ca22a..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/movable.rb
+++ /dev/null
@@ -1,137 +0,0 @@
-require 'awesome_nested_set/move'
-
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
- module Model
- module Movable
-
- def move_possible?(target)
- self != target && # Can't target self
- same_scope?(target) && # can't be in different scopes
- # detect impossible move
- within_bounds?(target.left, target.left) &&
- within_bounds?(target.right, target.right)
- end
-
- # Shorthand method for finding the left sibling and moving to the left of it.
- def move_left
- move_to_left_of left_sibling
- end
-
- # Shorthand method for finding the right sibling and moving to the right of it.
- def move_right
- move_to_right_of right_sibling
- end
-
- # Move the node to the left of another node
- def move_to_left_of(node)
- move_to node, :left
- end
-
- # Move the node to the left of another node
- def move_to_right_of(node)
- move_to node, :right
- end
-
- # Move the node to the child of another node
- def move_to_child_of(node)
- move_to node, :child
- end
-
- # Move the node to the child of another node with specify index
- def move_to_child_with_index(node, index)
- if node.children.empty?
- move_to_child_of(node)
- elsif node.children.count == index
- move_to_right_of(node.children.last)
- else
- move_to_left_of(node.children[index])
- end
- end
-
- # Move the node to root nodes
- def move_to_root
- move_to_right_of(root)
- end
-
- # Order children in a nested set by an attribute
- # Can order by any attribute class that uses the Comparable mixin, for example a string or integer
- # Usage example when sorting categories alphabetically: @new_category.move_to_ordered_child_of(@root, "name")
- def move_to_ordered_child_of(parent, order_attribute, ascending = true)
- self.move_to_root and return unless parent
-
- left_neighbor = find_left_neighbor(parent, order_attribute, ascending)
- self.move_to_child_of(parent)
-
- return unless parent.children.many?
-
- if left_neighbor
- self.move_to_right_of(left_neighbor)
- else # Self is the left most node.
- self.move_to_left_of(parent.children[0])
- end
- end
-
- # Find the node immediately to the left of this node.
- def find_left_neighbor(parent, order_attribute, ascending)
- left = nil
- parent.children.each do |n|
- if ascending
- left = n if n.send(order_attribute) < self.send(order_attribute)
- else
- left = n if n.send(order_attribute) > self.send(order_attribute)
- end
- end
- left
- end
-
- def move_to(target, position)
- prevent_unpersisted_move
-
- run_callbacks :move do
- in_tenacious_transaction do
- target = reload_target(target)
- self.reload_nested_set
-
- Move.new(target, position, self).move
- end
- after_move_to(target, position)
- end
- end
-
- protected
-
- def after_move_to(target, position)
- target.reload_nested_set if target
- self.set_depth!
- self.descendants.each(&:save)
- self.reload_nested_set
- end
-
- def move_to_new_parent
- if @move_to_new_parent_id.nil?
- move_to_root
- elsif @move_to_new_parent_id
- move_to_child_of(@move_to_new_parent_id)
- end
- end
-
- def out_of_bounds?(left_bound, right_bound)
- left <= left_bound && right >= right_bound
- end
-
- def prevent_unpersisted_move
- if self.new_record?
- raise ActiveRecord::ActiveRecordError, "You cannot move a new node"
- end
- end
-
- def within_bounds?(left_bound, right_bound)
- !out_of_bounds?(left_bound, right_bound)
- end
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb
deleted file mode 100644
index bb21d055a..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/prunable.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
- module Model
- module Prunable
-
- # Prunes a branch off of the tree, shifting all of the elements on the right
- # back to the left so the counts still work.
- def destroy_descendants
- return if right.nil? || left.nil? || skip_before_destroy
-
- in_tenacious_transaction do
- reload_nested_set
- # select the rows in the model that extend past the deletion point and apply a lock
- nested_set_scope.right_of(left).select(id).lock(true)
-
- destroy_or_delete_descendants
-
- # update lefts and rights for remaining nodes
- update_siblings_for_remaining_nodes
-
- # Reload is needed because children may have updated their parent (self) during deletion.
- reload
-
- # Don't allow multiple calls to destroy to corrupt the set
- self.skip_before_destroy = true
- end
- end
-
- def destroy_or_delete_descendants
- if acts_as_nested_set_options[:dependent] == :destroy
- descendants.each do |model|
- model.skip_before_destroy = true
- model.destroy
- end
- else
- descendants.delete_all
- end
- end
-
- def update_siblings_for_remaining_nodes
- update_siblings(:left)
- update_siblings(:right)
- end
-
- def update_siblings(direction)
- full_column_name = send("quoted_#{direction}_column_full_name")
- column_name = send("quoted_#{direction}_column_name")
-
- nested_set_scope.where(["#{full_column_name} > ?", right]).
- update_all(["#{column_name} = (#{column_name} - ?)", diff])
- end
-
- def diff
- right - left + 1
- end
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/rebuildable.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/rebuildable.rb
deleted file mode 100644
index 335736d72..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/rebuildable.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require 'awesome_nested_set/tree'
-
-module CollectiveIdea
- module Acts
- module NestedSet
- module Model
- module Rebuildable
-
-
- # Rebuilds the left & rights if unset or invalid.
- # Also very useful for converting from acts_as_tree.
- def rebuild!(validate_nodes = true)
- # default_scope with order may break database queries so we do all operation without scope
- unscoped do
- Tree.new(self, validate_nodes).rebuild!
- end
- end
-
- private
- def scope_for_rebuild
- scope = proc {}
-
- if acts_as_nested_set_options[:scope]
- scope = proc {|node|
- scope_column_names.inject("") {|str, column_name|
- column_value = node.send(column_name)
- cond = column_value.nil? ? "IS NULL" : "= #{connection.quote(column_value)}"
- str << "AND #{connection.quote_column_name(column_name)} #{cond} "
- }
- }
- end
- scope
- end
-
- def order_for_rebuild
- "#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, #{primary_key}"
- end
- end
-
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/relatable.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/relatable.rb
deleted file mode 100644
index 21de61a9d..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/relatable.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-module CollectiveIdea
- module Acts
- module NestedSet
- module Model
- module Relatable
-
- # Returns an collection of all parents
- def ancestors
- without_self self_and_ancestors
- end
-
- # Returns the collection of all parents and self
- def self_and_ancestors
- nested_set_scope.
- where(arel_table[left_column_name].lteq(left)).
- where(arel_table[right_column_name].gteq(right))
- end
-
- # Returns the collection of all children of the parent, except self
- def siblings
- without_self self_and_siblings
- end
-
- # Returns the collection of all children of the parent, including self
- def self_and_siblings
- nested_set_scope.children_of parent_id
- end
-
- # Returns a set of all of its nested children which do not have children
- def leaves
- descendants.where(
- "#{quoted_right_column_full_name} - #{quoted_left_column_full_name} = 1"
- )
- end
-
- # Returns the level of this object in the tree
- # root level is 0
- def level
- parent_id.nil? ? 0 : compute_level
- end
-
- # Returns a collection including all of its children and nested children
- def descendants
- without_self self_and_descendants
- end
-
- # Returns a collection including itself and all of its nested children
- def self_and_descendants
- # using _left_ for both sides here lets us benefit from an index on that column if one exists
- nested_set_scope.right_of(left).left_of(right)
- end
-
- def is_descendant_of?(other)
- within_node?(other, self) && same_scope?(other)
- end
-
- def is_or_is_descendant_of?(other)
- (other == self || within_node?(other, self)) && same_scope?(other)
- end
-
- def is_ancestor_of?(other)
- within_node?(self, other) && same_scope?(other)
- end
-
- def is_or_is_ancestor_of?(other)
- (self == other || within_node?(self, other)) && same_scope?(other)
- end
-
- # Check if other model is in the same scope
- def same_scope?(other)
- Array(acts_as_nested_set_options[:scope]).all? do |attr|
- self.send(attr) == other.send(attr)
- end
- end
-
- # Find the first sibling to the left
- def left_sibling
- siblings.left_of(left).last
- end
-
- # Find the first sibling to the right
- def right_sibling
- siblings.right_of(left).first
- end
-
- def root
- return self_and_ancestors.children_of(nil).first if persisted?
-
- if parent_id && current_parent = nested_set_scope.find(parent_id)
- current_parent.root
- else
- self
- end
- end
-
- protected
-
- def compute_level
- node, nesting = determine_depth
-
- node == self ? ancestors.count : node.level + nesting
- end
-
- def determine_depth(node = self, nesting = 0)
- while (association = node.association(:parent)).loaded? && association.target
- nesting += 1
- node = node.parent
- end if node.respond_to?(:association)
-
- [node, nesting]
- end
-
- def within_node?(node, within)
- node.left < within.left && within.left < node.right
- end
-
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/transactable.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/transactable.rb
deleted file mode 100644
index bef62d369..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/transactable.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
- module Model
- module Transactable
-
- protected
- def in_tenacious_transaction(&block)
- retry_count = 0
- begin
- transaction(&block)
- rescue ActiveRecord::StatementInvalid => error
- raise unless connection.open_transactions.zero?
- raise unless error.message =~ /Deadlock found when trying to get lock|Lock wait timeout exceeded/
- raise unless retry_count < 10
- retry_count += 1
- logger.info "Deadlock detected on retry #{retry_count}, restarting transaction"
- sleep(rand(retry_count)*0.1) # Aloha protocol
- retry
- end
- end
-
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb
deleted file mode 100644
index 2772dff5c..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/model/validatable.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-require 'awesome_nested_set/set_validator'
-
-module CollectiveIdea
- module Acts
- module NestedSet
- module Model
- module Validatable
-
- def valid?
- left_and_rights_valid? && no_duplicates_for_columns? && all_roots_valid?
- end
-
- def left_and_rights_valid?
- SetValidator.new(self).valid?
- end
-
- def no_duplicates_for_columns?
- [quoted_left_column_full_name, quoted_right_column_full_name].all? do |column|
- # No duplicates
- select("#{scope_string}#{column}, COUNT(#{column}) as _count").
- group("#{scope_string}#{column}").
- having("COUNT(#{column}) > 1").
- first.nil?
- end
- end
-
- # Wrapper for each_root_valid? that can deal with scope.
- def all_roots_valid?
- if acts_as_nested_set_options[:scope]
- all_roots_valid_by_scope?(roots)
- else
- each_root_valid?(roots)
- end
- end
-
- def all_roots_valid_by_scope?(roots_to_validate)
- roots_grouped_by_scope(roots_to_validate).all? do |scope, grouped_roots|
- each_root_valid?(grouped_roots)
- end
- end
-
- def each_root_valid?(roots_to_validate)
- left = right = 0
- roots_to_validate.all? do |root|
- (root.left > left && root.right > right).tap do
- left = root.left
- right = root.right
- end
- end
- end
-
- private
- def roots_grouped_by_scope(roots_to_group)
- roots_to_group.group_by {|record|
- scope_column_names.collect {|col| record.send(col) }
- }
- end
-
- def scope_string
- Array(acts_as_nested_set_options[:scope]).map do |c|
- connection.quote_column_name(c)
- end.push(nil).join(", ")
- end
-
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/move.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/move.rb
deleted file mode 100644
index c65e05e88..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/move.rb
+++ /dev/null
@@ -1,130 +0,0 @@
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
- class Move
- attr_reader :target, :position, :instance
-
- def initialize(target, position, instance)
- @target = target
- @position = position
- @instance = instance
- end
-
- def move
- prevent_impossible_move
-
- bound, other_bound = get_boundaries
-
- # there would be no change
- return if bound == right || bound == left
-
- # we have defined the boundaries of two non-overlapping intervals,
- # so sorting puts both the intervals and their boundaries in order
- a, b, c, d = [left, right, bound, other_bound].sort
-
- lock_nodes_between! a, d
-
- nested_set_scope.where(where_statement(a, d)).update_all(
- conditions(a, b, c, d)
- )
- end
-
- private
-
- delegate :left, :right, :left_column_name, :right_column_name,
- :quoted_left_column_name, :quoted_right_column_name,
- :quoted_parent_column_name, :parent_column_name, :nested_set_scope,
- :to => :instance
-
- delegate :arel_table, :class, :to => :instance, :prefix => true
- delegate :base_class, :to => :instance_class, :prefix => :instance
-
- def where_statement(left_bound, right_bound)
- instance_arel_table[left_column_name].in(left_bound..right_bound).
- or(instance_arel_table[right_column_name].in(left_bound..right_bound))
- end
-
- def conditions(a, b, c, d)
- _conditions = case_condition_for_direction(:quoted_left_column_name) +
- case_condition_for_direction(:quoted_right_column_name) +
- case_condition_for_parent
-
- # We want the record to be 'touched' if it timestamps.
- if @instance.respond_to?(:updated_at)
- _conditions << ", updated_at = :timestamp"
- end
-
- [
- _conditions,
- {
- :a => a, :b => b, :c => c, :d => d,
- :id => instance.id,
- :new_parent => new_parent,
- :timestamp => Time.now.utc
- }
- ]
- end
-
- def case_condition_for_direction(column_name)
- column = send(column_name)
- "#{column} = CASE " +
- "WHEN #{column} BETWEEN :a AND :b " +
- "THEN #{column} + :d - :b " +
- "WHEN #{column} BETWEEN :c AND :d " +
- "THEN #{column} + :a - :c " +
- "ELSE #{column} END, "
- end
-
- def case_condition_for_parent
- "#{quoted_parent_column_name} = CASE " +
- "WHEN #{instance_base_class.primary_key} = :id THEN :new_parent " +
- "ELSE #{quoted_parent_column_name} END"
- end
-
- def lock_nodes_between!(left_bound, right_bound)
- # select the rows in the model between a and d, and apply a lock
- instance_base_class.right_of(left_bound).left_of_right_side(right_bound).
- select(:id).lock(true)
- end
-
- def root
- position == :root
- end
-
- def new_parent
- case position
- when :child
- target.id
- else
- target[parent_column_name]
- end
- end
-
- def get_boundaries
- if (bound = target_bound) > right
- bound -= 1
- other_bound = right + 1
- else
- other_bound = left - 1
- end
- [bound, other_bound]
- end
-
- def prevent_impossible_move
- if !root && !instance.move_possible?(target)
- raise ActiveRecord::ActiveRecordError, "Impossible move, target node cannot be inside moved tree."
- end
- end
-
- def target_bound
- case position
- when :child; right(target)
- when :left; left(target)
- when :right; right(target) + 1
- else raise ActiveRecord::ActiveRecordError, "Position should be :child, :left, :right or :root ('#{position}' received)."
- end
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/set_validator.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/set_validator.rb
deleted file mode 100644
index 7cb9d3c30..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/set_validator.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
- class SetValidator
-
- def initialize(model)
- @model = model
- @scope = model.scoped
- @parent = arel_table.alias('parent')
- end
-
- def valid?
- query.count == 0
- end
-
- private
-
- attr_reader :model, :parent
- attr_accessor :scope
-
- delegate :parent_column_name, :primary_key, :left_column_name, :right_column_name, :arel_table,
- :quoted_table_name, :quoted_parent_column_full_name, :quoted_left_column_full_name, :quoted_right_column_full_name, :quoted_left_column_name, :quoted_right_column_name,
- :to => :model
-
- def query
- join_scope
- filter_scope
- end
-
- def join_scope
- join_arel = arel_table.join(parent, Arel::Nodes::OuterJoin).on(parent[primary_key].eq(arel_table[parent_column_name]))
- self.scope = scope.joins(join_arel.join_sql)
- end
-
- def filter_scope
- self.scope = scope.where(
- bound_is_null(left_column_name).
- or(bound_is_null(right_column_name)).
- or(left_bound_greater_than_right).
- or(parent_not_null.and(bounds_outside_parent))
- )
- end
-
- def bound_is_null(column_name)
- arel_table[column_name].eq(nil)
- end
-
- def left_bound_greater_than_right
- arel_table[left_column_name].gteq(arel_table[right_column_name])
- end
-
- def parent_not_null
- arel_table[parent_column_name].not_eq(nil)
- end
-
- def bounds_outside_parent
- arel_table[left_column_name].lteq(parent[left_column_name]).or(arel_table[right_column_name].gteq(parent[right_column_name]))
- end
-
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/tree.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/tree.rb
deleted file mode 100644
index 4a032c2a2..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/tree.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-module CollectiveIdea #:nodoc:
- module Acts #:nodoc:
- module NestedSet #:nodoc:
- class Tree
- attr_reader :model, :validate_nodes
- attr_accessor :indices
-
- delegate :left_column_name, :right_column_name, :quoted_parent_column_full_name,
- :order_for_rebuild, :scope_for_rebuild,
- :to => :model
-
- def initialize(model, validate_nodes)
- @model = model
- @validate_nodes = validate_nodes
- @indices = {}
- end
-
- def rebuild!
- # Don't rebuild a valid tree.
- return true if model.valid?
-
- root_nodes.each do |root_node|
- # setup index for this scope
- indices[scope_for_rebuild.call(root_node)] ||= 0
- set_left_and_rights(root_node)
- end
- end
-
- private
-
- def increment_indice!(node)
- indices[scope_for_rebuild.call(node)] += 1
- end
-
- def set_left_and_rights(node)
- set_left!(node)
- # find
- node_children(node).each { |n| set_left_and_rights(n) }
- set_right!(node)
-
- node.save!(:validate => validate_nodes)
- end
-
- def node_children(node)
- model.where(["#{quoted_parent_column_full_name} = ? #{scope_for_rebuild.call(node)}", node]).
- order(order_for_rebuild)
- end
-
- def root_nodes
- model.where("#{quoted_parent_column_full_name} IS NULL").order(order_for_rebuild)
- end
-
- def set_left!(node)
- node[left_column_name] = increment_indice!(node)
- end
-
- def set_right!(node)
- node[right_column_name] = increment_indice!(node)
- end
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/version.rb b/lib/plugins/awesome_nested_set/lib/awesome_nested_set/version.rb
deleted file mode 100644
index c7058f7f4..000000000
--- a/lib/plugins/awesome_nested_set/lib/awesome_nested_set/version.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-module AwesomeNestedSet
- VERSION = '2.1.7' unless defined?(::AwesomeNestedSet::VERSION)
-end
diff --git a/lib/plugins/awesome_nested_set/spec/awesome_nested_set/helper_spec.rb b/lib/plugins/awesome_nested_set/spec/awesome_nested_set/helper_spec.rb
deleted file mode 100644
index 9b2857e04..000000000
--- a/lib/plugins/awesome_nested_set/spec/awesome_nested_set/helper_spec.rb
+++ /dev/null
@@ -1,102 +0,0 @@
-require 'spec_helper'
-require 'awesome_nested_set/helper'
-
-describe "Helper" do
- include CollectiveIdea::Acts::NestedSet::Helper
-
- before(:all) do
- self.class.fixtures :categories
- end
-
- describe "nested_set_options" do
- it "test_nested_set_options" do
- expected = [
- [" Top Level", 1],
- ["- Child 1", 2],
- ['- Child 2', 3],
- ['-- Child 2.1', 4],
- ['- Child 3', 5],
- [" Top Level 2", 6]
- ]
- actual = nested_set_options(Category.scoped) do |c|
- "#{'-' * c.level} #{c.name}"
- end
- actual.should == expected
- end
-
- it "test_nested_set_options_with_mover" do
- expected = [
- [" Top Level", 1],
- ["- Child 1", 2],
- ['- Child 3', 5],
- [" Top Level 2", 6]
- ]
- actual = nested_set_options(Category.scoped, categories(:child_2)) do |c|
- "#{'-' * c.level} #{c.name}"
- end
- actual.should == expected
- end
-
- it "test_nested_set_options_with_class_as_argument" do
- expected = [
- [" Top Level", 1],
- ["- Child 1", 2],
- ['- Child 2', 3],
- ['-- Child 2.1', 4],
- ['- Child 3', 5],
- [" Top Level 2", 6]
- ]
- actual = nested_set_options(Category) do |c|
- "#{'-' * c.level} #{c.name}"
- end
- actual.should == expected
- end
-
- it "test_nested_set_options_with_class_as_argument_with_mover" do
- expected = [
- [" Top Level", 1],
- ["- Child 1", 2],
- ['- Child 3', 5],
- [" Top Level 2", 6]
- ]
- actual = nested_set_options(Category, categories(:child_2)) do |c|
- "#{'-' * c.level} #{c.name}"
- end
- actual.should == expected
- end
-
- it "test_nested_set_options_with_array_as_argument_without_mover" do
- expected = [
- [" Top Level", 1],
- ["- Child 1", 2],
- ['- Child 2', 3],
- ['-- Child 2.1', 4],
- ['- Child 3', 5],
- [" Top Level 2", 6]
- ]
- actual = nested_set_options(Category.all) do |c|
- "#{'-' * c.level} #{c.name}"
- end
- actual.length.should == expected.length
- expected.flatten.each do |node|
- actual.flatten.should include(node)
- end
- end
-
- it "test_nested_set_options_with_array_as_argument_with_mover" do
- expected = [
- [" Top Level", 1],
- ["- Child 1", 2],
- ['- Child 3', 5],
- [" Top Level 2", 6]
- ]
- actual = nested_set_options(Category.all, categories(:child_2)) do |c|
- "#{'-' * c.level} #{c.name}"
- end
- actual.length.should == expected.length
- expected.flatten.each do |node|
- actual.flatten.should include(node)
- end
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/spec/awesome_nested_set_spec.rb b/lib/plugins/awesome_nested_set/spec/awesome_nested_set_spec.rb
deleted file mode 100644
index 60cb888b2..000000000
--- a/lib/plugins/awesome_nested_set/spec/awesome_nested_set_spec.rb
+++ /dev/null
@@ -1,1098 +0,0 @@
-require 'spec_helper'
-
-describe "AwesomeNestedSet" do
- before(:all) do
- self.class.fixtures :categories, :departments, :notes, :things, :brokens
- end
-
- describe "defaults" do
- it "should have left_column_default" do
- Default.acts_as_nested_set_options[:left_column].should == 'lft'
- end
-
- it "should have right_column_default" do
- Default.acts_as_nested_set_options[:right_column].should == 'rgt'
- end
-
- it "should have parent_column_default" do
- Default.acts_as_nested_set_options[:parent_column].should == 'parent_id'
- end
-
- it "should have scope_default" do
- Default.acts_as_nested_set_options[:scope].should be_nil
- end
-
- it "should have left_column_name" do
- Default.left_column_name.should == 'lft'
- Default.new.left_column_name.should == 'lft'
- RenamedColumns.left_column_name.should == 'red'
- RenamedColumns.new.left_column_name.should == 'red'
- end
-
- it "should have right_column_name" do
- Default.right_column_name.should == 'rgt'
- Default.new.right_column_name.should == 'rgt'
- RenamedColumns.right_column_name.should == 'black'
- RenamedColumns.new.right_column_name.should == 'black'
- end
-
- it "has a depth_column_name" do
- Default.depth_column_name.should == 'depth'
- Default.new.depth_column_name.should == 'depth'
- RenamedColumns.depth_column_name.should == 'pitch'
- RenamedColumns.depth_column_name.should == 'pitch'
- end
-
- it "should have parent_column_name" do
- Default.parent_column_name.should == 'parent_id'
- Default.new.parent_column_name.should == 'parent_id'
- RenamedColumns.parent_column_name.should == 'mother_id'
- RenamedColumns.new.parent_column_name.should == 'mother_id'
- end
- end
-
- it "creation_with_altered_column_names" do
- lambda {
- RenamedColumns.create!()
- }.should_not raise_exception
- end
-
- it "creation when existing record has nil left column" do
- assert_nothing_raised do
- Broken.create!
- end
- end
-
- it "quoted_left_column_name" do
- quoted = Default.connection.quote_column_name('lft')
- Default.quoted_left_column_name.should == quoted
- Default.new.quoted_left_column_name.should == quoted
- end
-
- it "quoted_right_column_name" do
- quoted = Default.connection.quote_column_name('rgt')
- Default.quoted_right_column_name.should == quoted
- Default.new.quoted_right_column_name.should == quoted
- end
-
- it "quoted_depth_column_name" do
- quoted = Default.connection.quote_column_name('depth')
- Default.quoted_depth_column_name.should == quoted
- Default.new.quoted_depth_column_name.should == quoted
- end
-
- it "quoted_order_column_name" do
- quoted = Default.connection.quote_column_name('lft')
- Default.quoted_order_column_name.should == quoted
- Default.new.quoted_order_column_name.should == quoted
- end
-
- it "left_column_protected_from_assignment" do
- lambda {
- Category.new.lft = 1
- }.should raise_exception(ActiveRecord::ActiveRecordError)
- end
-
- it "right_column_protected_from_assignment" do
- lambda {
- Category.new.rgt = 1
- }.should raise_exception(ActiveRecord::ActiveRecordError)
- end
-
- it "depth_column_protected_from_assignment" do
- lambda {
- Category.new.depth = 1
- }.should raise_exception(ActiveRecord::ActiveRecordError)
- end
-
- it "scoped_appends_id" do
- ScopedCategory.acts_as_nested_set_options[:scope].should == :organization_id
- end
-
- it "roots_class_method" do
- found_by_us = Category.where(:parent_id => nil).to_a
- found_by_roots = Category.roots.to_a
- found_by_us.length.should == found_by_roots.length
- found_by_us.each do |root|
- found_by_roots.should include(root)
- end
- end
-
- it "root_class_method" do
- Category.root.should == categories(:top_level)
- end
-
- it "root" do
- categories(:child_3).root.should == categories(:top_level)
- end
-
- it "root when not persisted and parent_column_name value is self" do
- new_category = Category.new
- new_category.root.should == new_category
- end
-
- it "root when not persisted and parent_column_name value is set" do
- last_category = Category.last
- Category.new(Default.parent_column_name => last_category.id).root.should == last_category.root
- end
-
- it "root?" do
- categories(:top_level).root?.should be_true
- categories(:top_level_2).root?.should be_true
- end
-
- it "leaves_class_method" do
- Category.leaves.count.should == 4
- Category.leaves.should include(categories(:child_1))
- Category.leaves.should include(categories(:child_2_1))
- Category.leaves.should include(categories(:child_3))
- Category.leaves.should include(categories(:top_level_2))
- end
-
- it "leaf" do
- categories(:child_1).leaf?.should be_true
- categories(:child_2_1).leaf?.should be_true
- categories(:child_3).leaf?.should be_true
- categories(:top_level_2).leaf?.should be_true
-
- categories(:top_level).leaf?.should be_false
- categories(:child_2).leaf?.should be_false
- Category.new.leaf?.should be_false
- end
-
-
- it "parent" do
- categories(:child_2_1).parent.should == categories(:child_2)
- end
-
- it "self_and_ancestors" do
- child = categories(:child_2_1)
- self_and_ancestors = [categories(:top_level), categories(:child_2), child]
- child.self_and_ancestors.should == self_and_ancestors
- end
-
- it "ancestors" do
- child = categories(:child_2_1)
- ancestors = [categories(:top_level), categories(:child_2)]
- ancestors.should == child.ancestors
- end
-
- it "self_and_siblings" do
- child = categories(:child_2)
- self_and_siblings = [categories(:child_1), child, categories(:child_3)]
- self_and_siblings.should == child.self_and_siblings
- lambda do
- tops = [categories(:top_level), categories(:top_level_2)]
- assert_equal tops, categories(:top_level).self_and_siblings
- end.should_not raise_exception
- end
-
- it "siblings" do
- child = categories(:child_2)
- siblings = [categories(:child_1), categories(:child_3)]
- siblings.should == child.siblings
- end
-
- it "leaves" do
- leaves = [categories(:child_1), categories(:child_2_1), categories(:child_3)]
- categories(:top_level).leaves.should == leaves
- end
-
- describe "level" do
- it "returns the correct level" do
- categories(:top_level).level.should == 0
- categories(:child_1).level.should == 1
- categories(:child_2_1).level.should == 2
- end
-
- context "given parent associations are loaded" do
- it "returns the correct level" do
- child = categories(:child_1)
- if child.respond_to?(:association)
- child.association(:parent).load_target
- child.parent.association(:parent).load_target
- child.level.should == 1
- else
- pending 'associations not used where child#association is not a method'
- end
- end
- end
- end
-
- describe "depth" do
- let(:lawyers) { Category.create!(:name => "lawyers") }
- let(:us) { Category.create!(:name => "United States") }
- let(:new_york) { Category.create!(:name => "New York") }
- let(:patent) { Category.create!(:name => "Patent Law") }
-
- before(:each) do
- # lawyers > us > new_york > patent
- us.move_to_child_of(lawyers)
- new_york.move_to_child_of(us)
- patent.move_to_child_of(new_york)
- [lawyers, us, new_york, patent].each(&:reload)
- end
-
- it "updates depth when moved into child position" do
- lawyers.depth.should == 0
- us.depth.should == 1
- new_york.depth.should == 2
- patent.depth.should == 3
- end
-
- it "updates depth of all descendants when parent is moved" do
- # lawyers
- # us > new_york > patent
- us.move_to_right_of(lawyers)
- [lawyers, us, new_york, patent].each(&:reload)
- us.depth.should == 0
- new_york.depth.should == 1
- patent.depth.should == 2
- end
- end
-
- it "depth is magic and does not apply when column is missing" do
- lambda { NoDepth.create!(:name => "shallow") }.should_not raise_error
- lambda { NoDepth.first.save }.should_not raise_error
- lambda { NoDepth.rebuild! }.should_not raise_error
-
- NoDepth.method_defined?(:depth).should be_false
- NoDepth.first.respond_to?(:depth).should be_false
- end
-
- it "has_children?" do
- categories(:child_2_1).children.empty?.should be_true
- categories(:child_2).children.empty?.should be_false
- categories(:top_level).children.empty?.should be_false
- end
-
- it "self_and_descendants" do
- parent = categories(:top_level)
- self_and_descendants = [
- parent,
- categories(:child_1),
- categories(:child_2),
- categories(:child_2_1),
- categories(:child_3)
- ]
- self_and_descendants.should == parent.self_and_descendants
- self_and_descendants.count.should == parent.self_and_descendants.count
- end
-
- it "descendants" do
- lawyers = Category.create!(:name => "lawyers")
- us = Category.create!(:name => "United States")
- us.move_to_child_of(lawyers)
- patent = Category.create!(:name => "Patent Law")
- patent.move_to_child_of(us)
- lawyers.reload
-
- lawyers.children.size.should == 1
- us.children.size.should == 1
- lawyers.descendants.size.should == 2
- end
-
- it "self_and_descendants" do
- parent = categories(:top_level)
- descendants = [
- categories(:child_1),
- categories(:child_2),
- categories(:child_2_1),
- categories(:child_3)
- ]
- descendants.should == parent.descendants
- end
-
- it "children" do
- category = categories(:top_level)
- category.children.each {|c| category.id.should == c.parent_id }
- end
-
- it "order_of_children" do
- categories(:child_2).move_left
- categories(:child_2).should == categories(:top_level).children[0]
- categories(:child_1).should == categories(:top_level).children[1]
- categories(:child_3).should == categories(:top_level).children[2]
- end
-
- it "is_or_is_ancestor_of?" do
- categories(:top_level).is_or_is_ancestor_of?(categories(:child_1)).should be_true
- categories(:top_level).is_or_is_ancestor_of?(categories(:child_2_1)).should be_true
- categories(:child_2).is_or_is_ancestor_of?(categories(:child_2_1)).should be_true
- categories(:child_2_1).is_or_is_ancestor_of?(categories(:child_2)).should be_false
- categories(:child_1).is_or_is_ancestor_of?(categories(:child_2)).should be_false
- categories(:child_1).is_or_is_ancestor_of?(categories(:child_1)).should be_true
- end
-
- it "is_ancestor_of?" do
- categories(:top_level).is_ancestor_of?(categories(:child_1)).should be_true
- categories(:top_level).is_ancestor_of?(categories(:child_2_1)).should be_true
- categories(:child_2).is_ancestor_of?(categories(:child_2_1)).should be_true
- categories(:child_2_1).is_ancestor_of?(categories(:child_2)).should be_false
- categories(:child_1).is_ancestor_of?(categories(:child_2)).should be_false
- categories(:child_1).is_ancestor_of?(categories(:child_1)).should be_false
- end
-
- it "is_or_is_ancestor_of_with_scope" do
- root = ScopedCategory.root
- child = root.children.first
- root.is_or_is_ancestor_of?(child).should be_true
- child.update_attribute :organization_id, 'different'
- root.is_or_is_ancestor_of?(child).should be_false
- end
-
- it "is_or_is_descendant_of?" do
- categories(:child_1).is_or_is_descendant_of?(categories(:top_level)).should be_true
- categories(:child_2_1).is_or_is_descendant_of?(categories(:top_level)).should be_true
- categories(:child_2_1).is_or_is_descendant_of?(categories(:child_2)).should be_true
- categories(:child_2).is_or_is_descendant_of?(categories(:child_2_1)).should be_false
- categories(:child_2).is_or_is_descendant_of?(categories(:child_1)).should be_false
- categories(:child_1).is_or_is_descendant_of?(categories(:child_1)).should be_true
- end
-
- it "is_descendant_of?" do
- categories(:child_1).is_descendant_of?(categories(:top_level)).should be_true
- categories(:child_2_1).is_descendant_of?(categories(:top_level)).should be_true
- categories(:child_2_1).is_descendant_of?(categories(:child_2)).should be_true
- categories(:child_2).is_descendant_of?(categories(:child_2_1)).should be_false
- categories(:child_2).is_descendant_of?(categories(:child_1)).should be_false
- categories(:child_1).is_descendant_of?(categories(:child_1)).should be_false
- end
-
- it "is_or_is_descendant_of_with_scope" do
- root = ScopedCategory.root
- child = root.children.first
- child.is_or_is_descendant_of?(root).should be_true
- child.update_attribute :organization_id, 'different'
- child.is_or_is_descendant_of?(root).should be_false
- end
-
- it "same_scope?" do
- root = ScopedCategory.root
- child = root.children.first
- child.same_scope?(root).should be_true
- child.update_attribute :organization_id, 'different'
- child.same_scope?(root).should be_false
- end
-
- it "left_sibling" do
- categories(:child_1).should == categories(:child_2).left_sibling
- categories(:child_2).should == categories(:child_3).left_sibling
- end
-
- it "left_sibling_of_root" do
- categories(:top_level).left_sibling.should be_nil
- end
-
- it "left_sibling_without_siblings" do
- categories(:child_2_1).left_sibling.should be_nil
- end
-
- it "left_sibling_of_leftmost_node" do
- categories(:child_1).left_sibling.should be_nil
- end
-
- it "right_sibling" do
- categories(:child_3).should == categories(:child_2).right_sibling
- categories(:child_2).should == categories(:child_1).right_sibling
- end
-
- it "right_sibling_of_root" do
- categories(:top_level_2).should == categories(:top_level).right_sibling
- categories(:top_level_2).right_sibling.should be_nil
- end
-
- it "right_sibling_without_siblings" do
- categories(:child_2_1).right_sibling.should be_nil
- end
-
- it "right_sibling_of_rightmost_node" do
- categories(:child_3).right_sibling.should be_nil
- end
-
- it "move_left" do
- categories(:child_2).move_left
- categories(:child_2).left_sibling.should be_nil
- categories(:child_1).should == categories(:child_2).right_sibling
- Category.valid?.should be_true
- end
-
- it "move_right" do
- categories(:child_2).move_right
- categories(:child_2).right_sibling.should be_nil
- categories(:child_3).should == categories(:child_2).left_sibling
- Category.valid?.should be_true
- end
-
- it "move_to_left_of" do
- categories(:child_3).move_to_left_of(categories(:child_1))
- categories(:child_3).left_sibling.should be_nil
- categories(:child_1).should == categories(:child_3).right_sibling
- Category.valid?.should be_true
- end
-
- it "move_to_right_of" do
- categories(:child_1).move_to_right_of(categories(:child_3))
- categories(:child_1).right_sibling.should be_nil
- categories(:child_3).should == categories(:child_1).left_sibling
- Category.valid?.should be_true
- end
-
- it "move_to_root" do
- categories(:child_2).move_to_root
- categories(:child_2).parent.should be_nil
- categories(:child_2).level.should == 0
- categories(:child_2_1).level.should == 1
- categories(:child_2).left.should == 7
- categories(:child_2).right.should == 10
- Category.valid?.should be_true
- end
-
- it "move_to_child_of" do
- categories(:child_1).move_to_child_of(categories(:child_3))
- categories(:child_3).id.should == categories(:child_1).parent_id
- Category.valid?.should be_true
- end
-
- describe "#move_to_child_with_index" do
- it "move to a node without child" do
- categories(:child_1).move_to_child_with_index(categories(:child_3), 0)
- categories(:child_3).id.should == categories(:child_1).parent_id
- categories(:child_1).left.should == 7
- categories(:child_1).right.should == 8
- categories(:child_3).left.should == 6
- categories(:child_3).right.should == 9
- Category.valid?.should be_true
- end
-
- it "move to a node to the left child" do
- categories(:child_1).move_to_child_with_index(categories(:child_2), 0)
- categories(:child_1).parent_id.should == categories(:child_2).id
- categories(:child_2_1).left.should == 5
- categories(:child_2_1).right.should == 6
- categories(:child_1).left.should == 3
- categories(:child_1).right.should == 4
- categories(:child_2).reload
- categories(:child_2).left.should == 2
- categories(:child_2).right.should == 7
- end
-
- it "move to a node to the right child" do
- categories(:child_1).move_to_child_with_index(categories(:child_2), 1)
- categories(:child_1).parent_id.should == categories(:child_2).id
- categories(:child_2_1).left.should == 3
- categories(:child_2_1).right.should == 4
- categories(:child_1).left.should == 5
- categories(:child_1).right.should == 6
- categories(:child_2).reload
- categories(:child_2).left.should == 2
- categories(:child_2).right.should == 7
- end
-
- end
-
- it "move_to_child_of_appends_to_end" do
- child = Category.create! :name => 'New Child'
- child.move_to_child_of categories(:top_level)
- child.should == categories(:top_level).children.last
- end
-
- it "subtree_move_to_child_of" do
- categories(:child_2).left.should == 4
- categories(:child_2).right.should == 7
-
- categories(:child_1).left.should == 2
- categories(:child_1).right.should == 3
-
- categories(:child_2).move_to_child_of(categories(:child_1))
- Category.valid?.should be_true
- categories(:child_1).id.should == categories(:child_2).parent_id
-
- categories(:child_2).left.should == 3
- categories(:child_2).right.should == 6
- categories(:child_1).left.should == 2
- categories(:child_1).right.should == 7
- end
-
- it "slightly_difficult_move_to_child_of" do
- categories(:top_level_2).left.should == 11
- categories(:top_level_2).right.should == 12
-
- # create a new top-level node and move single-node top-level tree inside it.
- new_top = Category.create(:name => 'New Top')
- new_top.left.should == 13
- new_top.right.should == 14
-
- categories(:top_level_2).move_to_child_of(new_top)
-
- Category.valid?.should be_true
- new_top.id.should == categories(:top_level_2).parent_id
-
- categories(:top_level_2).left.should == 12
- categories(:top_level_2).right.should == 13
- new_top.left.should == 11
- new_top.right.should == 14
- end
-
- it "difficult_move_to_child_of" do
- categories(:top_level).left.should == 1
- categories(:top_level).right.should == 10
- categories(:child_2_1).left.should == 5
- categories(:child_2_1).right.should == 6
-
- # create a new top-level node and move an entire top-level tree inside it.
- new_top = Category.create(:name => 'New Top')
- categories(:top_level).move_to_child_of(new_top)
- categories(:child_2_1).reload
- Category.valid?.should be_true
- new_top.id.should == categories(:top_level).parent_id
-
- categories(:top_level).left.should == 4
- categories(:top_level).right.should == 13
- categories(:child_2_1).left.should == 8
- categories(:child_2_1).right.should == 9
- end
-
- #rebuild swaps the position of the 2 children when added using move_to_child twice onto same parent
- it "move_to_child_more_than_once_per_parent_rebuild" do
- root1 = Category.create(:name => 'Root1')
- root2 = Category.create(:name => 'Root2')
- root3 = Category.create(:name => 'Root3')
-
- root2.move_to_child_of root1
- root3.move_to_child_of root1
-
- output = Category.roots.last.to_text
- Category.update_all('lft = null, rgt = null')
- Category.rebuild!
-
- Category.roots.last.to_text.should == output
- end
-
- # doing move_to_child twice onto same parent from the furthest right first
- it "move_to_child_more_than_once_per_parent_outside_in" do
- node1 = Category.create(:name => 'Node-1')
- node2 = Category.create(:name => 'Node-2')
- node3 = Category.create(:name => 'Node-3')
-
- node2.move_to_child_of node1
- node3.move_to_child_of node1
-
- output = Category.roots.last.to_text
- Category.update_all('lft = null, rgt = null')
- Category.rebuild!
-
- Category.roots.last.to_text.should == output
- end
-
- it "should_move_to_ordered_child" do
- node1 = Category.create(:name => 'Node-1')
- node2 = Category.create(:name => 'Node-2')
- node3 = Category.create(:name => 'Node-3')
-
- node2.move_to_ordered_child_of(node1, "name")
-
- assert_equal node1, node2.parent
- assert_equal 1, node1.children.count
-
- node3.move_to_ordered_child_of(node1, "name", true) # acending
-
- assert_equal node1, node3.parent
- assert_equal 2, node1.children.count
- assert_equal node2.name, node1.children[0].name
- assert_equal node3.name, node1.children[1].name
-
- node3.move_to_ordered_child_of(node1, "name", false) # decending
- node1.reload
-
- assert_equal node1, node3.parent
- assert_equal 2, node1.children.count
- assert_equal node3.name, node1.children[0].name
- assert_equal node2.name, node1.children[1].name
- end
-
- it "should be able to rebuild without validating each record" do
- root1 = Category.create(:name => 'Root1')
- root2 = Category.create(:name => 'Root2')
- root3 = Category.create(:name => 'Root3')
-
- root2.move_to_child_of root1
- root3.move_to_child_of root1
-
- root2.name = nil
- root2.save!(:validate => false)
-
- output = Category.roots.last.to_text
- Category.update_all('lft = null, rgt = null')
- Category.rebuild!(false)
-
- Category.roots.last.to_text.should == output
- end
-
- it "valid_with_null_lefts" do
- Category.valid?.should be_true
- Category.update_all('lft = null')
- Category.valid?.should be_false
- end
-
- it "valid_with_null_rights" do
- Category.valid?.should be_true
- Category.update_all('rgt = null')
- Category.valid?.should be_false
- end
-
- it "valid_with_missing_intermediate_node" do
- # Even though child_2_1 will still exist, it is a sign of a sloppy delete, not an invalid tree.
- Category.valid?.should be_true
- Category.delete(categories(:child_2).id)
- Category.valid?.should be_true
- end
-
- it "valid_with_overlapping_and_rights" do
- Category.valid?.should be_true
- categories(:top_level_2)['lft'] = 0
- categories(:top_level_2).save
- Category.valid?.should be_false
- end
-
- it "rebuild" do
- Category.valid?.should be_true
- before_text = Category.root.to_text
- Category.update_all('lft = null, rgt = null')
- Category.rebuild!
- Category.valid?.should be_true
- before_text.should == Category.root.to_text
- end
-
- it "move_possible_for_sibling" do
- categories(:child_2).move_possible?(categories(:child_1)).should be_true
- end
-
- it "move_not_possible_to_self" do
- categories(:top_level).move_possible?(categories(:top_level)).should be_false
- end
-
- it "move_not_possible_to_parent" do
- categories(:top_level).descendants.each do |descendant|
- categories(:top_level).move_possible?(descendant).should be_false
- descendant.move_possible?(categories(:top_level)).should be_true
- end
- end
-
- it "is_or_is_ancestor_of?" do
- [:child_1, :child_2, :child_2_1, :child_3].each do |c|
- categories(:top_level).is_or_is_ancestor_of?(categories(c)).should be_true
- end
- categories(:top_level).is_or_is_ancestor_of?(categories(:top_level_2)).should be_false
- end
-
- it "left_and_rights_valid_with_blank_left" do
- Category.left_and_rights_valid?.should be_true
- categories(:child_2)[:lft] = nil
- categories(:child_2).save(:validate => false)
- Category.left_and_rights_valid?.should be_false
- end
-
- it "left_and_rights_valid_with_blank_right" do
- Category.left_and_rights_valid?.should be_true
- categories(:child_2)[:rgt] = nil
- categories(:child_2).save(:validate => false)
- Category.left_and_rights_valid?.should be_false
- end
-
- it "left_and_rights_valid_with_equal" do
- Category.left_and_rights_valid?.should be_true
- categories(:top_level_2)[:lft] = categories(:top_level_2)[:rgt]
- categories(:top_level_2).save(:validate => false)
- Category.left_and_rights_valid?.should be_false
- end
-
- it "left_and_rights_valid_with_left_equal_to_parent" do
- Category.left_and_rights_valid?.should be_true
- categories(:child_2)[:lft] = categories(:top_level)[:lft]
- categories(:child_2).save(:validate => false)
- Category.left_and_rights_valid?.should be_false
- end
-
- it "left_and_rights_valid_with_right_equal_to_parent" do
- Category.left_and_rights_valid?.should be_true
- categories(:child_2)[:rgt] = categories(:top_level)[:rgt]
- categories(:child_2).save(:validate => false)
- Category.left_and_rights_valid?.should be_false
- end
-
- it "moving_dirty_objects_doesnt_invalidate_tree" do
- r1 = Category.create :name => "Test 1"
- r2 = Category.create :name => "Test 2"
- r3 = Category.create :name => "Test 3"
- r4 = Category.create :name => "Test 4"
- nodes = [r1, r2, r3, r4]
-
- r2.move_to_child_of(r1)
- Category.valid?.should be_true
-
- r3.move_to_child_of(r1)
- Category.valid?.should be_true
-
- r4.move_to_child_of(r2)
- Category.valid?.should be_true
- end
-
- it "multi_scoped_no_duplicates_for_columns?" do
- lambda {
- Note.no_duplicates_for_columns?
- }.should_not raise_exception
- end
-
- it "multi_scoped_all_roots_valid?" do
- lambda {
- Note.all_roots_valid?
- }.should_not raise_exception
- end
-
- it "multi_scoped" do
- note1 = Note.create!(:body => "A", :notable_id => 2, :notable_type => 'Category')
- note2 = Note.create!(:body => "B", :notable_id => 2, :notable_type => 'Category')
- note3 = Note.create!(:body => "C", :notable_id => 2, :notable_type => 'Default')
-
- [note1, note2].should == note1.self_and_siblings
- [note3].should == note3.self_and_siblings
- end
-
- it "multi_scoped_rebuild" do
- root = Note.create!(:body => "A", :notable_id => 3, :notable_type => 'Category')
- child1 = Note.create!(:body => "B", :notable_id => 3, :notable_type => 'Category')
- child2 = Note.create!(:body => "C", :notable_id => 3, :notable_type => 'Category')
-
- child1.move_to_child_of root
- child2.move_to_child_of root
-
- Note.update_all('lft = null, rgt = null')
- Note.rebuild!
-
- Note.roots.find_by_body('A').should == root
- [child1, child2].should == Note.roots.find_by_body('A').children
- end
-
- it "same_scope_with_multi_scopes" do
- lambda {
- notes(:scope1).same_scope?(notes(:child_1))
- }.should_not raise_exception
- notes(:scope1).same_scope?(notes(:child_1)).should be_true
- notes(:child_1).same_scope?(notes(:scope1)).should be_true
- notes(:scope1).same_scope?(notes(:scope2)).should be_false
- end
-
- it "quoting_of_multi_scope_column_names" do
- ## Proper Array Assignment for different DBs as per their quoting column behavior
- if Note.connection.adapter_name.match(/oracle/i)
- expected_quoted_scope_column_names = ["\"NOTABLE_ID\"", "\"NOTABLE_TYPE\""]
- elsif Note.connection.adapter_name.match(/mysql/i)
- expected_quoted_scope_column_names = ["`notable_id`", "`notable_type`"]
- else
- expected_quoted_scope_column_names = ["\"notable_id\"", "\"notable_type\""]
- end
- Note.quoted_scope_column_names.should == expected_quoted_scope_column_names
- end
-
- it "equal_in_same_scope" do
- notes(:scope1).should == notes(:scope1)
- notes(:scope1).should_not == notes(:child_1)
- end
-
- it "equal_in_different_scopes" do
- notes(:scope1).should_not == notes(:scope2)
- end
-
- it "delete_does_not_invalidate" do
- Category.acts_as_nested_set_options[:dependent] = :delete
- categories(:child_2).destroy
- Category.valid?.should be_true
- end
-
- it "destroy_does_not_invalidate" do
- Category.acts_as_nested_set_options[:dependent] = :destroy
- categories(:child_2).destroy
- Category.valid?.should be_true
- end
-
- it "destroy_multiple_times_does_not_invalidate" do
- Category.acts_as_nested_set_options[:dependent] = :destroy
- categories(:child_2).destroy
- categories(:child_2).destroy
- Category.valid?.should be_true
- end
-
- it "assigning_parent_id_on_create" do
- category = Category.create!(:name => "Child", :parent_id => categories(:child_2).id)
- categories(:child_2).should == category.parent
- categories(:child_2).id.should == category.parent_id
- category.left.should_not be_nil
- category.right.should_not be_nil
- Category.valid?.should be_true
- end
-
- it "assigning_parent_on_create" do
- category = Category.create!(:name => "Child", :parent => categories(:child_2))
- categories(:child_2).should == category.parent
- categories(:child_2).id.should == category.parent_id
- category.left.should_not be_nil
- category.right.should_not be_nil
- Category.valid?.should be_true
- end
-
- it "assigning_parent_id_to_nil_on_create" do
- category = Category.create!(:name => "New Root", :parent_id => nil)
- category.parent.should be_nil
- category.parent_id.should be_nil
- category.left.should_not be_nil
- category.right.should_not be_nil
- Category.valid?.should be_true
- end
-
- it "assigning_parent_id_on_update" do
- category = categories(:child_2_1)
- category.parent_id = categories(:child_3).id
- category.save
- category.reload
- categories(:child_3).reload
- categories(:child_3).should == category.parent
- categories(:child_3).id.should == category.parent_id
- Category.valid?.should be_true
- end
-
- it "assigning_parent_on_update" do
- category = categories(:child_2_1)
- category.parent = categories(:child_3)
- category.save
- category.reload
- categories(:child_3).reload
- categories(:child_3).should == category.parent
- categories(:child_3).id.should == category.parent_id
- Category.valid?.should be_true
- end
-
- it "assigning_parent_id_to_nil_on_update" do
- category = categories(:child_2_1)
- category.parent_id = nil
- category.save
- category.parent.should be_nil
- category.parent_id.should be_nil
- Category.valid?.should be_true
- end
-
- it "creating_child_from_parent" do
- category = categories(:child_2).children.create!(:name => "Child")
- categories(:child_2).should == category.parent
- categories(:child_2).id.should == category.parent_id
- category.left.should_not be_nil
- category.right.should_not be_nil
- Category.valid?.should be_true
- end
-
- def check_structure(entries, structure)
- structure = structure.dup
- Category.each_with_level(entries) do |category, level|
- expected_level, expected_name = structure.shift
- expected_name.should == category.name
- expected_level.should == level
- end
- end
-
- it "each_with_level" do
- levels = [
- [0, "Top Level"],
- [1, "Child 1"],
- [1, "Child 2"],
- [2, "Child 2.1"],
- [1, "Child 3" ]
- ]
-
- check_structure(Category.root.self_and_descendants, levels)
-
- # test some deeper structures
- category = Category.find_by_name("Child 1")
- c1 = Category.new(:name => "Child 1.1")
- c2 = Category.new(:name => "Child 1.1.1")
- c3 = Category.new(:name => "Child 1.1.1.1")
- c4 = Category.new(:name => "Child 1.2")
- [c1, c2, c3, c4].each(&:save!)
-
- c1.move_to_child_of(category)
- c2.move_to_child_of(c1)
- c3.move_to_child_of(c2)
- c4.move_to_child_of(category)
-
- levels = [
- [0, "Top Level"],
- [1, "Child 1"],
- [2, "Child 1.1"],
- [3, "Child 1.1.1"],
- [4, "Child 1.1.1.1"],
- [2, "Child 1.2"],
- [1, "Child 2"],
- [2, "Child 2.1"],
- [1, "Child 3" ]
- ]
-
- check_structure(Category.root.self_and_descendants, levels)
- end
-
- it "should not error on a model with attr_accessible" do
- model = Class.new(ActiveRecord::Base)
- model.table_name = 'categories'
- model.attr_accessible :name
- lambda {
- model.acts_as_nested_set
- model.new(:name => 'foo')
- }.should_not raise_exception
- end
-
- describe "before_move_callback" do
- it "should fire the callback" do
- categories(:child_2).should_receive(:custom_before_move)
- categories(:child_2).move_to_root
- end
-
- it "should stop move when callback returns false" do
- Category.test_allows_move = false
- categories(:child_3).move_to_root.should be_false
- categories(:child_3).root?.should be_false
- end
-
- it "should not halt save actions" do
- Category.test_allows_move = false
- categories(:child_3).parent_id = nil
- categories(:child_3).save.should be_true
- end
- end
-
- describe "counter_cache" do
-
- it "should allow use of a counter cache for children" do
- note1 = things(:parent1)
- note1.children.count.should == 2
- end
-
- it "should increment the counter cache on create" do
- note1 = things(:parent1)
- note1.children.count.should == 2
- note1[:children_count].should == 2
- note1.children.create :body => 'Child 3'
- note1.children.count.should == 3
- note1.reload
- note1[:children_count].should == 3
- end
-
- it "should decrement the counter cache on destroy" do
- note1 = things(:parent1)
- note1.children.count.should == 2
- note1[:children_count].should == 2
- note1.children.last.destroy
- note1.children.count.should == 1
- note1.reload
- note1[:children_count].should == 1
- end
- end
-
- describe "association callbacks on children" do
- it "should call the appropriate callbacks on the children :has_many association " do
- root = DefaultWithCallbacks.create
- root.should_not be_new_record
-
- child = root.children.build
-
- root.before_add.should == child
- root.after_add.should == child
-
- root.before_remove.should_not == child
- root.after_remove.should_not == child
-
- child.save.should be_true
- root.children.delete(child).should be_true
-
- root.before_remove.should == child
- root.after_remove.should == child
- end
- end
-
- describe 'rebuilding tree with a default scope ordering' do
- it "doesn't throw exception" do
- expect { Position.rebuild! }.not_to raise_error
- end
- end
-
- describe 'creating roots with a default scope ordering' do
- it "assigns rgt and lft correctly" do
- alpha = Order.create(:name => 'Alpha')
- gamma = Order.create(:name => 'Gamma')
- omega = Order.create(:name => 'Omega')
-
- alpha.lft.should == 1
- alpha.rgt.should == 2
- gamma.lft.should == 3
- gamma.rgt.should == 4
- omega.lft.should == 5
- omega.rgt.should == 6
- end
- end
-
- describe 'moving node from one scoped tree to another' do
- xit "moves single node correctly" do
- root1 = Note.create!(:body => "A-1", :notable_id => 4, :notable_type => 'Category')
- child1_1 = Note.create!(:body => "B-1", :notable_id => 4, :notable_type => 'Category')
- child1_2 = Note.create!(:body => "C-1", :notable_id => 4, :notable_type => 'Category')
- child1_1.move_to_child_of root1
- child1_2.move_to_child_of root1
-
- root2 = Note.create!(:body => "A-2", :notable_id => 5, :notable_type => 'Category')
- child2_1 = Note.create!(:body => "B-2", :notable_id => 5, :notable_type => 'Category')
- child2_2 = Note.create!(:body => "C-2", :notable_id => 5, :notable_type => 'Category')
- child2_1.move_to_child_of root2
- child2_2.move_to_child_of root2
-
- child1_1.update_attributes!(:notable_id => 5)
- child1_1.move_to_child_of root2
-
- root1.children.should == [child1_2]
- root2.children.should == [child2_1, child2_2, child1_1]
-
- Note.valid?.should == true
- end
-
- xit "moves node with children correctly" do
- root1 = Note.create!(:body => "A-1", :notable_id => 4, :notable_type => 'Category')
- child1_1 = Note.create!(:body => "B-1", :notable_id => 4, :notable_type => 'Category')
- child1_2 = Note.create!(:body => "C-1", :notable_id => 4, :notable_type => 'Category')
- child1_1.move_to_child_of root1
- child1_2.move_to_child_of child1_1
-
- root2 = Note.create!(:body => "A-2", :notable_id => 5, :notable_type => 'Category')
- child2_1 = Note.create!(:body => "B-2", :notable_id => 5, :notable_type => 'Category')
- child2_2 = Note.create!(:body => "C-2", :notable_id => 5, :notable_type => 'Category')
- child2_1.move_to_child_of root2
- child2_2.move_to_child_of root2
-
- child1_1.update_attributes!(:notable_id => 5)
- child1_1.move_to_child_of root2
-
- root1.children.should == []
- root2.children.should == [child2_1, child2_2, child1_1]
- child1_1.children should == [child1_2]
- root2.siblings.should == [child2_1, child2_2, child1_1, child1_2]
-
- Note.valid?.should == true
- end
- end
-
- describe 'specifying custom sort column' do
- it "should sort by the default sort column" do
- Category.order_column.should == 'lft'
- end
-
- it "should sort by custom sort column" do
- OrderedCategory.acts_as_nested_set_options[:order_column].should == 'name'
- OrderedCategory.order_column.should == 'name'
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/spec/db/database.yml b/lib/plugins/awesome_nested_set/spec/db/database.yml
deleted file mode 100644
index 5218975a4..000000000
--- a/lib/plugins/awesome_nested_set/spec/db/database.yml
+++ /dev/null
@@ -1,27 +0,0 @@
-sqlite3:
- adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3
- database: awesome_nested_set.sqlite3.db
-sqlite3mem:
- adapter: <%= "jdbc" if defined? JRUBY_VERSION %>sqlite3
- database: ":memory:"
-postgresql:
- adapter: postgresql
- encoding: unicode
- database: awesome_nested_set_plugin_test
- pool: 5
- username: postgres
- password: postgres
- min_messages: warning
-mysql:
- adapter: mysql2
- host: localhost
- username: root
- password:
- database: awesome_nested_set_plugin_test
-## Add DB Configuration to run Oracle tests
-oracle:
- adapter: oracle_enhanced
- host: localhost
- username: awesome_nested_set_dev
- password:
- database: xe
diff --git a/lib/plugins/awesome_nested_set/spec/db/schema.rb b/lib/plugins/awesome_nested_set/spec/db/schema.rb
deleted file mode 100644
index b37322b14..000000000
--- a/lib/plugins/awesome_nested_set/spec/db/schema.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-ActiveRecord::Schema.define(:version => 0) do
-
- create_table :categories, :force => true do |t|
- t.column :name, :string
- t.column :parent_id, :integer
- t.column :lft, :integer
- t.column :rgt, :integer
- t.column :depth, :integer
- t.column :organization_id, :integer
- end
-
- create_table :departments, :force => true do |t|
- t.column :name, :string
- end
-
- create_table :notes, :force => true do |t|
- t.column :body, :text
- t.column :parent_id, :integer
- t.column :lft, :integer
- t.column :rgt, :integer
- t.column :depth, :integer
- t.column :notable_id, :integer
- t.column :notable_type, :string
- end
-
- create_table :renamed_columns, :force => true do |t|
- t.column :name, :string
- t.column :mother_id, :integer
- t.column :red, :integer
- t.column :black, :integer
- t.column :pitch, :integer
- end
-
- create_table :things, :force => true do |t|
- t.column :body, :text
- t.column :parent_id, :integer
- t.column :lft, :integer
- t.column :rgt, :integer
- t.column :depth, :integer
- t.column :children_count, :integer
- end
-
- create_table :brokens, :force => true do |t|
- t.column :name, :string
- t.column :parent_id, :integer
- t.column :lft, :integer
- t.column :rgt, :integer
- t.column :depth, :integer
- end
-
- create_table :orders, :force => true do |t|
- t.column :name, :string
- t.column :parent_id, :integer
- t.column :lft, :integer
- t.column :rgt, :integer
- t.column :depth, :integer
- end
-
- create_table :positions, :force => true do |t|
- t.column :name, :string
- t.column :parent_id, :integer
- t.column :lft, :integer
- t.column :rgt, :integer
- t.column :depth, :integer
- t.column :position, :integer
- end
-
- create_table :no_depths, :force => true do |t|
- t.column :name, :string
- t.column :parent_id, :integer
- t.column :lft, :integer
- t.column :rgt, :integer
- end
-end
diff --git a/lib/plugins/awesome_nested_set/spec/fixtures/brokens.yml b/lib/plugins/awesome_nested_set/spec/fixtures/brokens.yml
deleted file mode 100644
index 3cb6ce915..000000000
--- a/lib/plugins/awesome_nested_set/spec/fixtures/brokens.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-one:
- id: 1
- name: One \ No newline at end of file
diff --git a/lib/plugins/awesome_nested_set/spec/fixtures/categories.yml b/lib/plugins/awesome_nested_set/spec/fixtures/categories.yml
deleted file mode 100644
index bc8e078e8..000000000
--- a/lib/plugins/awesome_nested_set/spec/fixtures/categories.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-top_level:
- id: 1
- name: Top Level
- lft: 1
- rgt: 10
-child_1:
- id: 2
- name: Child 1
- parent_id: 1
- lft: 2
- rgt: 3
-child_2:
- id: 3
- name: Child 2
- parent_id: 1
- lft: 4
- rgt: 7
-child_2_1:
- id: 4
- name: Child 2.1
- parent_id: 3
- lft: 5
- rgt: 6
-child_3:
- id: 5
- name: Child 3
- parent_id: 1
- lft: 8
- rgt: 9
-top_level_2:
- id: 6
- name: Top Level 2
- lft: 11
- rgt: 12
diff --git a/lib/plugins/awesome_nested_set/spec/fixtures/departments.yml b/lib/plugins/awesome_nested_set/spec/fixtures/departments.yml
deleted file mode 100644
index e50a944f1..000000000
--- a/lib/plugins/awesome_nested_set/spec/fixtures/departments.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-top:
- id: 1
- name: Top \ No newline at end of file
diff --git a/lib/plugins/awesome_nested_set/spec/fixtures/notes.yml b/lib/plugins/awesome_nested_set/spec/fixtures/notes.yml
deleted file mode 100644
index 004a5335a..000000000
--- a/lib/plugins/awesome_nested_set/spec/fixtures/notes.yml
+++ /dev/null
@@ -1,38 +0,0 @@
-scope1:
- id: 1
- body: Top Level
- lft: 1
- rgt: 10
- notable_id: 1
- notable_type: Category
-child_1:
- id: 2
- body: Child 1
- parent_id: 1
- lft: 2
- rgt: 3
- notable_id: 1
- notable_type: Category
-child_2:
- id: 3
- body: Child 2
- parent_id: 1
- lft: 4
- rgt: 7
- notable_id: 1
- notable_type: Category
-child_3:
- id: 4
- body: Child 3
- parent_id: 1
- lft: 8
- rgt: 9
- notable_id: 1
- notable_type: Category
-scope2:
- id: 5
- body: Top Level 2
- lft: 1
- rgt: 2
- notable_id: 1
- notable_type: Departments
diff --git a/lib/plugins/awesome_nested_set/spec/fixtures/things.yml b/lib/plugins/awesome_nested_set/spec/fixtures/things.yml
deleted file mode 100644
index 207a682ed..000000000
--- a/lib/plugins/awesome_nested_set/spec/fixtures/things.yml
+++ /dev/null
@@ -1,27 +0,0 @@
-parent1:
- id: 1
- body: Top Level
- lft: 1
- rgt: 10
- children_count: 2
-child_1:
- id: 2
- body: Child 1
- parent_id: 1
- lft: 2
- rgt: 3
- children_count: 0
-child_2:
- id: 3
- body: Child 2
- parent_id: 1
- lft: 4
- rgt: 7
- children_count: 0
-child_2_1:
- id: 4
- body: Child 2.1
- parent_id: 3
- lft: 8
- rgt: 9
- children_count: 0
diff --git a/lib/plugins/awesome_nested_set/spec/spec_helper.rb b/lib/plugins/awesome_nested_set/spec/spec_helper.rb
deleted file mode 100644
index 2e637bfc8..000000000
--- a/lib/plugins/awesome_nested_set/spec/spec_helper.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-plugin_test_dir = File.dirname(__FILE__)
-
-require 'rubygems'
-require 'bundler/setup'
-require 'pry'
-
-require 'logger'
-require 'active_record'
-ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")
-
-require 'yaml'
-require 'erb'
-ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read(plugin_test_dir + "/db/database.yml")).result)
-ActiveRecord::Base.establish_connection(ENV["DB"] ||= "sqlite3mem")
-ActiveRecord::Migration.verbose = false
-
-require 'combustion/database'
-Combustion::Database.create_database(ActiveRecord::Base.configurations[ENV["DB"]])
-load(File.join(plugin_test_dir, "db", "schema.rb"))
-
-require 'awesome_nested_set'
-require 'support/models'
-
-require 'action_controller'
-require 'rspec/rails'
-require 'database_cleaner'
-RSpec.configure do |config|
- config.fixture_path = "#{plugin_test_dir}/fixtures"
- config.use_transactional_fixtures = true
- config.after(:suite) do
- unless /sqlite/ === ENV['DB']
- Combustion::Database.drop_database(ActiveRecord::Base.configurations[ENV['DB']])
- end
- end
-end
diff --git a/lib/plugins/awesome_nested_set/spec/support/models.rb b/lib/plugins/awesome_nested_set/spec/support/models.rb
deleted file mode 100644
index c54ff3e2c..000000000
--- a/lib/plugins/awesome_nested_set/spec/support/models.rb
+++ /dev/null
@@ -1,96 +0,0 @@
-class Note < ActiveRecord::Base
- acts_as_nested_set :scope => [:notable_id, :notable_type]
-end
-
-class Default < ActiveRecord::Base
- self.table_name = 'categories'
- acts_as_nested_set
-end
-
-class ScopedCategory < ActiveRecord::Base
- self.table_name = 'categories'
- acts_as_nested_set :scope => :organization
-end
-
-class OrderedCategory < ActiveRecord::Base
- self.table_name = 'categories'
- acts_as_nested_set :order_column => 'name'
-end
-
-class RenamedColumns < ActiveRecord::Base
- acts_as_nested_set :parent_column => 'mother_id',
- :left_column => 'red',
- :right_column => 'black',
- :depth_column => 'pitch'
-end
-
-class Category < ActiveRecord::Base
- acts_as_nested_set
-
- validates_presence_of :name
-
- # Setup a callback that we can switch to true or false per-test
- set_callback :move, :before, :custom_before_move
- cattr_accessor :test_allows_move
- @@test_allows_move = true
- def custom_before_move
- @@test_allows_move
- end
-
- def to_s
- name
- end
-
- def recurse &block
- block.call self, lambda{
- self.children.each do |child|
- child.recurse &block
- end
- }
- end
-end
-
-class Thing < ActiveRecord::Base
- acts_as_nested_set :counter_cache => 'children_count'
-end
-
-class DefaultWithCallbacks < ActiveRecord::Base
-
- self.table_name = 'categories'
-
- attr_accessor :before_add, :after_add, :before_remove, :after_remove
-
- acts_as_nested_set :before_add => :do_before_add_stuff,
- :after_add => :do_after_add_stuff,
- :before_remove => :do_before_remove_stuff,
- :after_remove => :do_after_remove_stuff
-
- private
-
- [ :before_add, :after_add, :before_remove, :after_remove ].each do |hook_name|
- define_method "do_#{hook_name}_stuff" do |child_node|
- self.send("#{hook_name}=", child_node)
- end
- end
-
-end
-
-class Broken < ActiveRecord::Base
- acts_as_nested_set
-end
-
-class Order < ActiveRecord::Base
- acts_as_nested_set
-
- default_scope order(:name)
-end
-
-class Position < ActiveRecord::Base
- acts_as_nested_set
-
- default_scope order(:position)
-end
-
-class NoDepth < ActiveRecord::Base
- acts_as_nested_set
-end
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 2e97b0418..9fad74f42 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -63,12 +63,7 @@ require 'redmine/themes'
require 'redmine/hook'
require 'redmine/plugin'
-if RUBY_VERSION < '1.9'
- require 'fastercsv'
-else
- require 'csv'
- FCSV = CSV
-end
+require 'csv'
Redmine::Scm::Base.add "Subversion"
Redmine::Scm::Base.add "Darcs"
diff --git a/lib/redmine/access_control.rb b/lib/redmine/access_control.rb
index 68de56965..21359508b 100644
--- a/lib/redmine/access_control.rb
+++ b/lib/redmine/access_control.rb
@@ -58,9 +58,11 @@ module Redmine
if action.is_a?(Symbol)
perm = permission(action)
!perm.nil? && perm.read?
- else
+ elsif action.is_a?(Hash)
s = "#{action[:controller]}/#{action[:action]}"
permissions.detect {|p| p.actions.include?(s) && p.read?}.present?
+ else
+ raise ArgumentError.new("Symbol or a Hash expected, #{action.class.name} given: #{action}")
end
end
diff --git a/lib/redmine/codeset_util.rb b/lib/redmine/codeset_util.rb
index 45a5c3524..bb1f972d4 100644
--- a/lib/redmine/codeset_util.rb
+++ b/lib/redmine/codeset_util.rb
@@ -1,160 +1,71 @@
-if RUBY_VERSION < '1.9'
- require 'iconv'
-end
module Redmine
module CodesetUtil
def self.replace_invalid_utf8(str)
return str if str.nil?
- if str.respond_to?(:force_encoding)
- str.force_encoding('UTF-8')
- if ! str.valid_encoding?
- str = str.encode("US-ASCII", :invalid => :replace,
- :undef => :replace, :replace => '?').encode("UTF-8")
- end
- elsif RUBY_PLATFORM == 'java'
- begin
- ic = Iconv.new('UTF-8', 'UTF-8')
- str = ic.iconv(str)
- rescue
- str = str.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
- end
- else
- ic = Iconv.new('UTF-8', 'UTF-8')
- txtar = ""
- begin
- txtar += ic.iconv(str)
- rescue Iconv::IllegalSequence
- txtar += $!.success
- str = '?' + $!.failed[1,$!.failed.length]
- retry
- rescue
- txtar += $!.success
- end
- str = txtar
+ str.force_encoding('UTF-8')
+ if ! str.valid_encoding?
+ str = str.encode("US-ASCII", :invalid => :replace,
+ :undef => :replace, :replace => '?').encode("UTF-8")
end
str
end
def self.to_utf8(str, encoding)
return str if str.nil?
- str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
+ str.force_encoding("ASCII-8BIT")
if str.empty?
- str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
+ str.force_encoding("UTF-8")
return str
end
enc = encoding.blank? ? "UTF-8" : encoding
- if str.respond_to?(:force_encoding)
- if enc.upcase != "UTF-8"
- str.force_encoding(enc)
- str = str.encode("UTF-8", :invalid => :replace,
- :undef => :replace, :replace => '?')
- else
- str.force_encoding("UTF-8")
- if ! str.valid_encoding?
- str = str.encode("US-ASCII", :invalid => :replace,
- :undef => :replace, :replace => '?').encode("UTF-8")
- end
- end
- elsif RUBY_PLATFORM == 'java'
- begin
- ic = Iconv.new('UTF-8', enc)
- str = ic.iconv(str)
- rescue
- str = str.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
- end
+ if enc.upcase != "UTF-8"
+ str.force_encoding(enc)
+ str = str.encode("UTF-8", :invalid => :replace,
+ :undef => :replace, :replace => '?')
else
- ic = Iconv.new('UTF-8', enc)
- txtar = ""
- begin
- txtar += ic.iconv(str)
- rescue Iconv::IllegalSequence
- txtar += $!.success
- str = '?' + $!.failed[1,$!.failed.length]
- retry
- rescue
- txtar += $!.success
+ str.force_encoding("UTF-8")
+ if ! str.valid_encoding?
+ str = str.encode("US-ASCII", :invalid => :replace,
+ :undef => :replace, :replace => '?').encode("UTF-8")
end
- str = txtar
end
str
end
def self.to_utf8_by_setting(str)
return str if str.nil?
- str = self.to_utf8_by_setting_internal(str)
- if str.respond_to?(:force_encoding)
- str.force_encoding('UTF-8')
- end
- str
+ self.to_utf8_by_setting_internal(str).force_encoding('UTF-8')
end
def self.to_utf8_by_setting_internal(str)
return str if str.nil?
- if str.respond_to?(:force_encoding)
- str.force_encoding('ASCII-8BIT')
- end
+ str.force_encoding('ASCII-8BIT')
return str if str.empty?
return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
- if str.respond_to?(:force_encoding)
- str.force_encoding('UTF-8')
- end
+ str.force_encoding('UTF-8')
encodings = Setting.repositories_encodings.split(',').collect(&:strip)
encodings.each do |encoding|
- if str.respond_to?(:force_encoding)
- begin
- str.force_encoding(encoding)
- utf8 = str.encode('UTF-8')
- return utf8 if utf8.valid_encoding?
- rescue
- # do nothing here and try the next encoding
- end
- else
- begin
- return Iconv.conv('UTF-8', encoding, str)
- rescue Iconv::Failure
- # do nothing here and try the next encoding
- end
+ begin
+ str.force_encoding(encoding)
+ utf8 = str.encode('UTF-8')
+ return utf8 if utf8.valid_encoding?
+ rescue
+ # do nothing here and try the next encoding
end
end
- str = self.replace_invalid_utf8(str)
- if str.respond_to?(:force_encoding)
- str.force_encoding('UTF-8')
- end
- str
+ self.replace_invalid_utf8(str).force_encoding('UTF-8')
end
def self.from_utf8(str, encoding)
str ||= ''
- if str.respond_to?(:force_encoding)
- str.force_encoding('UTF-8')
- if encoding.upcase != 'UTF-8'
- str = str.encode(encoding, :invalid => :replace,
- :undef => :replace, :replace => '?')
- else
- str = self.replace_invalid_utf8(str)
- end
- elsif RUBY_PLATFORM == 'java'
- begin
- ic = Iconv.new(encoding, 'UTF-8')
- str = ic.iconv(str)
- rescue
- str = str.gsub(%r{[^\r\n\t\x20-\x7e]}, '?')
- end
+ str.force_encoding('UTF-8')
+ if encoding.upcase != 'UTF-8'
+ str = str.encode(encoding, :invalid => :replace,
+ :undef => :replace, :replace => '?')
else
- ic = Iconv.new(encoding, 'UTF-8')
- txtar = ""
- begin
- txtar += ic.iconv(str)
- rescue Iconv::IllegalSequence
- txtar += $!.success
- str = '?' + $!.failed[1, $!.failed.length]
- retry
- rescue
- txtar += $!.success
- end
- str = txtar
+ str = self.replace_invalid_utf8(str)
end
end
end
diff --git a/lib/redmine/core_ext/active_record.rb b/lib/redmine/core_ext/active_record.rb
index 259da2e14..a1135d51d 100644
--- a/lib/redmine/core_ext/active_record.rb
+++ b/lib/redmine/core_ext/active_record.rb
@@ -15,35 +15,10 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-module ActiveRecord
- module FinderMethods
- def find_ids(*args)
- find_ids_with_associations
- end
-
- private
-
- def find_ids_with_associations
- join_dependency = construct_join_dependency_for_association_find
- relation = construct_relation_for_association_find_ids(join_dependency)
- rows = connection.select_all(relation, 'SQL', relation.bind_values)
- rows.map {|row| row["id"].to_i}
- rescue ThrowResult
- []
- end
-
- def construct_relation_for_association_find_ids(join_dependency)
- relation = except(:includes, :eager_load, :preload, :select).select("#{table_name}.id")
- apply_join_dependency(relation, join_dependency)
- end
- end
-end
-
class DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
before_type_cast = record.attributes_before_type_cast[attribute.to_s]
if before_type_cast.is_a?(String) && before_type_cast.present?
- # TODO: #*_date_before_type_cast returns a Mysql::Time with ruby1.8+mysql gem
unless before_type_cast =~ /\A\d{4}-\d{2}-\d{2}( 00:00:00)?\z/ && value
record.errors.add attribute, :not_a_date
end
diff --git a/lib/redmine/core_ext/string/conversions.rb b/lib/redmine/core_ext/string/conversions.rb
index 256f71afa..479f47c10 100644
--- a/lib/redmine/core_ext/string/conversions.rb
+++ b/lib/redmine/core_ext/string/conversions.rb
@@ -36,13 +36,6 @@ module Redmine #:nodoc:
s.gsub!(',', '.')
begin; Kernel.Float(s); rescue; nil; end
end
-
- # Object#to_a removed in ruby1.9
- if RUBY_VERSION > '1.9'
- def to_a
- [self.dup]
- end
- end
end
end
end
diff --git a/lib/redmine/export/pdf.rb b/lib/redmine/export/pdf.rb
index b555534a8..9903eaa42 100644
--- a/lib/redmine/export/pdf.rb
+++ b/lib/redmine/export/pdf.rb
@@ -678,9 +678,7 @@ module Redmine
def self.rdm_from_utf8(txt, encoding)
txt ||= ''
txt = Redmine::CodesetUtil.from_utf8(txt, encoding)
- if txt.respond_to?(:force_encoding)
- txt.force_encoding('ASCII-8BIT')
- end
+ txt.force_encoding('ASCII-8BIT')
txt
end
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb
index 18e5d74a8..e1387f2cf 100644
--- a/lib/redmine/field_format.rb
+++ b/lib/redmine/field_format.rb
@@ -597,18 +597,13 @@ module Redmine
def target_class
@target_class ||= self.class.name[/^(.*::)?(.+)Format$/, 2].constantize rescue nil
end
-
- def reset_target_class
- @target_class = nil
- end
def possible_custom_value_options(custom_value)
options = possible_values_options(custom_value.custom_field, custom_value.customized)
missing = [custom_value.value_was].flatten.reject(&:blank?) - options.map(&:last)
if missing.any?
options += target_class.where(:id => missing.map(&:to_i)).map {|o| [o.to_s, o.id.to_s]}
- #TODO: use #sort_by! when ruby1.8 support is dropped
- options = options.sort_by(&:first)
+ options.sort_by!(&:first)
end
options
end
diff --git a/lib/redmine/helpers/gantt.rb b/lib/redmine/helpers/gantt.rb
index 6b054bb6d..2e4255243 100644
--- a/lib/redmine/helpers/gantt.rb
+++ b/lib/redmine/helpers/gantt.rb
@@ -167,7 +167,7 @@ module Redmine
where("child.id IN (?)", ids).
order("#{Project.table_name}.lft ASC").
uniq.
- all
+ to_a
else
@projects = []
end
diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb
index 18759f26b..8dfd95abe 100644
--- a/lib/redmine/menu_manager.rb
+++ b/lib/redmine/menu_manager.rb
@@ -193,7 +193,7 @@ module Redmine
# * Checking the url target (project only)
# * Checking the conditions of the item
def allowed_node?(node, user, project)
- if project && user && !user.allowed_to?(node.url, project)
+ if node.url.is_a?(Hash) && project && user && !user.allowed_to?(node.url, project)
return false
end
if node.condition && !node.condition.call(project)
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb
index ec168bf84..0e60de610 100644
--- a/lib/redmine/scm/adapters/abstract_adapter.rb
+++ b/lib/redmine/scm/adapters/abstract_adapter.rb
@@ -18,17 +18,13 @@
require 'cgi'
require 'redmine/scm/adapters'
-if RUBY_VERSION < '1.9'
- require 'iconv'
-end
-
module Redmine
module Scm
module Adapters
class AbstractAdapter #:nodoc:
# raised if scm command exited with error, e.g. unknown revision.
- class ScmCommandAborted < CommandFailed; end
+ class ScmCommandAborted < ::Redmine::Scm::Adapters::CommandFailed; end
class << self
def client_command
@@ -288,21 +284,12 @@ module Redmine
def scm_iconv(to, from, str)
return nil if str.nil?
return str if to == from
- if str.respond_to?(:force_encoding)
- str.force_encoding(from)
- begin
- str.encode(to)
- rescue Exception => err
- logger.error("failed to convert from #{from} to #{to}. #{err}")
- nil
- end
- else
- begin
- Iconv.conv(to, from, str)
- rescue Iconv::Failure => err
- logger.error("failed to convert from #{from} to #{to}. #{err}")
- nil
- end
+ str.force_encoding(from)
+ begin
+ str.encode(to)
+ rescue Exception => err
+ logger.error("failed to convert from #{from} to #{to}. #{err}")
+ nil
end
end
diff --git a/lib/redmine/scm/adapters/bazaar_adapter.rb b/lib/redmine/scm/adapters/bazaar_adapter.rb
index 93ac13e02..c5e9d124d 100644
--- a/lib/redmine/scm/adapters/bazaar_adapter.rb
+++ b/lib/redmine/scm/adapters/bazaar_adapter.rb
@@ -43,10 +43,7 @@ module Redmine
end
def scm_command_version
- scm_version = scm_version_from_command_line.dup
- if scm_version.respond_to?(:force_encoding)
- scm_version.force_encoding('ASCII-8BIT')
- end
+ scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -100,7 +97,7 @@ module Redmine
prefix_utf8 = "#{url}/#{path}".gsub('\\', '/')
logger.debug "PREFIX: #{prefix_utf8}"
prefix = scm_iconv(@path_encoding, 'UTF-8', prefix_utf8)
- prefix.force_encoding('ASCII-8BIT') if prefix.respond_to?(:force_encoding)
+ prefix.force_encoding('ASCII-8BIT')
re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)\r?$}
io.each_line do |line|
next unless line =~ re
diff --git a/lib/redmine/scm/adapters/cvs_adapter.rb b/lib/redmine/scm/adapters/cvs_adapter.rb
index d1096e725..ec7ce7bcf 100644
--- a/lib/redmine/scm/adapters/cvs_adapter.rb
+++ b/lib/redmine/scm/adapters/cvs_adapter.rb
@@ -43,10 +43,7 @@ module Redmine
end
def scm_command_version
- scm_version = scm_version_from_command_line.dup
- if scm_version.respond_to?(:force_encoding)
- scm_version.force_encoding('ASCII-8BIT')
- end
+ scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)}m)
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -94,7 +91,7 @@ module Redmine
def entries(path=nil, identifier=nil, options={})
logger.debug "<cvs> entries '#{path}' with identifier '#{identifier}'"
path_locale = scm_iconv(@path_encoding, 'UTF-8', path)
- path_locale.force_encoding("ASCII-8BIT") if path_locale.respond_to?(:force_encoding)
+ path_locale.force_encoding("ASCII-8BIT")
entries = Entries.new
cmd_args = %w|-q rls -e|
cmd_args << "-D" << time_to_cvstime_rlog(identifier) if identifier
@@ -171,6 +168,7 @@ module Redmine
file_state = nil
branch_map = nil
io.each_line() do |line|
+ line = line.strip
if state != "revision" && /^#{ENDLOG}/ =~ line
commit_log = String.new
revision = nil
diff --git a/lib/redmine/scm/adapters/darcs_adapter.rb b/lib/redmine/scm/adapters/darcs_adapter.rb
index 3e4d55265..e2807352d 100644
--- a/lib/redmine/scm/adapters/darcs_adapter.rb
+++ b/lib/redmine/scm/adapters/darcs_adapter.rb
@@ -43,10 +43,7 @@ module Redmine
end
def darcs_binary_version
- darcsversion = darcs_binary_version_from_command_line.dup
- if darcsversion.respond_to?(:force_encoding)
- darcsversion.force_encoding('ASCII-8BIT')
- end
+ darcsversion = darcs_binary_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = darcsversion.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb
index 284a3f401..7a6a590b9 100644
--- a/lib/redmine/scm/adapters/git_adapter.rb
+++ b/lib/redmine/scm/adapters/git_adapter.rb
@@ -47,10 +47,7 @@ module Redmine
end
def scm_command_version
- scm_version = scm_version_from_command_line.dup
- if scm_version.respond_to?(:force_encoding)
- scm_version.force_encoding('ASCII-8BIT')
- end
+ scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -145,10 +142,7 @@ module Redmine
type = $1
sha = $2
size = $3
- name = $4
- if name.respond_to?(:force_encoding)
- name.force_encoding(@path_encoding)
- end
+ name = $4.force_encoding(@path_encoding)
full_path = p.empty? ? name : "#{p}/#{name}"
n = scm_iconv('UTF-8', @path_encoding, name)
full_p = scm_iconv('UTF-8', @path_encoding, full_path)
diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb
index 881fdc89c..c6aa388a7 100644
--- a/lib/redmine/scm/adapters/mercurial_adapter.rb
+++ b/lib/redmine/scm/adapters/mercurial_adapter.rb
@@ -54,10 +54,7 @@ module Redmine
# The hg version is expressed either as a
# release number (eg 0.9.5 or 1.0) or as a revision
# id composed of 12 hexa characters.
- theversion = hgversion_from_command_line.dup
- if theversion.respond_to?(:force_encoding)
- theversion.force_encoding('ASCII-8BIT')
- end
+ theversion = hgversion_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = theversion.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -130,10 +127,7 @@ module Redmine
def summary
return @summary if @summary
hg 'rhsummary' do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
@summary = parse_xml(output)['rhsummary']
rescue
@@ -146,10 +140,7 @@ module Redmine
p1 = scm_iconv(@path_encoding, 'UTF-8', path)
manifest = hg('rhmanifest', '-r', CGI.escape(hgrev(identifier)),
CGI.escape(without_leading_slash(p1.to_s))) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
parse_xml(output)['rhmanifest']['repository']['manifest']
rescue
@@ -193,10 +184,7 @@ module Redmine
hg_args << '--limit' << options[:limit] if options[:limit]
hg_args << hgtarget(path) unless path.blank?
log = hg(*hg_args) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
# Mercurial < 1.5 does not support footer template for '</log>'
parse_xml("#{output}</log>")['log']
@@ -278,7 +266,7 @@ module Redmine
blame = Annotate.new
hg 'rhannotate', '-ncu', '-r', CGI.escape(hgrev(identifier)), hgtarget(p) do |io|
io.each_line do |line|
- line.force_encoding('ASCII-8BIT') if line.respond_to?(:force_encoding)
+ line.force_encoding('ASCII-8BIT')
next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
r = Revision.new(:author => $1.strip, :revision => $2, :scmid => $3,
:identifier => $3)
diff --git a/lib/redmine/scm/adapters/subversion_adapter.rb b/lib/redmine/scm/adapters/subversion_adapter.rb
index fcc9be90d..30ebc0c18 100644
--- a/lib/redmine/scm/adapters/subversion_adapter.rb
+++ b/lib/redmine/scm/adapters/subversion_adapter.rb
@@ -46,10 +46,7 @@ module Redmine
end
def svn_binary_version
- scm_version = scm_version_from_command_line.dup
- if scm_version.respond_to?(:force_encoding)
- scm_version.force_encoding('ASCII-8BIT')
- end
+ scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -66,10 +63,7 @@ module Redmine
cmd << credentials_string
info = nil
shellout(cmd) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
doc = parse_xml(output)
# root_url = doc.elements["info/entry/repository/root"].text
@@ -98,10 +92,7 @@ module Redmine
cmd = "#{self.class.sq_bin} list --xml #{target(path)}@#{identifier}"
cmd << credentials_string
shellout(cmd) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
doc = parse_xml(output)
each_xml_element(doc['lists']['list'], 'entry') do |entry|
@@ -141,10 +132,7 @@ module Redmine
cmd << credentials_string
properties = {}
shellout(cmd) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
doc = parse_xml(output)
each_xml_element(doc['properties']['target'], 'property') do |property|
@@ -168,10 +156,7 @@ module Redmine
cmd << " --limit #{options[:limit].to_i}" if options[:limit]
cmd << ' ' + target(path)
shellout(cmd) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
doc = parse_xml(output)
each_xml_element(doc['log'], 'logentry') do |logentry|
diff --git a/lib/redmine/unified_diff.rb b/lib/redmine/unified_diff.rb
index ee4ac6987..b40205909 100644
--- a/lib/redmine/unified_diff.rb
+++ b/lib/redmine/unified_diff.rb
@@ -199,28 +199,10 @@ module Redmine
while starting < max && line_left[starting] == line_right[starting]
starting += 1
end
- if (! "".respond_to?(:force_encoding)) && starting < line_left.size
- while line_left[starting].ord.between?(128, 191) && starting > 0
- starting -= 1
- end
- end
ending = -1
while ending >= -(max - starting) && (line_left[ending] == line_right[ending])
ending -= 1
end
- if (! "".respond_to?(:force_encoding)) && ending > (-1 * line_left.size)
- while line_left[ending].ord.between?(128, 255) && ending < -1
- if line_left[ending].ord.between?(128, 191)
- if line_left[ending + 1].ord.between?(128, 191)
- ending += 1
- else
- break
- end
- else
- ending += 1
- end
- end
- end
unless starting == 0 && ending == -1
[starting, ending]
end
@@ -279,7 +261,7 @@ module Redmine
def line_to_html(line, offsets)
html = line_to_html_raw(line, offsets)
- html.force_encoding('UTF-8') if html.respond_to?(:force_encoding)
+ html.force_encoding('UTF-8')
html
end
diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake
index 41a334c5e..857cc232d 100644
--- a/lib/tasks/ci.rake
+++ b/lib/tasks/ci.rake
@@ -33,7 +33,7 @@ namespace :ci do
else
Rake::Task["test"].invoke
end
- # Rake::Task["test:ui"].invoke if RUBY_VERSION >= '1.9.3'
+ # Rake::Task["test:ui"].invoke
end
desc "Finish the build"
@@ -52,7 +52,7 @@ file 'config/database.yml' do
case database
when 'mysql'
- dev_conf = {'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'),
+ dev_conf = {'adapter' => 'mysql2',
'database' => dev_db_name, 'host' => 'localhost',
'encoding' => 'utf8'}
if ENV['RUN_ON_NOT_OFFICIAL']
diff --git a/lib/tasks/locales.rake b/lib/tasks/locales.rake
index 6311d6ab1..7d2ecfe80 100644
--- a/lib/tasks/locales.rake
+++ b/lib/tasks/locales.rake
@@ -68,9 +68,6 @@ namespace :locales do
desc <<-END_DESC
Removes a translation string from all locale file (only works for top-level childless non-multiline keys, probably doesn\'t work on windows).
-This task does not work on Ruby 1.8.6.
-You need to use Ruby 1.8.7 or later.
-
Options:
key=key_1,key_2 Comma-separated list of keys to delete
skip=en,de Comma-separated list of locale files to ignore (filename without extension)
diff --git a/lib/tasks/migrate_from_mantis.rake b/lib/tasks/migrate_from_mantis.rake
index 2d5f66f81..1040dbb0a 100644
--- a/lib/tasks/migrate_from_mantis.rake
+++ b/lib/tasks/migrate_from_mantis.rake
@@ -18,7 +18,6 @@
desc 'Mantis migration script'
require 'active_record'
-require 'iconv' if RUBY_VERSION < '1.9'
require 'pp'
namespace :redmine do
@@ -452,12 +451,7 @@ task :migrate_from_mantis => :environment do
end
def self.encode(text)
- if RUBY_VERSION < '1.9'
- @ic ||= Iconv.new('UTF-8', @charset)
- @ic.iconv text
- else
- text.to_s.force_encoding(@charset).encode('UTF-8')
- end
+ text.to_s.force_encoding(@charset).encode('UTF-8')
end
end
diff --git a/lib/tasks/migrate_from_trac.rake b/lib/tasks/migrate_from_trac.rake
index 0d1af9abc..d1a3873f5 100644
--- a/lib/tasks/migrate_from_trac.rake
+++ b/lib/tasks/migrate_from_trac.rake
@@ -16,7 +16,6 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'active_record'
-require 'iconv' if RUBY_VERSION < '1.9'
require 'pp'
namespace :redmine do
@@ -155,7 +154,7 @@ namespace :redmine do
attachment_type = read_attribute(:type)
#replace exotic characters with their hex representation to avoid invalid filenames
trac_file = filename.gsub( /[^a-zA-Z0-9\-_\.!~*']/n ) do |x|
- codepoint = RUBY_VERSION < '1.9' ? x[0] : x.codepoints.to_a[0]
+ codepoint = x.codepoints.to_a[0]
sprintf('%%%02x', codepoint)
end
"#{TracMigrate.trac_attachments_directory}/#{attachment_type}/#{id}/#{trac_file}"
@@ -715,12 +714,7 @@ namespace :redmine do
end
def self.encode(text)
- if RUBY_VERSION < '1.9'
- @ic ||= Iconv.new('UTF-8', @charset)
- @ic.iconv text
- else
- text.to_s.force_encoding(@charset).encode('UTF-8')
- end
+ text.to_s.force_encoding(@charset).encode('UTF-8')
end
end