From 4b62288d0a6da32636435354b23d2c36833374d8 Mon Sep 17 00:00:00 2001 From: Leandro Nunes dos Santos Date: Thu, 26 Jun 2014 17:20:06 -0300 Subject: [PATCH] updating with rails3 branch --- Gemfile | 1 + Gemfile.lock | 6 +++++- app/controllers/admin/admin_panel_controller.rb | 1 + app/controllers/admin/environment_design_controller.rb | 2 +- app/controllers/my_profile/cms_controller.rb | 1 + app/controllers/my_profile/profile_design_controller.rb | 6 ------ app/helpers/application_helper.rb | 6 +++--- app/helpers/sweeper_helper.rb | 4 +--- app/models/approve_article.rb | 2 +- app/models/article.rb | 28 ++++++++++++++-------------- app/models/box.rb | 6 ------ app/models/categories_block.rb | 2 ++ app/models/community.rb | 6 +----- app/models/enterprise.rb | 2 ++ app/models/environment.rb | 9 +++++++-- app/models/friends_block.rb | 26 -------------------------- app/models/members_block.rb | 52 ---------------------------------------------------- app/models/organization.rb | 2 +- app/models/people_block.rb | 25 ------------------------- app/models/person.rb | 4 ++-- app/models/profile_list_block.rb | 4 ++-- app/sweepers/friendship_sweeper.rb | 3 +-- app/views/account/signup.html.erb | 30 +++++++++++++++++------------- app/views/admin_panel/_signup_welcome_screen.html.erb | 5 +++++ app/views/admin_panel/site_info.html.erb | 2 ++ app/views/blocks/members.html.erb | 5 ----- app/views/content_viewer/_article_toolbar.html.erb | 6 +++--- app/views/layouts/application-ng.html.erb | 5 +++++ app/views/profile_members/_members_list.html.erb | 6 +++--- app/views/shared/_change_image.html.erb | 5 +---- app/views/shared/_show_thumbnail.html.erb | 15 ++++++++++----- app/views/user/mailer/activation_code.html.erb | 2 +- config/application.rb | 2 +- config/plugins/people_block | 1 + db/migrate/20140415125414_add_created_by_to_article.rb | 17 +++++++++++++++++ db/schema.rb | 4 +++- features/categories_block.feature | 15 ++++++++++----- features/edit_profile.feature | 4 ++-- features/my_network_block.feature | 10 ++++++++++ features/profile_domain.feature | 23 ++++++----------------- features/publish_article.feature | 1 + features/step_definitions/web_steps.rb | 4 ++-- lib/noosfero/plugin.rb | 6 ++++++ lib/noosfero/plugin.rb.orig | 639 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb | 5 ++++- plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb | 1 - plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb | 31 +++++++++++++++++++++++++++++++ plugins/display_content/lib/display_content_block.rb | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------- plugins/display_content/test/unit/display_content_block_test.rb | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- plugins/display_content/views/box_organizer/_choose_by_content_type.html.erb | 15 +++++++++++++++ plugins/display_content/views/box_organizer/_choose_directly.html.erb | 30 ++++++++++++++++++++++++++++++ plugins/display_content/views/box_organizer/_display_content_block.html.erb | 42 ++++++++++++------------------------------ plugins/people_block/before_disable.rb | 2 ++ plugins/people_block/controllers/people_block_plugin_profile_controller.rb | 19 +++++++++++++++++++ plugins/people_block/db/migrate/20140605222753_enable_people_block_plugin.rb | 16 ++++++++++++++++ plugins/people_block/lib/ext/person.rb | 9 +++++++++ plugins/people_block/lib/friends_block.rb | 30 ++++++++++++++++++++++++++++++ plugins/people_block/lib/members_block.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/people_block/lib/people_block.rb | 25 +++++++++++++++++++++++++ plugins/people_block/lib/people_block_base.rb | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/people_block/lib/people_block_plugin.rb | 27 +++++++++++++++++++++++++++ plugins/people_block/public/style.css | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb | 25 +++++++++++++++++++++++++ plugins/people_block/test/functional/people_block_plugin_profile_controller_test.rb | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/people_block/test/test_helper.rb | 1 + plugins/people_block/test/unit/friends_block_test.rb | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/people_block/test/unit/members_block_test.rb | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/people_block/test/unit/people_block_plugin_test.rb | 25 +++++++++++++++++++++++++ plugins/people_block/test/unit/people_block_test.rb | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/people_block/views/blocks/friends.html.erb | 1 + plugins/people_block/views/blocks/members.html.erb | 5 +++++ plugins/people_block/views/blocks/people.html.erb | 1 + plugins/people_block/views/box_organizer/_people_block_base.html.erb | 10 ++++++++++ plugins/people_block/views/environment_design | 1 + plugins/people_block/views/profile_design | 1 + plugins/piwik/controllers/piwik_plugin_admin_controller.rb | 16 ++++++++++++++++ plugins/piwik/lib/ext/environment.rb | 7 +++++++ plugins/piwik/lib/piwik_plugin.rb | 24 ++++++++++++++++++++++++ plugins/piwik/test/functional/piwik_plugin_test.rb | 31 +++++++++++++++++++++++++++++++ plugins/piwik/test/unit/piwik_plugin_test.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ plugins/piwik/views/piwik_plugin_admin/index.html.erb | 13 +++++++++++++ plugins/piwik/views/tracking-code.rhtml | 15 +++++++++++++++ plugins/require_auth_to_comment/lib/ext/profile.rb | 1 + plugins/video/lib/video_block.rb | 10 +++++++--- plugins/video/test/unit/video_block_test.rb | 7 +++++++ public/designs/themes/base/style.css | 30 ++---------------------------- public/plugins/people_block | 1 + script/noosfero-plugins | 31 +++++++++++++++++++------------ test/functional/account_controller_test.rb | 8 -------- test/functional/admin_panel_controller_test.rb | 18 ++++++++++-------- test/functional/application_controller_test.rb | 8 -------- test/functional/catalog_controller_test.rb | 8 -------- test/functional/categories_controller_test.rb | 8 -------- test/functional/cms_controller_test.rb | 35 ++++++++++++++++++++++++++--------- test/functional/content_viewer_controller_test.rb | 12 +----------- test/functional/edit_template_controller_test.rb | 8 -------- test/functional/enterprise_registration_controller_test.rb | 8 -------- test/functional/enterprise_validation_controller_test.rb | 12 ------------ test/functional/environment_design_controller_test.rb | 20 +------------------- test/functional/environment_role_manager_controller_test.rb | 12 ------------ test/functional/favorite_enterprises_controller_test.rb | 8 -------- test/functional/features_controller_test.rb | 8 -------- test/functional/friends_controller_test.rb | 8 -------- test/functional/home_controller_test.rb | 8 -------- test/functional/manage_products_controller_test.rb | 8 -------- test/functional/memberships_controller_test.rb | 8 -------- test/functional/my_profile_controller_test.rb | 10 ---------- test/functional/plugins_controller_test.rb | 8 -------- test/functional/profile_controller_test.rb | 8 -------- test/functional/profile_design_controller_test.rb | 28 +--------------------------- test/functional/profile_editor_controller_test.rb | 41 ++++++++++++++++++++++++++++++----------- test/functional/profile_members_controller_test.rb | 9 --------- test/functional/region_validators_controller_test.rb | 8 -------- test/functional/role_controller_test.rb | 8 -------- test/functional/search_controller_test.rb | 8 -------- test/functional/tasks_controller_test.rb | 8 -------- test/test_helper.rb | 51 --------------------------------------------------- test/unit/article_test.rb | 43 ++++++++++++++++++++++++++++++++----------- test/unit/box_test.rb | 6 ------ test/unit/environment_test.rb | 28 ++++++++++++++++++++++++++++ test/unit/forum_helper_test.rb | 2 +- test/unit/friends_block_test.rb | 86 -------------------------------------------------------------------------------------- test/unit/members_block_test.rb | 62 -------------------------------------------------------------- test/unit/people_block_test.rb | 50 -------------------------------------------------- test/unit/tiny_mce_article_test.rb | 13 +++++++++++-- vendor/plugins/acts_as_list/Rakefile | 12 ++++++++++++ vendor/plugins/acts_as_list/lib/active_record/acts/list.rb | 21 +++++++++++++-------- vendor/plugins/acts_as_list/test/list_test.rb | 236 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ 129 files changed, 2121 insertions(+), 1531 deletions(-) delete mode 100644 app/models/friends_block.rb delete mode 100644 app/models/members_block.rb delete mode 100644 app/models/people_block.rb create mode 100644 app/views/admin_panel/_signup_welcome_screen.html.erb delete mode 100644 app/views/blocks/members.html.erb create mode 120000 config/plugins/people_block create mode 100644 db/migrate/20140415125414_add_created_by_to_article.rb delete mode 100644 lib/noosfero/plugin.rb.orig create mode 100644 plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb create mode 100644 plugins/display_content/views/box_organizer/_choose_by_content_type.html.erb create mode 100644 plugins/display_content/views/box_organizer/_choose_directly.html.erb create mode 100644 plugins/people_block/before_disable.rb create mode 100644 plugins/people_block/controllers/people_block_plugin_profile_controller.rb create mode 100644 plugins/people_block/db/migrate/20140605222753_enable_people_block_plugin.rb create mode 100644 plugins/people_block/lib/ext/person.rb create mode 100644 plugins/people_block/lib/friends_block.rb create mode 100644 plugins/people_block/lib/members_block.rb create mode 100644 plugins/people_block/lib/people_block.rb create mode 100644 plugins/people_block/lib/people_block_base.rb create mode 100644 plugins/people_block/lib/people_block_plugin.rb create mode 100644 plugins/people_block/public/style.css create mode 100644 plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb create mode 100644 plugins/people_block/test/functional/people_block_plugin_profile_controller_test.rb create mode 100644 plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb create mode 100644 plugins/people_block/test/test_helper.rb create mode 100644 plugins/people_block/test/unit/friends_block_test.rb create mode 100644 plugins/people_block/test/unit/members_block_test.rb create mode 100644 plugins/people_block/test/unit/people_block_plugin_test.rb create mode 100644 plugins/people_block/test/unit/people_block_test.rb create mode 100644 plugins/people_block/views/blocks/friends.html.erb create mode 100644 plugins/people_block/views/blocks/members.html.erb create mode 100644 plugins/people_block/views/blocks/people.html.erb create mode 100644 plugins/people_block/views/box_organizer/_people_block_base.html.erb create mode 120000 plugins/people_block/views/environment_design create mode 120000 plugins/people_block/views/profile_design create mode 100644 plugins/piwik/controllers/piwik_plugin_admin_controller.rb create mode 100644 plugins/piwik/lib/ext/environment.rb create mode 100644 plugins/piwik/lib/piwik_plugin.rb create mode 100644 plugins/piwik/test/functional/piwik_plugin_test.rb create mode 100644 plugins/piwik/test/unit/piwik_plugin_test.rb create mode 100644 plugins/piwik/views/piwik_plugin_admin/index.html.erb create mode 100644 plugins/piwik/views/tracking-code.rhtml create mode 120000 public/plugins/people_block delete mode 100644 test/unit/friends_block_test.rb delete mode 100644 test/unit/members_block_test.rb delete mode 100644 test/unit/people_block_test.rb create mode 100644 vendor/plugins/acts_as_list/Rakefile diff --git a/Gemfile b/Gemfile index 49f23a6..f96a866 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,7 @@ end group :test do gem 'rspec' gem 'rspec-rails' + gem 'mocha', :require => false end group :cucumber do diff --git a/Gemfile.lock b/Gemfile.lock index 518e712..5485d00 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,7 +61,7 @@ GEM database_cleaner (1.2.0) diff-lcs (1.1.3) erubis (2.7.0) - eventmachine (0.12.11) + eventmachine (1.0.3) fast_gettext (0.6.8) ffi (1.0.11) gherkin (2.4.21) @@ -75,7 +75,10 @@ GEM i18n (>= 0.4.0) mime-types (~> 1.16) treetop (~> 1.4.8) + metaclass (0.0.4) mime-types (1.19) + mocha (0.11.3) + metaclass (~> 0.0.1) multi_json (1.3.6) nokogiri (1.5.5) pg (0.13.2) @@ -164,6 +167,7 @@ DEPENDENCIES database_cleaner fast_gettext hpricot + mocha nokogiri pg prototype-rails diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb index 14106cc..6c2b103 100644 --- a/app/controllers/admin/admin_panel_controller.rb +++ b/app/controllers/admin/admin_panel_controller.rb @@ -7,6 +7,7 @@ class AdminPanelController < AdminController end def site_info + @no_design_blocks = true if request.post? if params[:environment][:languages] params[:environment][:languages] = params[:environment][:languages].map {|lang, value| lang if value=='true'}.compact diff --git a/app/controllers/admin/environment_design_controller.rb b/app/controllers/admin/environment_design_controller.rb index da2e9b7..de82113 100644 --- a/app/controllers/admin/environment_design_controller.rb +++ b/app/controllers/admin/environment_design_controller.rb @@ -5,7 +5,7 @@ class EnvironmentDesignController < BoxOrganizerController 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, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] + @available_blocks ||= [ ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, 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/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 557bd6b..0a00238 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -144,6 +144,7 @@ class CmsController < MyProfileController @article.profile = profile @article.last_changed_by = user + @article.created_by = user translations if @article.translatable? diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index 8fb5245..97a4953 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -9,14 +9,8 @@ class ProfileDesignController < BoxOrganizerController blocks += plugins.dispatch(:extra_blocks) - # blocks exclusive for organizations - if profile.has_members? - blocks << MembersBlock - end - # blocks exclusive to people if profile.person? - blocks << FriendsBlock blocks << FavoriteEnterprisesBlock blocks << CommunitiesBlock blocks << EnterprisesBlock diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d5dbfac..216f92e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1034,7 +1034,7 @@ module ApplicationHelper end link_to(content_tag(:span, _('Contents'), :class => 'icon-menu-articles'), {:controller => "search", :action => 'contents', :category_path => nil}, :id => 'submenu-contents') + - link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger') + link_to(content_tag(:span, _('Contents menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-contents-trigger') end alias :browse_contents_menu :search_contents_menu @@ -1050,7 +1050,7 @@ module ApplicationHelper end link_to(content_tag(:span, _('People'), :class => 'icon-menu-people'), {:controller => "search", :action => 'people', :category_path => ''}, :id => 'submenu-people') + - link_to(content_tag(:span, _('People menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger') + link_to(content_tag(:span, _('People menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-people-trigger') end alias :browse_people_menu :search_people_menu @@ -1066,7 +1066,7 @@ module ApplicationHelper end link_to(content_tag(:span, _('Communities'), :class => 'icon-menu-community'), {:controller => "search", :action => 'communities'}, :id => 'submenu-communities') + - link_to(content_tag(:span, _('Communities menu')), '#', :onclick => "toggleSubmenu(this,'',#{j links.to_json}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger') + link_to(content_tag(:span, _('Communities menu')), '#', :onclick => "toggleSubmenu(this,'',#{CGI::escapeHTML(links.to_json)}); return false", :class => 'menu-submenu-trigger up', :id => 'submenu-communities-trigger') end alias :browse_communities_menu :search_communities_menu diff --git a/app/helpers/sweeper_helper.rb b/app/helpers/sweeper_helper.rb index 01db9bd..bb4a6a4 100644 --- a/app/helpers/sweeper_helper.rb +++ b/app/helpers/sweeper_helper.rb @@ -18,9 +18,7 @@ module SweeperHelper expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s)) end - # friends blocks - blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} - BlockSweeper.expire_blocks(blocks) + expire_blocks_cache(profile, [:profile]) end def expire_communities(profile) diff --git a/app/models/approve_article.rb b/app/models/approve_article.rb index 7f7fa4a..28f477e 100644 --- a/app/models/approve_article.rb +++ b/app/models/approve_article.rb @@ -48,7 +48,7 @@ class ApproveArticle < Task end def perform - article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.author_id) + article.copy!(:name => name, :abstract => abstract, :body => body, :profile => target, :reference_article => article, :parent => article_parent, :highlighted => highlighted, :source => article.source, :last_changed_by_id => article.last_changed_by_id, :created_by_id => article.created_by_id) end def title diff --git a/app/models/article.rb b/app/models/article.rb index d667bce..de7c1bd 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -40,12 +40,6 @@ class Article < ActiveRecord::Base # xss_terminate plugin can't sanitize array fields before_save :sanitize_tag_list - before_create do |article| - if article.last_changed_by_id - article.author_name = Person.find(article.last_changed_by_id).name - end - end - belongs_to :profile validates_presence_of :profile_id, :name validates_presence_of :slug, :path, :if => lambda { |article| !article.name.blank? } @@ -55,6 +49,7 @@ class Article < ActiveRecord::Base validates_uniqueness_of :slug, :scope => ['profile_id', 'parent_id'], :message => N_('The title (article name) is already being used by another article, please use another title.'), :if => lambda { |article| !article.slug.blank? } belongs_to :last_changed_by, :class_name => 'Person', :foreign_key => 'last_changed_by_id' + belongs_to :created_by, :class_name => 'Person', :foreign_key => 'created_by_id' has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc' @@ -89,6 +84,11 @@ class Article < ActiveRecord::Base article.parent = article.profile.blog end end + + if article.created_by + article.author_name = article.created_by.name + end + end after_destroy :destroy_activity @@ -205,6 +205,10 @@ class Article < ActiveRecord::Base acts_as_versioned self.non_versioned_columns << 'setting' + def version_condition_met? + (['name', 'body', 'abstract', 'filename', 'start_date', 'end_date', 'image_id', 'license_id'] & changed).length > 0 + end + def comment_data comments.map {|item| [item.title, item.body].join(' ') }.join(' ') end @@ -630,17 +634,13 @@ class Article < ActiveRecord::Base def author(version_number = nil) if version_number - version = versions.find_by_version(version_number) + version = self.versions.find_by_version(version_number) author_id = version.last_changed_by_id if version - Person.exists?(author_id) ? Person.find(author_id) : nil else - if versions.empty? - last_changed_by - else - author_id = versions.first.last_changed_by_id - Person.exists?(author_id) ? Person.find(author_id) : nil - end + author_id = self.created_by_id end + + environment.people.find_by_id(author_id) end def author_name(version_number = nil) diff --git a/app/models/box.rb b/app/models/box.rb index fbda1be..df97a41 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -34,14 +34,11 @@ class Box < ActiveRecord::Base FansBlock, FavoriteEnterprisesBlock, FeedReaderBlock, - FriendsBlock, HighlightsBlock, LinkListBlock, LoginBlock, MainBlock, - MembersBlock, MyNetworkBlock, - PeopleBlock, ProfileImageBlock, RawHTMLBlock, RecentDocumentsBlock, @@ -63,14 +60,11 @@ class Box < ActiveRecord::Base FavoriteEnterprisesBlock, FeaturedProductsBlock, FeedReaderBlock, - FriendsBlock, HighlightsBlock, LinkListBlock, LocationBlock, LoginBlock, - MembersBlock, MyNetworkBlock, - PeopleBlock, ProductsBlock, ProductCategoriesBlock, ProfileImageBlock, diff --git a/app/models/categories_block.rb b/app/models/categories_block.rb index bcf71cb..2601e98 100644 --- a/app/models/categories_block.rb +++ b/app/models/categories_block.rb @@ -8,6 +8,8 @@ class CategoriesBlock < Block settings_items :category_types, :type => Array, :default => [] + attr_accessible :category_types + def self.description _("Categories Menu") end diff --git a/app/models/community.rb b/app/models/community.rb index fd5b8d5..e36ddf0 100644 --- a/app/models/community.rb +++ b/app/models/community.rb @@ -1,6 +1,6 @@ class Community < Organization - attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type + attr_accessible :accessor_id, :accessor_type, :role_id, :resource_id, :resource_type, :address_reference, :district, :tag_list, :language after_destroy :check_invite_member_for_destroy def self.type_name @@ -85,10 +85,6 @@ class Community < Organization recent_documents(limit, ["articles.type != ? AND articles.highlighted = ?", 'Folder', highlight]) end - def blocks_to_expire_cache - [MembersBlock] - end - def each_member(offset=0) while member = self.members.first(:order => :id, :offset => offset) yield member diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index f9e0b32..87baedd 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -2,6 +2,8 @@ # only enterprises can offer products and services. class Enterprise < Organization + attr_accessible :business_name, :address_reference, :district, :tag_list, :organization_website, :historic_and_current_context, :activities_short_description, :products_per_catalog_page + SEARCH_DISPLAYS += %w[map full] def self.type_name diff --git a/app/models/environment.rb b/app/models/environment.rb index 579dfa7..840a666 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -3,7 +3,7 @@ # domains. class Environment < ActiveRecord::Base - attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound + attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound, :noreply_email, :signup_welcome_screen_body has_many :users @@ -182,7 +182,6 @@ class Environment < ActiveRecord::Base # "right" area env.boxes[2].blocks << CommunitiesBlock.new(:limit => 6) - env.boxes[2].blocks << PeopleBlock.new(:limit => 6) end # One Environment can be reached by many domains @@ -298,6 +297,12 @@ class Environment < ActiveRecord::Base settings_items :access_control_allow_origin, :type => Array, :default => [] settings_items :access_control_allow_methods, :type => String + settings_items :signup_welcome_screen_body, :type => String + + def has_custom_welcome_screen? + settings[:signup_welcome_screen_body].present? + end + def news_amount_by_folder=(amount) settings[:news_amount_by_folder] = amount.to_i end diff --git a/app/models/friends_block.rb b/app/models/friends_block.rb deleted file mode 100644 index 03604dc..0000000 --- a/app/models/friends_block.rb +++ /dev/null @@ -1,26 +0,0 @@ -class FriendsBlock < ProfileListBlock - - def self.description - _('Friends') - end - - def default_title - n_('{#} friend', '{#} friends', profile_count) - end - - def help - _('This block displays your friends.') - end - - def footer - owner_id = owner.identifier - proc do - link_to s_('friends|View all'), :profile => owner_id, :controller => 'profile', :action => 'friends' - end - end - - def profiles - owner.friends - end - -end diff --git a/app/models/members_block.rb b/app/models/members_block.rb deleted file mode 100644 index b0630e5..0000000 --- a/app/models/members_block.rb +++ /dev/null @@ -1,52 +0,0 @@ -class MembersBlock < ProfileListBlock - settings_items :show_join_leave_button, :type => :boolean, :default => false - - attr_accessible :show_join_leave_button - - def self.description - _('Members') - end - - def default_title - _('{#} members') - end - - def help - _('This block presents the members of a collective.') - end - - def footer - profile = self.owner - s = show_join_leave_button - - proc do - render :file => 'blocks/members', :locals => { :profile => profile, :show_join_leave_button => s} - end - end - - def profiles - owner.members - end - - def extra_option - data = { - :human_name => _("Show join leave button"), - :name => 'block[show_join_leave_button]', - :value => true, - :checked => show_join_leave_button, - :options => {} - } - end - - def cache_key(language='en', user=nil) - logged = '' - if user - logged += '-logged-in' - if user.is_member_of? self.owner - logged += '-member' - end - end - super + logged - end - -end diff --git a/app/models/organization.rb b/app/models/organization.rb index 69c9333..e0a3eb1 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -123,7 +123,7 @@ class Organization < Profile [ [MainBlock.new], [ProfileImageBlock.new, LinkListBlock.new(:links => links)], - [MembersBlock.new, RecentDocumentsBlock.new] + [RecentDocumentsBlock.new] ] end diff --git a/app/models/people_block.rb b/app/models/people_block.rb deleted file mode 100644 index d3f2627..0000000 --- a/app/models/people_block.rb +++ /dev/null @@ -1,25 +0,0 @@ -class PeopleBlock < ProfileListBlock - - def default_title - _('People') - end - - def help - _('Clicking a person takes you to his/her homepage') - end - - def self.description - _('Random people') - end - - def profiles - owner.people - end - - def footer - lambda do |context| - link_to _('View all'), :controller => 'search', :action => 'people' - end - end - -end diff --git a/app/models/person.rb b/app/models/person.rb index 3dc93c5..d0d0521 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,7 +1,7 @@ # A person is the profile of an user holding all relationships with the rest of the system class Person < Profile - attr_accessible :organization, :contact_information, :sex, :birth_date + attr_accessible :organization, :contact_information, :sex, :birth_date, :cell_phone, :comercial_phone, :jabber_id, :personal_website, :nationality, :address_reference, :district, :schooling, :schooling_status, :formation, :custom_formation, :area_of_study, :custom_area_of_study, :professional_activity, :organization_website SEARCH_FILTERS += %w[ more_popular @@ -269,7 +269,7 @@ class Person < Profile [ [MainBlock.new], [ProfileImageBlock.new(:show_name => true), LinkListBlock.new(:links => links), RecentDocumentsBlock.new], - [FriendsBlock.new, CommunitiesBlock.new] + [CommunitiesBlock.new] ] end diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index b6d1a0d..13e1afb 100644 --- a/app/models/profile_list_block.rb +++ b/app/models/profile_list_block.rb @@ -18,9 +18,9 @@ class ProfileListBlock < Block result = nil visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment]) if !prioritize_profiles_with_image - result = visible_profiles.all(:limit => limit, :order => 'updated_at DESC').sort_by{ rand } + result = visible_profiles.all(:limit => limit, :order => 'profiles.updated_at DESC').sort_by{ rand } elsif profiles.visible.with_image.count >= limit - result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand } + result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } else result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'profiles.updated_at DESC').sort_by{ rand } end diff --git a/app/sweepers/friendship_sweeper.rb b/app/sweepers/friendship_sweeper.rb index 400dc4e..f46b405 100644 --- a/app/sweepers/friendship_sweeper.rb +++ b/app/sweepers/friendship_sweeper.rb @@ -34,8 +34,7 @@ protected expire_timeout_fragment(profile.manage_friends_cache_key(:npage => i.to_s)) end - blocks = profile.blocks.select{|b| b.kind_of?(FriendsBlock)} - BlockSweeper.expire_blocks(blocks) + expire_blocks_cache(profile, [:profile]) end end diff --git a/app/views/account/signup.html.erb b/app/views/account/signup.html.erb index f0bc7fe..07ffd31 100644 --- a/app/views/account/signup.html.erb +++ b/app/views/account/signup.html.erb @@ -1,17 +1,21 @@ <% if @register_pending %> -
-

<%= _("Welcome to %s!") % environment.name %>

-

<%= _("Thanks for signing up, we're thrilled to have you on our social network!") %>

-

<%= _("Firstly, some tips for getting started:") %>

-

<%= _("Confirm your account!") %>

-

<%= _("You should receive a welcome email from us shortly. Please take a second to follow the link within to confirm your account.") %>

-

<%= _("You won't appear as %s until your account is confirmed.") % link_to(_('user'), {:controller => :search, :action => :people, :filter => 'more_recent'}, :target => '_blank') %>

-

<%= _("What to do next?") %>

-

<%= _("%s. Upload an avatar and let your friends find you easily :)") % link_to(_('Customize your profile'), {:controller => 'doc', :section => 'user', :topic => 'editing-person-info'}, :target => '_blank') %>

-

<%= _("Learn the guidelines. Read the %s for more details on how to use this social network!") % link_to(_('Documentation'), {:controller => 'doc'}, :target => '_blank') %>

-

<%= _("%s your Gmail, Yahoo and Hotmail contacts!") % link_to(_('Invite and find'), {:controller => 'doc', :section => 'user', :topic => 'invite-contacts'}, :target => '_blank') %>

-

<%= _("Start exploring and have fun!") %>

-
+
+ <% if environment.has_custom_welcome_screen? %> + <%= environment.settings[:signup_welcome_screen_body].html_safe %> + <% else %> +

<%= _("Welcome to %s!") % environment.name %>

+

<%= _("Thanks for signing up, we're thrilled to have you on our social network!") %>

+

<%= _("Firstly, some tips for getting started:") %>

+

<%= _("Confirm your account!") %>

+

<%= _("You should receive a welcome email from us shortly. Please take a second to follow the link within to confirm your account.") %>

+

<%= _("You won't appear as %s until your account is confirmed.") % link_to(_('user'), {:controller => :search, :action => :people, :filter => 'more_recent'}, :target => '_blank') %>

+

<%= _("What to do next?") %>

+

<%= _("%s. Upload an avatar and let your friends find you easily :)") % link_to(_('Customize your profile'), {:controller => 'doc', :section => 'user', :topic => 'editing-person-info'}, :target => '_blank') %>

+

<%= _("Learn the guidelines. Read the %s for more details on how to use this social network!") % link_to(_('Documentation'), {:controller => 'doc'}, :target => '_blank') %>

+

<%= _("%s your Gmail, Yahoo and Hotmail contacts!") % link_to(_('Invite and find'), {:controller => 'doc', :section => 'user', :topic => 'invite-contacts'}, :target => '_blank') %>

+

<%= _("Start exploring and have fun!") %>

+ <% end %> +
<% else %>

<%= _('Sign up for %s!') % environment.name %>

<%= render :partial => 'signup_form' %> diff --git a/app/views/admin_panel/_signup_welcome_screen.html.erb b/app/views/admin_panel/_signup_welcome_screen.html.erb new file mode 100644 index 0000000..26bdb53 --- /dev/null +++ b/app/views/admin_panel/_signup_welcome_screen.html.erb @@ -0,0 +1,5 @@ +
+ <%= _('This text will be showed as a welcome message to users after signup') %>

+
+ +<%= labelled_form_field(_('Body'), text_area(:environment, :signup_welcome_screen_body, :cols => 40, :style => 'width: 100%', :class => 'mceEditor')) %> diff --git a/app/views/admin_panel/site_info.html.erb b/app/views/admin_panel/site_info.html.erb index e2325bb..db84a91 100644 --- a/app/views/admin_panel/site_info.html.erb +++ b/app/views/admin_panel/site_info.html.erb @@ -12,6 +12,8 @@ :content => (render :partial => 'terms_of_use', :locals => {:f => f})} %> <% tabs << {:title => _('Signup welcome text'), :id => 'signup-welcome-text', :content => (render :partial => 'signup_welcome_text', :locals => {:f => f})} %> + <% tabs << {:title => _('Signup welcome message'), :id => 'signup-welcome-message', + :content => (render :partial => 'signup_welcome_screen', :locals => {:f => f}) }%> <%= render_tabs(tabs) %> <% button_bar do %> <%= submit_button(:save, _('Save'), :cancel => {:action => 'index'}) %> diff --git a/app/views/blocks/members.html.erb b/app/views/blocks/members.html.erb deleted file mode 100644 index 4bd47e1..0000000 --- a/app/views/blocks/members.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<%= link_to _('View all'), :profile => profile.identifier, :controller => 'profile', :action => 'members' %> - -<% if show_join_leave_button %> - <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %> -<% end %> diff --git a/app/views/content_viewer/_article_toolbar.html.erb b/app/views/content_viewer/_article_toolbar.html.erb index 3e9ce65..b371e22 100644 --- a/app/views/content_viewer/_article_toolbar.html.erb +++ b/app/views/content_viewer/_article_toolbar.html.erb @@ -10,7 +10,7 @@ <% if @page != profile.home_page && !@page.has_posts? && @page.allow_delete?(user) && !remove_content_button(:delete)%> <% content = content_tag( 'span', _('Delete') ) %> - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page}) %> + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'destroy', :id => @page.id}) %> <% options = {:method => :post, :confirm => delete_article_message(@page)} %> <%= expirable_button @page, :delete, content, url, options %> <% end %> @@ -19,9 +19,9 @@ <% content = content_tag( 'span', _('Spread this') ) %> <% url = nil %> <% if profile.kind_of?(Person) %> - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page }) %> + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish', :id => @page.id }) %> <% elsif profile.kind_of?(Community) && environment.portal_community %> - <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page }) %> + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'publish_on_portal_community', :id => @page.id }) %> <% end %> <%= expirable_button @page, :spread, content, url if url %> <% end %> diff --git a/app/views/layouts/application-ng.html.erb b/app/views/layouts/application-ng.html.erb index 44666c0..2bad06a 100644 --- a/app/views/layouts/application-ng.html.erb +++ b/app/views/layouts/application-ng.html.erb @@ -83,5 +83,10 @@ <%= noosfero_layout_features %> <%= theme_javascript_ng %> <%= addthis_javascript %> + <%= + @plugins.dispatch(:body_ending).map do |content| + if content.respond_to?(:call) then instance_exec(&content).html_safe else content.html_safe end + end.join("\n") + %> diff --git a/app/views/profile_members/_members_list.html.erb b/app/views/profile_members/_members_list.html.erb index a5d874d..84572c6 100644 --- a/app/views/profile_members/_members_list.html.erb +++ b/app/views/profile_members/_members_list.html.erb @@ -17,9 +17,9 @@ <%= button_without_text :edit, _('Edit'), :action => 'change_role', :id => m %> <%= button_to_remote_without_text(:remove, _('Remove'), :update => 'members-list', - :loading => j('$("members-list").addClassName("loading")'), - :success => j("$('tr-#{m.identifier}').show()"), - :complete => j('$("members-list").removeClassName("loading")'), + :loading => "$('members-list').addClassName('loading')", + :success => "$('tr-#{m.identifier}').show()", + :complete => "$('members-list').removeClassName('loading')", :url => { :id => m }.merge(remove_action)) if m != user %> diff --git a/app/views/shared/_change_image.html.erb b/app/views/shared/_change_image.html.erb index 3298b12..bbe353e 100644 --- a/app/views/shared/_change_image.html.erb +++ b/app/views/shared/_change_image.html.erb @@ -1,5 +1,2 @@ <%= i.file_field( :uploaded_data, { :onchange => 'updateImg(this.value)' } ) %> - <%= link_to_function(_('Cancel'), nil, :id => 'cancel-change-image-link', :class => 'button icon-cancel with-text', :style => 'display: none') do |page| - page['change-image-link'].show - page['change-image'].replace_html '' - end %> + <%= link_to_function(_('Cancel'), "jQuery('#change-image-link').show(); jQuery('#change-image').html('')", :id => 'cancel-change-image-link', :class => 'button icon-cancel with-text', :style => 'display: none') %> diff --git a/app/views/shared/_show_thumbnail.html.erb b/app/views/shared/_show_thumbnail.html.erb index a4f05e6..562eb51 100644 --- a/app/views/shared/_show_thumbnail.html.erb +++ b/app/views/shared/_show_thumbnail.html.erb @@ -2,10 +2,15 @@
- <%= link_to_function(_('Change image'), nil, :id => 'change-image-link', :class => 'button icon-photos with-text') do |page| - page['change-image'].replace_html :partial => 'shared/change_image', :locals => { :i => i, :image => image } - page['change-image-link'].hide - page['cancel-change-image-link'].show - end %> + <%= link_to_function(_('Change image'), 'display_change_image()', :id => 'change-image-link', :class => 'button icon-photos with-text') %> + +

