From 453004fab2b6b717a5ddb0541028319d907b4020 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Tue, 26 Oct 2010 21:02:48 -0300 Subject: [PATCH] Better defaults --- app/models/enterprise.rb | 25 +++++++++++++++---------- app/models/environment.rb | 24 ++++++++++++++++++++---- app/models/link_list_block.rb | 2 +- app/models/organization.rb | 20 +++++++++++++++++--- app/models/person.rb | 19 ++++++++++++++++--- app/models/profile.rb | 41 ++++++++++++++++++++++------------------- features/blog.feature | 1 + features/delete_profile.feature | 2 +- features/edit_article.feature | 5 +++-- features/edit_blog_archives_block.feature | 1 + features/events.feature | 3 +++ features/login.feature | 3 +++ features/publish_article.feature | 8 -------- features/search.feature | 10 +++++----- features/step_definitions/noosfero_steps.rb | 7 ++++++- public/designs/themes/base/footer.rhtml | 6 +----- public/designs/themes/base/style.css | 1 + public/images/noosfero-network.png | Bin 0 -> 99130 bytes script/sample-data | 14 +------------- test/functional/content_viewer_controller_test.rb | 24 ------------------------ test/functional/tasks_controller_test.rb | 14 +++++++++----- test/unit/community_test.rb | 19 +++++++------------ test/unit/enterprise_test.rb | 24 +++++++----------------- test/unit/person_test.rb | 30 ++++++++++++++++-------------- test/unit/profile_test.rb | 49 ++++++++++++------------------------------------- 25 files changed, 168 insertions(+), 184 deletions(-) create mode 100644 public/images/noosfero-network.png diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 1c7d35c..87d9886 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -122,17 +122,28 @@ class Enterprise < Organization end def default_set_of_blocks + links = [ + {:name => _("Enterprises's profile"), :address => '/profile/{profile}', :icon => 'ok'}, + {:name => _('Blog'), :address => '/{profile}/blog', :icon => 'edit'}, + {:name => _('Products'), :address => '/catalog/{profile}', :icon => 'new'}, + ] blocks = [ - [MainBlock], - [ProfileInfoBlock, MembersBlock], - [RecentDocumentsBlock] + [MainBlock.new], + [ProfileImageBlock.new, LinkListBlock.new(:links => links)], + [] ] if !environment.enabled?('disable_products_for_enterprises') - blocks[2].unshift ProductsBlock + blocks[2].unshift ProductsBlock.new end blocks end + def default_set_of_articles + [ + Blog.new(:name => _('Blog')), + ] + end + before_create do |enterprise| if enterprise.environment.enabled?('enterprises_are_disabled_when_created') enterprise.enabled = false @@ -154,10 +165,4 @@ class Enterprise < Organization enable_contact_us end - protected - - def default_homepage(attrs) - EnterpriseHomepage.new(attrs) - end - end diff --git a/app/models/environment.rb b/app/models/environment.rb index 1d870ff..48edec5 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -45,9 +45,7 @@ class Environment < ActiveRecord::Base :name => N_('Member'), :environment => self, :permissions => [ - 'edit_profile', - 'post_content', - 'manage_products' + 'invite_members', ] ) # moderators for enterprises, communities etc @@ -209,7 +207,7 @@ class Environment < ActiveRecord::Base settings_items :location, :type => String settings_items :layout_template, :type => String, :default => 'default' settings_items :homepage, :type => String - settings_items :description, :type => String + settings_items :description, :type => String, :default => '
Noosfero
' settings_items :category_types, :type => Array, :default => ['Category'] settings_items :enable_ssl settings_items :local_docs, :type => Array, :default => [] @@ -261,6 +259,24 @@ class Environment < ActiveRecord::Base features.delete_if{ |k, v| !self.enabled?(k) } end + before_create :enable_default_features + def enable_default_features + %w( + disable_asset_products + disable_gender_icon + disable_products_for_enterprises + disable_select_city_for_contact + enterprise_registration + media_panel + organizations_are_moderated_by_default + show_balloon_with_profile_links_when_clicked + use_portal_community + wysiwyg_editor_for_environment_home + ).each do |feature| + enable(feature) + end + end + # returns true if this Environment has terms of use to be # accepted by users before registration. def has_terms_of_use? diff --git a/app/models/link_list_block.rb b/app/models/link_list_block.rb index 36fce6f..d7f4d0e 100644 --- a/app/models/link_list_block.rb +++ b/app/models/link_list_block.rb @@ -52,7 +52,7 @@ class LinkListBlock < Block def link_html(link) klass = 'icon-' + link[:icon] if link[:icon] sanitize_link( - link_to(link[:name], expand_address(link[:address]), :class => klass) + link_to(_(link[:name]), expand_address(link[:address]), :class => klass) ) end diff --git a/app/models/organization.rb b/app/models/organization.rb index 5c070ee..57590b3 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -99,10 +99,24 @@ class Organization < Profile end def default_set_of_blocks + links = [ + {:name => _("Community's profile"), :address => '/profile/{profile}', :icon => 'ok'}, + {:name => _('Invite Friends'), :address => '/profile/{profile}/invite/friends', :icon => 'send'}, + {:name => _('Agenda'), :address => '/profile/{profile}/events', :icon => 'menu-events'}, + {:name => _('Image gallery'), :address => '/{profile}/gallery', :icon => 'photos'}, + {:name => _('Blog'), :address => '/{profile}/blog', :icon => 'edit'}, + ] + [ + [MainBlock.new], + [ProfileImageBlock.new, LinkListBlock.new(:links => links)], + [MembersBlock.new, RecentDocumentsBlock.new] + ] + end + + def default_set_of_articles [ - [MainBlock], - [ProfileInfoBlock, RecentDocumentsBlock], - [MembersBlock, TagsBlock] + Blog.new(:name => _('Blog')), + Folder.new(:name => _('Gallery'), :view_as => 'image_gallery'), ] end diff --git a/app/models/person.rb b/app/models/person.rb index 0510bd3..b6b1fe4 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -203,10 +203,23 @@ class Person < Profile end def default_set_of_blocks + links = [ + {:name => _('Profile'), :address => '/profile/{profile}', :icon => 'menu-people'}, + {:name => _('Image gallery'), :address => '/{profile}/gallery', :icon => 'photos'}, + {:name => _('Agenda'), :address => '/profile/{profile}/events', :icon => 'menu-events'}, + {:name => _('Blog'), :address => '/{profile}/blog', :icon => 'edit'}, + ] + [ + [MainBlock.new], + [ProfileImageBlock.new, LinkListBlock.new(:links => links), RecentDocumentsBlock.new], + [FriendsBlock.new, CommunitiesBlock.new] + ] + end + + def default_set_of_articles [ - [MainBlock], - [ProfileInfoBlock, RecentDocumentsBlock, TagsBlock], - [FriendsBlock, EnterprisesBlock, CommunitiesBlock] + Blog.new(:name => _('Blog')), + Folder.new(:name => _('Gallery'), :view_as => 'image_gallery'), ] end diff --git a/app/models/profile.rb b/app/models/profile.rb index 18a894d..8963ecc 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -293,7 +293,7 @@ class Profile < ActiveRecord::Base if self.respond_to?(:default_set_of_blocks) default_set_of_blocks.each_with_index do |blocks,i| blocks.each do |block| - self.boxes[i].blocks << block.new + self.boxes[i].blocks << block end end end @@ -507,25 +507,32 @@ private :generate_url, :url_options if template copy_articles_from template else - # a default homepage - hp = default_homepage(:name => _("My home page"), :body => _("

