diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb index 28eef4e..0698de6 100644 --- a/app/controllers/admin/admin_panel_controller.rb +++ b/app/controllers/admin/admin_panel_controller.rb @@ -40,7 +40,7 @@ class AdminPanelController < AdminController end redirect_to :action => 'set_portal_folders' else - flash[:notice] = __('Community not found. You must insert the identifier of a community from this environment') + session[:notice] = __('Community not found. You must insert the identifier of a community from this environment') end end end @@ -54,7 +54,7 @@ class AdminPanelController < AdminController folders = params[:folders].map{|fid| Folder.find(:first, :conditions => {:profile_id => env.portal_community, :id => fid})} if params[:folders] env.portal_folders = folders if env.save - flash[:notice] = _('Saved the portal folders') + session[:notice] = _('Saved the portal folders') redirect_to :action => 'set_portal_news_amount' end end @@ -63,7 +63,7 @@ class AdminPanelController < AdminController def set_portal_news_amount if request.post? if @environment.update_attributes(params[:environment]) - flash[:notice] = _('Saved the number of news on folders') + session[:notice] = _('Saved the number of news on folders') redirect_to :action => 'index' end end diff --git a/app/controllers/admin/environment_role_manager_controller.rb b/app/controllers/admin/environment_role_manager_controller.rb index e79c09a..6de4887 100644 --- a/app/controllers/admin/environment_role_manager_controller.rb +++ b/app/controllers/admin/environment_role_manager_controller.rb @@ -14,9 +14,9 @@ class EnvironmentRoleManagerController < AdminController @roles = params[:roles] ? Role.find(params[:roles]) : [] @person = Person.find(params[:person]) if @person.define_roles(@roles, environment) - flash[:notice] = _('Roles successfuly updated') + session[:notice] = _('Roles successfuly updated') else - flash[:notice] = _('Couldn\'t change the roles') + session[:notice] = _('Couldn\'t change the roles') end redirect_to :action => :index end @@ -42,9 +42,9 @@ class EnvironmentRoleManagerController < AdminController def remove_role @association = RoleAssignment.find(params[:id]) if @association.destroy - flash[:notice] = _('Member succefully unassociated') + session[:notice] = _('Member succefully unassociated') else - flash[:notice] = _('Failed to unassociate member') + session[:notice] = _('Failed to unassociate member') end redirect_to :aciton => 'index' end @@ -52,9 +52,9 @@ class EnvironmentRoleManagerController < AdminController def unassociate @association = RoleAssignment.find(params[:id]) if @association.destroy - flash[:notice] = _('Member succefully unassociated') + session[:notice] = _('Member succefully unassociated') else - flash[:notice] = _('Failed to unassociate member') + session[:notice] = _('Failed to unassociate member') end redirect_to :aciton => 'index' end diff --git a/app/controllers/admin/features_controller.rb b/app/controllers/admin/features_controller.rb index 1fc7f2b..c2aadae 100644 --- a/app/controllers/admin/features_controller.rb +++ b/app/controllers/admin/features_controller.rb @@ -8,7 +8,7 @@ class FeaturesController < AdminController post_only :update def update if @environment.update_attributes(params[:environment]) - flash[:notice] = _('Features updated successfully.') + session[:notice] = _('Features updated successfully.') redirect_to :action => 'index' else render :action => 'index' @@ -24,7 +24,7 @@ class FeaturesController < AdminController def manage_person_fields environment.custom_person_fields = params[:person_fields] if environment.save! - flash[:notice] = _('Person fields updated successfully.') + session[:notice] = _('Person fields updated successfully.') else flash[:error] = _('Person fields not updated successfully.') end @@ -34,7 +34,7 @@ class FeaturesController < AdminController def manage_enterprise_fields environment.custom_enterprise_fields = params[:enterprise_fields] if environment.save! - flash[:notice] = __('Enterprise fields updated successfully.') + session[:notice] = __('Enterprise fields updated successfully.') else flash[:error] = __('Enterprise fields not updated successfully.') end @@ -44,7 +44,7 @@ class FeaturesController < AdminController def manage_community_fields environment.custom_community_fields = params[:community_fields] if environment.save! - flash[:notice] = _('Community fields updated successfully.') + session[:notice] = _('Community fields updated successfully.') else flash[:error] = _('Community fields not updated successfully.') end diff --git a/app/controllers/admin/role_controller.rb b/app/controllers/admin/role_controller.rb index 51aec16..55319b4 100644 --- a/app/controllers/admin/role_controller.rb +++ b/app/controllers/admin/role_controller.rb @@ -19,7 +19,7 @@ class RoleController < AdminController if @role.save redirect_to :action => 'show', :id => @role else - flash[:notice] = _('Failed to create role') + session[:notice] = _('Failed to create role') render :action => 'new' end end @@ -33,7 +33,7 @@ class RoleController < AdminController if @role.update_attributes(params[:role]) redirect_to :action => 'show', :id => @role else - flash[:notice] = _('Failed to edit role') + session[:notice] = _('Failed to edit role') render :action => 'edit' end end @@ -43,7 +43,7 @@ class RoleController < AdminController if @role.destroy redirect_to :action => 'index' else - flash[:notice] = _('Failed to edit role') + session[:notice] = _('Failed to edit role') redirect_to :action => 'index' end end diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb index 30bec03..563b5e9 100644 --- a/app/controllers/box_organizer_controller.rb +++ b/app/controllers/box_organizer_controller.rb @@ -96,7 +96,7 @@ class BoxOrganizerController < ApplicationController expire_timeout_fragment(@block.cache_keys) redirect_to :action => 'index' else - flash[:notice] = _('Failed to remove block') + session[:notice] = _('Failed to remove block') end end diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 9d29e4f..d5ae455 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -143,7 +143,7 @@ class CmsController < MyProfileController @article = profile.articles.find(params[:id]) profile.home_page = @article profile.save(false) - flash[:notice] = _('"%s" configured as home page.') % @article.name + session[:notice] = _('"%s" configured as home page.') % @article.name redirect_to :action => 'view', :id => @article.id end @@ -232,7 +232,7 @@ class CmsController < MyProfileController end end if @failed.blank? - flash[:notice] = _("Your publish request was sent successfully") + session[:notice] = _("Your publish request was sent successfully") if @back_to redirect_to @back_to else diff --git a/app/controllers/my_profile/friends_controller.rb b/app/controllers/my_profile/friends_controller.rb index 93a401f..3eb0774 100644 --- a/app/controllers/my_profile/friends_controller.rb +++ b/app/controllers/my_profile/friends_controller.rb @@ -14,7 +14,7 @@ class FriendsController < MyProfileController # FIXME this shouldn't be in Person model? AddFriend.create!(:person => profile, :friend => @friend, :group_for_person => params[:group]) - flash[:notice] = _('%s still needs to accept being your friend.') % @friend.name + session[:notice] = _('%s still needs to accept being your friend.') % @friend.name # FIXME shouldn't redirect to the friend's page? redirect_to :action => 'index' end diff --git a/app/controllers/my_profile/mailconf_controller.rb b/app/controllers/my_profile/mailconf_controller.rb index 1c6e24f..df29905 100644 --- a/app/controllers/my_profile/mailconf_controller.rb +++ b/app/controllers/my_profile/mailconf_controller.rb @@ -20,20 +20,20 @@ class MailconfController < MyProfileController @task = EmailActivation.new(:target => environment, :requestor => profile) begin @task.save! - flash[:notice] = _('Please fill your personal information below in order to get your mailbox approved by one of the administrators') + session[:notice] = _('Please fill your personal information below in order to get your mailbox approved by one of the administrators') redirect_to :controller => 'profile_editor', :action => 'edit' rescue Exception => ex - flash[:notice] = _('e-Mail was not enabled successfully.') + session[:notice] = _('e-Mail was not enabled successfully.') render :action => 'index' end end post_only :disable def disable if profile.user.disable_email! - flash[:notice] = _('e-Mail disabled successfully.') + session[:notice] = _('e-Mail disabled successfully.') redirect_to :controller => 'profile_editor' else - flash[:notice] = _('e-Mail was not disabled successfully.') + session[:notice] = _('e-Mail was not disabled successfully.') redirect_to :action => 'index' end end diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb index 15d4632..d462fe1 100644 --- a/app/controllers/my_profile/manage_products_controller.rb +++ b/app/controllers/my_profile/manage_products_controller.rb @@ -43,7 +43,7 @@ class ManageProductsController < ApplicationController @level = 0 if request.post? if @product.save - flash[:notice] = _('Product succesfully created') + session[:notice] = _('Product succesfully created') render :partial => 'shared/redirect_via_javascript', :locals => { :url => url_for(:controller => 'manage_products', :action => 'show', :id => @product) } else @@ -101,10 +101,10 @@ class ManageProductsController < ApplicationController def destroy @product = @profile.products.find(params[:id]) if @product.destroy - flash[:notice] = _('Product succesfully removed') + session[:notice] = _('Product succesfully removed') redirect_back_or_default :action => 'index' else - flash[:notice] = _('Could not remove the product') + session[:notice] = _('Could not remove the product') redirect_back_or_default :action => 'show', :id => @product end end diff --git a/app/controllers/my_profile/maps_controller.rb b/app/controllers/my_profile/maps_controller.rb index dec4ec3..dccbca4 100644 --- a/app/controllers/my_profile/maps_controller.rb +++ b/app/controllers/my_profile/maps_controller.rb @@ -8,7 +8,7 @@ class MapsController < MyProfileController begin Profile.transaction do if profile.update_attributes!(params[:profile_data]) - flash[:notice] = _('Address was updated successfully!') + session[:notice] = _('Address was updated successfully!') redirect_to :action => 'edit_location' end end diff --git a/app/controllers/my_profile/memberships_controller.rb b/app/controllers/my_profile/memberships_controller.rb index b19841f..e9f8683 100644 --- a/app/controllers/my_profile/memberships_controller.rb +++ b/app/controllers/my_profile/memberships_controller.rb @@ -29,7 +29,7 @@ class MembershipsController < MyProfileController @community = Community.find(params[:id]) if request.post? if @community.destroy - flash[:notice] = _('%s was removed.') % @community.short_name + session[:notice] = _('%s was removed.') % @community.short_name redirect_to :action => 'index' end end diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index f30e017..7c194ba 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -25,7 +25,7 @@ class ProfileEditorController < MyProfileController if profile.identifier.blank? profile.identifier = params[:profile] end - flash[:notice] = _('Cannot update profile') + session[:notice] = _('Cannot update profile') end end end @@ -34,7 +34,7 @@ class ProfileEditorController < MyProfileController @to_enable = profile if request.post? && params[:confirmation] unless @to_enable.update_attribute('enabled', true) - flash[:notice] = _('%s was not enabled.') % @to_enable.name + session[:notice] = _('%s was not enabled.') % @to_enable.name end redirect_to :action => 'index' end @@ -44,7 +44,7 @@ class ProfileEditorController < MyProfileController @to_disable = profile if request.post? && params[:confirmation] unless @to_disable.update_attribute('enabled', false) - flash[:notice] = _('%s was not disabled.') % @to_disable.name + session[:notice] = _('%s was not disabled.') % @to_disable.name end redirect_to :action => 'index' end diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb index 38ac8d6..227848c 100644 --- a/app/controllers/my_profile/profile_members_controller.rb +++ b/app/controllers/my_profile/profile_members_controller.rb @@ -12,9 +12,9 @@ class ProfileMembersController < MyProfileController @roles = @roles.select{|r| r.has_kind?('Profile') } @person = profile.members.find { |m| m.id == params[:person].to_i } if @person && @person.define_roles(@roles, profile) - flash[:notice] = _('Roles successfuly updated') + session[:notice] = _('Roles successfuly updated') else - flash[:notice] = _('Couldn\'t change the roles') + session[:notice] = _('Couldn\'t change the roles') end redirect_to :action => :index end @@ -44,9 +44,9 @@ class ProfileMembersController < MyProfileController def remove_role @association = RoleAssignment.find(:all, :conditions => {:id => params[:id], :target_id => profile.id}) if @association.destroy - flash[:notice] = 'Member succefully unassociated' + session[:notice] = 'Member succefully unassociated' else - flash[:notice] = 'Failed to unassociate member' + session[:notice] = 'Failed to unassociate member' end render :layout => false end @@ -56,9 +56,9 @@ class ProfileMembersController < MyProfileController associations = member.find_roles(profile) RoleAssignment.transaction do if associations.map(&:destroy) - flash[:notice] = 'Member succefully unassociated' + session[:notice] = 'Member succefully unassociated' else - flash[:notice] = 'Failed to unassociate member' + session[:notice] = 'Failed to unassociate member' end end render :layout => false diff --git a/app/controllers/my_profile/tasks_controller.rb b/app/controllers/my_profile/tasks_controller.rb index 62dde55..ad2bada 100644 --- a/app/controllers/my_profile/tasks_controller.rb +++ b/app/controllers/my_profile/tasks_controller.rb @@ -20,7 +20,7 @@ class TasksController < MyProfileController begin task.send(decision) rescue Exception => ex - flash[:notice] = ex.clean_message + session[:notice] = ex.clean_message end end redirect_to :action => 'index' diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index ab71b27..5b0e39a 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -30,10 +30,10 @@ class AccountController < ApplicationController end if redirect? go_to_initial_page - flash[:notice] = _("Logged in successfully") + session[:notice] = _("Logged in successfully") end else - flash[:notice] = _('Incorrect username or password') if redirect? + session[:notice] = _('Incorrect username or password') if redirect? redirect_to :back if redirect? end end @@ -70,7 +70,7 @@ class AccountController < ApplicationController invitation.update_attributes!({:friend => @user.person}) invitation.finish end - flash[:notice] = _("Thanks for signing up!") + session[:notice] = _("Thanks for signing up!") if @wizard redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true return @@ -109,7 +109,7 @@ class AccountController < ApplicationController end cookies.delete :auth_token reset_session - flash[:notice] = _("You have been logged out.") + session[:notice] = _("You have been logged out.") redirect_to :controller => 'home', :action => 'index' end @@ -120,10 +120,10 @@ class AccountController < ApplicationController @user.change_password!(params[:current_password], params[:new_password], params[:new_password_confirmation]) - flash[:notice] = _('Your password has been changed successfully!') + session[:notice] = _('Your password has been changed successfully!') redirect_to :action => 'index' rescue User::IncorrectPassword => e - flash[:notice] = _('The supplied current password is incorrect.') + session[:notice] = _('The supplied current password is incorrect.') render :action => 'change_password' end else @@ -235,6 +235,21 @@ class AccountController < ApplicationController render :partial => 'identifier_status' end + def user_data + user_data = + if logged_in? + { "login" => current_user.login, "is_admin" => user.is_admin?(environment), 'since_month' => user.created_at.month, 'since_year' => user.created_at.year } + else + { } + end + if session[:notice] + user_data['notice'] = session[:notice] + session[:notice] = nil # consume the notice + end + + render :text => user_data.to_json, :layout => false, :content_type => "application/javascript" + end + protected def redirect? diff --git a/app/controllers/public/contact_controller.rb b/app/controllers/public/contact_controller.rb index 2379375..d7a58eb 100644 --- a/app/controllers/public/contact_controller.rb +++ b/app/controllers/public/contact_controller.rb @@ -12,10 +12,10 @@ class ContactController < PublicController @contact.city = (!params[:city].blank? && City.exists?(params[:city])) ? City.find(params[:city]).name : nil @contact.state = (!params[:state].blank? && State.exists?(params[:state])) ? State.find(params[:state]).name : nil if @contact.deliver - flash[:notice] = _('Contact successfully sent') + session[:notice] = _('Contact successfully sent') redirect_to :action => 'new' else - flash[:notice] = _('Contact not sent') + session[:notice] = _('Contact not sent') end else @contact = user.build_contact(profile) diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index dcf55cc..02a0946 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -110,7 +110,7 @@ class ContentViewerController < ApplicationController @comment = @page.comments.find(params[:remove_comment]) if (user == @comment.author || user == @page.profile || user.has_permission?(:moderate_comments, @page.profile)) @comment.destroy - flash[:notice] = _('Comment succesfully deleted') + session[:notice] = _('Comment succesfully deleted') end redirect_to :action => 'view_page', :profile => params[:profile], :page => @page.explode_path, :view => params[:view] end diff --git a/app/controllers/public/invite_controller.rb b/app/controllers/public/invite_controller.rb index 450d13e..4a3f64e 100644 --- a/app/controllers/public/invite_controller.rb +++ b/app/controllers/public/invite_controller.rb @@ -22,7 +22,7 @@ class InviteController < PublicController flash.now[:notice] = _('<url> is needed in invitation mail.') elsif !contacts_to_invite.empty? Invitation.invite(current_user.person, contacts_to_invite, params[:mail_template], profile) - flash[:notice] = _('Your invitations have been sent.') + session[:notice] = _('Your invitations have been sent.') if profile.person? redirect_to :controller => 'friends' else diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 000a69c..740eb49 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -76,7 +76,7 @@ class ProfileController < PublicController @wizard = params[:wizard] if request.post? && params[:confirmation] profile.add_member(current_user.person) - flash[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? + session[:notice] = _('%s administrator still needs to accept you as member.') % profile.name if profile.closed? if @wizard redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true else @@ -84,7 +84,7 @@ class ProfileController < PublicController end else if current_user.person.memberships.include?(profile) - flash[:notice] = _('You are already a member of "%s"') % profile.name + session[:notice] = _('You are already a member of "%s"') % profile.name redirect_to profile.url return end @@ -129,7 +129,7 @@ class ProfileController < PublicController def unblock if current_user.person.is_admin?(profile.environment) profile.unblock - flash[:notice] = _("You have unblocked %s successfully. ") % profile.name + session[:notice] = _("You have unblocked %s successfully. ") % profile.name redirect_to :controller => 'profile', :action => 'index' else message = __('You are not allowed to unblock enterprises in this environment.') diff --git a/app/models/environment.rb b/app/models/environment.rb index 45538fd..3575f3f 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -643,5 +643,9 @@ class Environment < ActiveRecord::Base Product.find(:all, {:conditions => {:highlighted => true, :enterprise_id => self.enterprises.find(:all, :select => :id) }, :joins => :image}.merge(options)) end + settings_items :home_cache_in_minutes, :type => :integer, :default => 5 + settings_items :general_cache_in_minutes, :type => :integer, :default => 15 + settings_items :profile_cache_in_minutes, :type => :integer, :default => 15 + end diff --git a/app/models/login_block.rb b/app/models/login_block.rb index 3d7b40c..9c16390 100644 --- a/app/models/login_block.rb +++ b/app/models/login_block.rb @@ -10,11 +10,7 @@ class LoginBlock < Block def content lambda do - if logged_in? - render :file => 'account/user_info' - else - render :file => 'account/login_block' - end + render :file => 'blocks/login_block' end end diff --git a/app/views/account/login_block.rhtml b/app/views/account/login_block.rhtml index 845e470..31ee47b 100644 --- a/app/views/account/login_block.rhtml +++ b/app/views/account/login_block.rhtml @@ -6,7 +6,7 @@
<% - @user = User.new if ! @user + @user ||= User.new %> <% labelled_form_for :user, @user, diff --git a/app/views/account/user_info.rhtml b/app/views/account/user_info.rhtml deleted file mode 100644 index cf12b13..0000000 --- a/app/views/account/user_info.rhtml +++ /dev/null @@ -1,16 +0,0 @@ -
- -