diff --git a/app/views/user/mailer/activation_code.html.erb b/app/views/user/mailer/activation_code.html.erb index ac03cc4..efe9df7 100644 --- a/app/views/user/mailer/activation_code.html.erb +++ b/app/views/user/mailer/activation_code.html.erb @@ -1,6 +1,6 @@ <%= _('Hi, %{recipient}!') % { :recipient => @recipient } %> -<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection) }) %> +<%= word_wrap(_('Welcome to %{environment}! To activate your account, follow the link: %{activation_url}') % { :environment => @environment, :activation_url => @url + url_for(:controller => :account, :action => :activate, :activation_code => @activation_code, :redirection => @redirection, :join => @join) }) %> <%= _("Greetings,") %> diff --git a/config/application.rb b/config/application.rb index 0da906e..332a598 100644 --- a/config/application.rb +++ b/config/application.rb @@ -20,7 +20,7 @@ module Noosfero require 'noosfero/plugin' # Adds custom attributes to the Set of allowed html attributes for the #sanitize helper - config.action_view.sanitized_allowed_attributes = 'align', 'border', 'alt', 'vspace', 'hspace', 'width', 'heigth', 'value', 'type', 'data', 'style', 'target', 'codebase', 'archive', 'classid', 'code', 'flashvars', 'scrolling', 'frameborder', 'controls', 'autoplay' + config.action_view.sanitized_allowed_attributes = 'align', 'border', 'alt', 'vspace', 'hspace', 'width', 'heigth', 'value', 'type', 'data', 'style', 'target', 'codebase', 'archive', 'classid', 'code', 'flashvars', 'scrolling', 'frameborder', 'controls', 'autoplay', 'colspan', 'rowspan' # Adds custom tags to the Set of allowed html tags for the #sanitize helper config.action_view.sanitized_allowed_tags = 'object', 'embed', 'param', 'table', 'tr', 'th', 'td', 'applet', 'comment', 'iframe', 'audio', 'video', 'source' diff --git a/config/plugins/people_block b/config/plugins/people_block new file mode 120000 index 0000000..4559c7b --- /dev/null +++ b/config/plugins/people_block @@ -0,0 +1 @@ +../../plugins/people_block \ No newline at end of file diff --git a/db/migrate/20140415125414_add_created_by_to_article.rb b/db/migrate/20140415125414_add_created_by_to_article.rb new file mode 100644 index 0000000..2c57775 --- /dev/null +++ b/db/migrate/20140415125414_add_created_by_to_article.rb @@ -0,0 +1,17 @@ +class AddCreatedByToArticle < ActiveRecord::Migration + def self.up + add_column :articles, :created_by_id, :integer + add_column :article_versions, :created_by_id, :integer + + execute("UPDATE article_versions SET created_by_id = last_changed_by_id") + + execute("UPDATE articles SET created_by_id = article_versions.created_by_id +FROM article_versions WHERE article_versions.article_id = articles.id AND +article_versions.version = 1") + end + + def self.down + remove_column :articles, :created_by_id + remove_column :article_versions, :created_by_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 98d6ffb..1046268 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 => 20140408172149) do +ActiveRecord::Schema.define(:version => 20140415125414) do create_table "abuse_reports", :force => true do |t| t.integer "reporter_id" @@ -95,6 +95,7 @@ ActiveRecord::Schema.define(:version => 20140408172149) do t.integer "license_id" t.integer "image_id" t.integer "position" + t.integer "created_by_id" end add_index "article_versions", ["article_id"], :name => "index_article_versions_on_article_id" @@ -140,6 +141,7 @@ ActiveRecord::Schema.define(:version => 20140408172149) do t.integer "license_id" t.integer "image_id" t.integer "position" + t.integer "created_by_id" end add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count" diff --git a/features/categories_block.feature b/features/categories_block.feature index 9957829..608cabc 100644 --- a/features/categories_block.feature +++ b/features/categories_block.feature @@ -28,7 +28,8 @@ Feature: categories_block @selenium Scenario: List just product categories - Given I follow "Edit" within ".categories-block" + Given display ".button-bar" + And I follow "Edit" within ".categories-block" And I check "Product" When I press "Save" Then I should see "Food" @@ -39,7 +40,8 @@ Feature: categories_block @selenium Scenario: Show submenu if it exists - Given I follow "Edit" within ".categories-block" + Given display ".button-bar" + And I follow "Edit" within ".categories-block" And I check "Product" And I press "Save" Then I should see "Food" @@ -56,7 +58,8 @@ Feature: categories_block @selenium Scenario: Show only one submenu per time - Given I follow "Edit" within ".categories-block" + Given display ".button-bar" + And I follow "Edit" within ".categories-block" And I check "Product" And I press "Save" Then I should see "Book" @@ -66,14 +69,16 @@ Feature: categories_block @selenium Scenario: List just general categories - Given I follow "Edit" within ".categories-block" + Given display ".button-bar" + And I follow "Edit" within ".categories-block" And I check "Generic category" When I press "Save" Then I should see "Wood" @selenium Scenario: List just regions - Given I follow "Edit" within ".categories-block" + Given display ".button-bar" + And I follow "Edit" within ".categories-block" And I check "Region" When I press "Save" Then I should see "Bahia" diff --git a/features/edit_profile.feature b/features/edit_profile.feature index 749d8a0..f21ff1f 100644 --- a/features/edit_profile.feature +++ b/features/edit_profile.feature @@ -12,7 +12,7 @@ Feature: edit profile | birth_date | When I go to joao's control panel And I follow "Edit Profile" - And I select "1980-11-15" from "profile_data_birth_date" + And I fill in "Birth date" with "1980-11-15" And I press "Save" Then I should not see "Birth date is invalid" And I should not see "Birth date is mandatory" @@ -23,7 +23,7 @@ Feature: edit profile | birth_date | When I go to joao's control panel And I follow "Edit Profile" - And I select "1980-11-15" from "profile_data_birth_date" + And I fill in "Birth date" with "1980-11-15" And I press "Save" Then I should not see "Birth date is invalid" And I should not see "Birth date is mandatory" diff --git a/features/my_network_block.feature b/features/my_network_block.feature index e3a0613..0333981 100644 --- a/features/my_network_block.feature +++ b/features/my_network_block.feature @@ -9,9 +9,11 @@ Feature: my_network_block And the following blocks | owner | type | | joaosilva | MyNetworkBlock | + | joaosilva | FriendsBlock | And the following communities | identifier | name | public_profile | | public-community | Public Community | true | + And plugin FriendsBlock is enabled on environment @selenium Scenario: display how many public/private communities I am member @@ -46,6 +48,10 @@ Feature: my_network_block | login | name | public_profile | | mariasilva | Maria Silva | true | | josesilva | Jose Silva | false | + And the following blocks + | owner | type | + | mariasilva | FriendsBlock | + | josesilva | FriendsBlock | And "joaosilva" is friend of "mariasilva" And I am logged in as "joaosilva" And I am on joaosilva's homepage @@ -59,6 +65,10 @@ Feature: my_network_block | login | name | | mariasilva | Maria Silva | | josesilva | Jose Silva | + And the following blocks + | owner | type | + | mariasilva | FriendsBlock | + | josesilva | FriendsBlock | And "josesilva" is invisible And "joaosilva" is friend of "mariasilva" And I am logged in as "joaosilva" diff --git a/features/profile_domain.feature b/features/profile_domain.feature index 1ab0865..ef2afe7 100644 --- a/features/profile_domain.feature +++ b/features/profile_domain.feature @@ -9,11 +9,11 @@ Feature: domain for profile | joaosilva | Joao Silva | And the following communities | identifier | name | domain | - | sample-community | Sample Community | localhost | + | sample-community | Sample Community | 127.0.0.1 | And the following blocks | owner | type | | joaosilva | ProfileInfoBlock | - And the environment domain is "127.0.0.1" + And the environment domain is "localhost" And "Joao Silva" is environment admin And "Joao Silva" is admin of "Sample Community" @@ -29,8 +29,7 @@ Feature: domain for profile @selenium Scenario: access user control panel Given I am logged in as "joaosilva" - When I go to the homepage - And I follow "joaosilva" + When I follow "joaosilva" And I go to sample-community's homepage And I follow "Login" And I fill in "joaosilva" for "Username" @@ -39,18 +38,13 @@ Feature: domain for profile And I follow "Control panel" within "div#user" Then I should see "Joao Silva" within "span.control-panel-title" - # Looking for page title is problematic on selenium since it considers the - # title to be invibible. Checkout some information about this: - # * https://github.com/jnicklas/capybara/issues/863 - # * https://github.com/jnicklas/capybara/pull/953 @selenium Scenario: access user page Given I am logged in as "joaosilva" - When I go to the homepage - And I follow "joaosilva" + When I follow "joaosilva" Then I should be on joaosilva's profile And I should see "Joao Silva" within any "h1" - #And the page title should be "Joao Silva" + And the page title should be "Joao Silva" Scenario: access community by domain Given I go to the search communities page @@ -64,7 +58,7 @@ Feature: domain for profile Given I am on sample-community's homepage When I go to /something-that-does-not-exist And I follow "Go to the home page" - Then the page title should be "Sample Community - Colivre.net" + Then the page title should be "Sample Community" Scenario: Go to environment homepage after clicking on home button on not found page Given I am on the homepage @@ -72,8 +66,3 @@ Feature: domain for profile And I follow "Go to the home page" Then I should be on the homepage And the page title should be "Colivre.net" - - @selenium - Scenario: Compose link to administration with environment domain - Given I am logged in as "joaosilva" - Then I should see "Administration" linking to "http://127.0.0.1.*/admin" diff --git a/features/publish_article.feature b/features/publish_article.feature index 6d5e26b..a23847f 100644 --- a/features/publish_article.feature +++ b/features/publish_article.feature @@ -56,6 +56,7 @@ Feature: publish article And I am on mariasilva's control panel And I follow "Manage Content" And I follow "New content" + And I should see "Text article with Textile markup language" And I follow "Text article with Textile markup language" And I fill in the following: | Title | Sample Article | diff --git a/features/step_definitions/web_steps.rb b/features/step_definitions/web_steps.rb index efdf4ab..d5a8891 100644 --- a/features/step_definitions/web_steps.rb +++ b/features/step_definitions/web_steps.rb @@ -118,9 +118,9 @@ end Then /^(?:|I )should see "([^"]*)" within any "([^"]*)"?$/ do |text, selector| if page.respond_to? :should - page.should have_css(selector, :content => text) + page.should have_css(selector, :text => text) else - assert page.has_css?(selector, :content => text) + assert page.has_css?(selector, :text => text) end end diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index a3608de..20be127 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -277,6 +277,12 @@ class Noosfero::Plugin nil end + # -> Adds content to the ending of the page + # returns = lambda block that creates html code or raw rhtml/html.erb + def body_ending + nil + end + # -> Adds content to the ending of the page head # returns = lambda block that creates html code or raw rhtml/html.erb def head_ending diff --git a/lib/noosfero/plugin.rb.orig b/lib/noosfero/plugin.rb.orig deleted file mode 100644 index ec68602..0000000 --- a/lib/noosfero/plugin.rb.orig +++ /dev/null @@ -1,639 +0,0 @@ -require 'noosfero' - -class Noosfero::Plugin - - attr_accessor :context - - def initialize(context=nil) - self.context = context - end - - class << self - - attr_writer :should_load - - def should_load - @should_load.nil? && true || @boot - end - -<<<<<<< HEAD - def initialize! - return if !should_load - enabled.each do |plugin_dir| - plugin_name = File.basename(plugin_dir) - plugin = load_plugin(plugin_name) - load_plugin_extensions(plugin_dir) - load_plugin_filters(plugin) - end - end - - def setup(config) - return if !should_load - enabled.each do |dir| - setup_plugin(dir, config) -======= - def init_system - available_plugins.each do |dir| - load_plugin dir ->>>>>>> rails235 - end - end - - def setup_plugin(dir, config) - plugin_name = File.basename(dir) - - plugin_dependencies_ok = true - plugin_dependencies_file = File.join(dir, 'dependencies.rb') - if File.exists?(plugin_dependencies_file) - begin - require plugin_dependencies_file - rescue LoadError => ex - plugin_dependencies_ok = false - $stderr.puts "W: Noosfero plugin #{plugin_name} failed to load (#{ex})" - end - end - - if plugin_dependencies_ok - %w[ - controllers - controllers/public - controllers/profile - controllers/myprofile - controllers/admin - ].each do |folder| - config.autoload_paths << File.join(dir, folder) - end - [ config.autoload_paths, $:].each do |path| - path << File.join(dir, 'models') - path << File.join(dir, 'lib') - # load vendor/plugins - Dir.glob(File.join(dir, '/vendor/plugins/*')).each do |vendor_plugin| - path << "#{vendor_plugin}/lib" - init = "#{vendor_plugin}/init.rb" - require init.gsub(/.rb$/, '') if File.file? init - end - end - - # add view path - ActionController::Base.view_paths.unshift(File.join(dir, 'views')) - end - end - - def load_plugin(plugin_name) - (plugin_name.to_s.camelize + 'Plugin').constantize - end - - # This is a generic method that initialize any possible filter defined by a - # plugin to a specific controller - def load_plugin_filters(plugin) - plugin_methods = plugin.instance_methods.select {|m| m.to_s.end_with?('_filters')} - plugin_methods.each do |plugin_method| - controller_class = plugin_method.to_s.gsub('_filters', '').camelize.constantize - filters = plugin.new.send(plugin_method) - filters = [filters] if !filters.kind_of?(Array) - - filters.each do |plugin_filter| - filter_method = (plugin.name.underscore.gsub('/','_') + '_' + plugin_filter[:method_name]).to_sym - controller_class.send(plugin_filter[:type], filter_method, (plugin_filter[:options] || {})) - controller_class.send(:define_method, filter_method) do - instance_eval(&plugin_filter[:block]) if environment.plugin_enabled?(plugin) - end - end - end - end - - def load_plugin_extensions(dir) - Rails.configuration.to_prepare do - Dir[File.join(dir, 'lib', 'ext', '*.rb')].each {|file| require_dependency file } - end - end - - def enabled - @enabled ||= - begin - plugins = Dir.glob(Rails.root.join('config', 'plugins', '*')) - if Rails.env.test? && !plugins.include?(Rails.root.join('config', 'plugins', 'foo')) - plugins << Rails.root.join('plugins', 'foo') - end - plugins.select do |entry| - File.directory?(entry) - end - end - end - -<<<<<<< HEAD - - def all - @all ||= [] -======= - def available_plugins - unless @available_plugins - path = File.join(Rails.root, 'config', 'plugins', '*') - @available_plugins = Dir.glob(path).select{ |i| File.directory?(i) } - if Rails.env.test? && !@available_plugins.include?(File.join(Rails.root, 'config', 'plugins', 'foo')) - @available_plugins << File.join(Rails.root, 'plugins', 'foo') - end - end - @available_plugins ->>>>>>> rails235 - end - - def all - @all ||= available_plugins.map{ |dir| (File.basename(dir) + "_plugin").camelize } - end - - def public_name - self.name.underscore.gsub('_plugin','') - end - - def public_path(file = '') - File.join('/plugins', public_name, file) - end - - def root_path - Rails.root.join('plugins', public_name) - end - - def view_path - File.join(root_path,'views') - end - - # Here the developer should specify the meta-informations that the plugin can - # inform. - def plugin_name - self.name.underscore.humanize - end - def plugin_description - _("No description informed.") - end - - def admin_url - {:controller => "#{name.underscore}_admin", :action => 'index'} - end - - def has_admin_url? - File.exists?(File.join(root_path, 'controllers', "#{name.underscore}_admin_controller.rb")) - end - end - - def expanded_template(file_path, locals = {}) - views_path = Rails.root.join('plugins', "#{self.class.public_name}", 'views') - ERB.new(File.read("#{views_path}/#{file_path}")).result(binding) - end - - def extra_blocks(params = {}) - return [] if self.class.extra_blocks.nil? - blocks = self.class.extra_blocks.map do |block, options| - type = options[:type] - type = type.is_a?(Array) ? type : [type].compact - type = type.map do |x| - x.is_a?(String) ? x.capitalize.constantize : x - end - raise "This is not a valid type" if !type.empty? && ![Person, Community, Enterprise, Environment].detect{|m| type.include?(m)} - - position = options[:position] - position = position.is_a?(Array) ? position : [position].compact - position = position.map{|p| p.to_i} - raise "This is not a valid position" if !position.empty? && ![1,2,3].detect{|m| position.include?(m)} - - if !type.empty? && (params[:type] != :all) - block = type.include?(params[:type]) ? block : nil - end - - if !position.empty? && !params[:position].nil? - block = position.detect{ |p| [params[:position]].flatten.include?(p)} ? block : nil - end - - block - end - blocks.compact! - blocks || [] - end - - def macros - self.class.constants.map do |constant_name| - self.class.const_get(constant_name) - end.select {|const| const.is_a?(Class) && const < Noosfero::Plugin::Macro} - end - - # Here the developer may specify the events to which the plugins can - # register and must return true or false. The default value must be false. - # Must also explicitly define its returning variables. - - # -> If true, noosfero will include plugin_dir/public/style.css into - # application - def stylesheet? - false - end - - # -> Adds buttons to the control panel - # returns = { :title => title, :icon => icon, :url => url } - # title = name that will be displayed. - # icon = css class name (for customized icons include them in a css file). - # url = url or route to which the button will redirect. - def control_panel_buttons - nil - end - - # -> Customize profile block design and behavior - # (overwrites profile_image_link function) - # returns = lambda block that creates html code. - def profile_image_link(profile, size, tag, extra_info) - nil - end - - # -> Adds tabs to the profile - # returns = { :title => title, :id => id, :content => content, :start => start } - # title = name that will be displayed. - # id = div id. - # content = lambda block that creates html code. - # start = boolean that specifies if the tab must come before noosfero tabs (optional). - def profile_tabs - nil - end - - # -> Adds plugin-specific content types to CMS - # returns = [ContentClass1, ContentClass2, ...] - def content_types - nil - end - - # -> Adds content to calalog item - # returns = lambda block that creates html code - def catalog_item_extras(item) - nil - end - - # -> Adds content to profile editor info and settings - # returns = lambda block that creates html code or raw rhtml/html.erb - def profile_editor_extras - nil - end - - # -> Adds content to calalog list item - # returns = lambda block that creates html code - def catalog_list_item_extras(item) - nil - end - - # -> Adds content to products info - # returns = lambda block that creates html code - def product_info_extras(product) - nil - end - - # -> Adds content to products on asset list - # returns = lambda block that creates html code - def asset_product_extras(product) - nil - end - - # -> Adds a property to the product on asset products - # returns = {:name => name, :content => content} - # name = Name of the property - # content = lambda block that creates an html - def asset_product_properties(product) - nil - end - - # -> Adds content to the beginning of the page - # returns = lambda block that creates html code or raw rhtml/html.erb - def body_beginning - nil - end - - # -> Adds content to the ending of the page head - # returns = lambda block that creates html code or raw rhtml/html.erb - def head_ending - nil - end - - # -> Adds plugins' javascript files to application - # returns = ['example1.js', 'javascripts/example2.js', 'example3.js'] - def js_files - [] - end - - # -> Adds stuff in user data hash - # returns = { :some_data => some_value, :another_data => another_value } - def user_data_extras - {} - end - - # -> Parse and possibly make changes of content (article, block, etc) during HTML rendering - # returns = content as string after parser and changes - def parse_content(html, source) - [html, source] - end - - # -> Adds links to the admin panel - # returns = {:title => title, :url => url} - # title = name that will be displayed in the link - # url = url or route to which the link will redirect to. - def admin_panel_links - nil - end - - # -> Adds buttons to manage members page - # returns = { :title => title, :icon => icon, :url => url } - # title = name that will be displayed. - # icon = css class name (for customized icons include them in a css file). - # url = url or route to which the button will redirect. - def manage_members_extra_buttons - nil - end - - # This method will be called just before a comment is saved to the database. - # - # It can modify the comment in several ways. In special, a plugin can call - # reject! on the comment and that will cause the comment to not be saved. - # - # example: - # - # def filter_comment(comment) - # if user_not_logged_in - # comment.reject! - # end - # end - # - def filter_comment(comment) - end - - # Define custom logic to filter loaded comments. - # - # Example: - # - # def unavailable_comments(scope) - # scope.without_spams - # end - # - def unavailable_comments(scope) - scope - end - - # -> Allows plugins to check weather object is a spam - def check_for_spam(object) - end - - # -> Allows plugins to know when an object is marked as a spam - def marked_as_spam(object) - end - - # -> Allows plugins to know when an object is marked as a ham - def marked_as_ham(object) - end - - # Adds extra actions for comments - # returns = list of hashes or lambda block that creates a list of hashes - # example: - # - # def comment_actions(comment) - # [{:link => link_to_function(...)}] - # end - # - def comment_actions(comment) - nil - end - - # This method is called when the user click on comment actions menu. - # returns = list or lambda block that return ids of enabled menu items for comments - # example: - # - # def check_comment_actions(comment) - # ['#action1', '#action2'] - # end - # - def check_comment_actions(comment) - [] - end - - # -> Adds adicional content to article - # returns = lambda block that creates html code - def article_extra_contents(article) - nil - end - - # -> Adds fields to the signup form - # returns = lambda block that creates html code - def signup_extra_contents - nil - end - - # -> Adds adicional content to profile info - # returns = lambda block that creates html code - def profile_info_extra_contents - nil - end - - # -> Removes the invite friend button from the friends controller - # returns = boolean - def remove_invite_friends_button - nil - end - - # -> Extends organization list of members - # returns = An instance of ActiveRecord::NamedScope::Scope retrieved through - # Person.members_of method. - def organization_members(organization) - nil - end - - # -> Extends person memberships list - # returns = An instance of ActiveRecord::NamedScope::Scope retrived through - # Person.memberships_of method. - def person_memberships(person) - nil - end - - # -> Extends person permission access - # returns = boolean - def has_permission?(person, permission, target) - nil - end - - # -> Adds hidden_fields to the new community view - # returns = {key => value} - def new_community_hidden_fields - nil - end - - # -> Adds hidden_fields to the enterprise registration view - # returns = {key => value} - def enterprise_registration_hidden_fields - nil - end - - # -> Add an alternative authentication method. - # Your plugin have to make the access control and return the logged user. - # returns = User - def alternative_authentication - nil - end - - # -> Adds adicional link to make the user authentication - # returns = lambda block that creates html code - def alternative_authentication_link - nil - end - - # -> Allow or not user registration - # returns = boolean - def allow_user_registration - true - end - - # -> Allow or not password recovery by users - # returns = boolean - def allow_password_recovery - true - end - - # -> Adds fields to the login form - # returns = lambda block that creates html code - def login_extra_contents - nil - end - - # -> Adds adicional content to comment form - # returns = lambda block that creates html code - def comment_form_extra_contents(args) - nil - end - - # -> Adds adicional content to article header - # returns = lambda block that creates html code - def article_header_extra_contents(article) - nil - end - - # -> Adds adittional content to comment visualization - # returns = lambda block that creates html code - def comment_extra_contents(args) - nil - end - - # This method is called when the user clicks to send a comment. - # A plugin can add new content to comment form and this method can process the params sent to avoid creating field on core tables. - # returns = params after processed by plugins - # example: - # - # def process_extra_comment_params(params) - # params.delete(:extra_field) - # end - # - def process_extra_comment_params(params) - params - end - - # -> Finds objects by their contents - # returns = {:results => [a, b, c, ...], ...} - # P.S.: The plugin might add other informations on the return hash for its - # own use in specific views - def find_by_contents(asset, scope, query, paginate_options={}, options={}) - end - - # -> Adds aditional fields for change_password - # returns = [{:field => 'field1', :name => 'field 1 name', :model => 'person'}, {...}] - def change_password_fields - nil - end - - # -> Adds additional blocks to profiles and environments. - # Your plugin must implements a class method called 'extra_blocks' - # that returns a hash with the following syntax. - # { - # 'block_name' => - # { - # :type => 'for which holder the block will be available', - # :position => 'where the block could be displayed' - # } - # } - # - # Where: - # - # - block_name: Name of the new block added to the blocks list - # - type: Might have some of the values - # - 'environment' or Environment: If the block is available only for Environment models - # - 'community' or Community: If the block is available only for Community models - # - 'enterprise' or Enterprise: If the block is available only for Enterprise models - # - 'person' or Person: If the block is available only for Person models - # - nil: If no type parameter is passed the block will be available for all types - # - position: Is the layout position of the block. It should be: - # - '1' or 1: Area 1 of layout - # - '2' or 2: Area 2 of layout - # - '3' or 3: Area 3 of layout - # - nil: If no position parameter is passed the block will be available for all positions - # - # OBS: Area 1 is where stay the main content of layout. Areas 2 and 3 are the sides of layout. - # - # examples: - # - # def self.extra_blocks(params) - # { - # #Display 'CustomBlock1' only for 'Person' on position '1' - # CustomBlock1 => {:type => 'person', :position => '1' }, - # - # #Display 'CustomBlock2' only for 'Community' on position '2' - # CustomBlock2 => {:type => Community, :position => '2' }, - # - # #Display 'CustomBlock3' only for 'Enterprise' on position '3' - # CustomBlock3 => {:type => 'enterprise', :position => 3 }, - # - # #Display 'CustomBlock2' for 'Environment' and 'Person' on positions '1' and '3' - # CustomBlock4 => {:type => ['environment', Person], :position => ['1','3'] }, - # - # #Display 'CustomBlock5' for all types and all positions - # CustomBlock5 => {}, - # } - # end - # - # OBS: The default value is a empty hash. - def self.extra_blocks - {} - end - - def method_missing(method, *args, &block) - # This is a generic hotspot for all controllers on Noosfero. - # If any plugin wants to define filters to run on any controller, the name of - # the hotspot must be in the following form: _filters. - # Example: for ProfileController the hotspot is profile_controller_filters - # - # -> Adds a filter to a controller - # returns = { :type => type, - # :method_name => method_name, - # :options => {:opt1 => opt1, :opt2 => opt2}, - # :block => Proc or lambda block} - # type = 'before_filter' or 'after_filter' - # method_name = The name of the filter - # option = Filter options, like :only or :except - # block = Block that the filter will call - if method.to_s =~ /^(.+)_controller_filters$/ - [] - # -> Removes the action button from the content - # returns = boolean - elsif method.to_s =~ /^content_remove_(#{content_actions.join('|')})$/ - nil - # -> Expire the action button from the content - # returns = string with reason of expiration - elsif method.to_s =~ /^content_expire_(#{content_actions.join('|')})$/ - nil - else - super - end - end - - private - - def content_actions - #FIXME 'new' and 'upload' only works for content_remove. It should work for - #content_expire too. - %w[edit delete spread locale suggest home new upload] - end - -end - -require 'noosfero/plugin/hot_spot' -require 'noosfero/plugin/manager' -require 'noosfero/plugin/active_record' -require 'noosfero/plugin/mailer_base' -require 'noosfero/plugin/settings' diff --git a/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb b/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb index 0afd736..c4258f9 100644 --- a/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb +++ b/plugins/comment_group/lib/comment_group_plugin/macros/allow_comment.rb @@ -16,6 +16,9 @@ class CommentGroupPlugin::AllowComment < Noosfero::Plugin::Macro article = source count = article.group_comments.without_spam.in_group(group_id).count - proc {render :partial => 'comment_group_plugin_profile/comment_group', :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier }} + proc { + render :partial => 'comment_group_plugin_profile/comment_group', + :locals => {:group_id => group_id, :article_id => article.id, :inner_html => inner_html, :count => count, :profile_identifier => article.profile.identifier } + } end end diff --git a/plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb b/plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb index 21856ae..3b04529 100644 --- a/plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb +++ b/plugins/comment_group/views/comment_group_plugin_profile/_comment_group.html.erb @@ -3,7 +3,6 @@
<%= link_to_remote(image_tag("/plugins/comment_group/images/comments.gif"), :url => { :profile => profile_identifier, :controller => 'comment_group_plugin_profile', :action => 'view_comments', :group_id => group_id, :article_id => article_id}, - :loaded => j(visual_effect(:highlight, "comments_list_group_#{group_id}")), :method => :post, :condition => "!toggleGroup(#{group_id})", :complete => "loadCompleted(#{group_id})")%> diff --git a/plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb b/plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb new file mode 100644 index 0000000..0ae3ac0 --- /dev/null +++ b/plugins/display_content/db/migrate/20140520100130_update_display_content_sections_array.rb @@ -0,0 +1,31 @@ +# encoding: UTF-8 +class UpdateDisplayContentSectionsArray < ActiveRecord::Migration + + def self.up + translator = {'Publish date' => 'publish_date', 'Title' => 'title', 'Abstract' => 'abstract', 'Body' => 'body', 'Image' => 'image', 'Tags' => 'tags', + 'Data de publicação' => 'publish_date', 'Título' => 'title', 'Resumo' => 'abstract', 'Corpo' => 'body', 'Imagem' => 'image'} + + DisplayContentBlock.find_each do |block| + new_sections = [] + + block.sections.each do |section| + new_value = translator[section["name"]] + new_section = new_value.blank? ? section : {:value => new_value, :checked => !section["checked"].blank? } + + new_section_to_update = new_sections.select {|s| s[:value] == new_value}.first + if new_section_to_update.blank? + new_sections << new_section + else + new_section_to_update[:checked] = new_section[:checked] + end + end + block.sections = new_sections + block.update_attribute(:settings, block.settings) + end + end + + def self.down + raise "this migration can't be reverted" + end + +end diff --git a/plugins/display_content/lib/display_content_block.rb b/plugins/display_content/lib/display_content_block.rb index 323ef88..91fc95b 100644 --- a/plugins/display_content/lib/display_content_block.rb +++ b/plugins/display_content/lib/display_content_block.rb @@ -15,16 +15,16 @@ class DisplayContentBlock < Block N_('December') ] + AVAILABLE_SECTIONS = ['publish_date', 'title', 'abstract', 'body', 'image' ,'tags'] + settings_items :nodes, :type => Array, :default => [] settings_items :sections, :type => Array, - :default => [{:name => _('Publish date'), :checked => true}, - {:name => _('Title'), :checked => true}, - {:name => _('Abstract'), :checked => true}, - {:name => _('Body'), :checked => false}, - {:name => _('Image'), :checked => false}, - {:name => _('Tags'), :checked => false}] + :default => [{:value => 'publish_date', :checked => true}, + {:value => 'title', :checked => true}, + {:value => 'abstract', :checked => true}] settings_items :display_folder_children, :type => :boolean, :default => true + settings_items :types, :type => Array, :default => ['TextileArticle', 'TinyMceArticle', 'RawHTMLArticle'] attr_accessible :sections, :checked_nodes, :display_folder_children @@ -36,6 +36,50 @@ class DisplayContentBlock < Block _('This block displays articles chosen by you. You can edit the block to select which of your articles is going to be displayed in the block.') end + def section_name(section) + { + 'publish_date' => _('Publish date'), + 'title' => _('Title'), + 'abstract' => _('Abstract'), + 'body' => _('Body'), + 'image' => _('Image'), + 'tags' => _('Tags') + }[section] || section + end + + alias :orig_sections :sections + def sections + available_sections = AVAILABLE_SECTIONS + available_sections = available_sections - orig_sections.map{|e|e[:value]} + sections = available_sections.map do |section| + {:value => section, :checked => false} + end + sections + orig_sections + end + + def available_content_types + @available_content_types ||= [TinyMceArticle, RawHTMLArticle, TextileArticle, UploadedFile, Event, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) + checked_types = types.map {|t| t.constantize} + checked_types + (@available_content_types - checked_types) + end + + #FIXME make this test copy of Context Content + def first_content_types + available_content_types.first(first_types_count) + end + + def more_content_types + available_content_types.drop(first_types_count) + end + + def first_types_count + [2, types.length].max + end + + def types=(new_types) + settings[:types] = new_types.reject(&:blank?) + end + def checked_nodes= params self.nodes = params.keys end @@ -45,7 +89,7 @@ class DisplayContentBlock < Block def expand_nodes return self.nodes if self.holder.nil? - articles = self.holder.articles.find(nodes) + articles = self.holder.articles.where(:id => nodes) children = articles.map { |article| article.children }.compact.flatten if display_folder_children @@ -58,7 +102,7 @@ class DisplayContentBlock < Block end def parent_nodes - @parent_nodes ||= self.holder.articles.find(nodes).map { |article| get_parent(article) }.compact.flatten + @parent_nodes ||= self.holder.articles.where(:id => nodes).map { |article| get_parent(article) }.compact.flatten end VALID_CONTENT = ['RawHTMLArticle', 'TextArticle', 'TextileArticle', 'TinyMceArticle', 'Folder', 'Blog', 'Forum'] @@ -73,9 +117,10 @@ class DisplayContentBlock < Block def content(args={}) block = self - extra_condition = display_folder_children ? 'OR articles.parent_id IN(:nodes)':'' - docs = nodes.blank? ? [] : owner.articles.find(:all, :conditions => ["(articles.id IN(:nodes) #{extra_condition}) AND articles.type IN(:types)", {:nodes => self.nodes, :types => VALID_CONTENT}]) + nodes_conditions = nodes.blank? ? '' : " AND articles.id IN(:nodes) " + nodes_conditions += ' OR articles.parent_id IN(:nodes) ' if !nodes.blank? && display_folder_children + docs = owner.articles.find(:all, :conditions => ["articles.type IN(:types) #{nodes.blank? ? '' : nodes_conditions}", {:nodes => self.nodes, :types => self.types}], :include => :profile) proc do block.block_title(block.title) + content_tag('ul', docs.map {|item| @@ -85,24 +130,24 @@ class DisplayContentBlock < Block tags_section = '' block.sections.select { |section| - case section[:name] - when 'Publish date' - content_sections += (block.display_section?(section) ? (content_tag('div', block.show_date(item.published_at, false), :class => 'published-at') ) : '') - when 'Title' + case section[:value] + when 'publish_date' + content_sections += (block.display_section?(section) ? (content_tag('div', show_date(item.published_at, false), :class => 'published-at') ) : '') + when 'title' content_sections += (block.display_section?(section) ? (content_tag('div', link_to(h(item.title), item.url), :class => 'title') ) : '') - when 'Abstract' + when 'abstract' content_sections += (block.display_section?(section) ? (content_tag('div', item.abstract , :class => 'lead')) : '' ) if block.display_section?(section) read_more_section = content_tag('div', link_to(_('Read more'), item.url), :class => 'read_more') end - when 'Body' + when 'body' content_sections += (block.display_section?(section) ? (content_tag('div', item.body ,:class => 'body')) : '' ) - when 'Image' + when 'image' image_section = image_tag item.image.public_filename if item.image if !image_section.blank? content_sections += (block.display_section?(section) ? (content_tag('div', link_to( image_section, item.url ) ,:class => 'image')) : '' ) end - when 'Tags' + when 'tags' if !item.tags.empty? tags_section = item.tags.map { |t| content_tag('span', t.name) }.join("") content_sections += (block.display_section?(section) ? (content_tag('div', tags_section, :class => 'tags')) : '') @@ -111,7 +156,7 @@ class DisplayContentBlock < Block } content_sections += read_more_section if !read_more_section.blank? - +#raise sections.inspect content_tag('li', content_sections) end }.join(" ")) diff --git a/plugins/display_content/test/unit/display_content_block_test.rb b/plugins/display_content/test/unit/display_content_block_test.rb index 7efad58..da37a9b 100644 --- a/plugins/display_content/test/unit/display_content_block_test.rb +++ b/plugins/display_content/test/unit/display_content_block_test.rb @@ -370,7 +370,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase a2 = fast_create(TextArticle, :name => 'test article 2', :profile_id => profile.id, :abstract => 'abstract article 2') block = DisplayContentBlock.new - block.sections = [{:name => 'Abstract', :checked => true}] + block.sections = [{:value => 'abstract', :checked => true}] block.nodes = [a1.id, a2.id] box = mock() block.stubs(:box).returns(box) @@ -425,7 +425,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new block.nodes = [a.id] - block.sections = [{:name => 'Title', :checked => true}] + block.sections = [{:value => 'title', :checked => true}] box = mock() block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) @@ -439,7 +439,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new block.nodes = [a.id] - block.sections = [{:name => 'Abstract', :checked => true}] + block.sections = [{:value => 'abstract', :checked => true}] box = mock() block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) @@ -453,7 +453,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new block.nodes = [a.id] - block.sections = [{:name => 'Body', :checked => true}] + block.sections = [{:value => 'body', :checked => true}] box = mock() block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) @@ -466,7 +466,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new - assert block.display_section?({:name => 'Title', :checked => true}) + assert block.display_section?({:value => 'title', :checked => true}) end should 'display_attribute be true if the attribute was chosen' do @@ -474,8 +474,8 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new - block.sections = [{:name => 'Body', :checked => true}] - section = block.sections.first + section = {:value => 'body', :checked => true} + block.sections = [section] assert block.display_section?(section) end @@ -485,7 +485,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new - assert block.display_section?({:name => 'Publish date', :checked => true}) + assert block.display_section?({:value => 'publish_date', :checked => true}) end should 'show publishd date if defined by user' do @@ -494,7 +494,7 @@ class DisplayContentBlockTest < ActiveSupport::TestCase block = DisplayContentBlock.new block.nodes = [a.id] - block.sections = [{:name => 'Publish date', :checked => true}] + block.sections = [{:value => 'publish_date', :checked => true}] box = mock() block.stubs(:box).returns(box) box.stubs(:owner).returns(profile) @@ -547,17 +547,104 @@ class DisplayContentBlockTest < ActiveSupport::TestCase profile = create_user('testuser').person Article.delete_all a1 = fast_create(PluginArticle, :name => 'test article 1', :profile_id => profile.id) - Noosfero::Plugin.stubs(:all).returns([Plugin1.name]) env = fast_create(Environment) - env.enable_plugin(Plugin1) + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new]) block = DisplayContentBlock.new box = mock() box.stubs(:owner).returns(profile) + Noosfero::Plugin.stubs(:all).returns(['DisplayContentBlockTest::Plugin1']) box.stubs(:environment).returns(env) block.stubs(:box).returns(box) assert_equal [a1], block.articles_of_parent end + should "the section display all available sections" do + block = DisplayContentBlock.new + assert_equivalent ['publish_date', 'abstract', 'body', 'image' ,'tags', 'title'], block.sections.map{|e|e[:value]} + end + + should "the section display all available sections if the section value has only one key" do + block = DisplayContentBlock.new + block.sections = [{:value => 'abstract', :checked => true}] + assert_equivalent ['publish_date', 'abstract', 'body', 'image' ,'tags', 'title'], block.sections.map{|e|e[:value]} + end + + should 'return available content types with checked types first' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + + block.types = ['TinyMceArticle', 'Folder'] + assert_equal [TinyMceArticle, Folder, UploadedFile, Event, TextileArticle, RawHTMLArticle, Blog, Forum, Gallery, RssFeed], block.available_content_types + end + + should 'return available content types' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + block.types = [] + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed], block.available_content_types + end + + should 'return first 2 content types' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + assert_equal 2, block.first_content_types.length + end + + should 'return all but first 2 content types' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + assert_equal block.available_content_types.length - 2, block.more_content_types.length + end + + should 'return 2 as default value for first_types_count' do + block = DisplayContentBlock.create! + block.types = ['TinyMceArticle'] + assert_equal 2, block.first_types_count + end + + should 'return types length if it has more than 2 selected types' do + block = DisplayContentBlock.create! + block.types = ['UploadedFile', 'Event', 'Folder'] + assert_equal 3, block.first_types_count + end + + should 'return selected types at first_content_types' do + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) + block = DisplayContentBlock.create! + block.types = ['UploadedFile', 'Event', 'Folder'] + assert_equal [UploadedFile, Event, Folder], block.first_content_types + assert_equal block.available_content_types - [UploadedFile, Event, Folder], block.more_content_types + end + + should 'include plugin content at available content types' do + block = DisplayContentBlock.create! + class SomePluginContent;end + class SomePlugin; def content_types; SomePluginContent end end + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) + + block.types = [] + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], block.available_content_types + end + + should 'do not fail if a selected article was removed' do + profile = create_user('testuser').person + Article.delete_all + f1 = fast_create(Folder, :name => 'test folder 1', :profile_id => profile.id) + a1 = fast_create(TextileArticle, :name => 'test article 1', :profile_id => profile.id, :parent_id => f1.id) + + checked_articles= {a1.id => true} + + block = DisplayContentBlock.new + block.stubs(:holder).returns(profile) + block.checked_nodes= checked_articles + a1.destroy + assert_equal [], block.parent_nodes + end + end diff --git a/plugins/display_content/views/box_organizer/_choose_by_content_type.html.erb b/plugins/display_content/views/box_organizer/_choose_by_content_type.html.erb new file mode 100644 index 0000000..1e095d0 --- /dev/null +++ b/plugins/display_content/views/box_organizer/_choose_by_content_type.html.erb @@ -0,0 +1,15 @@ +<%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> +
+ <% @block.first_content_types.each do |type| %> + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> + <% end %> + <% if !@block.more_content_types.empty? %> + <%= _('more') %> + <% end %> + +
+ diff --git a/plugins/display_content/views/box_organizer/_choose_directly.html.erb b/plugins/display_content/views/box_organizer/_choose_directly.html.erb new file mode 100644 index 0000000..9b0c8b1 --- /dev/null +++ b/plugins/display_content/views/box_organizer/_choose_directly.html.erb @@ -0,0 +1,30 @@ +
+
+ +
+ <%= labelled_form_field check_box(:block, :display_folder_children) + _('Dinamically load children of selected folders'), '' %> +
+ + diff --git a/plugins/display_content/views/box_organizer/_display_content_block.html.erb b/plugins/display_content/views/box_organizer/_display_content_block.html.erb index e096175..44ffd69 100644 --- a/plugins/display_content/views/box_organizer/_display_content_block.html.erb +++ b/plugins/display_content/views/box_organizer/_display_content_block.html.erb @@ -1,47 +1,29 @@
+<%= javascript_tag 'render_all_jquery_ui_widgets()' %> +