This is a default homepage created for me. It can be changed though the control panel.

"), :advertise => false) - hp.profile = self - hp.save! - self.home_page = hp - - # a default rss feed - feed = RssFeed.new(:name => 'feed') - self.articles << feed - - # a default private folder if public - if self.public? - folder = Folder.new(:name => _("Intranet"), :published => false) - self.articles << folder + default_set_of_articles.each do |article| + article.profile = self + article.advertise = false + article.save! end end self.save! end + # Override this method in subclasses of Profile to create a default article + # set upon creation. Note that this method will be called *only* if there is + # no template for the type of profile (i.e. if the template was removed or in + # the creation of the template itself). + # + # This method must return an array of pre-populated articles, which will be + # associated to the profile before being saved. Example: + # + # def default_set_of_articles + # [Blog.new(:name => 'Blog'), Folder.new(:name => 'Gallery', :view_as => 'image_gallery')] + # end + # + # By default, this method returns an empty array. + def default_set_of_articles + [] + end + def copy_articles_from other other.top_level_articles.each do |a| copy_article_tree a @@ -610,10 +617,6 @@ private :generate_url, :url_options !forbidden.include?(cat.class) end - def default_homepage(attrs) - TinyMceArticle.new(attrs) - end - include ActionView::Helpers::TextHelper def short_name(chars = 15) if self[:nickname].blank? diff --git a/features/blog.feature b/features/blog.feature index 8c75bf0..ccd22c2 100644 --- a/features/blog.feature +++ b/features/blog.feature @@ -7,6 +7,7 @@ Feature: blog And the following users | login | name | | joaosilva | Joao Silva | + And "joaosilva" has no articles And I am logged in as "joaosilva" Scenario: create a blog diff --git a/features/delete_profile.feature b/features/delete_profile.feature index 92b3bc7..a077e48 100644 --- a/features/delete_profile.feature +++ b/features/delete_profile.feature @@ -34,7 +34,7 @@ Feature: delete profile And I follow "Delete profile" Then I should see "Are you sure you want to delete this profile?" When I follow "No, I gave up" - Then I should be on Joao Silva's homepage + Then I should be on Joao Silva's profile Scenario: community admin can see link to delete profile Given the following community diff --git a/features/edit_article.feature b/features/edit_article.feature index 5b46eed..a1bd43c 100644 --- a/features/edit_article.feature +++ b/features/edit_article.feature @@ -123,8 +123,9 @@ Feature: edit article And I should be on "Save the whales" edit page Scenario: save and continue when creating a new article - Given I am on /joaosilva - When I follow "New article" + Given I am on Joao Silva's control panel + When I follow "Manage Content" + And I follow "New article" And I follow "Text article with visual editor" And I fill in "Title" with "My new article" And I fill in "Text" with "text for the new article" diff --git a/features/edit_blog_archives_block.feature b/features/edit_blog_archives_block.feature index f550849..9a34089 100644 --- a/features/edit_blog_archives_block.feature +++ b/features/edit_blog_archives_block.feature @@ -7,6 +7,7 @@ Feature: edit_blog_archives_block And the following users | login | name | | joaosilva | Joao Silva | + And "joaosilva" has no articles And the following blogs | owner | name | | joaosilva | Blog One | diff --git a/features/events.feature b/features/events.feature index 41a2897..a1c5409 100644 --- a/features/events.feature +++ b/features/events.feature @@ -143,6 +143,9 @@ Feature: events Then I should see "YAPC::Brasil 2010" Scenario: provide button to go back to profile homepage + Given the following articles + | owner | name | homepage | + | josesilva | my homepage | true | Given I am on /profile/josesilva/events When I follow "Back to josesilva" Then I should be on josesilva's homepage diff --git a/features/login.feature b/features/login.feature index 7b61281..72e9c98 100644 --- a/features/login.feature +++ b/features/login.feature @@ -22,6 +22,9 @@ Feature: login And the following users | login | name | | mariasilva | Maria Silva | + And the following articles + | owner | name | homepage | + | mariasilva | my home page | true | And I go to Maria Silva's homepage And I follow "Login" And I fill in the following: diff --git a/features/publish_article.feature b/features/publish_article.feature index 25c98c6..06efdf5 100644 --- a/features/publish_article.feature +++ b/features/publish_article.feature @@ -25,8 +25,6 @@ Feature: publish article And I follow "Spread" And I check "Sample Community" And I press "Spread this" - And I am on Sample Community's homepage - And I follow "View profile" And I go to Sample Community's sitemap When I follow "Sample Article" Then I should see "This is the first published article" @@ -40,8 +38,6 @@ Feature: publish article And I check "Sample Community" And I fill in "Title" with "Another name" And I press "Spread this" - And I am on Sample Community's homepage - And I follow "View profile" When I go to Sample Community's sitemap Then I should see "Another name" And I should not see "Sample Article" @@ -94,12 +90,8 @@ Feature: publish article And I check "Another Community2" When I press "Spread this" Then I should see "The title (article name) is already being used by another article, please use another title." - And I am on Another Community1's homepage - And I follow "View profile" When I go to Another Community1's sitemap Then I should see "Sample Article" - And I am on Another Community2's homepage - And I follow "View profile" When I go to Another Community2's sitemap Then I should see "Sample Article" diff --git a/features/search.feature b/features/search.feature index b764d11..932d843 100644 --- a/features/search.feature +++ b/features/search.feature @@ -28,13 +28,13 @@ Feature: search Scenario: simple search for enterprise Given the following enterprises | identifier | name | - | products-factory | Products factory | - | services-provider | Services Provider | + | shop1 | Shoes shop | + | shop2 | Fruits shop | And I go to the search page - And I fill in "query" with "services" + And I fill in "query" with "shoes" And I press "Search" - Then I should see "Services Provider" - And I should not see "Products factory" + Then I should see "Shoes shop" + And I should not see "Fruits shop" Scenario: simple search for content Given the following users diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index 625700a..53e7f98 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -51,7 +51,12 @@ Given /^the following (articles|events|blogs|folders)$/ do |content, table| table.hashes.map{|item| item.dup}.each do |item| owner_identifier = item.delete("owner") owner = Profile[owner_identifier] - klass.create!(item.merge(:profile => owner)) + home = item.delete("homepage") + result = klass.create!(item.merge(:profile => owner)) + if home + owner.home_page = result + owner.save! + end end end diff --git a/public/designs/themes/base/footer.rhtml b/public/designs/themes/base/footer.rhtml index 1a28bb7..7ac606e 100644 --- a/public/designs/themes/base/footer.rhtml +++ b/public/designs/themes/base/footer.rhtml @@ -2,10 +2,6 @@ <%= link_to _('Manual'), '/doc' %> <%= language_chooser %> diff --git a/public/designs/themes/base/style.css b/public/designs/themes/base/style.css index 9c26be2..0ff110c 100644 --- a/public/designs/themes/base/style.css +++ b/public/designs/themes/base/style.css @@ -363,6 +363,7 @@ body, th, td, input { padding: 0px; font-size: 11px; color: #555; + margin-bottom: 20px; } #theme-footer a { diff --git a/public/images/noosfero-network.png b/public/images/noosfero-network.png new file mode 100644 index 0000000..355d576 Binary files /dev/null and b/public/images/noosfero-network.png differ diff --git a/script/sample-data b/script/sample-data index c3ce589..c450ad8 100755 --- a/script/sample-data +++ b/script/sample-data @@ -9,19 +9,7 @@ environment = nil if environment_id environment = Environment.find(environment_id) else - DEFAULT_ENVIRONMENT_TEXT = <Environment homepage -

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis diam enim, et ultricies lacus. Pellentesque sit amet velit non ante bibendum consectetur. Etiam at aliquet mauris. Pellentesque volutpat pellentesque dolor, at cursus lacus suscipit varius. Nunc at lectus tortor, eu dapibus urna. Ut at odio sem, sed laoreet augue. Nunc vestibulum, lectus id tempor vulputate, turpis nisl placerat justo, non placerat est lectus a risus. Nullam elementum convallis lectus, eget volutpat sapien malesuada quis. Fusce aliquet elementum placerat. Donec dolor mauris, accumsan eu gravida sed, mollis a metus. Quisque dictum felis vel diam ornare dapibus. Cras vel est velit. Fusce in tincidunt urna. Proin tincidunt pellentesque turpis, nec blandit nulla volutpat at. Suspendisse potenti. -

