Commit 1a8aab81b6c0154bdded9520ce12d34e7111d529
Committed by
Daniela Feitosa
1 parent
ef2f3ba3
Exists in
master
and in
29 other branches
Fans Block
This is an enterprise block that shows all people that added the enterprise as "favorite". (ActionItem356)
Showing
8 changed files
with
97 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/profile_design_controller.rb
@@ -25,6 +25,7 @@ class ProfileDesignController < BoxOrganizerController | @@ -25,6 +25,7 @@ class ProfileDesignController < BoxOrganizerController | ||
25 | blocks << DisabledEnterpriseMessageBlock | 25 | blocks << DisabledEnterpriseMessageBlock |
26 | blocks << HighlightsBlock | 26 | blocks << HighlightsBlock |
27 | blocks << FeaturedProductsBlock | 27 | blocks << FeaturedProductsBlock |
28 | + blocks << FansBlock | ||
28 | end | 29 | end |
29 | 30 | ||
30 | # product block exclusive for enterprises in environments that permits it | 31 | # product block exclusive for enterprises in environments that permits it |
app/controllers/public/profile_controller.rb
@@ -71,6 +71,10 @@ class ProfileController < PublicController | @@ -71,6 +71,10 @@ class ProfileController < PublicController | ||
71 | end | 71 | end |
72 | end | 72 | end |
73 | 73 | ||
74 | + def fans | ||
75 | + @fans = profile.fans | ||
76 | + end | ||
77 | + | ||
74 | def favorite_enterprises | 78 | def favorite_enterprises |
75 | @favorite_enterprises = profile.favorite_enterprises | 79 | @favorite_enterprises = profile.favorite_enterprises |
76 | end | 80 | end |
app/models/enterprise.rb
@@ -7,6 +7,8 @@ class Enterprise < Organization | @@ -7,6 +7,8 @@ class Enterprise < Organization | ||
7 | has_many :products, :dependent => :destroy, :order => 'name ASC' | 7 | has_many :products, :dependent => :destroy, :order => 'name ASC' |
8 | has_many :inputs, :through => :products | 8 | has_many :inputs, :through => :products |
9 | 9 | ||
10 | + has_and_belongs_to_many :fans, :class_name => 'Person', :join_table => 'favorite_enteprises_people' | ||
11 | + | ||
10 | extra_data_for_index :product_categories | 12 | extra_data_for_index :product_categories |
11 | 13 | ||
12 | N_('Organization website'); N_('Historic and current context'); N_('Activities short description'); N_('City'); N_('State'); N_('Country'); N_('ZIP code') | 14 | N_('Organization website'); N_('Historic and current context'); N_('Activities short description'); N_('City'); N_('State'); N_('Country'); N_('ZIP code') |
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +class FansBlock < ProfileListBlock | ||
2 | + | ||
3 | + def self.description | ||
4 | + _('Fans') | ||
5 | + end | ||
6 | + | ||
7 | + def default_title | ||
8 | + n__('{#} fan', '{#} fans', profile_count) | ||
9 | + end | ||
10 | + | ||
11 | + def help | ||
12 | + _('This block presents the fans of an enterprise.') | ||
13 | + end | ||
14 | + | ||
15 | + def footer | ||
16 | + profile = self.owner | ||
17 | + lambda do | ||
18 | + link_to _('View all'), :profile => profile.identifier, :controller => | ||
19 | + 'profile', :action => 'fans' | ||
20 | + end | ||
21 | + end | ||
22 | + | ||
23 | + def profiles | ||
24 | + owner.fans | ||
25 | + end | ||
26 | + | ||
27 | + def profile_count | ||
28 | + profiles.visible.count | ||
29 | + end | ||
30 | + | ||
31 | +end |
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +<div class="common-profile-list-block"> | ||
2 | + | ||
3 | +<h1><%= __("%s's fans") % profile.name %></h1> | ||
4 | + | ||
5 | +<ul class='profile-list'> | ||
6 | +<% @fans.each do |person| %> | ||
7 | + <li><%= profile_image_link(person)%></li> | ||
8 | +<% end %> | ||
9 | +</ul> | ||
10 | + | ||
11 | +<% button_bar do %> | ||
12 | + <%= button :back, _('Go back'), { :controller => 'profile' }%> | ||
13 | +<% end %> | ||
14 | + | ||
15 | +</div><!-- fim class="common-profile-list-block" --> | ||
16 | + |
test/functional/profile_design_controller_test.rb
@@ -10,7 +10,7 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | @@ -10,7 +10,7 @@ class ProfileDesignControllerTest < Test::Unit::TestCase | ||
10 | PERSON_BLOCKS_WITH_MEMBERS = PERSON_BLOCKS + [MembersBlock] | 10 | PERSON_BLOCKS_WITH_MEMBERS = PERSON_BLOCKS + [MembersBlock] |
11 | PERSON_BLOCKS_WITH_BLOG = PERSON_BLOCKS + [BlogArchivesBlock] | 11 | PERSON_BLOCKS_WITH_BLOG = PERSON_BLOCKS + [BlogArchivesBlock] |
12 | 12 | ||
13 | - ENTERPRISE_BLOCKS = COMMOM_BLOCKS + [DisabledEnterpriseMessageBlock, HighlightsBlock, FeaturedProductsBlock] | 13 | + ENTERPRISE_BLOCKS = COMMOM_BLOCKS + [DisabledEnterpriseMessageBlock, HighlightsBlock, FeaturedProductsBlock, FansBlock] |
14 | ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE = ENTERPRISE_BLOCKS + [ProductsBlock] | 14 | ENTERPRISE_BLOCKS_WITH_PRODUCTS_ENABLE = ENTERPRISE_BLOCKS + [ProductsBlock] |
15 | 15 | ||
16 | attr_reader :holder | 16 | attr_reader :holder |
test/unit/enterprise_test.rb
@@ -49,6 +49,16 @@ class EnterpriseTest < Test::Unit::TestCase | @@ -49,6 +49,16 @@ class EnterpriseTest < Test::Unit::TestCase | ||
49 | end | 49 | end |
50 | end | 50 | end |
51 | 51 | ||
52 | + should 'have fans' do | ||
53 | + p = create_user('test_person').person | ||
54 | + e = fast_create(Enterprise) | ||
55 | + | ||
56 | + p.favorite_enterprises << e | ||
57 | + e.reload | ||
58 | + | ||
59 | + assert_includes e.fans, p | ||
60 | + end | ||
61 | + | ||
52 | should 'remove products when removing enterprise' do | 62 | should 'remove products when removing enterprise' do |
53 | e = fast_create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise') | 63 | e = fast_create(Enterprise, :name => "My enterprise", :identifier => 'myenterprise') |
54 | e.products.create!(:name => 'One product', :product_category => @product_category) | 64 | e.products.create!(:name => 'One product', :product_category => @product_category) |
@@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class FansBlockTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + should 'inherit from ProfileListBlock' do | ||
6 | + assert_kind_of ProfileListBlock, FansBlock.new | ||
7 | + end | ||
8 | + | ||
9 | + should 'declare its default title' do | ||
10 | + FansBlock.any_instance.stubs(:profile_count).returns(0) | ||
11 | + assert_not_equal ProfileListBlock.new.default_title, FansBlock.new.default_title | ||
12 | + end | ||
13 | + | ||
14 | + should 'describe itself' do | ||
15 | + assert_not_equal ProfileListBlock.description, FansBlock.description | ||
16 | + end | ||
17 | + | ||
18 | + should 'list owner fans' do | ||
19 | + | ||
20 | + block = FansBlock.new | ||
21 | + | ||
22 | + owner = mock | ||
23 | + block.expects(:owner).returns(owner) | ||
24 | + | ||
25 | + list = [] | ||
26 | + owner.expects(:fans).returns(list) | ||
27 | + | ||
28 | + assert_same list, block.profiles | ||
29 | + end | ||
30 | + | ||
31 | +end | ||
32 | + |