Commit 83c75a5c6a2a418e562638de40a4e119b1b081aa
1 parent
e9d69652
Exists in
master
and in
23 other branches
ActionItem153: adding EnvironmentStatisticsBlock
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1277 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
48 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
| 1 | +class EnvironmentStatisticsBlock < Block | ||
| 2 | + | ||
| 3 | + def self.description | ||
| 4 | + _('Statitical overview of your environment.') | ||
| 5 | + end | ||
| 6 | + | ||
| 7 | + def content | ||
| 8 | + users = owner.people.count | ||
| 9 | + enterprises = owner.enterprises.count | ||
| 10 | + | ||
| 11 | + info = [ | ||
| 12 | + n_('One user', '%{num} users', users) % { :num => users }, | ||
| 13 | + n_('One enterprise', '%{num} enterprises', enterprises) % { :num => enterprises} | ||
| 14 | + ] | ||
| 15 | + | ||
| 16 | + content_tag('h3', _('Statistics for %s') % owner.name, :class => 'block-title' ) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n")) | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | +end |
| @@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | + | ||
| 3 | +class EnvironmentStatisticsBlockTest < Test::Unit::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 'generate statistics' do | ||
| 14 | + env = Environment.create!(:name => "My test environment") | ||
| 15 | + user1 = create_user('testuser1', :environment_id => env.id) | ||
| 16 | + user2 = create_user('testuser2', :environment_id => env.id) | ||
| 17 | + | ||
| 18 | + env.enterprises.build(:identifier => 'mytestenterprise', :name => 'My test enterprise').save! | ||
| 19 | + | ||
| 20 | + block = EnvironmentStatisticsBlock.new | ||
| 21 | + env.boxes.first.blocks << block | ||
| 22 | + | ||
| 23 | + content = block.content | ||
| 24 | + | ||
| 25 | + assert_match /One enterprise/, content | ||
| 26 | + assert_match /2 users/, content | ||
| 27 | + end | ||
| 28 | + | ||
| 29 | +end |