-

- Nunc pellentesque sem in ante lacinia egestas nec et dolor. Fusce enim leo, condimentum nec iaculis in, convallis eget diam. Integer ultricies massa eu augue tristique eu semper lorem aliquam. Praesent nibh lorem, eleifend nec laoreet ac, tempus et augue. Phasellus pulvinar nibh eget magna pellentesque ultricies. Donec varius, sapien in fermentum pellentesque, odio risus viverra lectus, sed tincidunt arcu elit id ipsum. Nunc aliquet lobortis sem, vitae dapibus velit bibendum id. Vivamus nec augue arcu, sed adipiscing quam. Maecenas at porta odio. Ut felis arcu, commodo in vestibulum a, convallis et justo. Nulla feugiat odio in dui mollis a pretium orci porta. Morbi at nisl sem, non tempus dui. -

-

- Maecenas neque ante, bibendum sed mollis ac, aliquet eu dolor. Fusce quis enim mi, vestibulum laoreet purus. Curabitur vel odio non mi tempus commodo. Duis suscipit justo sit amet felis volutpat scelerisque. Integer in mi vulputate lacus porttitor posuere id sed sapien. Nam aliquam molestie est a eleifend. Integer at velit nec felis sodales ornare. Etiam magna elit, facilisis at consectetur nec, commodo sit amet sapien. Maecenas fermentum leo vitae turpis viverra auctor. Phasellus facilisis ipsum quis felis semper et condimentum augue porttitor. Morbi vitae mauris risus. Nunc lobortis quam eu tellus tempus ut tristique odio luctus. Fusce justo purus, tincidunt eu tristique et, pharetra non tortor. Cras malesuada accumsan venenatis. Donec ornare iaculis porttitor. Praesent vestibulum metus fermentum risus interdum gravida. Vivamus placerat commodo nunc vitae aliquet. Fusce sit amet libero facilisis ante dictum hendrerit ac sed massa. -

