Commit bb6b09d4f6b634ca27e0eb837b431556f643b425

Authored by AntonioTerceiro
1 parent f4a1a6b0

ActionItem43: supporting non-class finders


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1347 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/profile_list_block.rb
@@ -24,7 +24,13 @@ class ProfileListBlock < Block @@ -24,7 +24,13 @@ class ProfileListBlock < Block
24 24
25 def profiles 25 def profiles
26 # FIXME pick random people instead 26 # FIXME pick random people instead
27 - profile_finder.find(:all, :limit => self.limit, :order => 'created_at desc') 27 + finder = profile_finder
  28 + options = { :limit => self.limit, :order => 'created_at desc' }
  29 + if finder.is_a?(Class)
  30 + finder.find(:all, options)
  31 + else
  32 + finder.find(options)
  33 + end
28 end 34 end
29 35
30 def random(top) 36 def random(top)
test/unit/profile_list_block_test.rb
@@ -47,7 +47,15 @@ class ProfileListBlockTest < Test::Unit::TestCase @@ -47,7 +47,15 @@ class ProfileListBlockTest < Test::Unit::TestCase
47 should 'ask profile finder for profiles' do 47 should 'ask profile finder for profiles' do
48 block = ProfileListBlock.new 48 block = ProfileListBlock.new
49 block.expects(:profile_finder).returns(Profile).once 49 block.expects(:profile_finder).returns(Profile).once
50 - Profile.expects(:find).returns([]) 50 + Profile.expects(:find).with(:all, is_a(Hash)).returns([])
  51 + block.profiles
  52 + end
  53 +
  54 + should 'support non-class finders' do
  55 + block = ProfileListBlock.new
  56 + profile = create_user('mytestuser').person
  57 + block.expects(:profile_finder).returns(profile.members).once
  58 + profile.members.expects(:find).with(is_a(Hash)).once
51 block.profiles 59 block.profiles
52 end 60 end
53 61
@@ -58,4 +66,5 @@ class ProfileListBlockTest < Test::Unit::TestCase @@ -58,4 +66,5 @@ class ProfileListBlockTest < Test::Unit::TestCase
58 ProfileListBlock.new.random(77) 66 ProfileListBlock.new.random(77)
59 end 67 end
60 68
  69 +
61 end 70 end