diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb
index cb49e20..456b588 100644
--- a/app/models/profile_list_block.rb
+++ b/app/models/profile_list_block.rb
@@ -6,9 +6,25 @@ class ProfileListBlock < Block
_('A block that displays random profiles')
end
+ # Override this method to make the block list specific types of profiles
+ # instead of anyone.
+ #
+ # In this class this method just returns Profile (the class). In
+ # subclasses you could return Person, for instance, if you only want
+ # to list people, or Organization, if you want organizations only.
+ #
+ # You don't need to return only classes. You can for instance return an
+ # association array from a has_many ActiveRecord association, for example.
+ # Actually the only requirement for the object returned by this method is to
+ # have a find method that accepts the same interface as the
+ # ActiveRecord::Base's find method .
+ def profile_finder
+ Profile
+ end
+
def profiles
# FIXME pick random people instead
- Profile.find(:all, :limit => self.limit, :order => 'created_at desc')
+ profile_finder.find(:all, :limit => self.limit, :order => 'created_at desc')
end
def random(top)
diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb
index e6761d0..46c7003 100644
--- a/test/unit/profile_list_block_test.rb
+++ b/test/unit/profile_list_block_test.rb
@@ -40,6 +40,17 @@ class ProfileListBlockTest < Test::Unit::TestCase
assert_kind_of String, instance_eval(&block.content)
end
+ should 'find in Profile by default' do
+ assert_equal Profile, ProfileListBlock.new.profile_finder
+ end
+
+ should 'ask profile finder for profiles' do
+ block = ProfileListBlock.new
+ block.expects(:profile_finder).returns(Profile).once
+ Profile.expects(:find).returns([])
+ block.profiles
+ end
+
should 'pick random people'
should 'use Kernel.rand to generate random numbers' do
--
libgit2 0.21.2