-EOF - environment = Environment.create!(:name => 'Noosfero', :is_default => true, :description => DEFAULT_ENVIRONMENT_TEXT) unless (Environment.default) + environment = Environment.default || Environment.create!(:name => 'Noosfero', :is_default => true) end system('./script/sample-profiles') diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index cfc9d15..64f439c 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -344,30 +344,6 @@ class ContentViewerControllerTest < Test::Unit::TestCase assert_response :success end - should 'show message for disabled enterprises' do - login_as(@profile.identifier) - ent = Enterprise.create!(:name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false) - get :view_page, :profile => ent.identifier, :page => [] - assert_tag :tag => 'div', :attributes => { :id => 'profile-disabled' }, :content => Environment.default.message_for_disabled_enterprise - end - - should 'not show message for disabled enterprise to non-enterprises' do - login_as(@profile.identifier) - @profile.enabled = false; @profile.save! - get :view_page, :profile => @profile.identifier, :page => [] - assert_no_tag :tag => 'div', :attributes => { :id => 'profile-disabled' }, :content => Environment.default.message_for_disabled_enterprise - end - - should 'not show message for disabled enterprise if there is a block for it' do - login_as(@profile.identifier) - ent = fast_create(Enterprise, :name => 'my test enterprise', :identifier => 'my-test-enterprise', :enabled => false) - ent.boxes << Box.new - ent.boxes[0].blocks << DisabledEnterpriseMessageBlock.new - ent.save - get :view_page, :profile => ent.identifier, :page => [] - assert_no_tag :tag => 'div', :attributes => {:id => 'article'}, :descendant => { :tag => 'div', :attributes => { :id => 'profile-disabled' }} - end - should 'load the correct profile when using hosted domain' do profile = create_user('mytestuser').person profile.domains << Domain.create!(:name => 'micojones.net') diff --git a/test/functional/tasks_controller_test.rb b/test/functional/tasks_controller_test.rb index 763c2ee..4a14e5e 100644 --- a/test/functional/tasks_controller_test.rb +++ b/test/functional/tasks_controller_test.rb @@ -155,7 +155,8 @@ class TasksControllerTest < Test::Unit::TestCase should 'create published article after finish approve article task' do PublishedArticle.destroy_all - c = Community.create!(:name => 'test comm', :moderated_articles => false) + c = fast_create(Community) + c.update_attributes(:moderated_articles => false) @controller.stubs(:profile).returns(c) c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') @@ -167,7 +168,8 @@ class TasksControllerTest < Test::Unit::TestCase should 'create published article in folder after finish approve article task' do PublishedArticle.destroy_all - c = Community.create!(:name => 'test comm', :moderated_articles => false) + c = fast_create(Community) + c.update_attributes(:moderated_articles => false) @controller.stubs(:profile).returns(c) folder = c.articles.create!(:name => 'test folder', :type => 'Folder') c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) @@ -180,7 +182,8 @@ class TasksControllerTest < Test::Unit::TestCase should 'be highlighted if asked when approving a published article' do PublishedArticle.destroy_all - c = Community.create!(:name => 'test comm', :moderated_articles => false) + c = fast_create(Community) + c.update_attributes(:moderated_articles => false) @controller.stubs(:profile).returns(c) folder = c.articles.create!(:name => 'test folder', :type => 'Folder') c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) @@ -193,7 +196,8 @@ class TasksControllerTest < Test::Unit::TestCase should 'create published article after choosing root folder on approve article task' do PublishedArticle.destroy_all - c = Community.create!(:name => 'test comm', :moderated_articles => false) + c = fast_create(Community) + c.update_attributes(:moderated_articles => false) @controller.stubs(:profile).returns(c) c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') @@ -204,7 +208,7 @@ class TasksControllerTest < Test::Unit::TestCase end should 'handle blank names for published articles' do - c = Community.create!(:name => 'test comm') + c = fast_create(Community) @controller.stubs(:profile).returns(c) c.affiliate(profile, Profile::Roles.all_roles(c.environment)) person = create_user('test_user').person diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index a7181ed..c9f0c61 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -27,22 +27,17 @@ class CommunityTest < Test::Unit::TestCase should 'create default set of blocks' do c = Community.create!(:environment => Environment.default, :name => 'my new community') - assert c.boxes[0].blocks.map(&:class).include?(MainBlock) - - assert c.boxes[1].blocks.map(&:class).include?(ProfileInfoBlock) - assert c.boxes[1].blocks.map(&:class).include?(RecentDocumentsBlock) - - assert c.boxes[2].blocks.map(&:class).include?(MembersBlock) - assert c.boxes[2].blocks.map(&:class).include?(TagsBlock) - - assert_equal 5, c.blocks.size + assert !c.boxes[0].blocks.empty?, 'person must have blocks in area 1' + assert !c.boxes[1].blocks.empty?, 'person must have blocks in area 2' + assert !c.boxes[2].blocks.empty?, 'person must have blocks in area 3' end - should 'get a default home page and RSS feed' do + should 'create a default set of articles' do + Community.any_instance.stubs(:default_set_of_articles).returns([Blog.new(:name => 'blog')]) community = Community.create!(:environment => Environment.default, :name => 'my new community') - assert_kind_of Article, community.home_page - assert_kind_of RssFeed, community.articles.find_by_path('feed') + assert_kind_of Blog, community.articles.find_by_path('blog') + assert_kind_of RssFeed, community.articles.find_by_path('blog/feed') end should 'have contact_person' do diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index a7b580b..3b7e9e2 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -59,25 +59,20 @@ class EnterpriseTest < Test::Unit::TestCase end end - should 'get a default homepage and RSS feed' do + should 'create a default set of articles' do + Enterprise.any_instance.expects(:default_set_of_articles).returns([Blog.new(:name => 'Blog')]) enterprise = Enterprise.create!(:name => 'my test enterprise', :identifier => 'myenterprise') - assert_kind_of Article, enterprise.home_page - assert_kind_of RssFeed, enterprise.articles.find_by_path('feed') + assert_kind_of Blog, enterprise.articles.find_by_path('blog') + assert_kind_of RssFeed, enterprise.articles.find_by_path('blog/feed') end should 'create default set of blocks' do e = Enterprise.create(:name => 'my new community', :identifier => 'mynewcommunity') - assert e.boxes[0].blocks.map(&:class).include?(MainBlock), 'enterprise must have a MainBlock upon creation' - - assert e.boxes[1].blocks.map(&:class).include?(ProfileInfoBlock), 'enterprise must have a ProfileInfoBlock upon creation' - assert e.boxes[1].blocks.map(&:class).include?(MembersBlock), 'enterprise must have a MembersBlock upon creation' - - assert e.boxes[2].blocks.map(&:class).include?(RecentDocumentsBlock), 'enterprise must have a RecentDocumentsBlock upon creation' - assert e.boxes[2].blocks.map(&:class).include?(ProductsBlock), 'enterprise must have a ProductsBlock upon creation' - - assert_equal 5, e.blocks.size + assert !e.boxes[0].blocks.empty?, 'person must have blocks in area 1' + assert !e.boxes[1].blocks.empty?, 'person must have blocks in area 2' + assert !e.boxes[2].blocks.empty?, 'person must have blocks in area 3' end should 'be found in search for its product categories' do @@ -252,11 +247,6 @@ class EnterpriseTest < Test::Unit::TestCase assert_equal [p.category_full_name], ent.product_categories end - should 'default home page is a EnterpriseHomepage' do - enterprise = Enterprise.create!(:name => 'my test enterprise', :identifier => 'myenterprise') - assert_kind_of EnterpriseHomepage, enterprise.home_page - end - should 'not create a products block for enterprise if environment do not let' do env = Environment.default env.enable('disable_products_for_enterprises') diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 1bef6b0..a044c86 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -173,27 +173,29 @@ class PersonTest < Test::Unit::TestCase assert !person.is_admin?(env2) end - should 'get a default home page and a RSS feed' do + should 'create a default set of articles' do + Person.any_instance.stubs(:default_set_of_articles).returns([Blog.new(:name => 'blog')]) person = create_user_full('mytestuser').person - assert_kind_of Article, person.home_page - assert_kind_of RssFeed, person.articles.find_by_path('feed') + assert_kind_of Blog, person.articles.find_by_path('blog') + assert_kind_of RssFeed, person.articles.find_by_path('blog/feed') end - should 'create default set of blocks' do + should 'create a default set of blocks' do p = create_user_full('testingblocks').person - assert p.boxes[0].blocks.map(&:class).include?(MainBlock), 'person must have a MainBlock upon creation' - - assert p.boxes[1].blocks.map(&:class).include?(ProfileInfoBlock), 'person must have a ProfileInfoBlock upon creation' - assert p.boxes[1].blocks.map(&:class).include?(RecentDocumentsBlock), 'person must have a RecentDocumentsBlock upon creation' - assert p.boxes[1].blocks.map(&:class).include?(TagsBlock), 'person must have a Tags Block upon creation' - - assert p.boxes[2].blocks.map(&:class).include?(CommunitiesBlock), 'person must have a CommunitiesBlock upon creation' - assert p.boxes[2].blocks.map(&:class).include?(EnterprisesBlock), 'person must have a EnterprisesBlock upon creation' - assert p.boxes[2].blocks.map(&:class).include?(FriendsBlock), 'person must have a FriendsBlock upon creation' + assert !p.boxes[0].blocks.empty?, 'person must have blocks in area 1' + assert !p.boxes[1].blocks.empty?, 'person must have blocks in area 2' + assert !p.boxes[2].blocks.empty?, 'person must have blocks in area 3' + end - assert_equal 7, p.blocks.size + should 'link to all articles created by default' do + p = create_user_full('testingblocks').person + blocks = p.blocks.select { |b| b.is_a?(LinkListBlock) } + p.articles.reject { |a| a.is_a?(RssFeed) }.each do |article| + path = '/' + p.identifier + '/' + article.path + assert blocks.any? { |b| b.links.any? { |link| b.expand_address(link[:address]) == path }}, "#{path.inspect} must be linked by at least one of the blocks: #{blocks.inspect}" + end end should 'have friends' do diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index e9ba7de..2d9e36a 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -73,8 +73,8 @@ class ProfileTest < Test::Unit::TestCase end should 'provide access to home page' do - profile = create(Profile) - assert_kind_of Article, profile.home_page + profile = Profile.new + assert_nil profile.home_page end def test_name_should_be_mandatory @@ -335,13 +335,6 @@ class ProfileTest < Test::Unit::TestCase assert_equal false, Profile.new.has_members? end - should 'create a homepage and a feed on creation' do - profile = create(Profile) - - assert_kind_of Article, profile.home_page - assert_kind_of RssFeed, profile.articles.find_by_path('feed') - end - should 'not allow to add members' do c = fast_create(Profile) p = create_user('mytestuser').person @@ -429,26 +422,21 @@ class ProfileTest < Test::Unit::TestCase assert_equal [p3,p2], Profile.recent(2) end - should 'advertise false to homepage and feed on creation' do + should 'not advertise articles created together with the profile' do + Profile.any_instance.stubs(:default_set_of_articles).returns([Article.new(:name => 'home'), RssFeed.new(:name => 'feed')]) profile = create(Profile) - assert !profile.home_page.advertise? + assert !profile.articles.find_by_path('home').advertise? assert !profile.articles.find_by_path('feed').advertise? end - should 'advertise true to homepage after update' do + should 'advertise article after update' do + Profile.any_instance.stubs(:default_set_of_articles).returns([Article.new(:name => 'home')]) profile = create(Profile) - assert !profile.home_page.advertise? - profile.home_page.name = 'Changed name' - assert profile.home_page.save! - assert profile.home_page.advertise? - end - - should 'advertise true to feed after update' do - profile = create(Profile) - assert !profile.articles.find_by_path('feed').advertise? - profile.articles.find_by_path('feed').name = 'Changed name' - assert profile.articles.find_by_path('feed').save! - assert profile.articles.find_by_path('feed').advertise? + article = profile.articles.find_by_path('home') + assert !article.advertise? + article.name = 'Changed name' + article.save! + assert article.advertise? end should 'have latitude and longitude' do @@ -774,11 +762,6 @@ class ProfileTest < Test::Unit::TestCase end end - should 'default home page is a TinyMceArticle' do - profile = create(Profile) - assert_kind_of TinyMceArticle, profile.home_page - end - should 'not add a category twice to profile' do c1 = fast_create(Category) c2 = fast_create(Category, :parent_id => c1.id) @@ -923,14 +906,6 @@ class ProfileTest < Test::Unit::TestCase assert !p2.public? end - should 'create a initial private folder when a public profile is created' do - p1 = create(Profile) - p2 = create(Profile, :public_profile => false) - - assert p1.articles.find(:first, :conditions => {:published => false}) - assert !p2.articles.find(:first, :conditions => {:published => false}) - end - should 'remove member with many roles' do person = create_user('test_user').person community = fast_create(Community) -- libgit2 0.21.2