Skip to content

Commit

Permalink
Simpler method to find the subclass name
Browse files Browse the repository at this point in the history
Also added tests
  • Loading branch information
brendon committed Nov 26, 2014
1 parent 921eefe commit ac65ad2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/acts_as_list/active_record/acts/list.rb
Expand Up @@ -84,7 +84,7 @@ def acts_as_list_top
end
def acts_as_list_class
@acts_as_list_class ||= eval('::'+self.class.name.to_s)
self.class
end
def position_column
Expand Down
5 changes: 5 additions & 0 deletions test/shared_list_sub.rb
Expand Up @@ -118,5 +118,10 @@ def test_delete_middle
assert_equal 1, ListMixin.where(id: 3).first.pos
assert_equal 2, ListMixin.where(id: 4).first.pos
end

def test_acts_as_list_class
assert_equal TheSubClass1, TheSubClass1.new.acts_as_list_class
assert_equal TheSubClass2, TheSubClass2.new.acts_as_list_class
end
end
end
13 changes: 13 additions & 0 deletions test/test_list.rb
Expand Up @@ -92,6 +92,19 @@ class NoAdditionMixin < Mixin
acts_as_list column: "pos", add_new_at: nil, scope: :parent_id
end

class TheBaseClass < ActiveRecord::Base
self.abstract_class = true
acts_as_list column: "pos", scope: :parent
end

class TheSubClass1 < TheBaseClass
self.table_name = 'mixins'
end

class TheSubClass2 < TheBaseClass
self.table_name = 'mixins'
end

class ActsAsListTestCase < Minitest::Test
# No default test required as this class is abstract.
# Need for test/unit.
Expand Down

0 comments on commit ac65ad2

Please sign in to comment.