sortifiable 0.1.1 → 0.1.2

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,8 @@
1
+ *0.1.2 (February 7th, 2011)
2
+
3
+ * Configure association scopes correctly
4
+
5
+
1
6
  *0.1.1 (February 7th, 2011)
2
7
 
3
8
  * Use the class in which act_as_list is called
@@ -1,3 +1,3 @@
1
1
  module Sortifiable
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/sortifiable.rb CHANGED
@@ -58,7 +58,7 @@ module Sortifiable
58
58
  reflection.options[:foreign_type].to_sym
59
59
  ]
60
60
  else
61
- reflection.association_foreign_key.to_sym
61
+ options[:scope] = reflection.association_foreign_key.to_sym
62
62
  end
63
63
  else
64
64
  raise ArgumentError, "Only belongs_to associations can be used as a scope"
@@ -55,6 +55,20 @@ class ArrayScopeListMixin < ActiveRecord::Base
55
55
  default_scope order(:pos)
56
56
  end
57
57
 
58
+ class AssociationScopeListMixin < ActiveRecord::Base
59
+ belongs_to :parent
60
+ acts_as_list :column => "pos", :scope => :parent
61
+ set_table_name "mixins"
62
+ default_scope order(:pos)
63
+ end
64
+
65
+ class PolymorphicAssociationScopeListMixin < ActiveRecord::Base
66
+ belongs_to :parent, :polymorphic => true
67
+ acts_as_list :column => "pos", :scope => :parent
68
+ set_table_name "mixins"
69
+ default_scope order(:pos)
70
+ end
71
+
58
72
  teardown_db
59
73
 
60
74
  class NonListTest < Test::Unit::TestCase
@@ -603,3 +617,39 @@ class ArrayScopeListTest < Test::Unit::TestCase
603
617
  end
604
618
 
605
619
  end
620
+
621
+ class AssociationScopeListTest < Test::Unit::TestCase
622
+
623
+ def setup
624
+ setup_db
625
+ (1..4).each do |counter|
626
+ AssociationScopeListMixin.create!(
627
+ :pos => counter,
628
+ :parent_id => 5
629
+ )
630
+ end
631
+
632
+ (1..4).each do |counter|
633
+ PolymorphicAssociationScopeListMixin.create!(
634
+ :pos => counter,
635
+ :parent_id => 5,
636
+ :parent_type => 'ParentClass'
637
+ )
638
+ end
639
+ end
640
+
641
+ def teardown
642
+ teardown_db
643
+ end
644
+
645
+ def test_association_scope_is_configured
646
+ assert_equal :parent_id,
647
+ AssociationScopeListMixin.acts_as_list_options[:scope]
648
+ end
649
+
650
+ def test_polymorphic_association_scope_is_configured
651
+ assert_equal [:parent_id, :parent_type],
652
+ PolymorphicAssociationScopeListMixin.acts_as_list_options[:scope]
653
+ end
654
+
655
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortifiable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew White