shuber-sortable 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 2009-05-28 - Sean Huber (shuber@huberry.com)
2
+ * All active record versions >= 2.0.0 are now fully supported
3
+
1
4
  2009-05-27 - Sean Huber (shuber@huberry.com)
2
5
  * Use self.class.base_class when scoping records
3
6
  * Fix conflicts
data/README.rdoc CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Allows you to sort ActiveRecord items similar to http://github.com/rails/acts_as_list but with added support for multiple scopes and lists
4
4
 
5
+ Requires ActiveRecord >= 2.0.0
6
+
5
7
 
6
8
  == Installation
7
9
 
data/Rakefile CHANGED
@@ -4,7 +4,20 @@ require 'rake/rdoctask'
4
4
 
5
5
  desc 'Default: run the sortable tests'
6
6
  task :default => :test
7
-
7
+
8
+ namespace :test do
9
+ desc 'Test the sortable gem/plugin with all active record versions >= 2.0.0'
10
+ task :all do
11
+ versions = `gem list`.match(/activerecord \((.+)\)/).captures[0].split(/, /).select { |v| v[0,1].to_i > 1 }
12
+ versions.each do |version|
13
+ puts "\n============================================================="
14
+ puts "TESTING WITH ACTIVE RECORD VERSION #{version}\n\n"
15
+ system "rake test ACTIVE_RECORD_VERSION=#{version}"
16
+ puts "\n\n"
17
+ end
18
+ end
19
+ end
20
+
8
21
  desc 'Test the sortable gem/plugin.'
9
22
  Rake::TestTask.new(:test) do |t|
10
23
  t.libs << 'lib'
data/lib/sortable.rb CHANGED
@@ -146,7 +146,7 @@ module Huberry
146
146
  base.class_eval do
147
147
  before_create :add_to_lists
148
148
  before_destroy :remove_from_lists
149
- before_update :update_lists, :if => :sortable_scope_changed?
149
+ before_update :update_lists
150
150
  alias_method_chain :reload, :sortable
151
151
  end
152
152
  end
@@ -214,7 +214,8 @@ module Huberry
214
214
  def last_item(list_name = nil)
215
215
  options = evaluate_sortable_options(list_name)
216
216
  (options[:conditions].is_a?(Array) ? options[:conditions].first : options[:conditions]) << " AND #{self.class.table_name}.#{options[:column]} IS NOT NULL "
217
- self.class.base_class.find(:last, :conditions => options[:conditions], :order => options[:column].to_s)
217
+ klass, conditions = [self.class.base_class, { :conditions => options[:conditions] }]
218
+ klass.send("find_by_#{options[:column]}".to_sym, klass.maximum(options[:column].to_s, conditions), conditions)
218
219
  end
219
220
 
220
221
  # Returns a boolean after determining if the current item is the last item in the specified list
@@ -261,9 +262,9 @@ module Huberry
261
262
  end
262
263
 
263
264
  # Clears any <tt>sortable_scope_changes</tt> and reloads normally
264
- def reload_with_sortable
265
+ def reload_with_sortable(*args)
265
266
  @sortable_scope_changes = nil
266
- reload_without_sortable
267
+ reload_without_sortable(*args)
267
268
  end
268
269
 
269
270
  # Removes the current item from the specified list and saves
@@ -340,11 +341,13 @@ module Huberry
340
341
 
341
342
  # 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
342
343
  def update_lists
343
- new_values = sortable_scope_changes.inject({}) { |hash, scope| value = send(scope); hash[scope] = value.nil? ? nil : value.dup; hash }
344
- sortable_scope_changes.each { |scope| send("#{scope}=".to_sym, send("#{scope}_was".to_sym)) }
345
- remove_from_lists
346
- new_values.each { |scope, value| send("#{scope}=".to_sym, value) }
347
- add_to_lists
344
+ if self.sortable_scope_changed?
345
+ new_values = sortable_scope_changes.inject({}) { |hash, scope| value = send(scope); hash[scope] = value.nil? ? nil : value.dup; hash }
346
+ sortable_scope_changes.each { |scope| send("#{scope}=".to_sym, send("#{scope}_was".to_sym)) }
347
+ remove_from_lists
348
+ new_values.each { |scope, value| send("#{scope}=".to_sym, value) }
349
+ add_to_lists
350
+ end
348
351
  end
349
352
  end
350
353
  end
@@ -1,6 +1,10 @@
1
1
  require 'test/unit'
2
2
  require 'rubygems'
3
- gem 'activerecord'
3
+
4
+ args = ['activerecord']
5
+ args << ENV['ACTIVE_RECORD_VERSION'] if ENV['ACTIVE_RECORD_VERSION']
6
+ send(:gem, *args)
7
+
4
8
  require 'active_record'
5
9
  require File.dirname(__FILE__) + '/../lib/sortable'
6
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shuber-sortable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-27 00:00:00 -07:00
12
+ date: 2009-05-28 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15