Commit 2c1493ff8c707e121e6512973e2973ba4aeaa53d
1 parent
d25daf44
Exists in
master
and in
22 other branches
ActionItem114: fixed some tests
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@818 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
14 changed files
with
49 additions
and
36 deletions
Show diff stats
app/controllers/application.rb
| ... | ... | @@ -34,13 +34,17 @@ class ApplicationController < ActionController::Base |
| 34 | 34 | |
| 35 | 35 | def self.needs_profile |
| 36 | 36 | before_filter :load_profile |
| 37 | - design :holder => 'profile' | |
| 37 | + design :holder => 'profile' | |
| 38 | 38 | end |
| 39 | 39 | |
| 40 | 40 | def load_profile |
| 41 | - @profile = Profile.find_by_identifier(params[:profile]) | |
| 42 | - @profile ||= Profile.find(:first) #FIXME This is not correct it was made to the system don't crash | |
| 43 | - raise "The profile must be loaded %s" % params[:profile].to_s if @profile.nil? | |
| 41 | + @profile = Profile.find_by_identifier(params[:profile]) | |
| 42 | + render_not_found(request.path) unless @profile | |
| 43 | + end | |
| 44 | + | |
| 45 | + def render_not_found(path) | |
| 46 | + @path = path | |
| 47 | + render :file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404 | |
| 44 | 48 | end |
| 45 | 49 | |
| 46 | 50 | def self.acts_as_environment_admin_controller | ... | ... |
app/controllers/profile_admin/profile_editor_controller.rb
| ... | ... | @@ -5,7 +5,7 @@ class ProfileEditorController < ProfileAdminController |
| 5 | 5 | |
| 6 | 6 | design_editor :holder => 'profile', :autosave => true, :block_types => :block_types |
| 7 | 7 | |
| 8 | - protect [:edit], 'edit_profile', :profile | |
| 8 | + protect [:index, :edit], 'edit_profile', :profile | |
| 9 | 9 | |
| 10 | 10 | def block_types |
| 11 | 11 | { | ... | ... |
app/controllers/profile_admin_controller.rb
| ... | ... | @@ -13,7 +13,7 @@ class ProfileAdminController < ApplicationController |
| 13 | 13 | before_filter do |controller| |
| 14 | 14 | unless controller.profile.kind_of?(some_class) |
| 15 | 15 | controller.instance_variable_set('@message', _("This action is not available for \"%s\".") % controller.profile.name) |
| 16 | - controller.render :file => 'app/views/shared/access_denied.rhtml' , :layout => true, :status => 403 | |
| 16 | + controller.render :file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'access_denied.rhtml'), :layout => true, :status => 403 | |
| 17 | 17 | end |
| 18 | 18 | end |
| 19 | 19 | end | ... | ... |
app/controllers/public/content_viewer_controller.rb
app/helpers/application_helper.rb
app/models/person.rb
| ... | ... | @@ -8,12 +8,6 @@ class Person < Profile |
| 8 | 8 | # has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' |
| 9 | 9 | |
| 10 | 10 | has_one :person_info |
| 11 | -# has_many :role_assignments, :as => :accessor, :class_name => 'RoleAssignment' | |
| 12 | - | |
| 13 | -# def has_permission?(perm, res=nil) | |
| 14 | -# return true if res == self && PERMISSIONS[:profile].keys.include?(perm) | |
| 15 | -# role_assignments.any? {|ra| ra.has_permission?(perm, res)} | |
| 16 | -# end | |
| 17 | 11 | |
| 18 | 12 | def self.conditions_for_profiles(conditions, person) |
| 19 | 13 | new_conditions = sanitize_sql(['role_assignments.accessor_id = ?', person]) | ... | ... |
app/models/profile.rb
| ... | ... | @@ -43,6 +43,7 @@ class Profile < ActiveRecord::Base |
| 43 | 43 | community |
| 44 | 44 | test |
| 45 | 45 | search |
| 46 | + not_found | |
| 46 | 47 | ] |
| 47 | 48 | |
| 48 | 49 | acts_as_taggable |
| ... | ... | @@ -132,15 +133,4 @@ class Profile < ActiveRecord::Base |
| 132 | 133 | def superior_instance |
| 133 | 134 | environment |
| 134 | 135 | end |
| 135 | - | |
| 136 | -# def affiliate(person, roles) | |
| 137 | -# roles = [roles] unless roles.kind_of?(Array) | |
| 138 | -# roles.map do |role| | |
| 139 | -# unless RoleAssignment.find(:first, :conditions => {:person_id => person, :role_id => role, :resource_id => self, :resource_type => self.class.base_class.name}) | |
| 140 | -# RoleAssignment.new(:person => person, :role => role, :resource => self).save | |
| 141 | -# else | |
| 142 | -# false | |
| 143 | -# end | |
| 144 | -# end.any? | |
| 145 | -# end | |
| 146 | 136 | end | ... | ... |
lib/authenticated_test_helper.rb
test/functional/categories_controller_test.rb
| ... | ... | @@ -15,13 +15,17 @@ class CategoriesControllerTest < Test::Unit::TestCase |
| 15 | 15 | Environment.stubs(:default).returns(env) |
| 16 | 16 | assert (@cat1 = env.categories.create(:name => 'a test category')) |
| 17 | 17 | assert (@cat1 = env.categories.create(:name => 'another category')) |
| 18 | - login_as(:ze) | |
| 18 | + login_as(create_admin_user(@env)) | |
| 19 | 19 | end |
| 20 | 20 | all_fixtures |
| 21 | 21 | attr_reader :env, :cat1, :cat2 |
| 22 | 22 | |
| 23 | 23 | def test_index |
| 24 | + assert user = login_as(create_admin_user(Environment.default)) | |
| 25 | + assert user.person.has_permission?('manage_environment_categories',Environment.default ), "#{user.login} don't have permission to manage_environment_categories in #{Environment.default.name}" | |
| 24 | 26 | get :index |
| 27 | + assert_response :success | |
| 28 | + assert_template 'index' | |
| 25 | 29 | assert_kind_of Array, assigns(:categories) |
| 26 | 30 | assert_tag :tag => 'a', :attributes => { :href => '/admin/categories/new'} |
| 27 | 31 | end | ... | ... |
test/functional/content_viewer_controller_test.rb
| ... | ... | @@ -28,16 +28,21 @@ class ContentViewerControllerTest < Test::Unit::TestCase |
| 28 | 28 | def test_should_get_not_found_error_for_unexisting_page |
| 29 | 29 | uses_host 'anhetegua.net' |
| 30 | 30 | get :view_page, :profile => 'aprofile', :page => ['some_unexisting_page'] |
| 31 | - assert_response :redirect | |
| 32 | - assert_redirected_to :controller => 'search', :action => 'index' | |
| 31 | + assert_response :missing | |
| 32 | + # This is an idea of instead of give an error search for the term | |
| 33 | +# assert_response :redirect | |
| 34 | +# assert_redirected_to :controller => 'search', :action => 'index' | |
| 33 | 35 | end |
| 34 | 36 | |
| 35 | 37 | def test_should_get_not_found_error_for_unexisting_profile |
| 36 | 38 | Profile.delete_all |
| 37 | 39 | uses_host 'anhetegua' |
| 38 | 40 | get :view_page, :profile => 'some_unexisting_profile', :page => [] |
| 39 | - assert_response :redirect | |
| 40 | - assert_redirected_to :controller => 'search', :action => 'index' | |
| 41 | + assert_response :missing | |
| 42 | + | |
| 43 | + # This is an idea of instead of give an error search for the term | |
| 44 | +# assert_response :redirect | |
| 45 | +# assert_redirected_to :controller => 'search', :action => 'index' | |
| 41 | 46 | end |
| 42 | 47 | |
| 43 | 48 | end | ... | ... |
test/functional/features_controller_test.rb
| ... | ... | @@ -6,14 +6,14 @@ class FeaturesController; def rescue_action(e) raise e end; end |
| 6 | 6 | |
| 7 | 7 | class FeaturesControllerTest < Test::Unit::TestCase |
| 8 | 8 | |
| 9 | - fixtures :environments, :domains | |
| 10 | - | |
| 9 | + all_fixtures | |
| 11 | 10 | def setup |
| 12 | 11 | @controller = FeaturesController.new |
| 13 | 12 | @request = ActionController::TestRequest.new |
| 14 | 13 | @response = ActionController::TestResponse.new |
| 14 | + login_as(create_admin_user(Environment.find(2))) | |
| 15 | 15 | end |
| 16 | - | |
| 16 | + | |
| 17 | 17 | def test_listing_features |
| 18 | 18 | uses_host 'anhetegua.net' |
| 19 | 19 | get :index | ... | ... |
test/functional/membership_editor_controller_test.rb
| ... | ... | @@ -21,8 +21,6 @@ class MembershipEditorControllerTest < Test::Unit::TestCase |
| 21 | 21 | |
| 22 | 22 | should 'prompt for new enterprise data' do |
| 23 | 23 | get :new_enterprise, :profile => 'ze' |
| 24 | - assert assigns(:virtual_communities) | |
| 25 | - assert_kind_of Array, assigns(:virtual_communities) | |
| 26 | 24 | assert assigns(:validation_entities) |
| 27 | 25 | assert_kind_of Array, assigns(:validation_entities) |
| 28 | 26 | end | ... | ... |
test/test_helper.rb
| ... | ... | @@ -64,6 +64,13 @@ class Test::Unit::TestCase |
| 64 | 64 | raise "profile_identifier must be set!" unless extra_parameters[:profile] |
| 65 | 65 | end |
| 66 | 66 | |
| 67 | + def create_admin_user(env) | |
| 68 | + admin_user = User.find_by_login('root') || User.create!(:login => 'root', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root') | |
| 69 | + 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']) | |
| 70 | + 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]) | |
| 71 | + admin_user.login | |
| 72 | + end | |
| 73 | + | |
| 67 | 74 | private |
| 68 | 75 | |
| 69 | 76 | def uses_host(name) | ... | ... |