diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index ad666e2..b9cded4 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -25,6 +25,7 @@ class ProfileDesignController < BoxOrganizerController blocks << DisabledEnterpriseMessageBlock blocks << HighlightsBlock blocks << FeaturedProductsBlock + blocks << FansBlock end # product block exclusive for enterprises in environments that permits it diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index b9250b2..7db1da3 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -71,6 +71,10 @@ class ProfileController < PublicController end end + def fans + @fans = profile.fans + end + def favorite_enterprises @favorite_enterprises = profile.favorite_enterprises end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 87d9886..aa07583 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -7,6 +7,8 @@ class Enterprise < Organization has_many :products, :dependent => :destroy, :order => 'name ASC' has_many :inputs, :through => :products + has_and_belongs_to_many :fans, :class_name => 'Person', :join_table => 'favorite_enteprises_people' + extra_data_for_index :product_categories N_('Organization website'); N_('Historic and current context'); N_('Activities short description'); N_('City'); N_('State'); N_('Country'); N_('ZIP code') diff --git a/app/models/fans_block.rb b/app/models/fans_block.rb new file mode 100644 index 0000000..fd2f2e5 --- /dev/null +++ b/app/models/fans_block.rb @@ -0,0 +1,31 @@ +class FansBlock < ProfileListBlock + + def self.description + _('Fans') + end + + def default_title + n__('{#} fan', '{#} fans', profile_count) + end + + def help + _('This block presents the fans of an enterprise.') + end + + def footer + profile = self.owner + lambda do + link_to _('View all'), :profile => profile.identifier, :controller => + 'profile', :action => 'fans' + end + end + + def profiles + owner.fans + end + + def profile_count + profiles.visible.count + end + +end diff --git a/app/views/profile/fans.rhtml b/app/views/profile/fans.rhtml new file mode 100644 index 0000000..f634123 --- /dev/null +++ b/app/views/profile/fans.rhtml @@ -0,0 +1,16 @@ +
+ +

<%= __("%s's fans") % profile.name %>

+ + + +<% button_bar do %> + <%= button :back, _('Go back'), { :controller => 'profile' }%> +<% end %> + +
+ diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb index 128fd20..0f9f789 100644 --- a/test/functional/profile_design_controller_test.rb +++ b/test/functional/profile_design_controller_test.rb @@ -10,7 +10,7 @@ class ProfileDesignControllerTest < Test::Unit::TestCase PERSON_BLOCKS_WITH_MEMBERS = PERSON_BLOCKS + [MembersBlock] PERSON_BLOCKS_WITH_BLOG = PERSON_BLOCKS + [BlogArchivesBlock] - ENTERPRISE_BLOCKS = COMMOM_BLOCKS + [DisabledEnterpriseMessageBlock, HighlightsBlock, FeaturedProductsBlock] + ENTERPRISE_BLOCKS = COMMOM_BLOCKS + [DisabledEnterpriseMessageBlock, HighlightsBlock, FeaturedProductsBlock, FansBlock] ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE = ENTERPRISE_BLOCKS + [ProductsBlock] attr_reader :holder diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 9d205fa..8f4de56 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -49,6 +49,16 @@ class EnterpriseTest < Test::Unit::TestCase end end + should 'have fans' do + p = create_user('test_person').person + e = fast_create(Enterprise) + + p.favorite_enterprises << e + e.reload + + assert_includes e.fans, p + end + should 'remove products when removing enterprise' do e = fast_create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise') e.products.create!(:name => 'One product', :product_category => @product_category) diff --git a/test/unit/fans_block_test.rb b/test/unit/fans_block_test.rb new file mode 100644 index 0000000..5871ba5 --- /dev/null +++ b/test/unit/fans_block_test.rb @@ -0,0 +1,32 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FansBlockTest < ActiveSupport::TestCase + + should 'inherit from ProfileListBlock' do + assert_kind_of ProfileListBlock, FansBlock.new + end + + should 'declare its default title' do + FansBlock.any_instance.stubs(:profile_count).returns(0) + assert_not_equal ProfileListBlock.new.default_title, FansBlock.new.default_title + end + + should 'describe itself' do + assert_not_equal ProfileListBlock.description, FansBlock.description + end + + should 'list owner fans' do + + block = FansBlock.new + + owner = mock + block.expects(:owner).returns(owner) + + list = [] + owner.expects(:fans).returns(list) + + assert_same list, block.profiles + end + +end + -- libgit2 0.21.2