From 7d163bce8d0795a6b5d3beb5e6791e8277e3f5ce Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Wed, 10 Sep 2008 18:33:33 +0000 Subject: [PATCH] ActionItem614: expanding profile in list of links --- app/models/link_list_block.rb | 10 +++++++++- test/unit/link_list_block_test.rb | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/link_list_block.rb b/app/models/link_list_block.rb index 1364ade..e23c07b 100644 --- a/app/models/link_list_block.rb +++ b/app/models/link_list_block.rb @@ -17,10 +17,18 @@ class LinkListBlock < Block def content block_title(title) + content_tag('ul', - links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_to(i[:name], i[:address]))} + links.select{|i| !i[:name].blank? and !i[:address].blank?}.map{|i| content_tag('li', link_to(i[:name], expand_address(i[:address])))} ) end + def expand_address(address) + if owner.respond_to?(:identifier) + address.gsub('{profile}', owner.identifier) + else + address + end + end + def editable? true end diff --git a/test/unit/link_list_block_test.rb b/test/unit/link_list_block_test.rb index 7ba5654..06899c3 100644 --- a/test/unit/link_list_block_test.rb +++ b/test/unit/link_list_block_test.rb @@ -33,4 +33,11 @@ class LinkListBlockTest < ActiveSupport::TestCase assert_equal [{:name => 'categ', :address => '/address'}], l.links end + should 'replace {profile} with profile identifier' do + profile = Profile.new(:identifier => 'test_profile') + l = LinkListBlock.new(:links => [{:name => 'categ', :address => '/{profile}/address'}]) + l.stubs(:owner).returns(profile) + assert_tag_in_string l.content, :tag => 'a', :attributes => {:href => '/test_profile/address'} + end + end -- libgit2 0.21.2