From 914ea967ce52bf2ea6f8973ab7b433c396cd3acd Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Wed, 27 Aug 2014 20:41:41 -0300 Subject: [PATCH] Removing EnvironmentStatisticsBlock from core --- app/controllers/admin/environment_design_controller.rb | 4 +--- app/models/box.rb | 6 ------ app/models/environment.rb | 3 --- app/models/environment_statistics_block.rb | 33 --------------------------------- app/sweepers/profile_sweeper.rb | 10 ---------- baseplugins/statistics | 1 + db/migrate/20140827191326_remove_environment_statistics_block.rb | 9 +++++++++ db/schema.rb | 2 +- test/functional/environment_design_controller_test.rb | 16 +--------------- test/unit/box_test.rb | 6 ------ test/unit/environment_statistics_block_test.rb | 99 --------------------------------------------------------------------------------------------------- 11 files changed, 13 insertions(+), 176 deletions(-) delete mode 100644 app/models/environment_statistics_block.rb create mode 120000 baseplugins/statistics create mode 100644 db/migrate/20140827191326_remove_environment_statistics_block.rb delete mode 100644 test/unit/environment_statistics_block_test.rb diff --git a/app/controllers/admin/environment_design_controller.rb b/app/controllers/admin/environment_design_controller.rb index de82113..f5ce5fa 100644 --- a/app/controllers/admin/environment_design_controller.rb +++ b/app/controllers/admin/environment_design_controller.rb @@ -3,9 +3,7 @@ class EnvironmentDesignController < BoxOrganizerController protect 'edit_environment_design', :environment def available_blocks - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] + @available_blocks ||= [ ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] @available_blocks += plugins.dispatch(:extra_blocks, :type => Environment) end diff --git a/app/models/box.rb b/app/models/box.rb index df97a41..9aa00e8 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -28,9 +28,6 @@ class Box < ActiveRecord::Base CategoriesBlock, CommunitiesBlock, EnterprisesBlock, - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - EnvironmentStatisticsBlock, FansBlock, FavoriteEnterprisesBlock, FeedReaderBlock, @@ -53,9 +50,6 @@ class Box < ActiveRecord::Base CommunitiesBlock, DisabledEnterpriseMessageBlock, EnterprisesBlock, - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - EnvironmentStatisticsBlock, FansBlock, FavoriteEnterprisesBlock, FeaturedProductsBlock, diff --git a/app/models/environment.rb b/app/models/environment.rb index 952a165..861a932 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -177,9 +177,6 @@ class Environment < ActiveRecord::Base # "left" area env.boxes[1].blocks << LoginBlock.new - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - env.boxes[1].blocks << EnvironmentStatisticsBlock.new env.boxes[1].blocks << RecentDocumentsBlock.new # "right" area diff --git a/app/models/environment_statistics_block.rb b/app/models/environment_statistics_block.rb deleted file mode 100644 index 359891c..0000000 --- a/app/models/environment_statistics_block.rb +++ /dev/null @@ -1,33 +0,0 @@ -# TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from -# the Noosfero core soon, see ActionItem3045 - -class EnvironmentStatisticsBlock < Block - - def self.description - _('Environment stastistics (DEPRECATED)') - end - - def default_title - _('Statistics for %s') % owner.name - end - - def help - _('This block presents some statistics about your environment.') - end - - def content(args={}) - users = owner.people.visible.count - enterprises = owner.enterprises.visible.count - communities = owner.communities.visible.count - - info = [] - info << (n_('One user', '%{num} users', users) % { :num => users }) - unless owner.enabled?('disable_asset_enterprises') - info << (n_('One enterprise', '%{num} enterprises', enterprises) % { :num => enterprises }) - end - info << (n_('One community', '%{num} communities', communities) % { :num => communities }) - - block_title(title) + content_tag('ul', info.map {|item| content_tag('li', item) }.join("\n")) - end - -end diff --git a/app/sweepers/profile_sweeper.rb b/app/sweepers/profile_sweeper.rb index e23f9b4..454b593 100644 --- a/app/sweepers/profile_sweeper.rb +++ b/app/sweepers/profile_sweeper.rb @@ -8,9 +8,6 @@ class ProfileSweeper # < ActiveRecord::Observer end def after_create(profile) - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - expire_statistics_block_cache(profile) end protected @@ -31,13 +28,6 @@ protected expire_blogs(profile) if profile.organization? end - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - def expire_statistics_block_cache(profile) - blocks = profile.environment.blocks.select { |b| b.kind_of?(EnvironmentStatisticsBlock) } - BlockSweeper.expire_blocks(blocks) - end - def expire_blogs(profile) profile.blogs.select{|b| !b.empty?}.each do |blog| pages = blog.posts.count / blog.posts_per_page + 1 diff --git a/baseplugins/statistics b/baseplugins/statistics new file mode 120000 index 0000000..6620f62 --- /dev/null +++ b/baseplugins/statistics @@ -0,0 +1 @@ +../plugins/statistics \ No newline at end of file diff --git a/db/migrate/20140827191326_remove_environment_statistics_block.rb b/db/migrate/20140827191326_remove_environment_statistics_block.rb new file mode 100644 index 0000000..0a65ca9 --- /dev/null +++ b/db/migrate/20140827191326_remove_environment_statistics_block.rb @@ -0,0 +1,9 @@ +class RemoveEnvironmentStatisticsBlock < ActiveRecord::Migration + def self.up + update("UPDATE blocks SET type = 'StatisticsBlock' WHERE type = 'EnvironmentStatisticsBlock'") + end + + def self.down + say("Nothing to undo (cannot recover the data)") + end +end diff --git a/db/schema.rb b/db/schema.rb index a80f7c2..bce7a18 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140808185510) do +ActiveRecord::Schema.define(:version => 20140827191326) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" diff --git a/test/functional/environment_design_controller_test.rb b/test/functional/environment_design_controller_test.rb index 674c476..4b37a79 100644 --- a/test/functional/environment_design_controller_test.rb +++ b/test/functional/environment_design_controller_test.rb @@ -6,9 +6,7 @@ class EnvironmentDesignController; def rescue_action(e) raise e end; end class EnvironmentDesignControllerTest < ActionController::TestCase - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] + ALL_BLOCKS = [ArticleBlock, LoginBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] def setup @controller = EnvironmentDesignController.new @@ -77,18 +75,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase assert_tag :tag => 'p', :attributes => { :id => 'no_portal_community' } end - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - should 'be able to edit EnvironmentStatisticsBlock' do - login_as(create_admin_user(Environment.default)) - b = EnvironmentStatisticsBlock.create! - e = Environment.default - e.boxes.create! - e.boxes.first.blocks << b - get :edit, :id => b.id - assert_tag :tag => 'input', :attributes => { :id => 'block_title' } - end - should 'be able to edit EnterprisesBlock' do login_as(create_admin_user(Environment.default)) b = EnterprisesBlock.create! diff --git a/test/unit/box_test.rb b/test/unit/box_test.rb index 4a3c06a..d9f7e07 100644 --- a/test/unit/box_test.rb +++ b/test/unit/box_test.rb @@ -33,9 +33,6 @@ class BoxTest < ActiveSupport::TestCase assert blocks.include?('categories-block') assert blocks.include?('communities-block') assert blocks.include?('enterprises-block') - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - assert blocks.include?('environment-statistics-block') assert blocks.include?('fans-block') assert blocks.include?('favorite-enterprises-block') assert blocks.include?('feed-reader-block') @@ -64,9 +61,6 @@ class BoxTest < ActiveSupport::TestCase assert blocks.include?('communities-block') assert blocks.include?('disabled-enterprise-message-block') assert blocks.include?('enterprises-block') - # TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from - # the Noosfero core soon, see ActionItem3045 - assert blocks.include?('environment-statistics-block') assert blocks.include?('fans-block') assert blocks.include?('favorite-enterprises-block') assert blocks.include?('featured-products-block') diff --git a/test/unit/environment_statistics_block_test.rb b/test/unit/environment_statistics_block_test.rb deleted file mode 100644 index 53d740e..0000000 --- a/test/unit/environment_statistics_block_test.rb +++ /dev/null @@ -1,99 +0,0 @@ -# TODO EnvironmentStatisticsBlock is DEPRECATED and will be removed from -# the Noosfero core soon, see ActionItem3045 - -require File.dirname(__FILE__) + '/../test_helper' - -class EnvironmentStatisticsBlockTest < ActiveSupport::TestCase - - should 'inherit from Block' do - assert_kind_of Block, EnvironmentStatisticsBlock.new - end - - should 'describe itself' do - assert_not_equal Block.description, EnvironmentStatisticsBlock.description - end - - should 'provide a default title' do - owner = mock - owner.expects(:name).returns('my environment') - - block = EnvironmentStatisticsBlock.new - block.expects(:owner).returns(owner) - assert_equal 'Statistics for my environment', block.title - end - - should 'generate statistics' do - env = create(Environment) - user1 = create_user('testuser1', :environment_id => env.id) - user2 = create_user('testuser2', :environment_id => env.id) - - fast_create(Enterprise, :environment_id => env.id) - fast_create(Community, :environment_id => env.id) - - block = EnvironmentStatisticsBlock.new - env.boxes.first.blocks << block - - content = block.content - - assert_match(/One enterprise/, content) - assert_match(/2 users/, content) - assert_match(/One community/, content) - end - - should 'generate statistics including private profiles' do - env = create(Environment) - user1 = create_user('testuser1', :environment_id => env.id) - user2 = create_user('testuser2', :environment_id => env.id) - user3 = create_user('testuser3', :environment_id => env.id) - p = user3.person; p.public_profile = false; p.save! - - fast_create(Enterprise, :environment_id => env.id) - fast_create(Enterprise, :environment_id => env.id, :public_profile => false) - - fast_create(Community, :environment_id => env.id) - fast_create(Community, :environment_id => env.id, :public_profile => false) - - block = EnvironmentStatisticsBlock.new - env.boxes.first.blocks << block - - content = block.content - - assert_match /2 enterprises/, content - assert_match /3 users/, content - assert_match /2 communities/, content - end - - should 'generate statistics but not for not visible profiles' do - env = create(Environment) - user1 = create_user('testuser1', :environment_id => env.id) - user2 = create_user('testuser2', :environment_id => env.id) - user3 = create_user('testuser3', :environment_id => env.id) - p = user3.person; p.visible = false; p.save! - - fast_create(Enterprise, :environment_id => env.id) - fast_create(Enterprise, :environment_id => env.id, :visible => false) - - fast_create(Community, :environment_id => env.id) - fast_create(Community, :environment_id => env.id, :visible => false) - - block = EnvironmentStatisticsBlock.new - env.boxes.first.blocks << block - - content = block.content - - assert_match /One enterprise/, content - assert_match /2 users/, content - assert_match /One community/, content - end - - should 'not display enterprises if disabled' do - env = fast_create(Environment) - env.enable('disable_asset_enterprises', false) - - block = EnvironmentStatisticsBlock.new - block.stubs(:owner).returns(env) - - assert_no_match /enterprises/i, block.content - end - -end -- libgit2 0.21.2