Commit c3453051d6579a42528513f353a50fa7e928d8dd
Committed by
Joenio Costa
1 parent
031e5bd1
Exists in
master
and in
29 other branches
Make a plugin to display statistics from Environment and Profiles
- Removed EnvironmentStatisticsBlock from core. Environment's admins should enable the statistics block for its environment Signed-off-by: Leandro Nunes dos Santos <leandro.santos@serpro.gov.br> Signed-off-by: Francisco Marcelo de Araújo Lima Júnior <francisco.lima-junior@serpro.gov.br> Signed-off-by: Victor Costa <vfcosta@gmail.com> (ActionItem2851)
Showing
22 changed files
with
1039 additions
and
149 deletions
Show diff stats
app/controllers/admin/environment_design_controller.rb
@@ -3,7 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController | @@ -3,7 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController | ||
3 | protect 'edit_environment_design', :environment | 3 | protect 'edit_environment_design', :environment |
4 | 4 | ||
5 | def available_blocks | 5 | def available_blocks |
6 | - @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] | 6 | + @available_blocks ||= [ ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] |
7 | @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) | 7 | @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) |
8 | end | 8 | end |
9 | 9 |
app/models/box.rb
@@ -26,7 +26,6 @@ class Box < ActiveRecord::Base | @@ -26,7 +26,6 @@ class Box < ActiveRecord::Base | ||
26 | CategoriesBlock, | 26 | CategoriesBlock, |
27 | CommunitiesBlock, | 27 | CommunitiesBlock, |
28 | EnterprisesBlock, | 28 | EnterprisesBlock, |
29 | - EnvironmentStatisticsBlock, | ||
30 | FansBlock, | 29 | FansBlock, |
31 | FavoriteEnterprisesBlock, | 30 | FavoriteEnterprisesBlock, |
32 | FeedReaderBlock, | 31 | FeedReaderBlock, |
@@ -52,7 +51,6 @@ class Box < ActiveRecord::Base | @@ -52,7 +51,6 @@ class Box < ActiveRecord::Base | ||
52 | CommunitiesBlock, | 51 | CommunitiesBlock, |
53 | DisabledEnterpriseMessageBlock, | 52 | DisabledEnterpriseMessageBlock, |
54 | EnterprisesBlock, | 53 | EnterprisesBlock, |
55 | - EnvironmentStatisticsBlock, | ||
56 | FansBlock, | 54 | FansBlock, |
57 | FavoriteEnterprisesBlock, | 55 | FavoriteEnterprisesBlock, |
58 | FeaturedProductsBlock, | 56 | FeaturedProductsBlock, |
app/models/environment.rb
@@ -161,7 +161,6 @@ class Environment < ActiveRecord::Base | @@ -161,7 +161,6 @@ class Environment < ActiveRecord::Base | ||
161 | 161 | ||
162 | # "left" area | 162 | # "left" area |
163 | env.boxes[1].blocks << LoginBlock.new | 163 | env.boxes[1].blocks << LoginBlock.new |
164 | - env.boxes[1].blocks << EnvironmentStatisticsBlock.new | ||
165 | env.boxes[1].blocks << RecentDocumentsBlock.new | 164 | env.boxes[1].blocks << RecentDocumentsBlock.new |
166 | 165 | ||
167 | # "right" area | 166 | # "right" area |
app/models/environment_statistics_block.rb
@@ -1,30 +0,0 @@ | @@ -1,30 +0,0 @@ | ||
1 | -class EnvironmentStatisticsBlock < Block | ||
2 | - | ||
3 | - def self.description | ||
4 | - _('Environment stastistics') | ||
5 | - end | ||
6 | - | ||
7 | - def default_title | ||
8 | - _('Statistics for %s') % owner.name | ||
9 | - end | ||
10 | - | ||
11 | - def help | ||
12 | - _('This block presents some statistics about your environment.') | ||
13 | - end | ||
14 | - | ||
15 | - def content(args={}) | ||
16 | - users = owner.people.visible.count | ||
17 | - enterprises = owner.enterprises.visible.count | ||
18 | - communities = owner.communities.visible.count | ||
19 | - | ||
20 | - info = [] | ||
21 | - info << (n_('One user', '%{num} users', users) % { :num => users }) | ||
22 | - unless owner.enabled?('disable_asset_enterprises') | ||
23 | - info << (n__('One enterprise', '%{num} enterprises', enterprises) % { :num => enterprises }) | ||
24 | - end | ||
25 | - info << (n__('One community', '%{num} communities', communities) % { :num => communities }) | ||
26 | - | ||
27 | - block_title(title) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n")) | ||
28 | - end | ||
29 | - | ||
30 | -end |
app/sweepers/profile_sweeper.rb
@@ -8,7 +8,6 @@ class ProfileSweeper # < ActiveRecord::Observer | @@ -8,7 +8,6 @@ class ProfileSweeper # < ActiveRecord::Observer | ||
8 | end | 8 | end |
9 | 9 | ||
10 | def after_create(profile) | 10 | def after_create(profile) |
11 | - expire_statistics_block_cache(profile) | ||
12 | end | 11 | end |
13 | 12 | ||
14 | protected | 13 | protected |
@@ -29,11 +28,6 @@ protected | @@ -29,11 +28,6 @@ protected | ||
29 | expire_blogs(profile) if profile.organization? | 28 | expire_blogs(profile) if profile.organization? |
30 | end | 29 | end |
31 | 30 | ||
32 | - def expire_statistics_block_cache(profile) | ||
33 | - blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } | ||
34 | - BlockSweeper.expire_blocks(blocks) | ||
35 | - end | ||
36 | - | ||
37 | def expire_blogs(profile) | 31 | def expire_blogs(profile) |
38 | profile.blogs.select{|b| !b.empty?}.each do |blog| | 32 | profile.blogs.select{|b| !b.empty?}.each do |blog| |
39 | pages = blog.posts.count / blog.posts_per_page + 1 | 33 | pages = blog.posts.count / blog.posts_per_page + 1 |
db/migrate/20140316171151_remove_environment_statistics_block.rb
0 → 100644
@@ -0,0 +1,54 @@ | @@ -0,0 +1,54 @@ | ||
1 | +README - Statistics (Statistics Plugin) | ||
2 | +================================ | ||
3 | + | ||
4 | +Statistics is a plugin to allow the user adds a block where you could see statistics of it's context. | ||
5 | + | ||
6 | +The Statistics block will be available for all layout columns of communities, peole, enterprises and environments. | ||
7 | + | ||
8 | +INSTALL | ||
9 | +======= | ||
10 | + | ||
11 | +Enable Plugin | ||
12 | +------------- | ||
13 | + | ||
14 | +Also, you need to enable Statistics Plugin at you Noosfero: | ||
15 | + | ||
16 | +cd <your_noosfero_dir> | ||
17 | +./script/noosfero-plugins enable statistics | ||
18 | + | ||
19 | +Active Plugin | ||
20 | +------------- | ||
21 | + | ||
22 | +As a Noosfero administrator user, go to administrator panel: | ||
23 | + | ||
24 | +- Click on "Enable/disable plugins" option | ||
25 | +- Click on "Statistics Plugin" check-box | ||
26 | + | ||
27 | +Running Statistics tests | ||
28 | +-------------------- | ||
29 | + | ||
30 | +$ rake test:noosfero_plugins:statistics | ||
31 | + | ||
32 | + | ||
33 | +Get Involved | ||
34 | +============ | ||
35 | + | ||
36 | +If you found any bug and/or want to collaborate, please send an e-mail to eduardo.edington@gmail.com | ||
37 | + | ||
38 | +LICENSE | ||
39 | +======= | ||
40 | + | ||
41 | +Copyright (c) The Author developers. | ||
42 | + | ||
43 | +See Noosfero license. | ||
44 | + | ||
45 | + | ||
46 | +AUTHORS | ||
47 | +======= | ||
48 | + | ||
49 | + Eduardo Tourinho Edington (eduardo.edington at gmail.com) | ||
50 | + | ||
51 | +ACKNOWLEDGMENTS | ||
52 | +=============== | ||
53 | + | ||
54 | +The author has been supported by Serpro |
@@ -0,0 +1,146 @@ | @@ -0,0 +1,146 @@ | ||
1 | +class StatisticsBlock < Block | ||
2 | + | ||
3 | + settings_items :community_counter, :default => false | ||
4 | + settings_items :user_counter, :default => true | ||
5 | + settings_items :enterprise_counter, :default => false | ||
6 | + settings_items :category_counter, :default => false | ||
7 | + settings_items :tag_counter, :default => true | ||
8 | + settings_items :comment_counter, :default => true | ||
9 | + settings_items :hit_counter, :default => false | ||
10 | + settings_items :templates_ids_counter, Hash, :default => {} | ||
11 | + | ||
12 | + USER_COUNTERS = [:community_counter, :user_counter, :enterprise_counter, :tag_counter, :comment_counter, :hit_counter] | ||
13 | + COMMUNITY_COUNTERS = [:user_counter, :tag_counter, :comment_counter, :hit_counter] | ||
14 | + ENTERPRISE_COUNTERS = [:user_counter, :tag_counter, :comment_counter, :hit_counter] | ||
15 | + | ||
16 | + def self.description | ||
17 | + _('Statistics') | ||
18 | + end | ||
19 | + | ||
20 | + def default_title | ||
21 | + _('Statistics for %s') % owner.name | ||
22 | + end | ||
23 | + | ||
24 | + def is_visible? counter | ||
25 | + value = self.send(counter) | ||
26 | + value == '1' || value == true | ||
27 | + end | ||
28 | + | ||
29 | + def is_counter_available? counter | ||
30 | + if owner.kind_of?(Environment) | ||
31 | + true | ||
32 | + elsif owner.kind_of?(Person) | ||
33 | + USER_COUNTERS.include?(counter) | ||
34 | + elsif owner.kind_of?(Community) | ||
35 | + COMMUNITY_COUNTERS.include?(counter) | ||
36 | + elsif owner.kind_of?(Enterprise) | ||
37 | + ENTERPRISE_COUNTERS.include?(counter) | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | + def help | ||
43 | + _('This block presents some statistics about your context.') | ||
44 | + end | ||
45 | + | ||
46 | + def timeout | ||
47 | + 60.minutes | ||
48 | + end | ||
49 | + | ||
50 | + def environment | ||
51 | + if owner.kind_of?(Environment) | ||
52 | + owner | ||
53 | + elsif owner.kind_of?(Profile) | ||
54 | + owner.environment | ||
55 | + else | ||
56 | + nil | ||
57 | + end | ||
58 | + end | ||
59 | + | ||
60 | + def templates | ||
61 | + Community.templates(environment) | ||
62 | + end | ||
63 | + | ||
64 | + def is_template_counter_active? template_id | ||
65 | + self.templates_ids_counter[template_id.to_s].to_s == 'true' | ||
66 | + end | ||
67 | + | ||
68 | + def template_counter_count(template_id) | ||
69 | + owner.communities.visible.count(:conditions => {:template_id => template_id}) | ||
70 | + end | ||
71 | + | ||
72 | + def users | ||
73 | + if owner.kind_of?(Environment) | ||
74 | + owner.people.visible.count | ||
75 | + elsif owner.kind_of?(Organization) | ||
76 | + owner.members.visible.count | ||
77 | + elsif owner.kind_of?(Person) | ||
78 | + owner.friends.visible.count | ||
79 | + else | ||
80 | + 0 | ||
81 | + end | ||
82 | + end | ||
83 | + | ||
84 | + def enterprises | ||
85 | + if owner.kind_of?(Environment) || owner.kind_of?(Person) | ||
86 | + owner.enterprises.visible.count | ||
87 | + else | ||
88 | + 0 | ||
89 | + end | ||
90 | + end | ||
91 | + | ||
92 | + def communities | ||
93 | + if owner.kind_of?(Environment) || owner.kind_of?(Person) | ||
94 | + owner.communities.visible.count | ||
95 | + else | ||
96 | + 0 | ||
97 | + end | ||
98 | + end | ||
99 | + | ||
100 | + def categories | ||
101 | + if owner.kind_of?(Environment) then | ||
102 | + owner.categories.count | ||
103 | + else | ||
104 | + 0 | ||
105 | + end | ||
106 | + end | ||
107 | + | ||
108 | + def tags | ||
109 | + if owner.kind_of?(Environment) then | ||
110 | + owner.tag_counts.count | ||
111 | + elsif owner.kind_of?(Profile) then | ||
112 | + owner.article_tags.count | ||
113 | + else | ||
114 | + 0 | ||
115 | + end | ||
116 | + end | ||
117 | + | ||
118 | + def comments | ||
119 | + if owner.kind_of?(Environment) then | ||
120 | + owner.profiles.joins(:articles).sum(:comments_count).to_i | ||
121 | + elsif owner.kind_of?(Profile) then | ||
122 | + owner.articles.sum(:comments_count) | ||
123 | + else | ||
124 | + 0 | ||
125 | + end | ||
126 | + end | ||
127 | + | ||
128 | + def hits | ||
129 | + if owner.kind_of?(Environment) then | ||
130 | + owner.profiles.joins(:articles).sum(:hits).to_i | ||
131 | + elsif owner.kind_of?(Profile) then | ||
132 | + owner.articles.sum(:hits) | ||
133 | + else | ||
134 | + 0 | ||
135 | + end | ||
136 | + end | ||
137 | + | ||
138 | + def content(args={}) | ||
139 | + block = self | ||
140 | + | ||
141 | + lambda do | ||
142 | + render :file => 'statistics_block', :locals => { :block => block } | ||
143 | + end | ||
144 | + end | ||
145 | + | ||
146 | +end |
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +require_dependency File.dirname(__FILE__) + '/statistics_block' | ||
2 | + | ||
3 | +class StatisticsPlugin < Noosfero::Plugin | ||
4 | + | ||
5 | + def self.plugin_name | ||
6 | + "Statistics Plugin" | ||
7 | + end | ||
8 | + | ||
9 | + def self.plugin_description | ||
10 | + _("A plugin that adds a block where you can see statistics of it's context.") | ||
11 | + end | ||
12 | + | ||
13 | + def self.extra_blocks | ||
14 | + { | ||
15 | + StatisticsBlock => {} | ||
16 | + } | ||
17 | + end | ||
18 | + | ||
19 | +end |
plugins/statistics/test/functional/statistics_plugin_environment_design_controller_test.rb
0 → 100644
@@ -0,0 +1,161 @@ | @@ -0,0 +1,161 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +# Re-raise errors caught by the controller. | ||
4 | +class EnvironmentDesignController; def rescue_action(e) raise e end; end | ||
5 | + | ||
6 | +class EnvironmentDesignControllerTest < ActionController::TestCase | ||
7 | + | ||
8 | + def setup | ||
9 | + @controller = EnvironmentDesignController.new | ||
10 | + @request = ActionController::TestRequest.new | ||
11 | + @response = ActionController::TestResponse.new | ||
12 | + | ||
13 | + Environment.delete_all | ||
14 | + | ||
15 | + @environment = Environment.create(:name => 'testenv', :is_default => true) | ||
16 | + @environment.enabled_plugins = ['StatisticsPlugin'] | ||
17 | + @environment.save! | ||
18 | + | ||
19 | + user = create_user('testinguser') | ||
20 | + @environment.add_admin(user.person) | ||
21 | + | ||
22 | + StatisticsBlock.delete_all | ||
23 | + @box1 = Box.create!(:owner => @environment) | ||
24 | + @environment.boxes = [@box1] | ||
25 | + | ||
26 | + @block = StatisticsBlock.new | ||
27 | + @block.box = @box1 | ||
28 | + @block.save! | ||
29 | + | ||
30 | + login_as(user.login) | ||
31 | + end | ||
32 | + | ||
33 | + attr_accessor :block | ||
34 | + | ||
35 | + should 'be able to edit StatisticsBlock' do | ||
36 | + get :edit, :id => @block.id | ||
37 | + assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | ||
38 | + end | ||
39 | + | ||
40 | + should 'be able to save StatisticsBlock' do | ||
41 | + get :edit, :id => @block.id | ||
42 | + post :save, :id => @block.id, :block => {:title => 'Statistics' } | ||
43 | + @block.reload | ||
44 | + assert_equal 'Statistics', @block.title | ||
45 | + end | ||
46 | + | ||
47 | + should 'be able to uncheck core counters' do | ||
48 | + @block.user_counter = true | ||
49 | + @block.community_counter = true | ||
50 | + @block.enterprise_counter = true | ||
51 | + @block.category_counter = true | ||
52 | + @block.tag_counter = true | ||
53 | + @block.comment_counter = true | ||
54 | + @block.hit_counter = true | ||
55 | + @block.save! | ||
56 | + get :edit, :id => @block.id | ||
57 | + post :save, :id => @block.id, :block => {:user_counter => '0', :community_counter => '0', :enterprise_counter => '0', | ||
58 | + :category_counter => '0', :tag_counter => '0', :comment_counter => '0', :hit_counter => '0' } | ||
59 | + @block.reload | ||
60 | + any_checked = @block.is_visible?('user_counter') || | ||
61 | + @block.is_visible?('community_counter') || | ||
62 | + @block.is_visible?('enterprise_counter') || | ||
63 | + @block.is_visible?('category_counter') || | ||
64 | + @block.is_visible?('tag_counter') || | ||
65 | + @block.is_visible?('comment_counter') || | ||
66 | + @block.is_visible?('hit_counter') | ||
67 | + assert_equal false, any_checked | ||
68 | + | ||
69 | + end | ||
70 | + | ||
71 | + should 'be able to check core counters' do | ||
72 | + @block.user_counter = false | ||
73 | + @block.community_counter = false | ||
74 | + @block.enterprise_counter = false | ||
75 | + @block.category_counter = false | ||
76 | + @block.tag_counter = false | ||
77 | + @block.comment_counter = false | ||
78 | + @block.hit_counter = false | ||
79 | + @block.save! | ||
80 | + get :edit, :id => @block.id | ||
81 | + post :save, :id => @block.id, :block => {:user_counter => '1', :community_counter => '1', :enterprise_counter => '1', | ||
82 | + :category_counter => '1', :tag_counter => '1', :comment_counter => '1', :hit_counter => '1' } | ||
83 | + @block.reload | ||
84 | + all_checked = @block.is_visible?('user_counter') && | ||
85 | + @block.is_visible?('community_counter') && | ||
86 | + @block.is_visible?('enterprise_counter') && | ||
87 | + @block.is_visible?('category_counter') && | ||
88 | + @block.is_visible?('tag_counter') && | ||
89 | + @block.is_visible?('comment_counter') && | ||
90 | + @block.is_visible?('hit_counter') | ||
91 | + assert all_checked | ||
92 | + | ||
93 | + end | ||
94 | + | ||
95 | + should 'be able to check template counters' do | ||
96 | + template = fast_create(Community, :name => 'Councils', :is_template => true, :environment_id => @environment.id) | ||
97 | + @block.templates_ids_counter = {template.id.to_s => 'false'} | ||
98 | + @block.save! | ||
99 | + get :edit, :id => @block.id | ||
100 | + post :save, :id => @block.id, :block => {:templates_ids_counter => {template.id.to_s => 'true'}} | ||
101 | + @block.reload | ||
102 | + | ||
103 | + assert @block.is_template_counter_active?(template.id) | ||
104 | + end | ||
105 | + | ||
106 | + should 'be able to uncheck template counters' do | ||
107 | + template = fast_create(Community, :name => 'Councils', :is_template => true, :environment_id => @environment.id) | ||
108 | + @block.templates_ids_counter = {template.id.to_s => 'true'} | ||
109 | + @block.save! | ||
110 | + get :edit, :id => @block.id | ||
111 | + post :save, :id => @block.id, :block => {:templates_ids_counter => {template.id.to_s => 'false'}} | ||
112 | + @block.reload | ||
113 | + | ||
114 | + assert_equal false, @block.is_template_counter_active?(template.id) | ||
115 | + end | ||
116 | + | ||
117 | + should 'input user counter be checked by default' do | ||
118 | + get :edit, :id => @block.id | ||
119 | + | ||
120 | + assert_tag :input, :attributes => {:id => 'block_user_counter', :checked => 'checked'} | ||
121 | + end | ||
122 | + | ||
123 | + should 'not input community counter be checked by default' do | ||
124 | + get :edit, :id => @block.id | ||
125 | + | ||
126 | + assert_tag :input, :attributes => {:id => 'block_community_counter'} | ||
127 | + assert_no_tag :input, :attributes => {:id => 'block_community_counter', :checked => 'checked'} | ||
128 | + end | ||
129 | + | ||
130 | + should 'not input enterprise counter be checked by default' do | ||
131 | + get :edit, :id => @block.id | ||
132 | + | ||
133 | + assert_tag :input, :attributes => {:id => 'block_enterprise_counter'} | ||
134 | + assert_no_tag :input, :attributes => {:id => 'block_enterprise_counter', :checked => 'checked'} | ||
135 | + end | ||
136 | + | ||
137 | + should 'not input category counter be checked by default' do | ||
138 | + get :edit, :id => @block.id | ||
139 | + | ||
140 | + assert_tag :input, :attributes => {:id => 'block_category_counter'} | ||
141 | + assert_no_tag :input, :attributes => {:id => 'block_category_counter', :checked => 'checked'} | ||
142 | + end | ||
143 | + | ||
144 | + should 'input tag counter be checked by default' do | ||
145 | + get :edit, :id => @block.id | ||
146 | + | ||
147 | + assert_tag :input, :attributes => {:id => 'block_tag_counter', :checked => 'checked'} | ||
148 | + end | ||
149 | + | ||
150 | + should 'input comment counter be checked by default' do | ||
151 | + get :edit, :id => @block.id | ||
152 | + | ||
153 | + assert_tag :input, :attributes => {:id => 'block_comment_counter', :checked => 'checked'} | ||
154 | + end | ||
155 | + | ||
156 | + should 'input hit counter not be checked by default' do | ||
157 | + get :edit, :id => @block.id | ||
158 | + | ||
159 | + assert_no_tag :input, :attributes => {:id => 'block_hit_counter', :checked => 'checked'} | ||
160 | + end | ||
161 | +end |
plugins/statistics/test/functional/statistics_plugin_home_controller_test.rb
0 → 100644
@@ -0,0 +1,147 @@ | @@ -0,0 +1,147 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +# Re-raise errors caught by the controller. | ||
4 | +class HomeController; def rescue_action(e) raise e end; end | ||
5 | + | ||
6 | +class HomeControllerTest < ActionController::TestCase | ||
7 | + | ||
8 | + def setup | ||
9 | + @controller = HomeController.new | ||
10 | + @request = ActionController::TestRequest.new | ||
11 | + @response = ActionController::TestResponse.new | ||
12 | + | ||
13 | + Environment.delete_all | ||
14 | + | ||
15 | + @environment = Environment.create(:name => 'testenv', :is_default => true) | ||
16 | + @environment.enabled_plugins = ['StatisticsPlugin'] | ||
17 | + @environment.save! | ||
18 | + | ||
19 | + user = create_user('testinguser') | ||
20 | + @environment.add_admin(user.person) | ||
21 | + | ||
22 | + StatisticsBlock.delete_all | ||
23 | + @box1 = Box.create!(:owner => @environment) | ||
24 | + @environment.boxes = [@box1] | ||
25 | + | ||
26 | + @block = StatisticsBlock.new | ||
27 | + @block.box = @box1 | ||
28 | + @block.save! | ||
29 | + | ||
30 | + login_as(user.login) | ||
31 | + end | ||
32 | + | ||
33 | + attr_accessor :block | ||
34 | + | ||
35 | + should 'display statistics-block-data class in environment block edition' do | ||
36 | + get :index | ||
37 | + | ||
38 | + assert_tag :div, :attributes => {:class => 'statistics-block-data'} | ||
39 | + end | ||
40 | + | ||
41 | + should 'display users class in statistics-block-data block' do | ||
42 | + get :index | ||
43 | + | ||
44 | + assert_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'users'} } | ||
45 | + end | ||
46 | + | ||
47 | + should 'not display users class in statistics-block-data block' do | ||
48 | + @block.user_counter = false | ||
49 | + @block.save! | ||
50 | + get :index | ||
51 | + | ||
52 | + assert_no_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'users'} } | ||
53 | + end | ||
54 | + | ||
55 | + should 'display communities class in statistics-block-data block' do | ||
56 | + @block.community_counter = true | ||
57 | + @block.save! | ||
58 | + get :index | ||
59 | + | ||
60 | + assert_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'communities'} } | ||
61 | + end | ||
62 | + | ||
63 | + should 'not display communities class in statistics-block-data block' do | ||
64 | + get :index | ||
65 | + | ||
66 | + assert_no_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'communities'} } | ||
67 | + end | ||
68 | + | ||
69 | + should 'display enterprises class in statistics-block-data block' do | ||
70 | + @block.enterprise_counter = true | ||
71 | + @block.save! | ||
72 | + get :index | ||
73 | + | ||
74 | + assert_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'enterprises'} } | ||
75 | + end | ||
76 | + | ||
77 | + should 'not display enterprises class in statistics-block-data block' do | ||
78 | + get :index | ||
79 | + | ||
80 | + assert_no_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'enterprises'} } | ||
81 | + end | ||
82 | + | ||
83 | + should 'display categories class in statistics-block-data block' do | ||
84 | + @block.category_counter = true | ||
85 | + @block.save! | ||
86 | + get :index | ||
87 | + | ||
88 | + assert_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'categories'} } | ||
89 | + end | ||
90 | + | ||
91 | + should 'not display categories class in statistics-block-data block' do | ||
92 | + get :index | ||
93 | + | ||
94 | + assert_no_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'categories'} } | ||
95 | + end | ||
96 | + | ||
97 | + should 'display tags class in statistics-block-data block' do | ||
98 | + get :index | ||
99 | + | ||
100 | + assert_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'tags'} } | ||
101 | + end | ||
102 | + | ||
103 | + should 'not display tags class in statistics-block-data block' do | ||
104 | + @block.tag_counter = false | ||
105 | + @block.save! | ||
106 | + get :index | ||
107 | + | ||
108 | + assert_no_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'tags'} } | ||
109 | + end | ||
110 | + | ||
111 | + should 'display comments class in statistics-block-data block' do | ||
112 | + get :index | ||
113 | + | ||
114 | + assert_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'comments'} } | ||
115 | + end | ||
116 | + | ||
117 | + should 'not display comments class in statistics-block-data block' do | ||
118 | + @block.comment_counter = false | ||
119 | + @block.save! | ||
120 | + get :index | ||
121 | + | ||
122 | + assert_no_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'comments'} } | ||
123 | + end | ||
124 | + | ||
125 | + should 'display hits class in statistics-block-data block' do | ||
126 | + @block.hit_counter = true | ||
127 | + @block.save! | ||
128 | + get :index | ||
129 | + | ||
130 | + assert_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'hits'} } | ||
131 | + end | ||
132 | + | ||
133 | + should 'not display hits class in statistics-block-data block' do | ||
134 | + get :index | ||
135 | + | ||
136 | + assert_no_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'hits'} } | ||
137 | + end | ||
138 | + | ||
139 | + should 'display template name in class in statistics-block-data block' do | ||
140 | + template = fast_create(Community, :name => 'Councils', :is_template => true, :environment_id => @environment.id) | ||
141 | + @block.templates_ids_counter = {template.id.to_s => 'true'} | ||
142 | + @block.save! | ||
143 | + get :index | ||
144 | + | ||
145 | + assert_tag :tag => 'div', :attributes => {:class => 'statistics-block-data'}, :descendant => { :tag => 'li', :attributes => {:class => 'councils'} } | ||
146 | + end | ||
147 | +end |
plugins/statistics/test/functional/statistics_plugin_profile_design_controller_test.rb
0 → 100644
@@ -0,0 +1,85 @@ | @@ -0,0 +1,85 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +# Re-raise errors caught by the controller. | ||
4 | +class ProfileDesignController; def rescue_action(e) raise e end; end | ||
5 | + | ||
6 | +class ProfileDesignControllerTest < ActionController::TestCase | ||
7 | + | ||
8 | + def setup | ||
9 | + @controller = ProfileDesignController.new | ||
10 | + @request = ActionController::TestRequest.new | ||
11 | + @response = ActionController::TestResponse.new | ||
12 | + | ||
13 | + Environment.delete_all | ||
14 | + | ||
15 | + @environment = Environment.create(:name => 'testenv', :is_default => true) | ||
16 | + @environment.enabled_plugins = ['StatisticsPlugin'] | ||
17 | + @environment.save! | ||
18 | + | ||
19 | + user = create_user('testinguser') | ||
20 | + @person = user.person | ||
21 | + @environment.add_admin(@person) | ||
22 | + | ||
23 | + StatisticsBlock.delete_all | ||
24 | + @box1 = Box.create!(:owner => @person) | ||
25 | + @environment.boxes = [@box1] | ||
26 | + | ||
27 | + @block = StatisticsBlock.new | ||
28 | + @block.box = @box1 | ||
29 | + @block.save! | ||
30 | + | ||
31 | + login_as(user.login) | ||
32 | + end | ||
33 | + | ||
34 | + attr_accessor :block | ||
35 | + | ||
36 | + should 'be able to edit StatisticsBlock' do | ||
37 | + get :edit, :id => @block.id, :profile => @person.identifier | ||
38 | + assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | ||
39 | + end | ||
40 | + | ||
41 | + should 'be able to save StatisticsBlock' do | ||
42 | + get :edit, :id => @block.id, :profile => @person.identifier | ||
43 | + post :save, :id => @block.id, :block => {:title => 'Statistics' }, :profile => @person.identifier | ||
44 | + @block.reload | ||
45 | + assert_equal 'Statistics', @block.title | ||
46 | + end | ||
47 | + | ||
48 | + should 'be able to uncheck core counters' do | ||
49 | + @block.user_counter = true | ||
50 | + @block.tag_counter = true | ||
51 | + @block.comment_counter = true | ||
52 | + @block.hit_counter = true | ||
53 | + @block.save! | ||
54 | + get :edit, :id => @block.id, :profile => @person.identifier | ||
55 | + post :save, :id => @block.id, :block => {:user_counter => '0', :tag_counter => '0', :comment_counter => '0', :hit_counter => '0' }, :profile => @person.identifier | ||
56 | + @block.reload | ||
57 | + any_checked = @block.is_visible?('user_counter') || | ||
58 | + @block.is_visible?('tag_counter') || | ||
59 | + @block.is_visible?('comment_counter') || | ||
60 | + @block.is_visible?('hit_counter') | ||
61 | + assert_equal false, any_checked | ||
62 | + end | ||
63 | + | ||
64 | + should 'be able to check core counters' do | ||
65 | + @block.user_counter = false | ||
66 | + @block.community_counter = false | ||
67 | + @block.enterprise_counter = false | ||
68 | + @block.category_counter = false | ||
69 | + @block.tag_counter = false | ||
70 | + @block.comment_counter = false | ||
71 | + @block.hit_counter = false | ||
72 | + @block.save! | ||
73 | + get :edit, :id => @block.id, :profile => @person.identifier | ||
74 | + post :save, :id => @block.id, :block => {:user_counter => '1', | ||
75 | + :tag_counter => '1', :comment_counter => '1', :hit_counter => '1' }, :profile => @person.identifier | ||
76 | + @block.reload | ||
77 | + all_checked = @block.is_visible?('user_counter') && | ||
78 | + @block.is_visible?('tag_counter') && | ||
79 | + @block.is_visible?('comment_counter') && | ||
80 | + @block.is_visible?('hit_counter') | ||
81 | + assert all_checked | ||
82 | + | ||
83 | + end | ||
84 | + | ||
85 | +end |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../test/test_helper' |
@@ -0,0 +1,336 @@ | @@ -0,0 +1,336 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | +class StatisticsBlockTest < ActiveSupport::TestCase | ||
3 | + | ||
4 | + ['user_counter', 'tag_counter', 'comment_counter'].map do |counter| | ||
5 | + should "#{counter} be true by default" do | ||
6 | + b = StatisticsBlock.new | ||
7 | + assert b.is_visible?(counter) | ||
8 | + end | ||
9 | + end | ||
10 | + | ||
11 | + ['community_counter', 'enterprise_counter', 'category_counter', 'hit_counter'].map do |counter| | ||
12 | + should "#{counter} be false by default" do | ||
13 | + b = StatisticsBlock.new | ||
14 | + assert !b.is_visible?(counter) | ||
15 | + end | ||
16 | + end | ||
17 | + | ||
18 | + should 'inherit from Block' do | ||
19 | + assert_kind_of Block, StatisticsBlock.new | ||
20 | + end | ||
21 | + | ||
22 | + should 'provide a default title' do | ||
23 | + block = StatisticsBlock.new | ||
24 | + | ||
25 | + owner = mock | ||
26 | + owner.expects(:name).returns('my environment') | ||
27 | + block.expects(:owner).returns(owner) | ||
28 | + assert_equal 'Statistics for my environment', block.title | ||
29 | + end | ||
30 | + | ||
31 | + should 'describe itself' do | ||
32 | + assert_not_equal StatisticsBlock.description, Block.description | ||
33 | + end | ||
34 | + | ||
35 | + should 'is_visible? return true if setting is true' do | ||
36 | + b = StatisticsBlock.new | ||
37 | + b.community_counter = true | ||
38 | + assert b.is_visible?('community_counter') | ||
39 | + end | ||
40 | + | ||
41 | + should 'is_visible? return false if setting is false' do | ||
42 | + b = StatisticsBlock.new | ||
43 | + b.community_counter = false | ||
44 | + assert !b.is_visible?('community_counter') | ||
45 | + end | ||
46 | + | ||
47 | + should 'templates return the Community templates of the Environment' do | ||
48 | + b = StatisticsBlock.new | ||
49 | + e = fast_create(Environment) | ||
50 | + | ||
51 | + t1 = fast_create(Community, :is_template => true, :environment_id => e.id) | ||
52 | + t2 = fast_create(Community, :is_template => true, :environment_id => e.id) | ||
53 | + fast_create(Community, :is_template => false) | ||
54 | + | ||
55 | + b.expects(:owner).at_least_once.returns(e) | ||
56 | + | ||
57 | + t = b.templates | ||
58 | + assert_equal [], [t1,t2] - t | ||
59 | + assert_equal [], t - [t1,t2] | ||
60 | + end | ||
61 | + | ||
62 | + should 'users return the amount of users of the Environment' do | ||
63 | + b = StatisticsBlock.new | ||
64 | + e = fast_create(Environment) | ||
65 | + | ||
66 | + fast_create(Person, :environment_id => e.id) | ||
67 | + fast_create(Person, :environment_id => e.id) | ||
68 | + fast_create(Person, :visible => false, :environment_id => e.id) | ||
69 | + | ||
70 | + b.expects(:owner).at_least_once.returns(e) | ||
71 | + | ||
72 | + assert_equal 2, b.users | ||
73 | + end | ||
74 | + | ||
75 | + should 'users return the amount of members of the community' do | ||
76 | + b = StatisticsBlock.new | ||
77 | + | ||
78 | + c1 = fast_create(Community) | ||
79 | + c1.add_member(fast_create(Person)) | ||
80 | + c1.add_member(fast_create(Person)) | ||
81 | + c1.add_member(fast_create(Person)) | ||
82 | + c1.add_member(fast_create(Person, :visible => false)) | ||
83 | + c1.add_member(fast_create(Person, :visible => false)) | ||
84 | + | ||
85 | + b.expects(:owner).at_least_once.returns(c1) | ||
86 | + assert_equal 3, b.users | ||
87 | + end | ||
88 | + | ||
89 | + should 'users return the amount of friends of the person' do | ||
90 | + b = StatisticsBlock.new | ||
91 | + | ||
92 | + p1 = fast_create(Person) | ||
93 | + p1.add_friend(fast_create(Person)) | ||
94 | + p1.add_friend(fast_create(Person)) | ||
95 | + p1.add_friend(fast_create(Person)) | ||
96 | + p1.add_friend(fast_create(Person, :visible => false)) | ||
97 | + p1.add_friend(fast_create(Person, :visible => false)) | ||
98 | + | ||
99 | + b.expects(:owner).at_least_once.returns(p1) | ||
100 | + assert_equal 3, b.users | ||
101 | + end | ||
102 | + | ||
103 | + should 'communities return the amount of communities of the Environment' do | ||
104 | + b = StatisticsBlock.new | ||
105 | + e = fast_create(Environment) | ||
106 | + | ||
107 | + fast_create(Community, :environment_id => e.id) | ||
108 | + fast_create(Community, :environment_id => e.id) | ||
109 | + fast_create(Community, :visible => false, :environment_id => e.id) | ||
110 | + | ||
111 | + b.expects(:owner).at_least_once.returns(e) | ||
112 | + | ||
113 | + assert_equal 2, b.communities | ||
114 | + end | ||
115 | + | ||
116 | + should 'enterprises return the amount of enterprises of the Environment' do | ||
117 | + b = StatisticsBlock.new | ||
118 | + e = fast_create(Environment) | ||
119 | + | ||
120 | + fast_create(Enterprise, :environment_id => e.id) | ||
121 | + fast_create(Enterprise, :environment_id => e.id) | ||
122 | + fast_create(Enterprise, :visible => false, :environment_id => e.id) | ||
123 | + | ||
124 | + b.expects(:owner).at_least_once.returns(e) | ||
125 | + | ||
126 | + assert_equal 2, b.enterprises | ||
127 | + end | ||
128 | + | ||
129 | + should 'categories return the amount of categories of the Environment' do | ||
130 | + b = StatisticsBlock.new | ||
131 | + e = fast_create(Environment) | ||
132 | + | ||
133 | + fast_create(Category, :environment_id => e.id) | ||
134 | + fast_create(Category, :environment_id => e.id) | ||
135 | + | ||
136 | + b.expects(:owner).at_least_once.returns(e) | ||
137 | + | ||
138 | + assert_equal 2, b.categories | ||
139 | + end | ||
140 | + | ||
141 | + should 'tags return the amount of tags of the Environment' do | ||
142 | + b = StatisticsBlock.new | ||
143 | + e = fast_create(Environment) | ||
144 | + | ||
145 | + p1 = fast_create(Person, :environment_id => e.id) | ||
146 | + a1 = fast_create(Article, :profile_id => p1.id) | ||
147 | + t1 = fast_create(Tag, :name => 'T1') | ||
148 | + t2 = fast_create(Tag, :name => 'T2') | ||
149 | + a1.tags << t1 | ||
150 | + a1.tags << t2 | ||
151 | + a2 = fast_create(Article, :profile_id => p1.id) | ||
152 | + t3 = fast_create(Tag, :name => 'T3') | ||
153 | + t4 = fast_create(Tag, :name => 'T4') | ||
154 | + a2.tags << t3 | ||
155 | + a2.tags << t4 | ||
156 | + | ||
157 | + b.expects(:owner).at_least_once.returns(e) | ||
158 | + | ||
159 | + assert_equal 4, b.tags | ||
160 | + end | ||
161 | + | ||
162 | + should 'tags return the amount of tags of the community' do | ||
163 | + b = StatisticsBlock.new | ||
164 | + e = fast_create(Environment) | ||
165 | + | ||
166 | + c1 = fast_create(Community, :environment_id => e.id) | ||
167 | + a1 = fast_create(Article, :profile_id => c1.id) | ||
168 | + t1 = fast_create(Tag, :name => 'T1') | ||
169 | + t2 = fast_create(Tag, :name => 'T2') | ||
170 | + a1.tags << t1 | ||
171 | + a1.tags << t2 | ||
172 | + a2 = fast_create(Article, :profile_id => c1.id) | ||
173 | + t3 = fast_create(Tag, :name => 'T3') | ||
174 | + t4 = fast_create(Tag, :name => 'T4') | ||
175 | + a2.tags << t3 | ||
176 | + a2.tags << t4 | ||
177 | + | ||
178 | + b.expects(:owner).at_least_once.returns(c1) | ||
179 | + | ||
180 | + assert_equal 4, b.tags | ||
181 | + end | ||
182 | + | ||
183 | + should 'tags return the amount of tags of the profile (person)' do | ||
184 | + b = StatisticsBlock.new | ||
185 | + e = fast_create(Environment) | ||
186 | + | ||
187 | + p1 = fast_create(Person, :environment_id => e.id) | ||
188 | + a1 = fast_create(Article, :profile_id => p1.id) | ||
189 | + t1 = fast_create(Tag, :name => 'T1') | ||
190 | + t2 = fast_create(Tag, :name => 'T2') | ||
191 | + a1.tags << t1 | ||
192 | + a1.tags << t2 | ||
193 | + a2 = fast_create(Article, :profile_id => p1.id) | ||
194 | + t3 = fast_create(Tag, :name => 'T3') | ||
195 | + t4 = fast_create(Tag, :name => 'T4') | ||
196 | + a2.tags << t3 | ||
197 | + a2.tags << t4 | ||
198 | + | ||
199 | + b.expects(:owner).at_least_once.returns(p1) | ||
200 | + | ||
201 | + assert_equal 4, b.tags | ||
202 | + end | ||
203 | + | ||
204 | + should 'comments return the amount of comments of the Environment' do | ||
205 | + b = StatisticsBlock.new | ||
206 | + e = fast_create(Environment) | ||
207 | + | ||
208 | + p1 = fast_create(Person, :environment_id => e.id) | ||
209 | + a1 = fast_create(Article, :profile_id => p1.id) | ||
210 | + | ||
211 | + Comment.create!(:source => a1, :body => 'C1', :author_id => 1) | ||
212 | + Comment.create!(:source => a1, :body => 'C2', :author_id => 1) | ||
213 | + | ||
214 | + a2 = fast_create(Article, :profile_id => p1.id) | ||
215 | + Comment.create!(:source => a2, :body => 'C3', :author_id => 1) | ||
216 | + Comment.create!(:source => a2, :body => 'C4', :author_id => 1) | ||
217 | + | ||
218 | + b.expects(:owner).at_least_once.returns(e) | ||
219 | + | ||
220 | + assert_equal 4, b.comments | ||
221 | + end | ||
222 | + | ||
223 | + should 'comments return the amount of comments of the community' do | ||
224 | + b = StatisticsBlock.new | ||
225 | + e = Environment.default | ||
226 | + | ||
227 | + c1 = fast_create(Community, :environment_id => e.id) | ||
228 | + a1 = fast_create(Article, :profile_id => c1.id) | ||
229 | + Comment.create!(:source => a1, :body => 'C1', :author_id => 1) | ||
230 | + Comment.create!(:source => a1, :body => 'C2', :author_id => 1) | ||
231 | + | ||
232 | + a2 = fast_create(Article, :profile_id => c1.id) | ||
233 | + Comment.create!(:source => a2, :body => 'C3', :author_id => 1) | ||
234 | + Comment.create!(:source => a2, :body => 'C4', :author_id => 1) | ||
235 | + | ||
236 | + b.expects(:owner).at_least_once.returns(c1) | ||
237 | + | ||
238 | + assert_equal 4, b.comments | ||
239 | + end | ||
240 | + | ||
241 | + should 'comments return the amount of comments of the profile (person)' do | ||
242 | + b = StatisticsBlock.new | ||
243 | + e = fast_create(Environment) | ||
244 | + | ||
245 | + p1 = fast_create(Person, :environment_id => e.id) | ||
246 | + a1 = fast_create(Article, :profile_id => p1.id) | ||
247 | + Comment.create!(:source => a1, :body => 'C1', :author_id => 1) | ||
248 | + Comment.create!(:source => a1, :body => 'C2', :author_id => 1) | ||
249 | + | ||
250 | + a2 = fast_create(Article, :profile_id => p1.id) | ||
251 | + Comment.create!(:source => a1, :body => 'C3', :author_id => 1) | ||
252 | + Comment.create!(:source => a1, :body => 'C4', :author_id => 1) | ||
253 | + | ||
254 | + b.expects(:owner).at_least_once.returns(p1) | ||
255 | + | ||
256 | + assert_equal 4, b.comments | ||
257 | + end | ||
258 | + | ||
259 | + should 'hits return the amount of hits of the Environment' do | ||
260 | + b = StatisticsBlock.new | ||
261 | + e = fast_create(Environment) | ||
262 | + | ||
263 | + p1 = fast_create(Person, :environment_id => e.id) | ||
264 | + a1 = fast_create(Article, :profile_id => p1.id, :hits => 2) | ||
265 | + a2 = fast_create(Article, :profile_id => p1.id, :hits => 5) | ||
266 | + | ||
267 | + b.expects(:owner).at_least_once.returns(e) | ||
268 | + | ||
269 | + assert_equal 7, b.hits | ||
270 | + end | ||
271 | + | ||
272 | + should 'hits return the amount of hits of the community' do | ||
273 | + b = StatisticsBlock.new | ||
274 | + e = fast_create(Environment) | ||
275 | + | ||
276 | + c1 = fast_create(Community, :environment_id => e.id) | ||
277 | + a1 = fast_create(Article, :profile_id => c1.id, :hits => 2) | ||
278 | + a2 = fast_create(Article, :profile_id => c1.id, :hits => 5) | ||
279 | + | ||
280 | + b.expects(:owner).at_least_once.returns(c1) | ||
281 | + | ||
282 | + assert_equal 7, b.hits | ||
283 | + end | ||
284 | + | ||
285 | + should 'hits return the amount of hits of the profile (person)' do | ||
286 | + b = StatisticsBlock.new | ||
287 | + e = fast_create(Environment) | ||
288 | + | ||
289 | + p1 = fast_create(Person, :environment_id => e.id) | ||
290 | + a1 = fast_create(Article, :profile_id => p1.id, :hits => 2) | ||
291 | + a2 = fast_create(Article, :profile_id => p1.id, :hits => 5) | ||
292 | + | ||
293 | + b.expects(:owner).at_least_once.returns(p1) | ||
294 | + | ||
295 | + assert_equal 7, b.hits | ||
296 | + end | ||
297 | + | ||
298 | + should 'is_counter_available? return true for all counters if owner is environment' do | ||
299 | + b = StatisticsBlock.new | ||
300 | + e = fast_create(Environment) | ||
301 | + | ||
302 | + b.expects(:owner).at_least_once.returns(e) | ||
303 | + | ||
304 | + assert b.is_counter_available?(:user_counter) | ||
305 | + end | ||
306 | + | ||
307 | + should 'is_template_counter_active? return true if setting is true' do | ||
308 | + b = StatisticsBlock.new | ||
309 | + b.templates_ids_counter = {'1' => 'true'} | ||
310 | + assert b.is_template_counter_active?(1) | ||
311 | + end | ||
312 | + | ||
313 | + should 'is_template_counter_active? return false if setting is false' do | ||
314 | + b = StatisticsBlock.new | ||
315 | + b.templates_ids_counter = {'1' => 'false'} | ||
316 | + assert !b.is_template_counter_active?(1) | ||
317 | + end | ||
318 | + | ||
319 | + should 'template_counter_count return the amount of communities of the Environment using a template' do | ||
320 | + b = StatisticsBlock.new | ||
321 | + e = fast_create(Environment) | ||
322 | + | ||
323 | + t1 = fast_create(Community, :is_template => true, :environment_id => e.id) | ||
324 | + t2 = fast_create(Community, :is_template => true, :environment_id => e.id) | ||
325 | + fast_create(Community, :is_template => false, :environment_id => e.id, :template_id => t1.id, :visible => true) | ||
326 | + fast_create(Community, :is_template => false, :environment_id => e.id, :template_id => t1.id, :visible => true) | ||
327 | + fast_create(Community, :is_template => false, :environment_id => e.id, :template_id => t1.id, :visible => false) | ||
328 | + | ||
329 | + fast_create(Community, :is_template => false, :environment_id => e.id, :template_id => t2.id, :visible => true) | ||
330 | + fast_create(Community, :is_template => false, :environment_id => e.id, :template_id => t2.id, :visible => false) | ||
331 | + | ||
332 | + b.expects(:owner).at_least_once.returns(e) | ||
333 | + | ||
334 | + assert_equal 2, b.template_counter_count(t1.id) | ||
335 | + end | ||
336 | +end |
@@ -0,0 +1,9 @@ | @@ -0,0 +1,9 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class StatisticsPluginTest < ActiveSupport::TestCase | ||
4 | + | ||
5 | + should "return StatisticsBlock in extra_mlocks class method" do | ||
6 | + assert StatisticsPlugin.extra_blocks.keys.include?(StatisticsBlock) | ||
7 | + end | ||
8 | + | ||
9 | +end |
plugins/statistics/views/box_organizer/_statistics_block.rhtml
0 → 100644
@@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
1 | +<%= labelled_form_field check_box(:block, :user_counter) + _('Show user counter'), '' %> | ||
2 | + | ||
3 | +<% if @block.is_counter_available?(:community_counter) %> | ||
4 | +<%= labelled_form_field check_box(:block, :community_counter) + _('Show community counter'), '' %> | ||
5 | +<% end %> | ||
6 | + | ||
7 | +<% if @block.is_counter_available?(:enterprise_counter) %> | ||
8 | +<%= labelled_form_field check_box(:block, :enterprise_counter) + _('Show enterprise counter'), '' %> | ||
9 | +<% end %> | ||
10 | + | ||
11 | +<% if @block.is_counter_available?(:category_counter) %> | ||
12 | +<%= labelled_form_field check_box(:block, :category_counter) + _('Show category counter'), '' %> | ||
13 | +<% end %> | ||
14 | + | ||
15 | +<% if @block.is_counter_available?(:tag_counter) %> | ||
16 | +<%= labelled_form_field check_box(:block, :tag_counter) + _('Show tag counter'), '' %> | ||
17 | +<% end %> | ||
18 | + | ||
19 | +<% if @block.is_counter_available?(:comment_counter) %> | ||
20 | +<%= labelled_form_field check_box(:block, :comment_counter) + _('Show comment counter'), '' %> | ||
21 | +<% end %> | ||
22 | + | ||
23 | +<% if @block.is_counter_available?(:hit_counter) %> | ||
24 | +<%= labelled_form_field check_box(:block, :hit_counter) + _('Show hit counter'), '' %> | ||
25 | +<% end %> | ||
26 | + | ||
27 | +<% if @block.is_counter_available?(:templates_ids_counter) %> | ||
28 | +<% @block.templates.map do |item|%> | ||
29 | + <%= hidden_field_tag("block[templates_ids_counter][#{item.id}]", false)%> | ||
30 | + <%= labelled_form_field check_box_tag("block[templates_ids_counter][#{item.id}]", true, @block.is_template_counter_active?(item.id)) + _("Show counter for communities with template %s" % item.name), '' %> | ||
31 | +<% end %> | ||
32 | +<% end %> |
@@ -0,0 +1,36 @@ | @@ -0,0 +1,36 @@ | ||
1 | +<h3 class="block-title"> | ||
2 | + <span><%=block.title%></span> | ||
3 | +</h3> | ||
4 | +<div class="statistics-block-data"> | ||
5 | + <ul> | ||
6 | + <% if block.is_visible?('user_counter') %> | ||
7 | + <li class="users"><span class="amount"><%= block.users%> </span><span class="label"><%= _('users')%></span></li> | ||
8 | + <% end %> | ||
9 | + <% if block.is_visible?('enterprise_counter') && !block.environment.enabled?('disable_asset_enterprises') %> | ||
10 | + <li class="enterprises"><span class="amount"><%= block.enterprises%> </span><span class="label"><%= _('enterprises')%></span></li> | ||
11 | + <% end %> | ||
12 | + <% if block.is_visible?('community_counter') %> | ||
13 | + <li class="communities"><span class="amount"><%= block.communities%> </span><span class="label"><%= _('communities')%></span></li> | ||
14 | + <% end %> | ||
15 | + <% if block.is_visible?('category_counter') %> | ||
16 | + <li class="categories"><span class="amount"><%= block.categories%> </span><span class="label"><%= _('categories')%></span></li> | ||
17 | + <% end %> | ||
18 | + <% if block.is_visible?('tag_counter') %> | ||
19 | + <li class="tags"><span class="amount"><%= block.tags%> </span><span class="label"><%= _('tags')%></span></li> | ||
20 | + <% end %> | ||
21 | + <% if block.is_visible?('comment_counter') %> | ||
22 | + <li class="comments"><span class="amount"><%= block.comments%> </span><span class="label"><%= _('comments')%></span></li> | ||
23 | + <% end %> | ||
24 | + <% if block.is_visible?('hit_counter') %> | ||
25 | + <li class="hits"><span class="amount"><%= block.hits%> </span><span class="label"><%= _('hits')%></span></li> | ||
26 | + <% end %> | ||
27 | + | ||
28 | + <% if block.owner.kind_of?(Environment) then %> | ||
29 | + <% block.templates.each do |item| %> | ||
30 | + <% if block.is_template_counter_active? item.id %> | ||
31 | + <li class="<%= item.name.to_slug%>"><span class="amount"><%= block.template_counter_count(item.id)%> </span><span class="label"><%= item.name%></span></li> | ||
32 | + <% end %> | ||
33 | + <% end %> | ||
34 | + <% end %> | ||
35 | + </ul> | ||
36 | +</div> |
test/functional/environment_design_controller_test.rb
@@ -6,7 +6,7 @@ class EnvironmentDesignController; def rescue_action(e) raise e end; end | @@ -6,7 +6,7 @@ class EnvironmentDesignController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class EnvironmentDesignControllerTest < ActionController::TestCase | 7 | class EnvironmentDesignControllerTest < ActionController::TestCase |
8 | 8 | ||
9 | - ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] | 9 | + ALL_BLOCKS = [ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] |
10 | 10 | ||
11 | def setup | 11 | def setup |
12 | @controller = EnvironmentDesignController.new | 12 | @controller = EnvironmentDesignController.new |
@@ -83,16 +83,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | @@ -83,16 +83,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase | ||
83 | assert_tag :tag => 'p', :attributes => { :id => 'no_portal_community' } | 83 | assert_tag :tag => 'p', :attributes => { :id => 'no_portal_community' } |
84 | end | 84 | end |
85 | 85 | ||
86 | - should 'be able to edit EnvironmentStatisticsBlock' do | ||
87 | - login_as(create_admin_user(Environment.default)) | ||
88 | - b = EnvironmentStatisticsBlock.create! | ||
89 | - e = Environment.default | ||
90 | - e.boxes.create! | ||
91 | - e.boxes.first.blocks << b | ||
92 | - get :edit, :id => b.id | ||
93 | - assert_tag :tag => 'input', :attributes => { :id => 'block_title' } | ||
94 | - end | ||
95 | - | ||
96 | should 'be able to edit EnterprisesBlock' do | 86 | should 'be able to edit EnterprisesBlock' do |
97 | login_as(create_admin_user(Environment.default)) | 87 | login_as(create_admin_user(Environment.default)) |
98 | b = EnterprisesBlock.create! | 88 | b = EnterprisesBlock.create! |
test/unit/box_test.rb
@@ -33,7 +33,6 @@ class BoxTest < ActiveSupport::TestCase | @@ -33,7 +33,6 @@ class BoxTest < ActiveSupport::TestCase | ||
33 | assert blocks.include?('categories-block') | 33 | assert blocks.include?('categories-block') |
34 | assert blocks.include?('communities-block') | 34 | assert blocks.include?('communities-block') |
35 | assert blocks.include?('enterprises-block') | 35 | assert blocks.include?('enterprises-block') |
36 | - assert blocks.include?('environment-statistics-block') | ||
37 | assert blocks.include?('fans-block') | 36 | assert blocks.include?('fans-block') |
38 | assert blocks.include?('favorite-enterprises-block') | 37 | assert blocks.include?('favorite-enterprises-block') |
39 | assert blocks.include?('feed-reader-block') | 38 | assert blocks.include?('feed-reader-block') |
@@ -65,7 +64,6 @@ class BoxTest < ActiveSupport::TestCase | @@ -65,7 +64,6 @@ class BoxTest < ActiveSupport::TestCase | ||
65 | assert blocks.include?('communities-block') | 64 | assert blocks.include?('communities-block') |
66 | assert blocks.include?('disabled-enterprise-message-block') | 65 | assert blocks.include?('disabled-enterprise-message-block') |
67 | assert blocks.include?('enterprises-block') | 66 | assert blocks.include?('enterprises-block') |
68 | - assert blocks.include?('environment-statistics-block') | ||
69 | assert blocks.include?('fans-block') | 67 | assert blocks.include?('fans-block') |
70 | assert blocks.include?('favorite-enterprises-block') | 68 | assert blocks.include?('favorite-enterprises-block') |
71 | assert blocks.include?('featured-products-block') | 69 | assert blocks.include?('featured-products-block') |
test/unit/environment_statistics_block_test.rb
@@ -1,96 +0,0 @@ | @@ -1,96 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../test_helper' | ||
2 | - | ||
3 | -class EnvironmentStatisticsBlockTest < ActiveSupport::TestCase | ||
4 | - | ||
5 | - should 'inherit from Block' do | ||
6 | - assert_kind_of Block, EnvironmentStatisticsBlock.new | ||
7 | - end | ||
8 | - | ||
9 | - should 'describe itself' do | ||
10 | - assert_not_equal Block.description, EnvironmentStatisticsBlock.description | ||
11 | - end | ||
12 | - | ||
13 | - should 'provide a default title' do | ||
14 | - owner = mock | ||
15 | - owner.expects(:name).returns('my environment') | ||
16 | - | ||
17 | - block = EnvironmentStatisticsBlock.new | ||
18 | - block.expects(:owner).returns(owner) | ||
19 | - assert_equal 'Statistics for my environment', block.title | ||
20 | - end | ||
21 | - | ||
22 | - should 'generate statistics' do | ||
23 | - env = create(Environment) | ||
24 | - user1 = create_user('testuser1', :environment_id => env.id) | ||
25 | - user2 = create_user('testuser2', :environment_id => env.id) | ||
26 | - | ||
27 | - fast_create(Enterprise, :environment_id => env.id) | ||
28 | - fast_create(Community, :environment_id => env.id) | ||
29 | - | ||
30 | - block = EnvironmentStatisticsBlock.new | ||
31 | - env.boxes.first.blocks << block | ||
32 | - | ||
33 | - content = block.content | ||
34 | - | ||
35 | - assert_match(/One enterprise/, content) | ||
36 | - assert_match(/2 users/, content) | ||
37 | - assert_match(/One community/, content) | ||
38 | - end | ||
39 | - | ||
40 | - should 'generate statistics including private profiles' do | ||
41 | - env = create(Environment) | ||
42 | - user1 = create_user('testuser1', :environment_id => env.id) | ||
43 | - user2 = create_user('testuser2', :environment_id => env.id) | ||
44 | - user3 = create_user('testuser3', :environment_id => env.id) | ||
45 | - p = user3.person; p.public_profile = false; p.save! | ||
46 | - | ||
47 | - fast_create(Enterprise, :environment_id => env.id) | ||
48 | - fast_create(Enterprise, :environment_id => env.id, :public_profile => false) | ||
49 | - | ||
50 | - fast_create(Community, :environment_id => env.id) | ||
51 | - fast_create(Community, :environment_id => env.id, :public_profile => false) | ||
52 | - | ||
53 | - block = EnvironmentStatisticsBlock.new | ||
54 | - env.boxes.first.blocks << block | ||
55 | - | ||
56 | - content = block.content | ||
57 | - | ||
58 | - assert_match /2 enterprises/, content | ||
59 | - assert_match /3 users/, content | ||
60 | - assert_match /2 communities/, content | ||
61 | - end | ||
62 | - | ||
63 | - should 'generate statistics but not for not visible profiles' do | ||
64 | - env = create(Environment) | ||
65 | - user1 = create_user('testuser1', :environment_id => env.id) | ||
66 | - user2 = create_user('testuser2', :environment_id => env.id) | ||
67 | - user3 = create_user('testuser3', :environment_id => env.id) | ||
68 | - p = user3.person; p.visible = false; p.save! | ||
69 | - | ||
70 | - fast_create(Enterprise, :environment_id => env.id) | ||
71 | - fast_create(Enterprise, :environment_id => env.id, :visible => false) | ||
72 | - | ||
73 | - fast_create(Community, :environment_id => env.id) | ||
74 | - fast_create(Community, :environment_id => env.id, :visible => false) | ||
75 | - | ||
76 | - block = EnvironmentStatisticsBlock.new | ||
77 | - env.boxes.first.blocks << block | ||
78 | - | ||
79 | - content = block.content | ||
80 | - | ||
81 | - assert_match /One enterprise/, content | ||
82 | - assert_match /2 users/, content | ||
83 | - assert_match /One community/, content | ||
84 | - end | ||
85 | - | ||
86 | - should 'not display enterprises if disabled' do | ||
87 | - env = fast_create(Environment) | ||
88 | - env.enable('disable_asset_enterprises', false) | ||
89 | - | ||
90 | - block = EnvironmentStatisticsBlock.new | ||
91 | - block.stubs(:owner).returns(env) | ||
92 | - | ||
93 | - assert_no_match /enterprises/i, block.content | ||
94 | - end | ||
95 | - | ||
96 | -end |