From 2c1493ff8c707e121e6512973e2973ba4aeaa53d Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Tue, 23 Oct 2007 22:12:59 +0000 Subject: [PATCH] ActionItem114: fixed some tests --- app/controllers/application.rb | 12 ++++++++---- app/controllers/profile_admin/profile_editor_controller.rb | 2 +- app/controllers/profile_admin_controller.rb | 2 +- app/controllers/public/content_viewer_controller.rb | 2 +- app/helpers/application_helper.rb | 2 +- app/models/person.rb | 6 ------ app/models/profile.rb | 12 +----------- app/views/layouts/not_found.rhtml | 11 +++++++++++ lib/authenticated_test_helper.rb | 2 +- test/functional/categories_controller_test.rb | 6 +++++- test/functional/content_viewer_controller_test.rb | 13 +++++++++---- test/functional/features_controller_test.rb | 6 +++--- test/functional/membership_editor_controller_test.rb | 2 -- test/test_helper.rb | 7 +++++++ 14 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 app/views/layouts/not_found.rhtml diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 02ef848..dd868b1 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -34,13 +34,17 @@ class ApplicationController < ActionController::Base def self.needs_profile before_filter :load_profile - design :holder => 'profile' + design :holder => 'profile' end def load_profile - @profile = Profile.find_by_identifier(params[:profile]) - @profile ||= Profile.find(:first) #FIXME This is not correct it was made to the system don't crash - raise "The profile must be loaded %s" % params[:profile].to_s if @profile.nil? + @profile = Profile.find_by_identifier(params[:profile]) + render_not_found(request.path) unless @profile + end + + def render_not_found(path) + @path = path + render :file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404 end def self.acts_as_environment_admin_controller diff --git a/app/controllers/profile_admin/profile_editor_controller.rb b/app/controllers/profile_admin/profile_editor_controller.rb index 6f24301..59d9259 100644 --- a/app/controllers/profile_admin/profile_editor_controller.rb +++ b/app/controllers/profile_admin/profile_editor_controller.rb @@ -5,7 +5,7 @@ class ProfileEditorController < ProfileAdminController design_editor :holder => 'profile', :autosave => true, :block_types => :block_types - protect [:edit], 'edit_profile', :profile + protect [:index, :edit], 'edit_profile', :profile def block_types { diff --git a/app/controllers/profile_admin_controller.rb b/app/controllers/profile_admin_controller.rb index e08d798..fbeac79 100644 --- a/app/controllers/profile_admin_controller.rb +++ b/app/controllers/profile_admin_controller.rb @@ -13,7 +13,7 @@ class ProfileAdminController < ApplicationController before_filter do |controller| unless controller.profile.kind_of?(some_class) controller.instance_variable_set('@message', _("This action is not available for \"%s\".") % controller.profile.name) - controller.render :file => 'app/views/shared/access_denied.rhtml' , :layout => true, :status => 403 + controller.render :file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'access_denied.rhtml'), :layout => true, :status => 403 end end end diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index f99aa15..d4bc834 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -8,7 +8,7 @@ class ContentViewerController < PublicController @path = path.join('/') @page = Article.find_by_path(@path) if @page.nil? - render :action => 'not_found', :status => 404 + render_not_found(@path) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c955914..092b3fe 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -139,7 +139,7 @@ module ApplicationHelper [ accessibility_link, ( link_to content_tag('span', _('Login')), :controller => 'account', :action => 'login'), ] - end + end.join(" ") end def header diff --git a/app/models/person.rb b/app/models/person.rb index d9ca38e..5308aa5 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -8,12 +8,6 @@ class Person < Profile # has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' has_one :person_info -# has_many :role_assignments, :as => :accessor, :class_name => 'RoleAssignment' - -# def has_permission?(perm, res=nil) -# return true if res == self && PERMISSIONS[:profile].keys.include?(perm) -# role_assignments.any? {|ra| ra.has_permission?(perm, res)} -# end def self.conditions_for_profiles(conditions, person) new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person]) diff --git a/app/models/profile.rb b/app/models/profile.rb index 03666f1..f55e406 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -43,6 +43,7 @@ class Profile < ActiveRecord::Base community test search + not_found ] acts_as_taggable @@ -132,15 +133,4 @@ class Profile < ActiveRecord::Base def superior_instance environment end - -# def affiliate(person, roles) -# roles = [roles] unless roles.kind_of?(Array) -# roles.map do |role| -# unless RoleAssignment.find(:first, :conditions => {:person_id => person, :role_id => role, :resource_id => self, :resource_type => self.class.base_class.name}) -# RoleAssignment.new(:person => person, :role => role, :resource => self).save -# else -# false -# end -# end.any? -# end end diff --git a/app/views/layouts/not_found.rhtml b/app/views/layouts/not_found.rhtml new file mode 100644 index 0000000..3a50aa0 --- /dev/null +++ b/app/views/layouts/not_found.rhtml @@ -0,0 +1,11 @@ + + + + + <%= _('Page not found') %> + + + + <%= yield %> + + diff --git a/lib/authenticated_test_helper.rb b/lib/authenticated_test_helper.rb index 6ab4b17..7685258 100644 --- a/lib/authenticated_test_helper.rb +++ b/lib/authenticated_test_helper.rb @@ -1,7 +1,7 @@ module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) - @request.session[:user] = user ? users(user).id : nil + @request.session[:user] = User.find_by_login(user.to_s) end def content_type(type) diff --git a/test/functional/categories_controller_test.rb b/test/functional/categories_controller_test.rb index a8eb1bf..734b563 100644 --- a/test/functional/categories_controller_test.rb +++ b/test/functional/categories_controller_test.rb @@ -15,13 +15,17 @@ class CategoriesControllerTest < Test::Unit::TestCase Environment.stubs(:default).returns(env) assert (@cat1 = env.categories.create(:name => 'a test category')) assert (@cat1 = env.categories.create(:name => 'another category')) - login_as(:ze) + login_as(create_admin_user(@env)) end all_fixtures attr_reader :env, :cat1, :cat2 def test_index + assert user = login_as(create_admin_user(Environment.default)) + assert user.person.has_permission?('manage_environment_categories',Environment.default ), "#{user.login} don't have permission to manage_environment_categories in #{Environment.default.name}" get :index + assert_response :success + assert_template 'index' assert_kind_of Array, assigns(:categories) assert_tag :tag => 'a', :attributes => { :href => '/admin/categories/new'} end diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index be1de8b..8f61c3f 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -28,16 +28,21 @@ class ContentViewerControllerTest < Test::Unit::TestCase def test_should_get_not_found_error_for_unexisting_page uses_host 'anhetegua.net' get :view_page, :profile => 'aprofile', :page => ['some_unexisting_page'] - assert_response :redirect - assert_redirected_to :controller => 'search', :action => 'index' + assert_response :missing + # This is an idea of instead of give an error search for the term +# assert_response :redirect +# assert_redirected_to :controller => 'search', :action => 'index' end def test_should_get_not_found_error_for_unexisting_profile Profile.delete_all uses_host 'anhetegua' get :view_page, :profile => 'some_unexisting_profile', :page => [] - assert_response :redirect - assert_redirected_to :controller => 'search', :action => 'index' + assert_response :missing + + # This is an idea of instead of give an error search for the term +# assert_response :redirect +# assert_redirected_to :controller => 'search', :action => 'index' end end diff --git a/test/functional/features_controller_test.rb b/test/functional/features_controller_test.rb index fb8dfd4..e214344 100644 --- a/test/functional/features_controller_test.rb +++ b/test/functional/features_controller_test.rb @@ -6,14 +6,14 @@ class FeaturesController; def rescue_action(e) raise e end; end class FeaturesControllerTest < Test::Unit::TestCase - fixtures :environments, :domains - + all_fixtures def setup @controller = FeaturesController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + login_as(create_admin_user(Environment.find(2))) end - + def test_listing_features uses_host 'anhetegua.net' get :index diff --git a/test/functional/membership_editor_controller_test.rb b/test/functional/membership_editor_controller_test.rb index baf6d65..bb8df48 100644 --- a/test/functional/membership_editor_controller_test.rb +++ b/test/functional/membership_editor_controller_test.rb @@ -21,8 +21,6 @@ class MembershipEditorControllerTest < Test::Unit::TestCase should 'prompt for new enterprise data' do get :new_enterprise, :profile => 'ze' - assert assigns(:virtual_communities) - assert_kind_of Array, assigns(:virtual_communities) assert assigns(:validation_entities) assert_kind_of Array, assigns(:validation_entities) end diff --git a/test/test_helper.rb b/test/test_helper.rb index fb91117..3a6ab20 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -64,6 +64,13 @@ class Test::Unit::TestCase raise "profile_identifier must be set!" unless extra_parameters[:profile] end + def create_admin_user(env) + admin_user = User.find_by_login('root') || User.create!(:login => 'root', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root') + admin_role = Role.find_by_name('admin_role') || Role.create!(:name => 'admin_role', :permissions => ['view_environment_admin_panel','edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators']) + RoleAssignment.create!(:accessor => admin_user.person, :role => admin_role, :resource => env) unless admin_user.person.role_assignments.map{|ra|[ra.role, ra.accessor, ra.resource]}.include?([admin_role, admin_user, env]) + admin_user.login + end + private def uses_host(name) -- libgit2 0.21.2