<%= _('Choose which attributes should be displayed and drag to reorder them:') %>

<% for section in @block.sections do %> - - + + <% end %>
<%= hidden_field_tag 'block[sections][][name]', section[:name] %> <%= check_box_tag 'block[sections][][checked]', section[:name], section[:checked] %><%= section[:name]%> + <%= hidden_field_tag 'block[sections][][value]', section[:value] %> + <%= check_box_tag 'block[sections][][checked]', section[:value], section[:checked] %> + <%= @block.section_name(section[:value]) %>

<%= _('Choose which content should be displayed:') %>

-
-
- -
- <%= labelled_form_field check_box(:block, :display_folder_children) + _('Dinamically load children of selected folders'), '' %> -
+<% tabs = [] %> +<% tabs << {:title => _('Choose directly'), :id => 'choose-directly', :content => (render :partial => 'choose_directly')} %> +<% tabs << {:title => _('Choose by Content Type'), :id => 'choose_by_content_type', :content => (render :partial => 'choose_by_content_type')} %> -
+ diff --git a/plugins/people_block/before_disable.rb b/plugins/people_block/before_disable.rb new file mode 100644 index 0000000..77914a7 --- /dev/null +++ b/plugins/people_block/before_disable.rb @@ -0,0 +1,2 @@ +raise "\nPeopleBlockPlugin shouldn't be enabled/disabled by hand, Noosfero" + + "\ninstallation already comes with it enabled by default!\n" diff --git a/plugins/people_block/controllers/people_block_plugin_profile_controller.rb b/plugins/people_block/controllers/people_block_plugin_profile_controller.rb new file mode 100644 index 0000000..dd3ee0e --- /dev/null +++ b/plugins/people_block/controllers/people_block_plugin_profile_controller.rb @@ -0,0 +1,19 @@ +class PeopleBlockPluginProfileController < ProfileController + + append_view_path File.join(File.dirname(__FILE__) + '/../views') + + def members + if is_cache_expired?(profile.members_cache_key(params)) + if(params[:role_key]) + role = Role.find_by_key_and_environment_id(params[:role_key], profile.environment) + @members = profile.members.with_role(role.id).includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage]) + @members_title = role.name + else + @members = profile.members.includes(relations_to_include).paginate(:per_page => members_per_page, :page => params[:npage]) + @members_title = 'members' + end + end + render "profile/members" + end + +end diff --git a/plugins/people_block/db/migrate/20140605222753_enable_people_block_plugin.rb b/plugins/people_block/db/migrate/20140605222753_enable_people_block_plugin.rb new file mode 100644 index 0000000..4aa5ef6 --- /dev/null +++ b/plugins/people_block/db/migrate/20140605222753_enable_people_block_plugin.rb @@ -0,0 +1,16 @@ +class EnablePeopleBlockPlugin < ActiveRecord::Migration + def up + Environment.all.each do |env| + env.enabled_plugins << 'PeopleBlockPlugin' + env.enabled_plugins.uniq! + env.save! + end + end + + def down + Environment.all.each do |env| + env.enabled_plugins.delete_if {|i| i== 'PeopleBlockPlugin'} + env.save! + end + end +end diff --git a/plugins/people_block/lib/ext/person.rb b/plugins/people_block/lib/ext/person.rb new file mode 100644 index 0000000..8c6f94b --- /dev/null +++ b/plugins/people_block/lib/ext/person.rb @@ -0,0 +1,9 @@ +require_dependency 'person' + +class Person + + scope :with_role, lambda { |role_id| + { :select => 'DISTINCT profiles.*', :joins => :role_assignments, :conditions => ["role_assignments.role_id = #{role_id}"] } + } + +end diff --git a/plugins/people_block/lib/friends_block.rb b/plugins/people_block/lib/friends_block.rb new file mode 100644 index 0000000..72e23fd --- /dev/null +++ b/plugins/people_block/lib/friends_block.rb @@ -0,0 +1,30 @@ +class FriendsBlock < PeopleBlockBase + + def self.description + _('Friends') + end + + def help + _('Clicking a friend takes you to his/her homepage') + end + + def default_title + n_('{#} friend', '{#} friends', profile_count) + end + + def profiles + owner.friends + end + + def footer + profile = self.owner + proc do + render :file => 'blocks/friends', :locals => { :profile => profile } + end + end + + def self.expire_on + { :profile => [:profile] } + end + +end diff --git a/plugins/people_block/lib/members_block.rb b/plugins/people_block/lib/members_block.rb new file mode 100644 index 0000000..1e98467 --- /dev/null +++ b/plugins/people_block/lib/members_block.rb @@ -0,0 +1,50 @@ +class MembersBlock < PeopleBlockBase + settings_items :show_join_leave_button, :type => :boolean, :default => false + settings_items :visible_role, :type => :string, :default => nil + attr_accessible :show_join_leave_button, :visible_role + + def self.description + _('Members') + end + + def help + _('Clicking a member takes you to his/her homepage') + end + + def default_title + title = role ? role.name : n_('members') + _('{#} %s') % title + end + + def profiles + role ? owner.members.with_role(role.id) : owner.members + end + + def footer + profile = self.owner + role_key = visible_role + s = show_join_leave_button + proc do + render :file => 'blocks/members', :locals => { :profile => profile, :show_join_leave_button => s, :role_key => role_key} + end + end + + def role + visible_role && !visible_role.empty? ? Role.find_by_key_and_environment_id(visible_role, owner.environment) : nil + end + + def roles + Profile::Roles.organization_member_roles(owner.environment) + end + + def extra_option + data = { + :human_name => _("Show join leave button"), + :name => 'block[show_join_leave_button]', + :value => true, + :checked => show_join_leave_button, + :options => {} + } + end + +end diff --git a/plugins/people_block/lib/people_block.rb b/plugins/people_block/lib/people_block.rb new file mode 100644 index 0000000..6b3fe90 --- /dev/null +++ b/plugins/people_block/lib/people_block.rb @@ -0,0 +1,25 @@ +class PeopleBlock < PeopleBlockBase + + def self.description + _('People') + end + + def help + _('Clicking a person takes you to his/her homepage') + end + + def default_title + _('{#} People') + end + + def profiles + owner.people + end + + def footer + proc do + render :file => 'blocks/people' + end + end + +end diff --git a/plugins/people_block/lib/people_block_base.rb b/plugins/people_block/lib/people_block_base.rb new file mode 100644 index 0000000..114ae8a --- /dev/null +++ b/plugins/people_block/lib/people_block_base.rb @@ -0,0 +1,100 @@ +class PeopleBlockBase < Block + settings_items :prioritize_profiles_with_image, :type => :boolean, :default => true + settings_items :limit, :type => :integer, :default => 6 + settings_items :name, :type => String, :default => "" + settings_items :address, :type => String, :default => "" + attr_accessible :name, :address, :prioritize_profiles_with_image + + def self.description + _('Random people') + end + + def help + _('Clicking on the people or groups will take you to their home page.') + end + + def default_title + _('{#} People') + end + + def view_title + title.gsub('{#}', profile_count.to_s) + end + + def profiles + owner.profiles + end + + def profile_list + result = nil + visible_profiles = profiles.visible.includes([:image,:domains,:preferred_domain,:environment]) + if !prioritize_profiles_with_image + result = visible_profiles.all(:limit => limit, :order => 'updated_at DESC').sort_by{ rand } + elsif visible_profiles.with_image.count >= limit + result = visible_profiles.with_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand } + else + result = visible_profiles.with_image.sort_by{ rand } + visible_profiles.without_image.all(:limit => limit * 5, :order => 'updated_at DESC').sort_by{ rand } + end + result.slice(0..limit-1) + end + + def profile_count + profiles.visible.count + end + + def content(args={}) + profiles = self.profile_list + title = self.view_title + + if !self.name.blank? && !self.address.blank? + name = self.name + expanded_address = expand_address(self.address) + end + + proc do + count = 0 + list = profiles.map {|item| + count += 1 + send(:profile_image_link, item, :minor ) + }.join("\n") + if list.empty? + list = content_tag 'div', _('None'), :class => 'common-profile-list-block-none' + else + if !name.blank? && !expanded_address.blank? + list << content_tag( + 'div', + content_tag( + 'li', + content_tag( + 'div', + link_to( + content_tag('span', name, :class => 'banner-span' ), + expanded_address, + :title => name + ), + :class => 'banner-div' + ), + :class => 'vcard' + ), + :class => 'common-profile-list-block' + ) + end + list = content_tag 'ul', list + end + block_title(title) + content_tag('div', list + tag('br', :style => 'clear:both')) + end + end + + def expand_address(address) + if address !~ /^[a-z]+:\/\// && address !~ /^\// + 'http://' + address + else + address + end + end + + def extra_option + { } + end + +end diff --git a/plugins/people_block/lib/people_block_plugin.rb b/plugins/people_block/lib/people_block_plugin.rb new file mode 100644 index 0000000..21c68f3 --- /dev/null +++ b/plugins/people_block/lib/people_block_plugin.rb @@ -0,0 +1,27 @@ +class PeopleBlockPlugin < Noosfero::Plugin + + def self.plugin_name + "People Block Plugin" + end + + def self.plugin_description + _("A plugin that adds a people block") + end + + def self.extra_blocks + { + PeopleBlock => {:type => Environment}, + MembersBlock => {:type => Community}, + FriendsBlock => {:type => Person} + } + end + + def self.has_admin_url? + false + end + + def stylesheet? + true + end + +end diff --git a/plugins/people_block/public/style.css b/plugins/people_block/public/style.css new file mode 100644 index 0000000..1c00554 --- /dev/null +++ b/plugins/people_block/public/style.css @@ -0,0 +1,104 @@ +/******************************************************************* + * COMMON * + *******************************************************************/ +.people-block .block-footer-content a { + position: absolute; + top: 2px; + right: 0px; + font-size: 11px; + color: #000; + text-decoration: none; + padding-right: 15px; +} + +.people-block .banner-span { + color: #000; + font-size: 14pt; + font-weight: bold; + background-color: #EEE; +} + + +/******************************************************************* + * MAIN BOX - 1 * + *******************************************************************/ +.box-1 .people-block .banner-div { + line-height: 112px; +} + +.box-1 .people-block .banner-span { + width: 204px; +} + + +/******************************************************************* + * LEFT/RIGHT BOXES * + *******************************************************************/ +.box-2 .people-block .banner-div, +.box-3 .people-block .banner-div { + line-height: 78px; +} + +.box-2 .people-block .banner-div a, +.box-3 .people-block .banner-div a { + height: 78px; +} + +.box-2 .people-block .banner-span, +.box-3 .people-block .banner-span { + width: 116px; +} + +.box-2 .people-block ul, +.box-3 .people-block ul { + min-width: 196px; + width: 192px; + margin: 0px 0px 0px -3px; + padding: 0px; +} + +/******************************************************************* + * BLOCKs * + *******************************************************************/ +#content .friends-block ul, +#content .members-block ul { + min-width: 196px; + width: 192px; + margin: 0px 0px 0px -3px; + padding: 0px; +} +#content .box-1 .people-block ul, +#content .box-1 .friends-block ul, +#content .box-1 .members-block ul { + width: auto; + display: block; +} +#content .people-block .block-footer-content a, +#content .friends-block .block-footer-content a, +#content .members-block .block-footer-content a { + position: absolute; + top: 2px; + right: 0px; + font-size: 11px; + color: #000; + text-decoration: none; + padding-right: 15px; +} +#content .members-block .block-footer-content .join-leave-button a { + position: relative; + background-color: #EEE; + border: 1px solid #CCC; + color: #555; + padding-right: inherit; +} +#content .members-block .block-footer-content .join-leave-button a:hover { + color: #FFF; + background-color: #555; + border: 1px solid #2e3436; + text-decoration: none; +} +#content .people-block .block-footer-content a.view-all, +#content .friends-block .block-footer-content a.view-all, +#content .members-block .block-footer-content a.view-all { + background: url(/designs/themes/base/imgs/arrow-right-p.png) 100% 50% no-repeat; +} diff --git a/plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb b/plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb new file mode 100644 index 0000000..66629db --- /dev/null +++ b/plugins/people_block/test/functional/people_block_plugin_environment_design_controller_test.rb @@ -0,0 +1,25 @@ +require File.dirname(__FILE__) + '/../test_helper' + +# Re-raise errors caught by the controller. +class EnvironmentDesignController; def rescue_action(e) raise e end; end + +class EnvironmentDesignControllerTest < ActionController::TestCase + + def setup + @controller = EnvironmentDesignController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) + end + + should 'be able to edit PeopleBlock' do + login_as(create_admin_user(Environment.default)) + b = PeopleBlock.create! + e = Environment.default + e.boxes.create! + e.boxes.first.blocks << b + get :edit, :id => b.id + assert_tag :tag => 'input', :attributes => { :id => 'block_limit' } + end + +end diff --git a/plugins/people_block/test/functional/people_block_plugin_profile_controller_test.rb b/plugins/people_block/test/functional/people_block_plugin_profile_controller_test.rb new file mode 100644 index 0000000..cd5ae8b --- /dev/null +++ b/plugins/people_block/test/functional/people_block_plugin_profile_controller_test.rb @@ -0,0 +1,76 @@ +require File.dirname(__FILE__) + '/../test_helper' +require File.dirname(__FILE__) + '/../../controllers/people_block_plugin_profile_controller' + + +# Re-raise errors caught by the controller. +class PeopleBlockPluginProfileController; def rescue_action(e) raise e end; end + +class PeopleBlockPluginProfileControllerTest < ActionController::TestCase + + def setup + @controller = PeopleBlockPluginProfileController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @profile = fast_create(Community) + + @environment = @profile.environment + @environment.enabled_plugins = ['PeopleBlockPlugin'] + @environment.save! + + MembersBlock.delete_all + @block = MembersBlock.new + @block.box = @profile.boxes.first + @block.save! + + @admin = create_user('adminprofile').person + @member = create_user('memberprofile').person + @moderator = create_user('moderatorprofile').person + @profile.add_moderator(@moderator) + @profile.add_member(@member) + @profile.add_admin(@admin) + end + + attr_accessor :profile, :block, :admin, :member, :moderator + + should 'list members without role_key' do + get :members, :profile => profile.identifier + assert_response :success + assert_template 'members' + assert_equivalent [@admin, @member, @moderator], assigns(:members) + assert_match /adminprofile/, @response.body + assert_match /memberprofile/, @response.body + assert_match /moderatorprofile/, @response.body + end + + should 'list members with role_key=nil' do + get :members, :profile => profile.identifier, :role_key => nil + assert_response :success + assert_template 'members' + assert_equivalent [@admin, @member, @moderator], assigns(:members) + assert_match /adminprofile/, @response.body + assert_match /memberprofile/, @response.body + assert_match /moderatorprofile/, @response.body + end + + should 'list members only' do + get :members, :profile => profile.identifier, :role_key => Profile::Roles.member(profile.environment.id).key + assert_response :success + assert_template 'members' + assert_equal [@member], assigns(:members) + assert_no_match /adminprofile/, @response.body + assert_match /memberprofile/, @response.body + assert_no_match /moderatorprofile/, @response.body + end + + should 'list moderators only' do + get :members, :profile => profile.identifier, :role_key => Profile::Roles.moderator(profile.environment.id).key + assert_response :success + assert_template 'members' + assert_equal [@moderator], assigns(:members) + assert_no_match /adminprofile/, @response.body + assert_no_match /memberprofile/, @response.body + assert_match /moderatorprofile/, @response.body + end + +end diff --git a/plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb b/plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb new file mode 100644 index 0000000..b92d580 --- /dev/null +++ b/plugins/people_block/test/functional/people_block_plugin_profile_design_controller_test.rb @@ -0,0 +1,70 @@ +require File.dirname(__FILE__) + '/../test_helper' + +# Re-raise errors caught by the controller. +class ProfileDesignController; def rescue_action(e) raise e end; end + +class ProfileDesignControllerTest < ActionController::TestCase + + def setup + @controller = ProfileDesignController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([PeopleBlockPlugin.new]) + end + + should 'display *block people-block* class at design blocks page' do + user = create_user('testinguser') + login_as(user.login) + + @profile = user.person + @environment = @profile.environment + @environment.save! + + FriendsBlock.delete_all + @box1 = Box.create!(:owner => @profile) + @profile.boxes = [@box1] + + @block = FriendsBlock.new + @block.box = @box1 + @block.save! + + @profile.blocks<<@block + @profile.save! + + get :index, :profile => @profile.identifier + assert_tag :div, :attributes => {:class => 'block friends-block'} + end + + should 'the people block is available for person profile' do + profile = mock + profile.stubs(:has_members?).returns(false) + profile.stubs(:person?).returns(true) + profile.stubs(:community?).returns(false) + profile.stubs(:enterprise?).returns(false) + profile.stubs(:has_blog?).returns(false) + profile.stubs(:is_admin?).with(anything).returns(false) + environment = mock + profile.stubs(:environment).returns(environment) + environment.stubs(:enabled?).returns(false) + @controller.stubs(:profile).returns(profile) + @controller.stubs(:user).returns(profile) + assert_includes @controller.available_blocks, FriendsBlock + end + + should 'the people block is available for community profile' do + profile = mock + profile.stubs(:has_members?).returns(true) + profile.stubs(:person?).returns(false) + profile.stubs(:community?).returns(true) + profile.stubs(:enterprise?).returns(false) + profile.stubs(:has_blog?).returns(false) + profile.stubs(:is_admin?).with(anything).returns(false) + environment = mock + profile.stubs(:environment).returns(environment) + environment.stubs(:enabled?).returns(false) + @controller.stubs(:profile).returns(profile) + @controller.stubs(:user).returns(profile) + assert_includes @controller.available_blocks, MembersBlock + end + +end diff --git a/plugins/people_block/test/test_helper.rb b/plugins/people_block/test/test_helper.rb new file mode 100644 index 0000000..cca1fd3 --- /dev/null +++ b/plugins/people_block/test/test_helper.rb @@ -0,0 +1 @@ +require File.dirname(__FILE__) + '/../../../test/test_helper' diff --git a/plugins/people_block/test/unit/friends_block_test.rb b/plugins/people_block/test/unit/friends_block_test.rb new file mode 100644 index 0000000..0e19ae7 --- /dev/null +++ b/plugins/people_block/test/unit/friends_block_test.rb @@ -0,0 +1,156 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class FriendsBlockTest < ActiveSupport::TestCase + + should 'inherit from Block' do + assert_kind_of Block, FriendsBlock.new + end + + + should 'declare its default title' do + assert_not_equal Block.new.default_title, FriendsBlock.new.default_title + end + + + should 'describe itself' do + assert_not_equal Block.description, FriendsBlock.description + end + + + should 'is editable' do + block = FriendsBlock.new + assert block.editable? + end + + + should 'have field limit' do + block = FriendsBlock.new + assert_respond_to block, :limit + end + + + should 'default value of limit' do + block = FriendsBlock.new + assert_equal 6, block.limit + end + + + should 'have field name' do + block = FriendsBlock.new + assert_respond_to block, :name + end + + + should 'default value of name' do + block = FriendsBlock.new + assert_equal "", block.name + end + + + should 'have field address' do + block = FriendsBlock.new + assert_respond_to block, :address + end + + + should 'default value of address' do + block = FriendsBlock.new + assert_equal "", block.address + end + + + should 'prioritize profiles with image by default' do + assert FriendsBlock.new.prioritize_people_with_image + end + + + should 'accept a limit of people to be displayed' do + block = FriendsBlock.new + block.limit = 20 + assert_equal 20, block.limit + end + + + should 'list friends from person' do + owner = fast_create(Person) + friend1 = fast_create(Person) + friend2 = fast_create(Person) + owner.add_friend(friend1) + owner.add_friend(friend2) + + block = FriendsBlock.new + + block.expects(:owner).returns(owner).at_least_once + expects(:profile_image_link).with(friend1, :minor).returns(friend1.name) + expects(:profile_image_link).with(friend2, :minor).returns(friend2.name) + expects(:block_title).with(anything).returns('') + + content = instance_eval(&block.content) + + assert_match(/#{friend1.name}/, content) + assert_match(/#{friend2.name}/, content) + end + + + should 'link to "all friends"' do + person1 = create_user('mytestperson').person + + block = FriendsBlock.new + block.expects(:owner).returns(person1).at_least_once + + expects(:_).with('View all').returns('View all') + expects(:link_to).with('View all', :profile => 'mytestperson', :controller => 'profile', :action => 'friends').returns('link-to-friends') + + assert_equal 'link-to-friends', instance_eval(&block.footer) + end + + + should 'count number of owner friends' do + owner = fast_create(Person) + friend1 = fast_create(Person) + friend2 = fast_create(Person) + friend3 = fast_create(Person) + owner.add_friend(friend1) + owner.add_friend(friend2) + owner.add_friend(friend3) + + block = FriendsBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 3, block.profile_count + end + + + should 'count number of public and private friends' do + owner = fast_create(Person) + private_p = fast_create(Person, {:public_profile => false}) + public_p = fast_create(Person, {:public_profile => true}) + + owner.add_friend(private_p) + owner.add_friend(public_p) + + block = FriendsBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 2, block.profile_count + end + + + should 'not count number of invisible friends' do + owner = fast_create(Person) + private_p = fast_create(Person, {:visible => false}) + public_p = fast_create(Person, {:visible => true}) + + owner.add_friend(private_p) + owner.add_friend(public_p) + + block = FriendsBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 1, block.profile_count + end + + protected + include NoosferoTestHelper + +end diff --git a/plugins/people_block/test/unit/members_block_test.rb b/plugins/people_block/test/unit/members_block_test.rb new file mode 100644 index 0000000..f3c6355 --- /dev/null +++ b/plugins/people_block/test/unit/members_block_test.rb @@ -0,0 +1,252 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class MembersBlockTest < ActiveSupport::TestCase + + should 'inherit from Block' do + assert_kind_of Block, MembersBlock.new + end + + + should 'declare its default title' do + assert_not_equal Block.new.default_title, MembersBlock.new.default_title + end + + + should 'describe itself' do + assert_not_equal Block.description, MembersBlock.description + end + + + should 'is editable' do + block = MembersBlock.new + assert block.editable? + end + + + should 'have field limit' do + block = MembersBlock.new + assert_respond_to block, :limit + end + + + should 'default value of limit' do + block = MembersBlock.new + assert_equal 6, block.limit + end + + + should 'have field name' do + block = MembersBlock.new + assert_respond_to block, :name + end + + + should 'default value of name' do + block = MembersBlock.new + assert_equal "", block.name + end + + + should 'have field address' do + block = MembersBlock.new + assert_respond_to block, :address + end + + + should 'default value of address' do + block = MembersBlock.new + assert_equal "", block.address + end + + + should 'prioritize profiles with image by default' do + assert MembersBlock.new.prioritize_people_with_image + end + + + should 'respect limit when listing members' do + community = fast_create(Community) + p1 = fast_create(Person) + p2 = fast_create(Person) + p3 = fast_create(Person) + p4 = fast_create(Person) + + community.add_member(p1) + community.add_member(p2) + community.add_member(p3) + community.add_member(p4) + + block = MembersBlock.new(:limit => 3) + block.stubs(:owner).returns(community) + + assert_equal 3, block.profile_list.size + end + + + should 'accept a limit of members to be displayed' do + block = MembersBlock.new + block.limit = 20 + assert_equal 20, block.limit + end + + + should 'list members from community' do + owner = fast_create(Community) + person1 = fast_create(Person) + person2 = fast_create(Person) + owner.add_member(person1) + owner.add_member(person2) + + block = MembersBlock.new + + block.expects(:owner).returns(owner).at_least_once + expects(:profile_image_link).with(person1, :minor).returns(person1.name) + expects(:profile_image_link).with(person2, :minor).returns(person2.name) + expects(:block_title).with(anything).returns('') + + content = instance_eval(&block.content) + + assert_match(/#{person1.name}/, content) + assert_match(/#{person2.name}/, content) + end + + should 'count number of public and private members' do + owner = fast_create(Community) + private_p = fast_create(Person, {:public_profile => false}) + public_p = fast_create(Person, {:public_profile => true}) + + owner.add_member(private_p) + owner.add_member(public_p) + + block = MembersBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 2, block.profile_count + end + + + should 'not count number of invisible members' do + owner = fast_create(Community) + private_p = fast_create(Person, {:visible => false}) + public_p = fast_create(Person, {:visible => true}) + + owner.add_member(private_p) + owner.add_member(public_p) + + block = MembersBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 1, block.profile_count + end + + should 'provide link to members page without a visible_role selected' do + profile = create_user('mytestuser').person + block = MembersBlock.new + block.box = profile.boxes.first + block.save! + + expects(:_).with('View all').returns('View all') + expects(:link_to).with('View all' , :profile => 'mytestuser', :controller => 'people_block_plugin_profile', :action => 'members', :role_key => block.visible_role).returns('link-to-members') + + assert_equal 'link-to-members', instance_eval(&block.footer) + end + + should 'provide link to members page with a selected role' do + profile = create_user('mytestuser').person + block = MembersBlock.new + block.box = profile.boxes.first + block.visible_role = 'profile_member' + block.save! + + expects(:_).with('View all').returns('View all') + expects(:link_to).with('View all' , :profile => 'mytestuser', :controller => 'people_block_plugin_profile', :action => 'members', :role_key => block.visible_role).returns('link-to-members') + + assert_equal 'link-to-members', instance_eval(&block.footer) + end + + should 'provide a role to be displayed (and default to nil)' do + env = fast_create(Environment) + env.boxes << Box.new + block = MembersBlock.new + assert_equal nil, block.visible_role + env.boxes.first.blocks << block + block.visible_role = 'profile_member' + block.save! + assert_equal 'profile_member', block.visible_role + end + + should 'list all members' do + env = fast_create(Environment) + env.boxes << Box.new + profile1 = fast_create(Person, :environment_id => env.id) + profile2 = fast_create(Person, :environment_id => env.id) + + block = MembersBlock.new + owner = fast_create(Community) + block.stubs(:owner).returns(owner) + env.boxes.first.blocks << block + block.save! + + owner.add_member profile1 + owner.add_member profile2 + profiles = block.profiles + + assert_includes profiles, profile1 + assert_includes profiles, profile2 + end + + should 'list only profiles with moderator role' do + env = fast_create(Environment) + env.boxes << Box.new + profile1 = fast_create(Person, :environment_id => env.id) + profile2 = fast_create(Person, :environment_id => env.id) + + block = MembersBlock.new + owner = fast_create(Community) + block.visible_role = Profile::Roles.moderator(owner.environment.id).key + block.stubs(:owner).returns(owner) + env.boxes.first.blocks << block + block.save! + + owner.add_member profile2 + owner.add_moderator profile1 + profiles = block.profiles + + assert_includes profiles, profile1 + assert_not_includes profiles, profile2 + end + + should 'list only profiles with member role' do + env = fast_create(Environment) + env.boxes << Box.new + profile1 = fast_create(Person, :environment_id => env.id) + profile2 = fast_create(Person, :environment_id => env.id) + + block = MembersBlock.new + owner = fast_create(Community) + block.visible_role = Profile::Roles.member(owner.environment.id).key + block.stubs(:owner).returns(owner) + env.boxes.first.blocks << block + block.save! + + owner.add_member profile2 + owner.add_moderator profile1 + profiles = block.profiles + + assert_not_includes profiles, profile1 + assert_includes profiles, profile2 + end + + should 'list available roles' do + block = MembersBlock.new + owner = fast_create(Community) + block.stubs(:owner).returns(owner) + assert_includes block.roles, Profile::Roles.member(owner.environment.id) + assert_includes block.roles, Profile::Roles.admin(owner.environment.id) + assert_includes block.roles, Profile::Roles.moderator(owner.environment.id) + end + + protected + include NoosferoTestHelper + +end diff --git a/plugins/people_block/test/unit/people_block_plugin_test.rb b/plugins/people_block/test/unit/people_block_plugin_test.rb new file mode 100644 index 0000000..1c84109 --- /dev/null +++ b/plugins/people_block/test/unit/people_block_plugin_test.rb @@ -0,0 +1,25 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class PeopleBlockPluginTest < ActiveSupport::TestCase + + should "return PeopleBlock in extra_blocks class method" do + assert PeopleBlockPlugin.extra_blocks.keys.include?(PeopleBlock) + end + + should "return MembersBlock in extra_blocks class method" do + assert PeopleBlockPlugin.extra_blocks.keys.include?(MembersBlock) + end + + should "return FriendsBlock in extra_blocks class method" do + assert PeopleBlockPlugin.extra_blocks.keys.include?(FriendsBlock) + end + + should "return false for class method has_admin_url?" do + assert !PeopleBlockPlugin.has_admin_url? + end + + should "return false for class method stylesheet?" do + assert PeopleBlockPlugin.new.stylesheet? + end + +end diff --git a/plugins/people_block/test/unit/people_block_test.rb b/plugins/people_block/test/unit/people_block_test.rb new file mode 100644 index 0000000..201a521 --- /dev/null +++ b/plugins/people_block/test/unit/people_block_test.rb @@ -0,0 +1,146 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class PeopleBlockTest < ActiveSupport::TestCase + + should 'inherit from Block' do + assert_kind_of Block, PeopleBlock.new + end + + + should 'declare its default title' do + assert_not_equal Block.new.default_title, PeopleBlock.new.default_title + end + + + should 'describe itself' do + assert_not_equal Block.description, PeopleBlock.description + end + + + should 'is editable' do + block = PeopleBlock.new + assert block.editable? + end + + + should 'have field limit' do + block = PeopleBlock.new + assert_respond_to block, :limit + end + + + should 'default value of limit' do + block = PeopleBlock.new + assert_equal 6, block.limit + end + + + should 'have field name' do + block = PeopleBlock.new + assert_respond_to block, :name + end + + + should 'default value of name' do + block = PeopleBlock.new + assert_equal "", block.name + end + + + should 'have field address' do + block = PeopleBlock.new + assert_respond_to block, :address + end + + + should 'default value of address' do + block = PeopleBlock.new + assert_equal "", block.address + end + + + should 'prioritize profiles with image by default' do + assert PeopleBlock.new.prioritize_profiles_with_image + end + + + should 'respect limit when listing people' do + env = fast_create(Environment) + p1 = fast_create(Person, :environment_id => env.id) + p2 = fast_create(Person, :environment_id => env.id) + p3 = fast_create(Person, :environment_id => env.id) + p4 = fast_create(Person, :environment_id => env.id) + + block = PeopleBlock.new(:limit => 3) + block.stubs(:owner).returns(env) + + assert_equal 3, block.profile_list.size + end + + + should 'accept a limit of people to be displayed' do + block = PeopleBlock.new + block.limit = 20 + assert_equal 20, block.limit + end + + + should 'list people from environment' do + owner = fast_create(Environment) + person1 = fast_create(Person, :environment_id => owner.id) + person2 = fast_create(Person, :environment_id => owner.id) + + block = PeopleBlock.new + + block.expects(:owner).returns(owner).at_least_once + expects(:profile_image_link).with(person1, :minor).returns(person1.name) + expects(:profile_image_link).with(person2, :minor).returns(person2.name) + expects(:block_title).with(anything).returns('') + + content = instance_exec(&block.content) + + assert_match(/#{person1.name}/, content) + assert_match(/#{person2.name}/, content) + end + + + should 'link to "all people"' do + env = fast_create(Environment) + + block = PeopleBlock.new + + stubs(:_).with('View all').returns('View all') + stubs(:link_to).returns('link-to-people') + stubs(:url_for).returns(' ') + + assert_equal 'link-to-people', instance_exec(&block.footer) + end + + + should 'count number of public and private people' do + owner = fast_create(Environment) + private_p = fast_create(Person, :public_profile => false, :environment_id => owner.id) + public_p = fast_create(Person, :public_profile => true, :environment_id => owner.id) + + block = PeopleBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 2, block.profile_count + end + + + should 'not count number of invisible people' do + owner = fast_create(Environment) + private_p = fast_create(Person, :visible => false, :environment_id => owner.id) + public_p = fast_create(Person, :visible => true, :environment_id => owner.id) + + block = PeopleBlock.new + block.expects(:owner).returns(owner).at_least_once + + assert_equal 1, block.profile_count + end + + protected + include NoosferoTestHelper + +end diff --git a/plugins/people_block/views/blocks/friends.html.erb b/plugins/people_block/views/blocks/friends.html.erb new file mode 100644 index 0000000..04410ae --- /dev/null +++ b/plugins/people_block/views/blocks/friends.html.erb @@ -0,0 +1 @@ +<%= link_to s_('friends|View all'), {:profile => profile.identifier, :controller => 'profile', :action => 'friends'}, :class => 'view-all' %> diff --git a/plugins/people_block/views/blocks/members.html.erb b/plugins/people_block/views/blocks/members.html.erb new file mode 100644 index 0000000..f1c1202 --- /dev/null +++ b/plugins/people_block/views/blocks/members.html.erb @@ -0,0 +1,5 @@ +<%= link_to _('View all'), {:profile => profile.identifier, :controller => 'people_block_plugin_profile', :action => 'members', :role_key => role_key}, :class => 'view-all' %> + +<% if show_join_leave_button %> + <%= render :partial => 'blocks/profile_info_actions/join_leave_community' %> +<% end %> diff --git a/plugins/people_block/views/blocks/people.html.erb b/plugins/people_block/views/blocks/people.html.erb new file mode 100644 index 0000000..843a87f --- /dev/null +++ b/plugins/people_block/views/blocks/people.html.erb @@ -0,0 +1 @@ +<%= link_to _('View all'), {:controller => 'search', :action => 'people'}, :class => 'view-all' %> diff --git a/plugins/people_block/views/box_organizer/_people_block_base.html.erb b/plugins/people_block/views/box_organizer/_people_block_base.html.erb new file mode 100644 index 0000000..0ec382e --- /dev/null +++ b/plugins/people_block/views/box_organizer/_people_block_base.html.erb @@ -0,0 +1,10 @@ +<%= labelled_form_field _('Name:'), text_field(:block, :name) %> + +<%= labelled_form_field _('Address:'), text_field(:block, :address) %> + +<% if @block.kind_of?(MembersBlock) %> + <%= labelled_form_field _('Filter by role:'), '' %> + <%= select_tag 'block[visible_role]', options_for_select(@block.roles.map{|r| [r.name, r.key]}.insert(0,''), @block.visible_role) %> +<% end %> + +<%= render :partial => 'profile_list_block' %> diff --git a/plugins/people_block/views/environment_design b/plugins/people_block/views/environment_design new file mode 120000 index 0000000..a75d184 --- /dev/null +++ b/plugins/people_block/views/environment_design @@ -0,0 +1 @@ +box_organizer \ No newline at end of file diff --git a/plugins/people_block/views/profile_design b/plugins/people_block/views/profile_design new file mode 120000 index 0000000..a75d184 --- /dev/null +++ b/plugins/people_block/views/profile_design @@ -0,0 +1 @@ +box_organizer \ No newline at end of file diff --git a/plugins/piwik/controllers/piwik_plugin_admin_controller.rb b/plugins/piwik/controllers/piwik_plugin_admin_controller.rb new file mode 100644 index 0000000..b7d5d38 --- /dev/null +++ b/plugins/piwik/controllers/piwik_plugin_admin_controller.rb @@ -0,0 +1,16 @@ +class PiwikPluginAdminController < AdminController + + append_view_path File.join(File.dirname(__FILE__) + '/../views') + + def index + if request.post? + if @environment.update_attributes(params[:environment]) + session[:notice] = _('Piwik plugin settings updated successfully.') + else + session[:notice] = _('Piwik plugin settings could not be saved.') + end + redirect_to :controller => 'plugins', :action => 'index' + end + end + +end diff --git a/plugins/piwik/lib/ext/environment.rb b/plugins/piwik/lib/ext/environment.rb new file mode 100644 index 0000000..33157e1 --- /dev/null +++ b/plugins/piwik/lib/ext/environment.rb @@ -0,0 +1,7 @@ +require_dependency 'environment' + +class Environment + settings_items :piwik_domain + settings_items :piwik_site_id + attr_accessible :piwik_domain, :piwik_site_id +end diff --git a/plugins/piwik/lib/piwik_plugin.rb b/plugins/piwik/lib/piwik_plugin.rb new file mode 100644 index 0000000..a7c3500 --- /dev/null +++ b/plugins/piwik/lib/piwik_plugin.rb @@ -0,0 +1,24 @@ +class PiwikPlugin < Noosfero::Plugin + + include ActionView::Helpers::JavaScriptHelper + include ActionView::Helpers::FormHelper + include ActionView::Helpers::UrlHelper + include ActionView::Helpers::TagHelper + + def self.plugin_name + "Piwik" + end + + def self.plugin_description + _("Tracking and web analytics to your Noosfero's environment") + end + + def body_ending + domain = context.environment.piwik_domain + site_id = context.environment.piwik_site_id + unless domain.blank? || site_id.blank? + expanded_template('tracking-code.rhtml',{:domain => domain, :site_id => site_id}) + end + end + +end diff --git a/plugins/piwik/test/functional/piwik_plugin_test.rb b/plugins/piwik/test/functional/piwik_plugin_test.rb new file mode 100644 index 0000000..0267f95 --- /dev/null +++ b/plugins/piwik/test/functional/piwik_plugin_test.rb @@ -0,0 +1,31 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../controllers/piwik_plugin_admin_controller' + +# Re-raise errors caught by the controller. +class PiwikPluginAdminController; def rescue_action(e) raise e end; end + +class PiwikPluginAdminControllerTest < ActionController::TestCase + + def setup + @environment = Environment.default + user_login = create_admin_user(@environment) + login_as(user_login) + @environment.enabled_plugins = ['PiwikPlugin'] + @environment.save! + end + + should 'access index action' do + get :index + assert_template 'index' + assert_response :success + end + + should 'update piwik plugin settings' do + assert_nil @environment.reload.piwik_domain + assert_nil @environment.reload.piwik_site_id + post :index, :environment => { :piwik_domain => 'http://something', :piwik_site_id => 10 } + assert_not_nil @environment.reload.piwik_domain + assert_not_nil @environment.reload.piwik_site_id + end + +end diff --git a/plugins/piwik/test/unit/piwik_plugin_test.rb b/plugins/piwik/test/unit/piwik_plugin_test.rb new file mode 100644 index 0000000..f3eca89 --- /dev/null +++ b/plugins/piwik/test/unit/piwik_plugin_test.rb @@ -0,0 +1,42 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' + +class PiwikPluginTest < ActiveSupport::TestCase + + def setup + @plugin = PiwikPlugin.new + @context = mock() + @plugin.context = @context + @environment = Environment.new + @context.stubs(:environment).returns(@environment) + end + + should 'add content at the body ending unless domain and site_id are blank' do + @environment.piwik_domain = 'piwik.domain.example.com' + @environment.piwik_site_id = 5 + @plugin.stubs(:expanded_template).returns('content') + assert_equal 'content', @plugin.body_ending + end + + should 'not add any content at the body ending if domain is blank' do + @environment.piwik_domain = nil + @environment.piwik_site_id = 5 + @plugin.stubs(:expanded_template).returns('content') + assert_equal nil, @plugin.body_ending + end + + should 'not add any content at the body ending if site_id is blank' do + @environment.piwik_domain = 'piwik.domain.example.com' + @environment.piwik_site_id = nil + @plugin.stubs(:expanded_template).returns('content') + assert_equal nil, @plugin.body_ending + end + + should 'extends Environment with attr piwik_domain' do + assert_respond_to Environment.new, :piwik_domain + end + + should 'extends Environment with attr piwik_site_id' do + assert_respond_to Environment.new, :piwik_site_id + end + +end diff --git a/plugins/piwik/views/piwik_plugin_admin/index.html.erb b/plugins/piwik/views/piwik_plugin_admin/index.html.erb new file mode 100644 index 0000000..edd31f2 --- /dev/null +++ b/plugins/piwik/views/piwik_plugin_admin/index.html.erb @@ -0,0 +1,13 @@ +

