Permalink
Browse files

All active record versions >= 2.0.0 are now fully supported

  • Loading branch information...
1 parent 60f4120 commit 88857828d37c4a1d0a9c224da4ddccfc550c00a9 @shuber committed May 28, 2009
Showing with 38 additions and 13 deletions.
  1. +3 −0 CHANGELOG
  2. +2 −0 README.rdoc
  3. +14 −1 Rakefile
  4. +12 −9 lib/sortable.rb
  5. +2 −2 sortable.gemspec
  6. +5 −1 test/sortable_test.rb
View
@@ -1,3 +1,6 @@
+2009-05-28 - Sean Huber (shuber@huberry.com)
+ * All active record versions >= 2.0.0 are now fully supported
+
2009-05-27 - Sean Huber (shuber@huberry.com)
* Use self.class.base_class when scoping records
* Fix conflicts
View
@@ -2,6 +2,8 @@
Allows you to sort ActiveRecord items similar to http://github.com/rails/acts_as_list but with added support for multiple scopes and lists
+Requires ActiveRecord >= 2.0.0
+
== Installation
View
@@ -4,7 +4,20 @@ require 'rake/rdoctask'
desc 'Default: run the sortable tests'
task :default => :test
-
+
+namespace :test do
+ desc 'Test the sortable gem/plugin with all active record versions >= 2.0.0'
+ task :all do
+ versions = `gem list`.match(/activerecord \((.+)\)/).captures[0].split(/, /).select { |v| v[0,1].to_i > 1 }
+ versions.each do |version|
+ puts "\n============================================================="
+ puts "TESTING WITH ACTIVE RECORD VERSION #{version}\n\n"
+ system "rake test ACTIVE_RECORD_VERSION=#{version}"
+ puts "\n\n"
+ end
+ end
+end
+
desc 'Test the sortable gem/plugin.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
View
@@ -146,7 +146,7 @@ def self.included(base)
base.class_eval do
before_create :add_to_lists
before_destroy :remove_from_lists
- before_update :update_lists, :if => :sortable_scope_changed?
+ before_update :update_lists
alias_method_chain :reload, :sortable
end
end
@@ -214,7 +214,8 @@ def item_at_offset(offset, list_name = nil)
def last_item(list_name = nil)
options = evaluate_sortable_options(list_name)
(options[:conditions].is_a?(Array) ? options[:conditions].first : options[:conditions]) << " AND #{self.class.table_name}.#{options[:column]} IS NOT NULL "
- self.class.base_class.find(:last, :conditions => options[:conditions], :order => options[:column].to_s)
+ klass, conditions = [self.class.base_class, { :conditions => options[:conditions] }]
+ klass.send("find_by_#{options[:column]}".to_sym, klass.maximum(options[:column].to_s, conditions), conditions)
end
# Returns a boolean after determining if the current item is the last item in the specified list
@@ -261,9 +262,9 @@ def previous_item(list_name = nil)
end
# Clears any <tt>sortable_scope_changes</tt> and reloads normally
- def reload_with_sortable
+ def reload_with_sortable(*args)
@sortable_scope_changes = nil
- reload_without_sortable
+ reload_without_sortable(*args)
end
# Removes the current item from the specified list and saves
@@ -340,11 +341,13 @@ def remove_from_lists
# Removes the current item from its old lists and adds it to new lists if any attributes specified as a <tt>:scope</tt> have been changed
def update_lists
- new_values = sortable_scope_changes.inject({}) { |hash, scope| value = send(scope); hash[scope] = value.nil? ? nil : value.dup; hash }
- sortable_scope_changes.each { |scope| send("#{scope}=".to_sym, send("#{scope}_was".to_sym)) }
- remove_from_lists
- new_values.each { |scope, value| send("#{scope}=".to_sym, value) }
- add_to_lists
+ if self.sortable_scope_changed?
+ new_values = sortable_scope_changes.inject({}) { |hash, scope| value = send(scope); hash[scope] = value.nil? ? nil : value.dup; hash }
+ sortable_scope_changes.each { |scope| send("#{scope}=".to_sym, send("#{scope}_was".to_sym)) }
+ remove_from_lists
+ new_values.each { |scope, value| send("#{scope}=".to_sym, value) }
+ add_to_lists
+ end
end
end
end
View
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'sortable'
- s.version = '1.0.3'
- s.date = '2009-05-27'
+ s.version = '1.0.4'
+ s.date = '2009-05-28'
s.summary = 'Allows you to sort ActiveRecord items in multiple lists with multiple scopes'
s.description = 'Allows you to sort ActiveRecord items in multiple lists with multiple scopes'
View
@@ -1,6 +1,10 @@
require 'test/unit'
require 'rubygems'
-gem 'activerecord'
+
+args = ['activerecord']
+args << ENV['ACTIVE_RECORD_VERSION'] if ENV['ACTIVE_RECORD_VERSION']
+send(:gem, *args)
+
require 'active_record'
require File.dirname(__FILE__) + '/../lib/sortable'

0 comments on commit 8885782

Please sign in to comment.