<%= _('Logged in as %s') % user.identifier %>

- - - - - -
diff --git a/app/views/blocks/login_block.rhtml b/app/views/blocks/login_block.rhtml new file mode 100644 index 0000000..25c639d --- /dev/null +++ b/app/views/blocks/login_block.rhtml @@ -0,0 +1,13 @@ + + diff --git a/app/views/cms/media_listing.rhtml b/app/views/cms/media_listing.rhtml index 331f375..df547f0 100644 --- a/app/views/cms/media_listing.rhtml +++ b/app/views/cms/media_listing.rhtml @@ -33,7 +33,7 @@ diff --git a/app/views/layouts/application-ng.rhtml b/app/views/layouts/application-ng.rhtml index 8e1312a..75183fd 100644 --- a/app/views/layouts/application-ng.rhtml +++ b/app/views/layouts/application-ng.rhtml @@ -41,24 +41,18 @@
- <% if logged_in? %> - <%= _('Welcome, %s.') % link_to('' + user.identifier + '', user.url, :id => "homepage-link", :title => _('Go to your homepage')) %> - <% if user.is_admin?(environment) %> - <%= link_to('' + _('Administration') + '', { :controller => 'admin_panel', :action => 'index' }, :id => "controlpanel", :title => _("Configure the environment")) %> - <% end %> - <% if (user.environment == environment) %> - <%= link_to('' + _('Control panel') + '', user.admin_url, :id => "controlpanel", :title => _("Configure your personal account and content")) %> - <% end %> + +
- <%= flash[:notice] %> - <%= javascript_tag( - visual_effect( :appear, 'notice', :duration => 1.5, :to => 0.8, :queue => :end ) + - 'setTimeout(function() { %s }, 5000)' % visual_effect( :fade, 'notice', :duration => 1.0, :from => 0.8, :queue => :end ) - ) %> -
- <% end %> - <% if is_testing_theme %> <%= render :file => 'shared/theme_test_panel' %> <% end %> diff --git a/db/schema.rb b/db/schema.rb index 5792443..38e865b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20100730141134) do +ActiveRecord::Schema.define(:version => 20100811211216) do create_table "article_versions", :force => true do |t| t.integer "article_id" diff --git a/features/blog.feature b/features/blog.feature index f7a680b..b9cbae6 100644 --- a/features/blog.feature +++ b/features/blog.feature @@ -10,7 +10,7 @@ Feature: blog And I am logged in as "joaosilva" Scenario: create a blog - Given I follow "Control panel" + Given I go to the Control panel And I follow "Create blog" Then I should see "My Blog" When I fill in "Title" with "My Blog" @@ -19,7 +19,7 @@ Feature: blog Then I should see "Configure blog" Scenario: redirect to blog after create blog from control panel - Given I follow "Control panel" + Given I go to the Control panel And I follow "Create blog" Then I should see "My Blog" When I fill in "Title" with "My Blog" @@ -27,7 +27,7 @@ Feature: blog Then I should be on /joaosilva/my-blog Scenario: redirect to blog after create blog from cms - Given I follow "Control panel" + Given I go to the Control panel And I follow "Manage Content" When I follow "New Blog" And I fill in "Title" with "Blog from cms" @@ -35,12 +35,12 @@ Feature: blog Then I should be on /joaosilva/blog-from-cms Scenario: create multiple blogs - Given I follow "Control panel" + Given I go to the Control panel And I follow "Manage Content" And I follow "New Blog" And I fill in "Title" with "Blog One" And I press "Save" - Then I follow "Control panel" + Then I go to the Control panel And I follow "Manage Content" And I follow "New Blog" And I fill in "Title" with "Blog Two" @@ -49,16 +49,16 @@ Feature: blog And I should be on /joaosilva/blog-two Scenario: cancel button back to cms - Given I follow "Control panel" + Given I go to the Control panel And I follow "Manage Content" And I follow "New Blog" - When I follow "Cancel" + When I follow "Cancel" within ".main-block" Then I should be on /myprofile/joaosilva/cms Scenario: cancel button back to myprofile - Given I follow "Control panel" + Given I go to the Control panel And I follow "Create blog" - When I follow "Cancel" + When I follow "Cancel" within ".main-block" Then I should be on /myprofile/joaosilva Scenario: configure blog link to cms @@ -66,7 +66,7 @@ Feature: blog | owner | name | | joaosilva | Blog One | | joaosilva | Blog Two | - And I follow "Control panel" + And I go to the Control panel When I follow "Configure blog" Then I should be on /myprofile/joaosilva/cms @@ -74,7 +74,7 @@ Feature: blog Given the following blogs | owner | name | | joaosilva | Blog One | - And I follow "Control panel" + And I go to the Control panel When I follow "Configure blog" Then I should be on edit "Blog One" by joaosilva @@ -82,7 +82,7 @@ Feature: blog Given the following blogs | owner | name | | joaosilva | Blog One | - And I follow "Control panel" + And I go to the Control panel And I follow "Configure blog" And I fill in "Address" with "blog-two" And I press "Save" @@ -90,7 +90,7 @@ Feature: blog Then I should see "Blog One" Scenario: display tag list field when creating new blog - Given I follow "Control panel" + Given I go to the Control panel And I follow "Manage Content" When I follow "New blog" Then I should see "Tag list" diff --git a/features/create_community.feature b/features/create_community.feature index 2c588e1..9de12c2 100644 --- a/features/create_community.feature +++ b/features/create_community.feature @@ -11,7 +11,7 @@ Feature: create community Scenario: a user creates a community Given I am logged in as "joaosilva" And feature "admin_must_approve_new_communities" is disabled on environment - And I follow "Control panel" + And I go to the Control panel And I follow "Manage my groups" When I follow "Create a new community" And I fill in "Name" with "Fancy community" @@ -21,7 +21,7 @@ Feature: create community Scenario: a user creates a community when environment moderates it Given I am logged in as "joaosilva" And feature "admin_must_approve_new_communities" is enabled on environment - When I follow "Control panel" + When I go to the Control panel And I follow "Manage my groups" And I follow "Create a new community" And I fill in "Name" with "Community for moderation" @@ -31,7 +31,7 @@ Feature: create community Scenario: a user tries to create a community without a name Given I am logged in as "joaosilva" And feature "admin_must_approve_new_communities" is disabled on environment - And I follow "Control panel" + And I go to the Control panel And I follow "Manage my groups" When I follow "Create a new community" And I press "Create" @@ -41,20 +41,20 @@ Feature: create community Given I am logged in as admin And feature "admin_must_approve_new_communities" is enabled on environment When I create community "Community for approval" - And I follow "Control Panel" + And I go to the Control panel Then I should see "admin_user wants to create community Community for approval" Scenario: environment admin accepts new community task Given I am logged in as admin And feature "admin_must_approve_new_communities" is enabled on environment When I create community "Community for approval" - And I follow "Control Panel" + And I go to the Control panel And I follow "Process requests" And I should see "admin_user wants to create community Community for approval" And I choose "Approve" When I press "Ok!" Then I should not see "admin_user wants to create community Community for approval" - When I follow "Control panel" + When I go to the Control panel And I follow "Manage my groups" Then I should see "Community for approval" @@ -62,13 +62,13 @@ Feature: create community Given I am logged in as admin And feature "admin_must_approve_new_communities" is enabled on environment When I create community "Community for approval" - And I follow "Control Panel" + And I go to the Control panel And I follow "Process requests" And I should see "admin_user wants to create community Community for approval" And I choose "Reject" When I press "Ok!" Then I should not see "admin_user wants to create community Community for approval" - When I follow "Control panel" + When I go to the Control panel And I follow "Manage my groups" Then I should not see "Community for approval" @@ -77,7 +77,7 @@ Feature: create community And feature "admin_must_approve_new_communities" is enabled on environment When I create community "Community for approval" And I approve community "Community for approval" - When I follow "Control panel" + When I go to the Control panel And I follow "Manage my groups" Then I should see "Community for approval" @@ -86,7 +86,7 @@ Feature: create community And feature "admin_must_approve_new_communities" is enabled on environment When I create community "Community for approval" And I reject community "Community for approval" - When I follow "Control panel" + When I go to the Control panel And I follow "Manage my groups" Then I should not see "Community for approval" diff --git a/features/edit_article.feature b/features/edit_article.feature index b60bd33..53a94b9 100644 --- a/features/edit_article.feature +++ b/features/edit_article.feature @@ -31,27 +31,27 @@ Feature: edit article And I should be on /joaosilva/my-folder Scenario: cancel button back to cms - Given I follow "Control panel" + Given I go to the Control panel And I follow "Manage Content" And I follow "New Folder" - When I follow "Cancel" + When I follow "Cancel" within ".main-block" Then I should be on Joao Silva's cms Scenario: display tag list field when creating event - Given I follow "Control panel" + Given I go to the Control panel And I follow "Manage Content" And I follow "New article" When I follow "Event" Then I should see "Tag list" Scenario: display tag list field when creating folder - Given I follow "Control panel" + Given I go to the Control panel And I follow "Manage Content" When I follow "New folder" Then I should see "Tag list" Scenario: create new article with tags - Given I follow "Control panel" + Given I go to the Control panel And I follow "Manage Content" And I follow "New article" When I follow "Text article with Textile markup language" @@ -85,7 +85,7 @@ Feature: edit article Given I am on Joao Silva's sitemap And I follow "Save the whales" And I follow "Edit" - When I follow "Cancel" + When I follow "Cancel" within ".main-block" Then I should be on /joaosilva/save-the-whales Scenario: create an article inside a folder @@ -111,6 +111,6 @@ Feature: edit article Then I should be on /joaosilva/my-folder When I follow "New article" And I follow "Text article with visual editor" - When I follow "Cancel" + When I follow "Cancel" within ".no-boxes" And I should be on /joaosilva/my-folder diff --git a/features/http_caching.feature b/features/http_caching.feature new file mode 100644 index 0000000..f3ad1bc --- /dev/null +++ b/features/http_caching.feature @@ -0,0 +1,60 @@ +Feature: HTTP caching + + As a sysdamin + I want Noosfero to provide appropriate cache headers + So that Varnish can serve content from the cache, everything works faster and everyone is happy + + Background: + Given the following user + | login | name | + | joao | João Silva | + + Scenario: home page, default configuration + When I go to the homepage + Then the response should be valid for 5 minutes + And the cache should be public + + Scenario: home page, custom configuration + Given the following environment configuration + | home_cache_in_minutes | 10 | + When I go to the homepage + Then the response should be valid for 10 minutes + + Scenario: search results, default configuration + Given I am on the search page + When I fill in "query" with "anything" + And I press "Search" + Then the response should be valid for 15 minutes + + Scenario: search results, custom configuration + Given the following environment configuration + | general_cache_in_minutes | 90 | + When I go to the search page + And I fill in "query" with "anything" + And I press "Search" + Then the response should be valid for 90 minutes + + Scenario: profile pages, default configuaration + When I go to João Silva's homepage + Then the response should be valid for 15 minutes + + Scenario: profile pages, custom configuration + Given the following environment configuration + | profile_cache_in_minutes | 90 | + When I go to João Silva's homepage + Then the response should be valid for 90 minutes + + Scenario: account controller should not be cached at all + When I go to /account/login + Then there must be no cache at all + + Scenario: profile administration + Given I am logged in as "joao" + When I go to João Silva's control panel + Then there must be no cache at all + + Scenario: environment administration + Given I am logged in as admin + When I go to /admin + Then there must be no cache at all + diff --git a/features/invitation.feature b/features/invitation.feature index 46b124d..6f39b01 100644 --- a/features/invitation.feature +++ b/features/invitation.feature @@ -92,32 +92,32 @@ Feature: invitation And I fill in "mail_template" with "Follow this link " And I press "Invite my friends!" When I am logged in as "josesantos" - And I follow "Control Panel" + And I go to the Control panel And I should see "josesilva invites you to join the community 26 Bsslines." Scenario: noosfero user accepts to join community Given I invite email "santos@invalid.br" to join community "26 Bsslines" When I am logged in as "josesantos" - And I follow "Control panel" + And I go to the Control panel And I follow "Process requests" And I should see "josesilva invites you to join the community 26 Bsslines." And I choose "Accept" When I press "Ok!" Then I should not see "josesilva invites you to join the community 26 Bsslines." - When I follow "Control panel" + When I go to the Control panel And I follow "Manage my groups" Then I should see "26 Bsslines" Scenario: noosfero user rejects to join community Given I invite email "santos@invalid.br" to join community "26 Bsslines" When I am logged in as "josesantos" - And I follow "Control panel" + And I go to the Control panel And I follow "Process requests" And I should see "josesilva invites you to join the community 26 Bsslines." And I choose "Reject" When I press "Ok!" Then I should not see "josesilva invites you to join the community 26 Bsslines." - When I follow "Control panel" + When I go to the Control panel And I follow "Manage my groups" Then I should not see "26 Bsslines" @@ -130,31 +130,31 @@ Feature: invitation And I fill in "mail_template" with "Follow this link " And I press "Invite my friends!" When I am logged in as "josesantos" - And I follow "Control Panel" + And I go to the Control panel And I should see "josesilva wants to be your friend." Scenario: noosfero user accepts to be friend Given I invite email "santos@invalid.br" to be my friend When I am logged in as "josesantos" - And I follow "Control panel" + And I go to the Control panel And I follow "Process requests" And I should see "josesilva wants to be your friend." And I choose "Accept" When I press "Ok!" And I should not see "josesilva wants to be your friend." - When I follow "Control panel" + When I go to the Control panel And I follow "Manage friends" Then I should see "josesilva" Scenario: noosfero user rejects to be friend Given I invite email "santos@invalid.br" to be my friend When I am logged in as "josesantos" - And I follow "Control panel" + And I go to the Control panel And I follow "Process requests" And I should see "josesilva wants to be your friend." And I choose "Ignore" When I press "Ok!" And I should not see "josesilva wants to be your friend." - When I follow "Control panel" + When I go to the Control panel And I follow "Manage friends" Then I should not see "josesilva" diff --git a/features/join_community.feature b/features/join_community.feature index 53b1ec9..a55b4d8 100644 --- a/features/join_community.feature +++ b/features/join_community.feature @@ -48,7 +48,7 @@ Feature: join a community And I go to Sample Community's homepage And I press "Yes" And I follow "New user" - And I fill in the following: + And I fill in the following within ".no-boxes": | e-mail | jose@domain.br | | Username | joseoliveira | | Password | 123456 | diff --git a/features/location.feature b/features/location.feature index a99fb1f..18c84ef 100644 --- a/features/location.feature +++ b/features/location.feature @@ -16,7 +16,7 @@ Feature: Location | state | | city | | zip_code | - And I follow "Control panel" + And I go to the Control panel And I follow "Location" When I fill in "Address" with "Rua Marechal Floriano, 28" And I select "Brazil" from "Country" diff --git a/features/organization_custom_fields.feature b/features/organization_custom_fields.feature index 26ab78a..fc467d1 100644 --- a/features/organization_custom_fields.feature +++ b/features/organization_custom_fields.feature @@ -9,7 +9,7 @@ Feature: organization custom fields | joaosilva | Joao Silva | And I am logged in as "joaosilva" And feature "enterprise_registration" is enabled on environment - And I follow "Control panel" + And I go to the Control panel Scenario Outline: organization active fields are not displayed on creation Given the following fields are active fields diff --git a/features/publish_article.feature b/features/publish_article.feature index f824ee4..d9dbf5a 100644 --- a/features/publish_article.feature +++ b/features/publish_article.feature @@ -110,9 +110,11 @@ Feature: publish article And I am on Sample Community's control panel And I follow "Tasks" And I press "Ok!" - And I should not see "The title (article name) is already being used by another article, please use another title." - When I press "Ok!" - Then I should see "The title (article name) is already being used by another article, please use another title." + And I press "Ok!" + Then I should see "wants to publish" + When I fill in "Name for publishing" with "other title" + And I press "Ok!" + Then I should not see "wants to publish" Scenario: ask to publish an article that was deleted before approval Given I am logged in as "joaosilva" diff --git a/features/register_enterprise.feature b/features/register_enterprise.feature index f906388..e81bb70 100644 --- a/features/register_enterprise.feature +++ b/features/register_enterprise.feature @@ -92,7 +92,7 @@ Feature: register enterprise And I press "Next" Then I should see "Enterprise registration completed" And I am logged in as admin - And I follow "Control panel" + And I go to the Control panel When I follow "Tasks" Then I should see /Processing task: Enterprise registration: "My Enterprise"/ And the first mail is to admin_user@example.com @@ -118,7 +118,7 @@ Feature: register enterprise And I press "Next" Then I should see "Enterprise registration completed" And I am logged in as admin - And I follow "Control panel" + And I go to the Control panel When I follow "Tasks" Then I should see /Processing task: Enterprise registration: "My Enterprise"/ And the first mail is to admin_user@example.com diff --git a/features/session_and_cookies_handling.feature b/features/session_and_cookies_handling.feature new file mode 100644 index 0000000..d01cd31 --- /dev/null +++ b/features/session_and_cookies_handling.feature @@ -0,0 +1,22 @@ +Feature: session and cookies handling + + As a Noosfero system administrator + I want Noosfero to manage well it usage of sessions and cookies + So that we can use HTTP caching effectively + + Scenario: home page, logged in + Given the following users + | login | + | joaosilva | + When I am logged in as "joaosilva" + And I go to the homepage + Then there must be a cookie "_noosfero_session" + + Scenario: home page, not logged in + When I go to the homepage + Then there must be no cookies + + Scenario: logout + Given I am logged in as "joao" + When I go to /logout + Then there must be a cookie "auth_token" diff --git a/features/signup.feature b/features/signup.feature index cb57856..43e49b0 100644 --- a/features/signup.feature +++ b/features/signup.feature @@ -7,13 +7,14 @@ Feature: signup Given I am on the homepage When I follow "Login" And I follow "New user" - And I fill in "e-Mail" with "josesilva@example.com" - And I fill in "Username" with "josesilva" - And I fill in "Password" with "secret" - And I fill in "Password confirmation" with "secret" - And I fill in "Name" with "José da Silva" + And I fill in the following within ".no-boxes": + | e-Mail | josesilva@example.com | + | Username | josesilva | + | Password | secret | + | Password confirmation | secret | + | Name | José da Silva | And I press "Sign up" - Then I should see "Thanks for signing up!" + Then I should be logged in as "josesilva" Scenario: be redirected if user goes to signup page and is logged Given the following users diff --git a/features/step_definitions/create_community_steps.rb b/features/step_definitions/create_community_steps.rb index 0f06e06..82c36d3 100644 --- a/features/step_definitions/create_community_steps.rb +++ b/features/step_definitions/create_community_steps.rb @@ -1,5 +1,5 @@ Given /^I create community "(.+)"$/ do |community| - click_link('Control panel') + Given 'I go to the Control panel' click_link('Manage my groups') click_link('Create a new community') fill_in("Name", :with => community) @@ -8,7 +8,7 @@ end Given /^I approve community "(.+)"$/ do |community| task = CreateCommunity.all.select {|c| c.name == community}.first - click_link('Control Panel') + Given 'I go to the Control panel' click_link('Process requests') choose("decision-finish-#{task.id}") click_button('OK!') @@ -16,7 +16,7 @@ end Given /^I reject community "(.+)"$/ do |community| task = CreateCommunity.all.select {|c| c.name == community}.first - click_link('Control Panel') + Given 'I go to the Control panel' click_link('Process requests') choose("decision-cancel-#{task.id}") click_button('OK!') diff --git a/features/step_definitions/custom_webrat_steps.rb b/features/step_definitions/custom_webrat_steps.rb index 7035954..019ca1f 100644 --- a/features/step_definitions/custom_webrat_steps.rb +++ b/features/step_definitions/custom_webrat_steps.rb @@ -18,3 +18,15 @@ When /^I select "([^\"]*)"$/ do |value| selenium.wait_for_ajax end end + +When /^I fill in the following within "([^\"]*)":$/ do |parent, fields| + fields.rows_hash.each do |name, value| + When %{I fill in "#{name}" with "#{value}" within "#{parent}"} + end +end + +When /^I fill in "([^\"]*)" with "([^\"]*)" within "([^\"]*)"$/ do |field, value, parent| + within(parent) do |content| + content.fill_in(field, :with => value) + end +end diff --git a/features/step_definitions/http_caching_steps.rb b/features/step_definitions/http_caching_steps.rb new file mode 100644 index 0000000..e08d3cf --- /dev/null +++ b/features/step_definitions/http_caching_steps.rb @@ -0,0 +1,21 @@ +Then /^the response should be valid for (.+) minutes$/ do |n| + response.headers['Cache-Control'].split(/,\s*/).should include("max-age=#{n.to_i * 60}") +end + +Then /^the cache should be public/ do + response.headers['Cache-Control'].split(/,\s*/).should include("public") +end + +Then /^there must be no cache at all$/ do + parts = response.headers['Cache-Control'].split(/,\s*/) + parts.should include('must-revalidate') + parts.should include('max-age=0') +end + +Then 'there must be no cookies' do + cookies.should == {} +end + +Then /^there must be a cookie "(.+)"$/ do |cookie_name| + cookies.keys.should include(cookie_name) +end diff --git a/features/step_definitions/invitation_steps.rb b/features/step_definitions/invitation_steps.rb index 7dabb97..e81f0bd 100644 --- a/features/step_definitions/invitation_steps.rb +++ b/features/step_definitions/invitation_steps.rb @@ -9,7 +9,7 @@ Given /^I invite email "(.+)" to join community "(.+)"$/ do |email, community| end Given /^I invite email "(.+)" to be my friend$/ do |email| - click_link('Control panel') + Given "I go to the Control panel" click_link('Manage friends') click_link('Invite people from my e-mail contacts') click_button('Next') diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index 291403a..52e2825 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -231,3 +231,15 @@ Given /^the (.+) mail (.+) is like (.+)$/ do |position, field, regexp| re =~ ActionMailer::Base.deliveries.send(position)[field.to_sym] end end + +Given /^the following environment configuration$/ do |table| + env = Environment.default + table.raw.each do |item| + env.send("#{item[0]}=", item[1]) + end + env.save +end + +Then /^I should be logged in as "(.+)"$/ do |login| + User.find(session[:user]).login.should == login +end diff --git a/features/support/paths.rb b/features/support/paths.rb index 3d196f8..a8cced1 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -42,6 +42,9 @@ module NavigationHelpers when /^(.*)'s control panel$/ '/myprofile/%s' % Profile.find_by_name($1).identifier + when /^the Control panel$/ + '/myprofile/%s' % User.find_by_id(session[:user]).login + when /^the search page$/ '/search' diff --git a/features/tags.feature b/features/tags.feature index ff92901..30f7e94 100644 --- a/features/tags.feature +++ b/features/tags.feature @@ -22,7 +22,7 @@ Feature: tags Scenario: viewing a single tag When I go to /tag - And I follow "environment" + And I follow "environment" within ".no-boxes" Then I should see "save the whales" And I should see "the Amazon is being destroyed" diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 3c5b4a2..179a039 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -263,3 +263,27 @@ jQuery(document).ready(function() { jQuery('body').click(function() { hideAllSubmenus(); }); jQuery('.menu-submenu-trigger').click(function(e) { e.stopPropagation(); }); }); + +// controls the display of the login/logout stuff +jQuery(function($) { + $.getJSON('/account/user_data', function(data) { + if (data.login) { + // logged in + $('#user .logged-in, .login-block .logged-user-info').each(function() { + $(this).find('a[href]').each(function() { + $(this).attr('href', $(this).attr('href').replace('%{login}', data.login)) + }); + var html = $(this).html().replace('%{login}', data.login).replace('%{month}', data.since_month).replace('%{year}', data.since_year); + $(this).html(html).fadeIn(); + }); + } else { + // not logged in + $('#user .not-logged-in, .login-block .not-logged-user').fadeIn(); + } + if (data.notice) { + var $noticeBox = $('
').html(data.notice).appendTo('body').fadeTo('fast', 0.8); + $noticeBox.click(function() { $(this).hide(); }); + setTimeout(function() { $noticeBox.fadeOut('fast'); }, 5000); + } + }); +}); diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 42ab059..2199302 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -2342,6 +2342,10 @@ div#activation_enterprise div { margin: auto; } +.login-block { + min-height: 100px; +} + .login-block .login-box { } diff --git a/test/functional/features_controller_test.rb b/test/functional/features_controller_test.rb index afc6b5f..1ce4315 100644 --- a/test/functional/features_controller_test.rb +++ b/test/functional/features_controller_test.rb @@ -36,7 +36,7 @@ class FeaturesControllerTest < Test::Unit::TestCase uses_host 'anhetegua.net' post :update, :environment => { :enabled_features => [ 'feature1', 'feature2' ] } assert_redirected_to :action => 'index' - assert_kind_of String, flash[:notice] + assert_kind_of String, session[:notice] v = Environment.find(environments(:anhetegua_net).id) assert v.enabled?('feature2') assert v.enabled?('feature2') @@ -47,7 +47,7 @@ class FeaturesControllerTest < Test::Unit::TestCase uses_host 'anhetegua.net' post :update # no features assert_redirected_to :action => 'index' - assert_kind_of String, flash[:notice] + assert_kind_of String, session[:notice] v = Environment.find(environments(:anhetegua_net).id) assert !v.enabled?('feature1') assert !v.enabled?('feature2') @@ -64,7 +64,7 @@ class FeaturesControllerTest < Test::Unit::TestCase uses_host 'anhetegua.net' post :update, :environment => { :organization_approval_method => 'region' } assert_redirected_to :action => 'index' - assert_kind_of String, flash[:notice] + assert_kind_of String, session[:notice] v = Environment.find(environments(:anhetegua_net).id) assert_equal :region, v.organization_approval_method end diff --git a/test/functional/mailconf_controller_test.rb b/test/functional/mailconf_controller_test.rb index 5d5e4a5..50b53c2 100644 --- a/test/functional/mailconf_controller_test.rb +++ b/test/functional/mailconf_controller_test.rb @@ -112,7 +112,7 @@ class MailconfControllerTest < Test::Unit::TestCase should 'display notice after saving' do login_as('ze') post :enable, :profile => 'ze' - assert_kind_of String, flash[:notice] + assert_kind_of String, session[:notice] end should 'link back to control panel' do diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 7c33326..5b91ca5 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -183,7 +183,7 @@ class ProfileControllerTest < Test::Unit::TestCase community = Community.create!(:name => 'my test community') community.add_admin(@profile) get :index, :profile => community.identifier - assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/#{@profile.identifier}/ }, :content => 'Control panel' + assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/%\{login\}/ }, :content => 'Control panel' end should 'show create community in own profile' do diff --git a/test/functional/role_controller_test.rb b/test/functional/role_controller_test.rb index 4dbce9c..9ab2fcd 100644 --- a/test/functional/role_controller_test.rb +++ b/test/functional/role_controller_test.rb @@ -42,7 +42,7 @@ class RoleControllerTest < Test::Unit::TestCase Role.any_instance.stubs(:valid?).returns(true) post 'create' assert !assigns(:role).new_record? - assert_nil flash[:notice] + assert_nil session[:notice] assert_response :redirect end @@ -50,7 +50,7 @@ class RoleControllerTest < Test::Unit::TestCase Role.any_instance.stubs(:valid?).returns(false) post 'create' assert assigns(:role).new_record? - assert_not_nil flash[:notice] + assert_not_nil session[:notice] assert_response :success end @@ -65,7 +65,7 @@ class RoleControllerTest < Test::Unit::TestCase post 'update', :id => @role.id assert_response :redirect assert_not_nil assigns(:role) - assert_nil flash[:notice] + assert_nil session[:notice] end def test_should_not_update_to_invalid_paramters @@ -73,7 +73,7 @@ class RoleControllerTest < Test::Unit::TestCase post 'update', :id => @role.id assert_response :success assert_not_nil assigns(:role) - assert_not_nil flash[:notice] + assert_not_nil session[:notice] end def test_should_destroy diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index aecc31c..2e8ce4c 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -1005,4 +1005,73 @@ class EnvironmentTest < Test::Unit::TestCase assert_not_includes env.users, user_from_other_environment end + should 'provide cache time for home page' do + env = Environment.new + assert env.respond_to?(:home_cache_in_minutes) + end + + should 'store cache time for home page' do + env = Environment.new(:home_cache_in_minutes => 99) + assert_equal 99, env.home_cache_in_minutes + end + + should 'retrieve cache time for home page' do + env = fast_create(Environment) + env.home_cache_in_minutes = 33 + env.save! + + assert_equal 33, Environment.find(env.id).home_cache_in_minutes + end + + should 'cache home page for 5 minutes by default' do + env = Environment.new + assert_equal 5, env.home_cache_in_minutes + end + + should 'provide cache time for general content' do + env = Environment.new + assert env.respond_to?(:general_cache_in_minutes) + end + + should 'store cache time for general content' do + env = Environment.new(:general_cache_in_minutes => 99) + assert_equal 99, env.general_cache_in_minutes + end + + should 'retrieve cache time for general content' do + env = fast_create(Environment) + env.general_cache_in_minutes = 33 + env.save! + + assert_equal 33, Environment.find(env.id).general_cache_in_minutes + end + + should 'cache general content for 15 minutes by default' do + env = Environment.new + assert_equal 15, env.general_cache_in_minutes + end + + should 'provide cache time for profile content' do + env = Environment.new + assert env.respond_to?(:profile_cache_in_minutes) + end + + should 'store cache time for profile content' do + env = Environment.new(:profile_cache_in_minutes => 99) + assert_equal 99, env.profile_cache_in_minutes + end + + should 'retrieve cache time for profile content' do + env = fast_create(Environment) + env.profile_cache_in_minutes = 33 + env.save! + + assert_equal 33, Environment.find(env.id).profile_cache_in_minutes + end + + should 'cache profile content for 15 minutes by default' do + env = Environment.new + assert_equal 15, env.profile_cache_in_minutes + end + end diff --git a/test/unit/login_block_test.rb b/test/unit/login_block_test.rb index 43cdd1a..d9bd25a 100644 --- a/test/unit/login_block_test.rb +++ b/test/unit/login_block_test.rb @@ -11,16 +11,4 @@ class LoginBlockTest < Test::Unit::TestCase assert_not_equal Block.description, LoginBlock.description end - should 'point to account/login_block' do - self.expects(:logged_in?).returns(false) - self.expects(:render).with(:file => 'account/login_block') - self.instance_eval(& block.content) - end - - should 'display user_info if not logged' do - self.expects(:logged_in?).returns(true) - self.expects(:render).with(:file => 'account/user_info') - self.instance_eval(& block.content) - end - end diff --git a/vendor/plugins/noosfero_caching/init.rb b/vendor/plugins/noosfero_caching/init.rb new file mode 100644 index 0000000..9dc7e67 --- /dev/null +++ b/vendor/plugins/noosfero_caching/init.rb @@ -0,0 +1,65 @@ +module NoosferoHttpCaching + + def self.included(c) + c.send(:after_filter, :noosfero_set_cache) + c.send(:before_filter, :noosfero_session_check_before) + c.send(:after_filter, :noosfero_session_check_after) + end + + def noosfero_set_cache + n = nil + if profile + unless request.path =~ /^\/myprofile/ + n = environment.profile_cache_in_minutes + end + else + if request.path == '/' + n = environment.home_cache_in_minutes + else + if params[:controller] != 'account' && request.path !~ /^\/admin/ + n = environment.general_cache_in_minutes + end + end + end + if n + expires_in n.minutes, :private => false, :public => true + end + end + + def noosfero_session_check_before + return if params[:controller] == 'account' + headers["X-Noosfero-Auth"] = (session[:user] != nil).to_s + end + + def noosfero_session_check_after + if headers['X-Noosfero-Auth'] == 'true' + # special case: logout + if !session[:user] + session.delete + end + else + # special case: login + if session[:user] + headers['X-Noosfero-Auth'] = 'true' + end + end + end + +end + +class ActionController::CgiResponse + + def out_with_noosfero_session_check(output = $stdout) + if headers['X-Noosfero-Auth'] == 'false' + @cgi.send(:instance_variable_set, '@output_cookies', nil) + end + headers.delete('X-Noosfero-Auth') + out_without_noosfero_session_check(output) + end + alias_method_chain :out, :noosfero_session_check + +end + +if Rails.env != 'development' + ActionController::Base.send(:include, NoosferoHttpCaching) +end -- libgit2 0.21.2