<%= _("Piwik plugin settings") %>

+ +<%= form_for(:environment) do |f| %> + + <%= labelled_form_field _('Piwik domain'), f.text_field(:piwik_domain) %> + + <%= labelled_form_field _('Piwik site id'), f.text_field(:piwik_site_id) %> + + <% button_bar do %> + <%= submit_button(:save, _('Save'), :cancel => {:controller => 'plugins', :action => 'index'}) %> + <% end %> + +<% end %> diff --git a/plugins/piwik/views/tracking-code.rhtml b/plugins/piwik/views/tracking-code.rhtml new file mode 100644 index 0000000..0ff2fcb --- /dev/null +++ b/plugins/piwik/views/tracking-code.rhtml @@ -0,0 +1,15 @@ + + + + diff --git a/plugins/require_auth_to_comment/lib/ext/profile.rb b/plugins/require_auth_to_comment/lib/ext/profile.rb index 9847e7b..c9871e3 100644 --- a/plugins/require_auth_to_comment/lib/ext/profile.rb +++ b/plugins/require_auth_to_comment/lib/ext/profile.rb @@ -2,4 +2,5 @@ require_dependency 'profile' class Profile settings_items :allow_unauthenticated_comments, :type => :boolean + attr_accessible :allow_unauthenticated_comments end diff --git a/plugins/video/lib/video_block.rb b/plugins/video/lib/video_block.rb index fb7615d..cbe729a 100644 --- a/plugins/video/lib/video_block.rb +++ b/plugins/video/lib/video_block.rb @@ -1,11 +1,15 @@ class VideoBlock < Block + attr_accessible :url, :width, :height + settings_items :url, :type => :string, :default => "" settings_items :width, :type => :integer, :default => 400 settings_items :height, :type => :integer, :default => 315 + YOUTUBE_ID_FORMAT = '\w-' + def is_youtube? - url.match(/.*(youtube.com.*v=[[:alnum:]]+|youtu.be\/[[:alnum:]]+).*/) ? true : false + url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false end def is_vimeo? @@ -44,8 +48,8 @@ class VideoBlock < Block def extract_youtube_id return nil unless is_youtube? - youtube_match = url.match('v=([[:alnum:]]*)') - youtube_match ||= url.match('youtu.be\/([[:alnum:]]*)') + youtube_match = url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") + youtube_match ||= url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") youtube_match[1] unless youtube_match.nil? end diff --git a/plugins/video/test/unit/video_block_test.rb b/plugins/video/test/unit/video_block_test.rb index a7e3587..0ebdae4 100644 --- a/plugins/video/test/unit/video_block_test.rb +++ b/plugins/video/test/unit/video_block_test.rb @@ -70,6 +70,13 @@ class VideoBlockTest < ActiveSupport::TestCase assert_equal id, block.send('extract_youtube_id') end + should "extract youtube id from youtube video url's if it has underline and hyphen" do + block = VideoBlock.new + id = 'oi43_re-d2' + block.url = "youtube.com/?v=#{id}" + assert_equal id, block.send('extract_youtube_id') + end + should "extract youtube id from youtube video url's if it's a valid youtube short url" do block = VideoBlock.new id = 'oi43jre2d2' diff --git a/public/designs/themes/base/style.css b/public/designs/themes/base/style.css index 6f868a9..38019d3 100644 --- a/public/designs/themes/base/style.css +++ b/public/designs/themes/base/style.css @@ -478,12 +478,9 @@ div#notice { /************************** Profile List *****************************/ -#content .people-block ul, #content .profile-list-block ul, #content .enterprises-block ul, -#content .members-block ul, #content .communities-block ul, -#content .friends-block ul, #content .fans-block ul { min-width: 196px; width: 192px; @@ -491,24 +488,18 @@ div#notice { padding: 0px; } -#content .box-1 .people-block ul, #content .box-1 .profile-list-block ul, #content .box-1 .enterprises-block ul, -#content .box-1 .members-block ul, #content .box-1 .communities-block ul, -#content .box-1 .friends-block ul, #content .box-1 .fans-block ul { width: auto; display: block; } #content .tags-block .block-footer-content a, -#content .people-block .block-footer-content a, #content .profile-list-block .block-footer-content a, #content .enterprises-block .block-footer-content a, -#content .members-block .block-footer-content a, -#content .communities-block .block-footer-content a, -#content .friends-block .block-footer-content a { +#content .communities-block .block-footer-content a { position: absolute; top: 2px; right: 0px; @@ -518,29 +509,12 @@ div#notice { padding-right: 15px; } #content .tags-block .block-footer-content a, -#content .people-block .block-footer-content a, #content .profile-list-block .block-footer-content a, #content .enterprises-block .block-footer-content a, -#content .communities-block .block-footer-content a, -#content .friends-block .block-footer-content a { +#content .communities-block .block-footer-content a { background: url(imgs/arrow-right-p.png) 100% 50% no-repeat; } -#content .members-block .block-footer-content .join-leave-button a { - position: relative; - background-color: #EEE; - border: 1px solid #CCC; - color: #555; - padding-right: inherit; -} - -#content .members-block .block-footer-content .join-leave-button a:hover { - color: #FFF; - background-color: #555; - border: 1px solid #2e3436; - text-decoration: none; -} - #content .profile-list-block .block-title { text-align: left; } diff --git a/public/plugins/people_block b/public/plugins/people_block new file mode 120000 index 0000000..ecbcf78 --- /dev/null +++ b/public/plugins/people_block @@ -0,0 +1 @@ +../../plugins/people_block/public \ No newline at end of file diff --git a/script/noosfero-plugins b/script/noosfero-plugins index 053292f..f1662b8 100755 --- a/script/noosfero-plugins +++ b/script/noosfero-plugins @@ -76,7 +76,8 @@ run(){ _enable(){ plugin="$1" - source="$available_plugins_dir/$plugin" + cd $enabled_plugins_dir + source="../../plugins/$plugin" target="$enabled_plugins_dir/$plugin" run "$source/before_enable.rb" if [ -h "$target" ]; then @@ -98,11 +99,13 @@ _enable(){ fi fi if [ "$installation_ok" = true ] && [ "$dependencies_ok" = true ]; then - ln -s "$source" "$target" + ln -s "$source" "$plugin" plugins_public_dir="$NOOSFERO_DIR/public/plugins" plugins_features_dir="$NOOSFERO_DIR/features/plugins" - test -d "$target/public/" && ln -s "$target/public" "$plugins_public_dir/$plugin" - test -d "$NOOSFERO_DIR/features" && test -d "$target/features" && ln -s "$target/features" "$plugins_features_dir/$plugin" + cd $plugins_public_dir + test -d "$source/public" && ln -s "$source/public" "$plugin" + cd $plugins_features_dir + test -d "$NOOSFERO_DIR/features" && test -d "$source/features" && ln -s "$source/features" "$plugin" _say "$plugin enabled" run "$source/after_enable.rb" needs_migrate=true @@ -122,15 +125,19 @@ _disable(){ target="$enabled_plugins_dir/$plugin" plugins_public_dir="$NOOSFERO_DIR/public/plugins" plugins_features_dir="$NOOSFERO_DIR/features/plugins" - run "$source/before_disable.rb" - if [ -h "$target" ]; then - rm "$target" - test -h "$plugins_public_dir/$plugin" && rm "$plugins_public_dir/$plugin" - test -h "$plugins_features_dir/$plugin" && rm "$plugins_features_dir/$plugin" - _say "$plugin disabled" - run "$source/after_disable.rb" + if ! run "$source/before_disable.rb"; then + echo "W: failed to disabling $plugin" + echo else - _say "$plugin already disabled" + if [ -h "$target" ]; then + rm "$target" + test -h "$plugins_public_dir/$plugin" && rm "$plugins_public_dir/$plugin" + test -h "$plugins_features_dir/$plugin" && rm "$plugins_features_dir/$plugin" + _say "$plugin disabled" + run "$source/after_disable.rb" + else + _say "$plugin already disabled" + fi fi } diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 65645e3..b2879b9 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -21,14 +21,6 @@ class AccountControllerTest < ActionController::TestCase disable_signup_bot_check end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - def test_should_login_and_redirect post :login, :user => {:login => 'johndoe', :password => 'test'} assert session[:user] diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb index da36c0f..55db96c 100644 --- a/test/functional/admin_panel_controller_test.rb +++ b/test/functional/admin_panel_controller_test.rb @@ -14,14 +14,6 @@ class AdminPanelControllerTest < ActionController::TestCase login_as(create_admin_user(Environment.default)) end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'manage the correct environment' do current = fast_create(Environment, :name => 'test environment', :is_default => false) current.domains.create!(:name => 'example.com') @@ -73,6 +65,7 @@ class AdminPanelControllerTest < ActionController::TestCase assert_tag :tag => 'textarea', :attributes => { :name => 'environment[terms_of_use]'} assert_tag :tag => 'input', :attributes => { :name => 'environment[signup_welcome_text_subject]'} assert_tag :tag => 'textarea', :attributes => { :name => 'environment[signup_welcome_text_body]'} + assert_tag :tag => 'textarea', :attributes => { :name => 'environment[signup_welcome_screen_body]'} end should 'display form for editing message for disabled enterprise' do @@ -381,4 +374,13 @@ class AdminPanelControllerTest < ActionController::TestCase assert_not_includes environment.languages, 'en' end + should 'save body of signup welcome screen' do + body = "This is my welcome body" + post :site_info, :environment => { :signup_welcome_screen_body => body } + assert_redirected_to :action => 'index' + + assert_equal body, Environment.default.signup_welcome_screen_body + assert !Environment.default.signup_welcome_screen_body.blank? + end + end diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index 1affcd3..72d7b38 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -60,14 +60,6 @@ class ApplicationControllerTest < ActionController::TestCase end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - def test_exist_environment_variable_to_helper_environment_identification get :index assert_not_nil assigns(:environment) diff --git a/test/functional/catalog_controller_test.rb b/test/functional/catalog_controller_test.rb index 6419c90..9ba4849 100644 --- a/test/functional/catalog_controller_test.rb +++ b/test/functional/catalog_controller_test.rb @@ -16,14 +16,6 @@ class CatalogControllerTest < ActionController::TestCase end attr_accessor :enterprise - def test_local_files_reference - assert_local_files_reference :get, :index, :profile => @enterprise.identifier - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'not display for non-enterprises' do u = create_user('testinguser').person get :index, :profile => 'testinguser' diff --git a/test/functional/categories_controller_test.rb b/test/functional/categories_controller_test.rb index ce4737c..8917ec6 100644 --- a/test/functional/categories_controller_test.rb +++ b/test/functional/categories_controller_test.rb @@ -20,14 +20,6 @@ class CategoriesControllerTest < ActionController::TestCase attr_reader :env, :cat1, :cat2 - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - def test_index login_as(create_admin_user(Environment.default)) get :index diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 4332a15..f31b09a 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -18,14 +18,6 @@ class CmsControllerTest < ActionController::TestCase attr_reader :profile - def test_local_files_reference - assert_local_files_reference :get, :index, :profile => profile.identifier - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'list top level documents on index' do get :index, :profile => profile.identifier @@ -1228,7 +1220,7 @@ class CmsControllerTest < ActionController::TestCase should 'allow user edit article if he is owner and has publish permission' do c = Community.create!(:name => 'test_comm', :identifier => 'test_comm') u = create_user_with_permission('test_user', 'publish_content', c) - a = create(Article, :profile => c, :name => 'test_article', :last_changed_by => u) + a = create(Article, :profile => c, :name => 'test_article', :created_by => u) login_as :test_user @controller.stubs(:user).returns(u) @@ -1774,6 +1766,31 @@ class CmsControllerTest < ActionController::TestCase assert_equal 'first version', Article.find(article.id).name end + should 'set created_by when creating article' do + login_as(profile.identifier) + + post :new, :type => 'TinyMceArticle', :profile => profile.identifier, :article => { :name => 'changed by me', :body => 'content ...' } + + a = profile.articles.find_by_path('changed-by-me') + assert_not_nil a + assert_equal profile, a.created_by + end + + should 'not change created_by when updating article' do + other_person = create_user('otherperson').person + + a = profile.articles.build(:name => 'my article') + a.created_by = other_person + a.save! + + login_as(profile.identifier) + post :edit, :profile => profile.identifier, :id => a.id, :article => { :body => 'new content for this article' } + + a.reload + + assert_equal other_person, a.created_by + end + protected # FIXME this is to avoid adding an extra dependency for a proper JSON parser. diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 6aa88e5..bc78b31 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -18,16 +18,6 @@ class ContentViewerControllerTest < ActionController::TestCase end attr_reader :profile, :environment - def test_local_files_reference - page = profile.articles.build(:name => 'test') - page.save! - assert_local_files_reference :get, :view_page, :profile => profile.identifier, :page => [ 'test' ] - end - - def test_valid_xhtml - assert_valid_xhtml - end - def test_should_display_page page = profile.articles.build(:name => 'test') page.save! @@ -743,7 +733,7 @@ class ContentViewerControllerTest < ActionController::TestCase c = Community.create!(:name => 'test_com') u = create_user_with_permission('test_user', 'publish_content', c) login_as u.identifier - a = create(Article, :profile => c, :name => 'test-article', :last_changed_by => u, :published => false) + a = create(Article, :profile => c, :name => 'test-article', :created_by => u, :published => false) get :view_page, :profile => c.identifier, :page => a.path diff --git a/test/functional/edit_template_controller_test.rb b/test/functional/edit_template_controller_test.rb index 056603b..3f5572b 100644 --- a/test/functional/edit_template_controller_test.rb +++ b/test/functional/edit_template_controller_test.rb @@ -15,14 +15,6 @@ class EditTemplateControllerTest < ActionController::TestCase login_as 'ze' end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - def test_redirect_to_design_editor_when_index_action_is_called give_permission('ze', 'edit_environment_design', Environment.default) get :index diff --git a/test/functional/enterprise_registration_controller_test.rb b/test/functional/enterprise_registration_controller_test.rb index 1a9213e..cc2f9a9 100644 --- a/test/functional/enterprise_registration_controller_test.rb +++ b/test/functional/enterprise_registration_controller_test.rb @@ -17,14 +17,6 @@ class EnterpriseRegistrationControllerTest < ActionController::TestCase login_as 'ze' end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'go to the first step on index' do get :index assert_response :success diff --git a/test/functional/enterprise_validation_controller_test.rb b/test/functional/enterprise_validation_controller_test.rb index 13d2305..a2f4002 100644 --- a/test/functional/enterprise_validation_controller_test.rb +++ b/test/functional/enterprise_validation_controller_test.rb @@ -19,18 +19,6 @@ class EnterpriseValidationControllerTest < ActionController::TestCase Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once end - def test_local_files_reference - assert_local_files_reference :get, :index, :profile => 'myorg' - end - - def test_valid_xhtml - - # FIXME remove this after enable assert_valid_xhtml - Profile.find_by_identifier('myorg') - - assert_valid_xhtml :get, :index, :profile => 'myorg' - end - should 'list pending validations on index' do empty = [] @org.expects(:pending_validations).returns(empty) diff --git a/test/functional/environment_design_controller_test.rb b/test/functional/environment_design_controller_test.rb index 8d774c1..674c476 100644 --- a/test/functional/environment_design_controller_test.rb +++ b/test/functional/environment_design_controller_test.rb @@ -8,7 +8,7 @@ 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, PeopleBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] + ALL_BLOCKS = [ArticleBlock, LoginBlock, EnvironmentStatisticsBlock, RecentDocumentsBlock, EnterprisesBlock, CommunitiesBlock, SellersSearchBlock, LinkListBlock, FeedReaderBlock, SlideshowBlock, HighlightsBlock, FeaturedProductsBlock, CategoriesBlock, RawHTMLBlock, TagsBlock ] def setup @controller = EnvironmentDesignController.new @@ -17,14 +17,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'indicate only actual blocks as such' do assert(@controller.available_blocks.all? {|item| item.new.is_a? Block}) end @@ -107,16 +99,6 @@ class EnvironmentDesignControllerTest < ActionController::TestCase assert_tag :tag => 'input', :attributes => { :id => 'block_limit' } end - should 'be able to edit PeopleBlock' do - login_as(create_admin_user(Environment.default)) - b = PeopleBlock.create! - e = Environment.default - e.boxes.create! - e.boxes.first.blocks << b - get :edit, :id => b.id - assert_tag :tag => 'input', :attributes => { :id => 'block_limit' } - end - should 'be able to edit SlideshowBlock' do login_as(create_admin_user(Environment.default)) b = SlideshowBlock.create! diff --git a/test/functional/environment_role_manager_controller_test.rb b/test/functional/environment_role_manager_controller_test.rb index 9f22720..822933c 100644 --- a/test/functional/environment_role_manager_controller_test.rb +++ b/test/functional/environment_role_manager_controller_test.rb @@ -11,16 +11,4 @@ class EnvironmentRoleManagerControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - - # Replace this with your real tests. - def test_truth - assert true - end end diff --git a/test/functional/favorite_enterprises_controller_test.rb b/test/functional/favorite_enterprises_controller_test.rb index 0d51347..78412af 100644 --- a/test/functional/favorite_enterprises_controller_test.rb +++ b/test/functional/favorite_enterprises_controller_test.rb @@ -18,14 +18,6 @@ class FavoriteEnterprisesControllerTest < ActionController::TestCase end attr_accessor :profile, :favorite_enterprise - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'list favorite enterprises' do get :index assert_response :success diff --git a/test/functional/features_controller_test.rb b/test/functional/features_controller_test.rb index 6c56915..e291fba 100644 --- a/test/functional/features_controller_test.rb +++ b/test/functional/features_controller_test.rb @@ -14,14 +14,6 @@ class FeaturesControllerTest < ActionController::TestCase login_as(create_admin_user(Environment.find(2))) end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - def test_listing_features uses_host 'anhetegua.net' get :index diff --git a/test/functional/friends_controller_test.rb b/test/functional/friends_controller_test.rb index 153dde0..c692e85 100644 --- a/test/functional/friends_controller_test.rb +++ b/test/functional/friends_controller_test.rb @@ -18,14 +18,6 @@ class FriendsControllerTest < ActionController::TestCase end attr_accessor :profile, :friend - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'list friends' do get :index assert_response :success diff --git a/test/functional/home_controller_test.rb b/test/functional/home_controller_test.rb index c4578a6..855c61e 100644 --- a/test/functional/home_controller_test.rb +++ b/test/functional/home_controller_test.rb @@ -17,14 +17,6 @@ class HomeControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'not display news from portal if disabled in environment' do env = Environment.default env.disable('use_portal_community') diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index 7f0a877..1803b98 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -18,14 +18,6 @@ class ManageProductsControllerTest < ActionController::TestCase login_as :test_user end - def test_local_files_reference - assert_local_files_reference :get, :index, :profile => @enterprise.identifier - end - - def test_valid_xhtml - assert_valid_xhtml - end - should "not have permission" do u = create_user('user_test') login_as :user_test diff --git a/test/functional/memberships_controller_test.rb b/test/functional/memberships_controller_test.rb index 5f69ac5..dbaa697 100644 --- a/test/functional/memberships_controller_test.rb +++ b/test/functional/memberships_controller_test.rb @@ -19,14 +19,6 @@ class MembershipsControllerTest < ActionController::TestCase end attr_reader :profile - def test_local_files_reference - assert_local_files_reference :get, :index, :profile => profile.identifier - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'list current memberships' do get :index, :profile => profile.identifier diff --git a/test/functional/my_profile_controller_test.rb b/test/functional/my_profile_controller_test.rb index 18561a9..91776f0 100644 --- a/test/functional/my_profile_controller_test.rb +++ b/test/functional/my_profile_controller_test.rb @@ -20,16 +20,6 @@ class MyProfileControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new end - def test_local_files_reference - @controller = OnlyForPersonTestController.new - user = create_user('test_user').person - assert_local_files_reference :get, :index, :profile => user.identifier - end - - def test_valid_xhtml - assert_valid_xhtml - end - def test_should_allow_person @controller = OnlyForPersonTestController.new person = create_user('random_joe') diff --git a/test/functional/plugins_controller_test.rb b/test/functional/plugins_controller_test.rb index 9478f4e..37a1f9e 100644 --- a/test/functional/plugins_controller_test.rb +++ b/test/functional/plugins_controller_test.rb @@ -16,14 +16,6 @@ class PluginsControllerTest < ActionController::TestCase end attr_reader :environment - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'list system active plugins' do class Plugin1 < Noosfero::Plugin class << self diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index f18d909..ca54a6c 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -11,14 +11,6 @@ class ProfileControllerTest < ActionController::TestCase end attr_reader :profile - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - noosfero_test :profile => 'testuser' should 'list friends' do diff --git a/test/functional/profile_design_controller_test.rb b/test/functional/profile_design_controller_test.rb index 28dd850..010aaa9 100644 --- a/test/functional/profile_design_controller_test.rb +++ b/test/functional/profile_design_controller_test.rb @@ -6,8 +6,7 @@ class ProfileDesignController; def rescue_action(e) raise e end; end class ProfileDesignControllerTest < ActionController::TestCase COMMOM_BLOCKS = [ ArticleBlock, TagsBlock, RecentDocumentsBlock, ProfileInfoBlock, LinkListBlock, MyNetworkBlock, FeedReaderBlock, ProfileImageBlock, LocationBlock, SlideshowBlock, ProfileSearchBlock, HighlightsBlock ] - PERSON_BLOCKS = COMMOM_BLOCKS + [FriendsBlock, FavoriteEnterprisesBlock, CommunitiesBlock, EnterprisesBlock ] - PERSON_BLOCKS_WITH_MEMBERS = PERSON_BLOCKS + [MembersBlock] + PERSON_BLOCKS = COMMOM_BLOCKS + [ FavoriteEnterprisesBlock, CommunitiesBlock, EnterprisesBlock ] PERSON_BLOCKS_WITH_BLOG = PERSON_BLOCKS + [BlogArchivesBlock] ENTERPRISE_BLOCKS = COMMOM_BLOCKS + [DisabledEnterpriseMessageBlock, FeaturedProductsBlock, FansBlock, ProductCategoriesBlock] @@ -76,14 +75,6 @@ class ProfileDesignControllerTest < ActionController::TestCase end attr_reader :profile - def test_local_files_reference - assert_local_files_reference :get, :index, :profile => 'designtestuser' - end - - def test_valid_xhtml - assert_valid_xhtml - end - ###################################################### # BEGIN - tests for BoxOrganizerController features ###################################################### @@ -525,23 +516,6 @@ class ProfileDesignControllerTest < ActionController::TestCase assert_equal PERSON_BLOCKS, @controller.available_blocks end - should 'the person with members blocks are all available' do - profile = mock - profile.stubs(:has_members?).returns(true) - profile.stubs(:person?).returns(true) - profile.stubs(:community?).returns(true) - profile.stubs(:enterprise?).returns(false) - profile.stubs(:has_blog?).returns(false) - profile.stubs(:is_admin?).with(anything).returns(false) - environment = mock - profile.stubs(:environment).returns(environment) - environment.stubs(:enabled?).returns(false) - @controller.stubs(:profile).returns(profile) - @controller.stubs(:user).returns(profile) - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([]) - assert_equal [], @controller.available_blocks - PERSON_BLOCKS_WITH_MEMBERS - end - should 'the person with blog blocks are all available' do profile = mock profile.stubs(:has_members?).returns(false) diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index a6b0f28..854dcea 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -6,7 +6,7 @@ class ProfileEditorController; def rescue_action(e) raise e end; end class ProfileEditorControllerTest < ActionController::TestCase all_fixtures - + def setup @controller = ProfileEditorController.new @request = ActionController::TestRequest.new @@ -17,14 +17,6 @@ class ProfileEditorControllerTest < ActionController::TestCase end attr_reader :profile - def test_local_files_reference - assert_local_files_reference :get, :index, :profile => profile.identifier - end - - def test_valid_xhtml - assert_valid_xhtml - end - def test_index get :index, :profile => profile.identifier assert_template 'index' @@ -50,7 +42,7 @@ class ProfileEditorControllerTest < ActionController::TestCase end should 'saving profile info' do - person = profile + person = profile post :edit, :profile => profile.identifier, :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address', 'sex' => 'female' } assert_redirected_to :controller => 'profile_editor', :action => 'index' person = Person.find(person.id) @@ -60,6 +52,15 @@ class ProfileEditorControllerTest < ActionController::TestCase assert_equal 'female', person.sex end + should 'mass assign all environment configurable person fields' do + person = profile + + post :edit, :profile => profile.identifier, :profile_data => { "nickname" => "ze", "description" => "Just a regular ze.", "contact_information" => "What?", "contact_phone" => "+0551133445566", "cell_phone" => "+0551188889999", "comercial_phone" => "+0551144336655", "jabber_id" => "ze1234", "personal_website" => "http://ze.com.br", "sex" => "male", "birth_date" => "2014-06-04", "nationality" => "Brazilian", "country" => "BR", "state" => "DF", "city" => "Brasilia", "zip_code" => "70300-010", "address" => "Palacio do Planalto", "address_reference" => "Praca dos tres poderes", "district" => "DF", "schooling" => "Undergraduate", "schooling_status" => "Concluded", "formation" => "Engineerings", "area_of_study" => "Metallurgy", "professional_activity" => "Metallurgic", "organization" => "Metal Corp.", "organization_website" => "http://metal.com" } + + assert_response :redirect + assert_redirected_to :controller => 'profile_editor', :action => 'index' + end + should 'not permmit if not logged' do logout get :index, :profile => profile.identifier @@ -164,6 +165,15 @@ class ProfileEditorControllerTest < ActionController::TestCase assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } end + should 'mass assign all environment configurable community fields' do + cmm = fast_create(Community) + + post :edit, :profile => cmm.identifier, :profile_data => { "name" => "new name", "display_name" => "N&w N@me", "description"=>"We sell food and other stuff.", "contact_person"=>"Joseph of the Jungle", "contact_email"=>"sac@company.net", "contact_phone"=>"+0551133445566", "legal_form"=>"New Name corp.", "economic_activity"=>"Food", "management_information"=>"No need for that here.", "address"=>"123, baufas street", "address_reference"=>"Next to baufas house", "district"=>"DC", "zip_code"=>"123456", "city"=>"Whashington", "state"=>"DC", "country"=>"US", "tag_list"=>"food, corporations", "language"=>"English" } + + assert_response :redirect + assert_redirected_to :controller => 'profile_editor', :action => 'index' + end + should 'show field values on edit enterprise info' do Enterprise.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once org = fast_create(Enterprise) @@ -173,6 +183,15 @@ class ProfileEditorControllerTest < ActionController::TestCase assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } end + should 'mass assign all environment configurable enterprise fields' do + enterprise = fast_create(Enterprise) + + post :edit, :profile => enterprise.identifier, :profile_data => { "name"=>"Enterprise", "display_name"=>"Enterprise name", "business_name"=>"Enterprise", "description"=>"Hello IT.", "contact_person"=>"Joseph", "contact_email"=>"joe@enterprise.net", "contact_phone"=>"+0551133445566", "legal_form"=>"Enterprise corp.", "economic_activity"=>"Food", "management_information"=>"None.", "address"=>"123, baufas street", "address_reference"=>"Next to baufas house", "district"=>"DC", "zip_code"=>"123456", "city"=>"Washington", "state"=>"DC", "country"=>"US", "tag_list"=>"food, corporations", "organization_website"=>"http://enterprise.net", "historic_and_current_context"=>"Historic.", "activities_short_description"=>"Activies.", "acronym"=>"E", "foundation_year"=>"1995",} + + assert_response :redirect + assert_redirected_to :controller => 'profile_editor', :action => 'index' + end + should 'display profile publication option in edit profile screen' do get :edit, :profile => profile.identifier assert_tag :tag => 'input', :attributes => { :type => 'radio', :checked => 'checked', :name => 'profile_data[public_profile]', :value => 'true' } @@ -426,7 +445,7 @@ class ProfileEditorControllerTest < ActionController::TestCase get :index, :profile => ent.identifier assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{ent.identifier}/profile_editor/enable" } end - + should 'link to disable enterprise' do ent = fast_create(Enterprise, :enabled => true) get :index, :profile => ent.identifier diff --git a/test/functional/profile_members_controller_test.rb b/test/functional/profile_members_controller_test.rb index 0177d81..4f10269 100644 --- a/test/functional/profile_members_controller_test.rb +++ b/test/functional/profile_members_controller_test.rb @@ -12,15 +12,6 @@ class ProfileMembersControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new end - def test_local_files_reference - user = create_user('test_user').person - assert_local_files_reference :get, :index, :profile => user.identifier - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'not access index if dont have permission' do user = create_user('test_user') fast_create(Enterprise, :identifier => 'test_enterprise', :name => 'test enterprise') diff --git a/test/functional/region_validators_controller_test.rb b/test/functional/region_validators_controller_test.rb index 7449ca0..abdf0aa 100644 --- a/test/functional/region_validators_controller_test.rb +++ b/test/functional/region_validators_controller_test.rb @@ -12,14 +12,6 @@ class RegionValidatorsControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new login_as('ze') end - - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end # Replace this with your real tests. should 'list regions at index' do diff --git a/test/functional/role_controller_test.rb b/test/functional/role_controller_test.rb index 10bc6f7..b343b60 100644 --- a/test/functional/role_controller_test.rb +++ b/test/functional/role_controller_test.rb @@ -15,14 +15,6 @@ class RoleControllerTest < ActionController::TestCase login_as(:ze) end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - def test_index_should_get_roles get 'index' assert_response :success diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 83a407a..61a97a7 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -45,14 +45,6 @@ class SearchControllerTest < ActionController::TestCase fast_create(klass, { :name => name }.merge(data), :search => true, :category => category) end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'espape xss attack' do get 'index', :query => '' assert_no_tag :tag => 'wslite' diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 0b61258..3517bba 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -22,14 +22,6 @@ class TasksControllerTest < ActionController::TestCase super({ :controller => 'tasks', :profile => profile.identifier }.merge(options)) end - def test_local_files_reference - assert_local_files_reference - end - - def test_valid_xhtml - assert_valid_xhtml - end - should 'list pending tasks' do get :index diff --git a/test/test_helper.rb b/test/test_helper.rb index dcb70c5..b9c3f9c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,7 +3,6 @@ ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'rails/test_help' require 'mocha' -require 'tidy' require 'hpricot' require 'noosfero/test' @@ -111,56 +110,6 @@ class ActiveSupport::TestCase assert_equal parent, child.superclass, "Class #{child} expected to be a subclass of #{parent}" end - def assert_valid_xhtml(method=:get, action=:index, params = {}) - return true - if method.to_s() == 'post' - post action, params - else - get action, params - end - tidy = Tidy.open(:show_warnings=>false) - tidy.options.output_xml = true - tidy.clean @response.body - if tidy.errors - flunk "HTML ERROR - Tidy Diagnostics:\n "+ - tidy.errors.join("\n ") +"\n "+ - tidy.diagnostics.join("\n ") - end - end - - def assert_local_files_reference(method=:get, action=:index, params = {}) - if method.to_s() == 'post' - post action, params - else - get action, params - end - doc = Hpricot @response.body - - # Test style references: - (doc/'style').each do |s| - s = s.to_s().gsub( /\/\*.*\*\//, '' ). - split( /;|<|>|\n/ ). - map do |l| - patch = l.match( /@import url\((.*)\)/ ) - patch ? patch[1] : nil - end.compact - s.each do |css_ref| - if ! File.exists?(File.join(Rails.root, 'public', css_ref)) - flunk 'CSS reference missed on HTML: "%s"' % css_ref - end - end - end - - # Test image references: - (doc/'img').each do |img| - src = img.get_attribute( 'src' ).gsub(/\?[0-9]+$/, '') - if ! File.exists?(File.join(Rails.root, 'public', src)) - flunk 'Image reference missed on HTML: "%s"' % src - end - end - - end - # this check only if text has html tag def assert_sanitized(text) assert !text.index('<'), "Text '#{text}' expected to be sanitized" diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 9ef40bc..655b472 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -154,7 +154,7 @@ class ArticleTest < ActiveSupport::TestCase assert a4.errors[:slug.to_s].present? end - should 'record who did the last change' do + should 'last_changed_by be a person' do a = profile.articles.build(:name => 'test') # must be a person @@ -167,6 +167,19 @@ class ArticleTest < ActiveSupport::TestCase end end + should 'created_by be a person' do + a = profile.articles.build(:name => 'test') + + # must be a person + assert_raise ActiveRecord::AssociationTypeMismatch do + a.created_by = Profile.new + end + assert_nothing_raised do + a.created_by = Person.new + a.save! + end + end + should 'not show private documents as recent' do p = create_user('usr1').person Article.destroy_all @@ -802,7 +815,7 @@ class ArticleTest < ActiveSupport::TestCase should 'allow author to edit if is publisher' do c = fast_create(Community) p = create_user_with_permission('test_user', 'publish_content', c) - a = create(Article, :name => 'a test article', :last_changed_by => p, :profile_id => c.id) + a = create(Article, :name => 'a test article', :created_by => p, :profile_id => c.id) assert a.allow_post_content?(p) end @@ -1380,17 +1393,17 @@ class ArticleTest < ActiveSupport::TestCase should "the author_name returns the name of the article's author" do author = fast_create(Person) - a = create(Article, :name => 'a test article', :last_changed_by => author, :profile_id => profile.id) + a = create(Article, :name => 'a test article', :created_by => author, :profile_id => profile.id) assert_equal author.name, a.author_name author.destroy - a.reload + a = Article.find(a.id) a.author_name = 'some name' assert_equal 'some name', a.author_name end should 'retrieve latest info from topic when has no comments' do forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id) - post = fast_create(TextileArticle, :name => 'First post', :profile_id => profile.id, :parent_id => forum.id, :updated_at => Time.now, :last_changed_by_id => profile.id) + post = fast_create(TextileArticle, :name => 'First post', :profile_id => profile.id, :parent_id => forum.id, :updated_at => Time.now, :last_changed_by_id => profile.id, :created_by_id => profile.id) assert_equal post.updated_at, post.info_from_last_update[:date] assert_equal profile.name, post.info_from_last_update[:author_name] assert_equal profile.url, post.info_from_last_update[:author_url] @@ -1744,30 +1757,30 @@ class ArticleTest < ActiveSupport::TestCase should 'set author_name before creating article if there is an author' do author = fast_create(Person) - article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => author) + article = create(Article, :name => 'Test', :profile => profile, :created_by => author) assert_equal author.name, article.author_name author_name = author.name author.destroy - article.reload + article = Article.find(article.id) assert_equal author_name, article.author_name end should "author_id return the author id of the article's author" do author = fast_create(Person) - article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => author) + article = create(Article, :name => 'Test', :profile => profile, :created_by => author) assert_equal author.id, article.author_id end should "author_id return nil if there is no article's author" do - article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil) + article = create(Article, :name => 'Test', :profile => profile, :created_by => nil) assert_nil article.author_id end should "return the author of a specific version" do author1 = fast_create(Person) author2 = fast_create(Person) - article = create(Article, :name => 'first version', :profile => profile, :last_changed_by => author1) + article = create(Article, :name => 'first version', :profile => profile, :created_by => author1, :last_changed_by => author1) article.name = 'second version' article.last_changed_by = author2 article.save @@ -1778,7 +1791,7 @@ class ArticleTest < ActiveSupport::TestCase should "return the author_name of a specific version" do author1 = fast_create(Person) author2 = fast_create(Person) - article = create(Article, :name => 'first version', :profile => profile, :last_changed_by => author1) + article = create(Article, :name => 'first version', :profile => profile, :created_by => author1) article.name = 'second version' article.last_changed_by = author2 article.save @@ -1828,4 +1841,12 @@ class ArticleTest < ActiveSupport::TestCase assert_equivalent [c3], Article.with_types(['Event']) end + should 'not create version when receive a comment' do + a = Article.new(:name => 'my article', :body => 'my text') + a.profile = profile + a.save! + Comment.create!(:title => 'test', :body => 'asdsad', :author => profile, :source => a) + assert_equal 1, a.versions.count + end + end diff --git a/test/unit/box_test.rb b/test/unit/box_test.rb index 57127e7..4a3c06a 100644 --- a/test/unit/box_test.rb +++ b/test/unit/box_test.rb @@ -39,14 +39,11 @@ class BoxTest < ActiveSupport::TestCase assert blocks.include?('fans-block') assert blocks.include?('favorite-enterprises-block') assert blocks.include?('feed-reader-block') - assert blocks.include?('friends-block') assert blocks.include?('highlights-block') assert blocks.include?('link-list-block') assert blocks.include?('login-block') assert blocks.include?('main-block') - assert blocks.include?('members-block') assert blocks.include?('my-network-block') - assert blocks.include?('people-block') assert blocks.include?('profile-image-block') assert blocks.include?('raw-html-block') assert blocks.include?('recent-documents-block') @@ -74,14 +71,11 @@ class BoxTest < ActiveSupport::TestCase assert blocks.include?('favorite-enterprises-block') assert blocks.include?('featured-products-block') assert blocks.include?('feed-reader-block') - assert blocks.include?('friends-block') assert blocks.include?('highlights-block') assert blocks.include?('link-list-block') assert blocks.include?('location-block') assert blocks.include?('login-block') - assert blocks.include?('members-block') assert blocks.include?('my-network-block') - assert blocks.include?('people-block') assert blocks.include?('products-block') assert blocks.include?('profile-image-block') assert blocks.include?('profile-info-block') diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index e4a531c..eaa3911 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -1382,4 +1382,32 @@ class EnvironmentTest < ActiveSupport::TestCase environment.save! assert_equal ['en', 'pt'], environment.available_locales end + + should 'not consider custom welcome screen text if not defined' do + env = Environment.default + assert !env.has_custom_welcome_screen? + end + + should 'not consider custom welcome screen text if nil' do + env = Environment.default + + env.signup_welcome_screen_body = nil + assert !env.has_custom_welcome_screen? + end + + should 'consider signup welcome screen if body is defined' do + env = Environment.default + env.signup_welcome_screen_body = 'Welcome to the environment' + assert env.has_custom_welcome_screen? + end + + should 'store custom welcome screen body' do + environment = Environment.default + + environment.signup_welcome_screen_body = 'Welcome to the environment' + environment.save + environment.reload + + assert_equal 'Welcome to the environment', environment.signup_welcome_screen_body + end end diff --git a/test/unit/forum_helper_test.rb b/test/unit/forum_helper_test.rb index f54f015..680615b 100644 --- a/test/unit/forum_helper_test.rb +++ b/test/unit/forum_helper_test.rb @@ -38,7 +38,7 @@ class ForumHelperTest < ActiveSupport::TestCase should 'return post update if it has no comments' do author = create_user('forum test author').person - some_post = create(TextileArticle, :name => 'First post', :profile => profile, :parent => forum, :published => true, :last_changed_by => author) + some_post = create(TextileArticle, :name => 'First post', :profile => profile, :parent => forum, :published => true, :created_by => author) assert some_post.comments.empty? out = last_topic_update(some_post) assert_match some_post.updated_at.to_s, out diff --git a/test/unit/friends_block_test.rb b/test/unit/friends_block_test.rb deleted file mode 100644 index 106920a..0000000 --- a/test/unit/friends_block_test.rb +++ /dev/null @@ -1,86 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class FriendsBlockTest < ActiveSupport::TestCase - - should 'describe itself' do - assert_not_equal ProfileListBlock.description, FriendsBlock.description - end - - should 'declare its default title' do - FriendsBlock.any_instance.stubs(:profile_count).returns(0) - assert_not_equal ProfileListBlock.new.default_title, FriendsBlock.new.default_title - end - - should 'list owner friends' do - p1 = create_user('testuser1').person - p2 = create_user('testuser2').person - p3 = create_user('testuser3').person - p4 = create_user('testuser4').person - - p1.add_friend(p2) - p1.add_friend(p3) - p1.add_friend(p4) - p1.friends.reload - - block = FriendsBlock.new - block.expects(:owner).returns(p1) - - assert_equivalent [p2, p3, p4], block.profiles - end - - should 'point to list with all friends' do - block = FriendsBlock.new - user = mock - user.expects(:identifier).returns('theuser') - block.expects(:owner).returns(user) - - expects(:link_to).with('View all', :profile => 'theuser', :controller => 'profile', :action => 'friends') - - instance_eval(&block.footer) - end - - should 'count number of owner friends' do - p1 = create_user('testuser1').person - p2 = create_user('testuser2').person - p3 = create_user('testuser3').person - p4 = create_user('testuser4').person - - p1.add_friend(p2) - p1.add_friend(p3) - p1.add_friend(p4) - - block = FriendsBlock.new - block.expects(:owner).returns(p1) - - assert_equal 3, block.profile_count - end - - should 'count number of public and private people' do - owner = create_user('testuser1').person - private_p = fast_create(Person, {:public_profile => false}) - public_p = fast_create(Person, {:public_profile => true}) - - owner.add_friend(private_p) - owner.add_friend(public_p) - - block = FriendsBlock.new - block.expects(:owner).returns(owner) - - assert_equal 2, block.profile_count - end - - should 'not count number of invisible people' do - owner = create_user('testuser1').person - private_p = fast_create(Person, {:visible => false}) - public_p = fast_create(Person, {:visible => true}) - - owner.add_friend(private_p) - owner.add_friend(public_p) - - block = FriendsBlock.new - block.expects(:owner).returns(owner) - - assert_equal 1, block.profile_count - end - -end diff --git a/test/unit/members_block_test.rb b/test/unit/members_block_test.rb deleted file mode 100644 index 8254a98..0000000 --- a/test/unit/members_block_test.rb +++ /dev/null @@ -1,62 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class MembersBlockTest < ActiveSupport::TestCase - - should 'inherit from ProfileListBlock' do - assert_kind_of ProfileListBlock, MembersBlock.new - end - - should 'describe itself' do - assert_not_equal ProfileListBlock.description, MembersBlock.description - end - - should 'provide a default title' do - assert_not_equal ProfileListBlock.new.default_title, MembersBlock.new.default_title - end - - should 'display members file' do - community = fast_create(Community) - block = MembersBlock.create - block.expects(:owner).returns(community) - - self.expects(:render).with(:file => 'blocks/members', :locals => { :profile => community, :show_join_leave_button => false}).returns('file-with-members-list') - assert_equal 'file-with-members-list', instance_eval(&block.footer) - end - - should 'pick random members' do - block = MembersBlock.new - - owner = mock - block.expects(:owner).returns(owner) - - list = [] - owner.expects(:members).returns(list) - - assert_same list, block.profiles - end - - should 'use logged-in to compose cache key' do - person = fast_create(Person) - community = fast_create(Community) - block = MembersBlock.create - block.expects(:owner).returns(community) - - assert_match(/-logged-in/,block.cache_key('en', person)) - end - - should 'use logged-in and member to compose cache key for members' do - person = fast_create(Person) - community = fast_create(Community) - community.add_member person - block = MembersBlock.create - block.expects(:owner).returns(community) - - assert_match(/-logged-in-member/,block.cache_key('en', person)) - end - - should 'not change block cache key if user is nil' do - block = MembersBlock.new - assert_equal block.cache_key('en'), block.cache_key('en', nil) - end - -end diff --git a/test/unit/people_block_test.rb b/test/unit/people_block_test.rb deleted file mode 100644 index 1684fc8..0000000 --- a/test/unit/people_block_test.rb +++ /dev/null @@ -1,50 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class PeopleBlockTest < ActiveSupport::TestCase - - should 'inherit from ProfileListBlock' do - assert_kind_of ProfileListBlock, PeopleBlock.new - end - - should 'declare its default title' do - assert_not_equal ProfileListBlock.new.default_title, PeopleBlock.new.default_title - end - - should 'describe itself' do - assert_not_equal ProfileListBlock.description, PeopleBlock.description - end - - should 'give help' do - assert_not_equal ProfileListBlock.new.help, PeopleBlock.new.help - end - - should 'list people' do - owner = fast_create(Environment) - block = PeopleBlock.new - block.expects(:owner).returns(owner).at_least_once - person1 = fast_create(Person, :environment_id => owner.id) - person2 = fast_create(Person, :environment_id => owner.id) - - expects(:profile_image_link).with(person1, :minor).returns(person1.name) - expects(:profile_image_link).with(person2, :minor).returns(person2.name) - expects(:block_title).with(anything).returns('') - - content = instance_eval(&block.content) - - assert_match(/#{person1.name}/, content) - assert_match(/#{person2.name}/, content) - end - - should 'link to browse people' do - block = PeopleBlock.new - block.stubs(:owner).returns(Environment.default) - - expects(:_).with('View all').returns('View all people') - expects(:link_to).with('View all people', :controller => 'search', :action => 'people') - instance_eval(&block.footer) - end - - protected - include NoosferoTestHelper - -end diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb index b7ba9a4..ee3ace4 100644 --- a/test/unit/tiny_mce_article_test.rb +++ b/test/unit/tiny_mce_article_test.rb @@ -8,7 +8,7 @@ class TinyMceArticleTest < ActiveSupport::TestCase @profile = create_user('zezinho').person end attr_reader :profile - + # this test can be removed when we get real tests for TinyMceArticle should 'be an article' do assert_subclass TextArticle, TinyMceArticle @@ -210,7 +210,7 @@ end assert_equal true, a.notifiable? assert_equal true, a.advertise? assert_equal true, a.is_trackable? - + a.published=false assert_equal false, a.published? assert_equal false, a.is_trackable? @@ -237,4 +237,13 @@ end assert_tag_in_string article.body, :tag => 'source', :attributes => {:src => 'http://example.ogv', :type => 'video/ogg'} end + should 'not sanitize colspan and rowspan attributes' do + article = TinyMceArticle.create!(:name => 'table with colspan and rowspan', + :body => "
", + :profile => profile + ) + assert_tag_in_string article.body, :tag => 'table', + :attributes => { :colspan => 2, :rowspan => 3 } + end + end diff --git a/vendor/plugins/acts_as_list/Rakefile b/vendor/plugins/acts_as_list/Rakefile new file mode 100644 index 0000000..e6c6369 --- /dev/null +++ b/vendor/plugins/acts_as_list/Rakefile @@ -0,0 +1,12 @@ +require 'rake' +require 'rake/testtask' + +desc 'Default: run acts_as_list unit tests.' +task :default => :test + +desc 'Test the acts_as_ordered_tree plugin.' +Rake::TestTask.new(:test) do |t| + t.libs << 'lib' + t.pattern = 'test/**/*_test.rb' + t.verbose = true +end diff --git a/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb b/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb index 00d8692..65790f9 100644 --- a/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +++ b/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb @@ -26,8 +26,8 @@ module ActiveRecord # Configuration options are: # # * +column+ - specifies the column name to use for keeping the position integer (default: +position+) - # * +scope+ - restricts what is to be considered a list. Given a symbol, it'll attach _id - # (if it hasn't already been added) and use that as the foreign key restriction. It's also possible + # * +scope+ - restricts what is to be considered a list. Given a symbol, it'll attach _id + # (if it hasn't already been added) and use that as the foreign key restriction. It's also possible # to give it an entire string that is interpolated if you need a tighter scope than just a foreign key. # Example: acts_as_list :scope => 'todo_list_id = #{todo_list_id} AND completed = 0' def acts_as_list(options = {}) @@ -39,11 +39,16 @@ module ActiveRecord if configuration[:scope].is_a?(Symbol) scope_condition_method = %( def scope_condition - if #{configuration[:scope].to_s}.nil? - "#{configuration[:scope].to_s} IS NULL" - else - "#{configuration[:scope].to_s} = \#{#{configuration[:scope].to_s}}" + self.class.send(:sanitize_sql_hash_for_conditions, { :#{configuration[:scope].to_s} => send(:#{configuration[:scope].to_s}) }) + end + ) + elsif configuration[:scope].is_a?(Array) + scope_condition_method = %( + def scope_condition + attrs = %w(#{configuration[:scope].join(" ")}).inject({}) do |memo,column| + memo[column.intern] = send(column.intern); memo end + self.class.send(:sanitize_sql_hash_for_conditions, attrs) end ) else @@ -63,7 +68,7 @@ module ActiveRecord #{scope_condition_method} - before_destroy :remove_from_list + before_destroy :decrement_positions_on_lower_items before_create :add_to_list_bottom EOV end @@ -250,7 +255,7 @@ module ActiveRecord increment_positions_on_lower_items(position) self.update_attribute(position_column, position) end - end + end end end end diff --git a/vendor/plugins/acts_as_list/test/list_test.rb b/vendor/plugins/acts_as_list/test/list_test.rb index e89cb8e..a99451c 100644 --- a/vendor/plugins/acts_as_list/test/list_test.rb +++ b/vendor/plugins/acts_as_list/test/list_test.rb @@ -6,14 +6,15 @@ require 'active_record' require "#{File.dirname(__FILE__)}/../init" -ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:") +ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:") def setup_db ActiveRecord::Schema.define(:version => 1) do create_table :mixins do |t| t.column :pos, :integer t.column :parent_id, :integer - t.column :created_at, :datetime + t.column :parent_type, :string + t.column :created_at, :datetime t.column :updated_at, :datetime end end @@ -46,6 +47,11 @@ class ListWithStringScopeMixin < ActiveRecord::Base def self.table_name() "mixins" end end +class ArrayScopeListMixin < Mixin + acts_as_list :column => "pos", :scope => [:parent_id, :parent_type] + + def self.table_name() "mixins" end +end class ListTest < Test::Unit::TestCase @@ -95,7 +101,7 @@ class ListTest < Test::Unit::TestCase def test_injection item = ListMixin.new(:parent_id => 1) - assert_equal "parent_id = 1", item.scope_condition + assert_equal '"mixins"."parent_id" = 1', item.scope_condition assert_equal "pos", item.position_column end @@ -187,40 +193,60 @@ class ListTest < Test::Unit::TestCase new2.move_higher assert_equal [new2, new1, new3], ListMixin.find(:all, :conditions => 'parent_id IS NULL', :order => 'pos') end - - - def test_remove_from_list_should_then_fail_in_list? + + def test_remove_from_list_should_then_fail_in_list? assert_equal true, ListMixin.find(1).in_list? ListMixin.find(1).remove_from_list assert_equal false, ListMixin.find(1).in_list? - end - - def test_remove_from_list_should_set_position_to_nil + end + + def test_remove_from_list_should_set_position_to_nil assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) - - ListMixin.find(2).remove_from_list - + + ListMixin.find(2).remove_from_list + assert_equal [2, 1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) - + assert_equal 1, ListMixin.find(1).pos assert_equal nil, ListMixin.find(2).pos assert_equal 2, ListMixin.find(3).pos assert_equal 3, ListMixin.find(4).pos - end - - def test_remove_before_destroy_does_not_shift_lower_items_twice + end + + def test_remove_before_destroy_does_not_shift_lower_items_twice assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) - - ListMixin.find(2).remove_from_list - ListMixin.find(2).destroy - + + ListMixin.find(2).remove_from_list + ListMixin.find(2).destroy + assert_equal [1, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) - + + assert_equal 1, ListMixin.find(1).pos + assert_equal 2, ListMixin.find(3).pos + assert_equal 3, ListMixin.find(4).pos + end + + def test_before_destroy_callbacks_do_not_update_position_to_nil_before_deleting_the_record + assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) + + # We need to trigger all the before_destroy callbacks without actually + # destroying the record so we can see the affect the callbacks have on + # the record. + list = ListMixin.find(2) + if list.respond_to?(:run_callbacks) + list.run_callbacks(:destroy) + else + list.send(:callback, :before_destroy) + end + + assert_equal [1, 2, 3, 4], ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos').map(&:id) + assert_equal 1, ListMixin.find(1).pos + assert_equal 2, ListMixin.find(2).pos assert_equal 2, ListMixin.find(3).pos assert_equal 3, ListMixin.find(4).pos - end - + end + end class ListSubTest < Test::Unit::TestCase @@ -271,7 +297,7 @@ class ListSubTest < Test::Unit::TestCase def test_injection item = ListMixin.new("parent_id"=>1) - assert_equal "parent_id = 1", item.scope_condition + assert_equal '"mixins"."parent_id" = 1', item.scope_condition assert_equal "pos", item.position_column end @@ -330,3 +356,165 @@ class ListSubTest < Test::Unit::TestCase end end + +class ArrayScopeListTest < Test::Unit::TestCase + + def setup + setup_db + (1..4).each { |counter| ArrayScopeListMixin.create! :pos => counter, :parent_id => 5, :parent_type => 'ParentClass' } + end + + def teardown + teardown_db + end + + def test_reordering + assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + ArrayScopeListMixin.find(2).move_lower + assert_equal [1, 3, 2, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + ArrayScopeListMixin.find(2).move_higher + assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + ArrayScopeListMixin.find(1).move_to_bottom + assert_equal [2, 3, 4, 1], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + ArrayScopeListMixin.find(1).move_to_top + assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + ArrayScopeListMixin.find(2).move_to_bottom + assert_equal [1, 3, 4, 2], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + ArrayScopeListMixin.find(4).move_to_top + assert_equal [4, 1, 3, 2], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + end + + def test_move_to_bottom_with_next_to_last_item + assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + ArrayScopeListMixin.find(3).move_to_bottom + assert_equal [1, 2, 4, 3], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + end + + def test_next_prev + assert_equal ArrayScopeListMixin.find(2), ArrayScopeListMixin.find(1).lower_item + assert_nil ArrayScopeListMixin.find(1).higher_item + assert_equal ArrayScopeListMixin.find(3), ArrayScopeListMixin.find(4).higher_item + assert_nil ArrayScopeListMixin.find(4).lower_item + end + + def test_injection + item = ArrayScopeListMixin.new(:parent_id => 1, :parent_type => 'ParentClass') + assert_equal '"mixins"."parent_id" = 1 AND "mixins"."parent_type" = \'ParentClass\'', item.scope_condition + assert_equal "pos", item.position_column + end + + def test_insert + new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass') + assert_equal 1, new.pos + assert new.first? + assert new.last? + + new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass') + assert_equal 2, new.pos + assert !new.first? + assert new.last? + + new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass') + assert_equal 3, new.pos + assert !new.first? + assert new.last? + + new = ArrayScopeListMixin.create(:parent_id => 0, :parent_type => 'ParentClass') + assert_equal 1, new.pos + assert new.first? + assert new.last? + end + + def test_insert_at + new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass') + assert_equal 1, new.pos + + new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass') + assert_equal 2, new.pos + + new = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass') + assert_equal 3, new.pos + + new4 = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass') + assert_equal 4, new4.pos + + new4.insert_at(3) + assert_equal 3, new4.pos + + new.reload + assert_equal 4, new.pos + + new.insert_at(2) + assert_equal 2, new.pos + + new4.reload + assert_equal 4, new4.pos + + new5 = ArrayScopeListMixin.create(:parent_id => 20, :parent_type => 'ParentClass') + assert_equal 5, new5.pos + + new5.insert_at(1) + assert_equal 1, new5.pos + + new4.reload + assert_equal 5, new4.pos + end + + def test_delete_middle + assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + ArrayScopeListMixin.find(2).destroy + + assert_equal [1, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + assert_equal 1, ArrayScopeListMixin.find(1).pos + assert_equal 2, ArrayScopeListMixin.find(3).pos + assert_equal 3, ArrayScopeListMixin.find(4).pos + + ArrayScopeListMixin.find(1).destroy + + assert_equal [3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + assert_equal 1, ArrayScopeListMixin.find(3).pos + assert_equal 2, ArrayScopeListMixin.find(4).pos + end + + def test_remove_from_list_should_then_fail_in_list? + assert_equal true, ArrayScopeListMixin.find(1).in_list? + ArrayScopeListMixin.find(1).remove_from_list + assert_equal false, ArrayScopeListMixin.find(1).in_list? + end + + def test_remove_from_list_should_set_position_to_nil + assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + ArrayScopeListMixin.find(2).remove_from_list + + assert_equal [2, 1, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + assert_equal 1, ArrayScopeListMixin.find(1).pos + assert_equal nil, ArrayScopeListMixin.find(2).pos + assert_equal 2, ArrayScopeListMixin.find(3).pos + assert_equal 3, ArrayScopeListMixin.find(4).pos + end + + def test_remove_before_destroy_does_not_shift_lower_items_twice + assert_equal [1, 2, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + ArrayScopeListMixin.find(2).remove_from_list + ArrayScopeListMixin.find(2).destroy + + assert_equal [1, 3, 4], ArrayScopeListMixin.find(:all, :conditions => "parent_id = 5 AND parent_type = 'ParentClass'", :order => 'pos').map(&:id) + + assert_equal 1, ArrayScopeListMixin.find(1).pos + assert_equal 2, ArrayScopeListMixin.find(3).pos + assert_equal 3, ArrayScopeListMixin.find(4).pos + end + +end -- libgit2 0.21.2