From b2764fd63a0173985cc72cf847fcc55ce3b63bb8 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Sat, 9 Feb 2008 17:58:08 +0000 Subject: [PATCH] ActionItem41: adding a block to display profiles --- app/models/profile_list_block.rb | 16 ++++++++++++++++ test/unit/profile_list_block_test.rb | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 0 deletions(-) create mode 100644 app/models/profile_list_block.rb create mode 100644 test/unit/profile_list_block_test.rb diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb new file mode 100644 index 0000000..0ba6eea --- /dev/null +++ b/app/models/profile_list_block.rb @@ -0,0 +1,16 @@ +class ProfileListBlock < Block + + settings_items :limit, :default => 10 + + def self.description + _('A block that displays random profiles') + end + + def content + profiles = self.profiles + lambda do + profiles.map {|item| profile_image_link(item) } + end + end + +end diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb new file mode 100644 index 0000000..4fbf153 --- /dev/null +++ b/test/unit/profile_list_block_test.rb @@ -0,0 +1,39 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ProfileListBlockTest < Test::Unit::TestCase + + should 'describe itself' do + assert_not_equal Block.description, ProfileListBlock.description + end + + should 'accept a limit of people to be displayed (and default to 10)' do + block = ProfileListBlock.new + assert_equal 10, block.limit + + block.limit = 20 + assert_equal 20, block.limit + end + + should 'list people' do + User.destroy_all + person1 = create_user('testperson1').person + person2 = create_user('testperson2').person + person3 = create_user('testperson3').person + + owner = create_user('mytestuser').person + block = ProfileListBlock.new + owner.boxes.first.blocks << block + block.save! + + # faking that we are picking random people + profiles = [person1, person3] + block.expects(:profiles).returns(profiles) + + self.expects(:profile_image_link).with(person1).once + self.expects(:profile_image_link).with(person2).never + self.expects(:profile_image_link).with(person3).once + + instance_eval(&block.content) + end + +end -- libgit2 0.21.2