shuber-sortable 1.0.5 → 1.0.6
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 +4 -0
- data/lib/sortable.rb +9 -2
- data/test/sortable_test.rb +13 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/sortable.rb
CHANGED
@@ -369,8 +369,15 @@ module Huberry
|
|
369
369
|
# 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
|
370
370
|
def update_lists
|
371
371
|
if self.sortable_scope_changed?
|
372
|
-
new_values = sortable_scope_changes.inject({})
|
373
|
-
|
372
|
+
new_values = sortable_scope_changes.inject({}) do |hash, scope|
|
373
|
+
value = send(scope)
|
374
|
+
hash[scope] = value.nil? ? nil : (value.dup rescue value)
|
375
|
+
hash
|
376
|
+
end
|
377
|
+
sortable_scope_changes.each do |scope|
|
378
|
+
old_value = respond_to?("#{scope}_was".to_sym) ? send("#{scope}_was".to_sym) : !send(scope) # booleans don't have _was methods in older versions
|
379
|
+
send("#{scope}=".to_sym, old_value)
|
380
|
+
end
|
374
381
|
remove_from_lists
|
375
382
|
new_values.each { |scope, value| send("#{scope}=".to_sym, value) }
|
376
383
|
add_to_lists
|
data/test/sortable_test.rb
CHANGED
@@ -27,6 +27,8 @@ def create_tables
|
|
27
27
|
t.string :name
|
28
28
|
t.integer :position
|
29
29
|
t.integer :steves_position
|
30
|
+
t.boolean :topuser
|
31
|
+
t.integer :topuser_position
|
30
32
|
end
|
31
33
|
end
|
32
34
|
end
|
@@ -47,6 +49,7 @@ end
|
|
47
49
|
class User < ActiveRecord::Base
|
48
50
|
sortable :scope => :type
|
49
51
|
sortable :conditions => { :name => 'steve' }, :column => :steves_position, :list_name => :steves
|
52
|
+
sortable :scope => :topuser, :column => :topuser_position, :list_name => :topusers
|
50
53
|
end
|
51
54
|
|
52
55
|
class Admin < User
|
@@ -323,4 +326,14 @@ class SortableTest < Test::Unit::TestCase
|
|
323
326
|
assert_equal [@user_2, @user_3], @user.lower_items
|
324
327
|
end
|
325
328
|
|
329
|
+
def test_should_work_with_boolean_scope
|
330
|
+
@user = User.create :topuser => false
|
331
|
+
@user_2 = User.create :topuser => false
|
332
|
+
assert_equal 1, @user.topuser_position
|
333
|
+
assert_equal 2, @user_2.topuser_position
|
334
|
+
@user_2.topuser = true
|
335
|
+
@user_2.save
|
336
|
+
assert_equal 1, @user_2.topuser_position
|
337
|
+
end
|
338
|
+
|
326
339
|
end
|
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.
|
4
|
+
version: 1.0.6
|
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-
|
12
|
+
date: 2009-07-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|