Commit d1b3f21894841bbdd5d0117a8477d39f52cf9e95

Authored by MoisesMachado
1 parent 11212b3f

ActionItem111: fixed some tests

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@749 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/person.rb
@@ -8,7 +8,7 @@ class Person < Profile @@ -8,7 +8,7 @@ class Person < Profile
8 # has_many :people, :through => :person_friendships, :foreign_key => 'friend_id' 8 # has_many :people, :through => :person_friendships, :foreign_key => 'friend_id'
9 9
10 has_one :person_info 10 has_one :person_info
11 -# has_many :role_assignments 11 +# has_many :role_assignments, :as => :accessor, :class_name => 'RoleAssignment'
12 12
13 # def has_permission?(perm, res=nil) 13 # def has_permission?(perm, res=nil)
14 # return true if res == self && PERMISSIONS[:profile].keys.include?(perm) 14 # return true if res == self && PERMISSIONS[:profile].keys.include?(perm)
script/populate
1 #!/usr/bin/env ruby 1 #!/usr/bin/env ruby
2 require File.dirname(__FILE__) + '/../config/environment' 2 require File.dirname(__FILE__) + '/../config/environment'
3 3
  4 +Profile.destroy_all
4 anhetegua = Profile.create!(:name => 'noosfero', :identifier => 'noosfero') 5 anhetegua = Profile.create!(:name => 'noosfero', :identifier => 'noosfero')
5 6
  7 +User.destroy_all
6 User.create!(:login => 'testprofile', :email => 'admin@localhost.localdomain', :password => 'test', :password_confirmation => 'test') 8 User.create!(:login => 'testprofile', :email => 'admin@localhost.localdomain', :password => 'test', :password_confirmation => 'test')
7 User.create!(:login => 'user', :email => 'user@localhost.localdomain', :password => 'user', :password_confirmation => 'user') 9 User.create!(:login => 'user', :email => 'user@localhost.localdomain', :password => 'user', :password_confirmation => 'user')
8 User.create!(:login => 'usuario', :email => 'usuario@localhost.localdomain', :password => 'usuario', :password_confirmation => 'usuario') 10 User.create!(:login => 'usuario', :email => 'usuario@localhost.localdomain', :password => 'usuario', :password_confirmation => 'usuario')
9 -ze = User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test') 11 +ze = User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test').person
10 root = User.create!(:login => 'root', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root').person 12 root = User.create!(:login => 'root', :email => 'root@noosfero.org', :password => 'root', :password_confirmation => 'root').person
11 13
  14 +Role.destroy_all
12 admin_role = Role.create!(:name => 'admin', :permissions => ['edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators']) 15 admin_role = Role.create!(:name => 'admin', :permissions => ['edit_environment_features', 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators'])
13 16
14 RoleAssignment.create!(:accessor => root, :role => admin_role, :resource => nil) 17 RoleAssignment.create!(:accessor => root, :role => admin_role, :resource => nil)
script/reset_db
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 require File.dirname(__FILE__) + '/../config/environment' 2 require File.dirname(__FILE__) + '/../config/environment'
3 3
4 system "rm #{RAILS_ROOT}/tmp/*.db" 4 system "rm #{RAILS_ROOT}/tmp/*.db"
  5 +system "rm #{RAILS_ROOT}/db/*.db"
5 system "rake db:migrate VERSION=0" 6 system "rake db:migrate VERSION=0"
6 system "rake db:migrate" 7 system "rake db:migrate"
7 system "ruby #{RAILS_ROOT}/script/anhetegua" 8 system "ruby #{RAILS_ROOT}/script/anhetegua"
test/fixtures/role_assignments.yml
@@ -2,28 +2,28 @@ @@ -2,28 +2,28 @@
2 one: 2 one:
3 id: 1 3 id: 1
4 accessor_id: 4 4 accessor_id: 4
5 - accessor_type: 'Person' 5 + accessor_type: 'Profile'
6 role_id: 2 6 role_id: 2
7 resource_id: 5 7 resource_id: 5
8 resource_type: 'Profile' 8 resource_type: 'Profile'
9 two: 9 two:
10 id: 2 10 id: 2
11 accessor_id: 1 11 accessor_id: 1
12 - accessor_type: 'Person' 12 + accessor_type: 'Profile'
13 role_id: 1 13 role_id: 1
14 resource_id: 5 14 resource_id: 5
15 resource_type: 'Profile' 15 resource_type: 'Profile'
16 three: 16 three:
17 id: 3 17 id: 3
18 accessor_id: 1 18 accessor_id: 1
19 - accessor_type: 'Person' 19 + accessor_type: 'Profile'
20 role_id: 1 20 role_id: 1
21 resource_id: 6 21 resource_id: 6
22 resource_type: 'Profile' 22 resource_type: 'Profile'
23 four: 23 four:
24 id: 4 24 id: 4
25 accessor_id: 4 25 accessor_id: 4
26 - accessor_type: 'Person' 26 + accessor_type: 'Profile'
27 role_id: 4 27 role_id: 4
28 resource_id: 1 28 resource_id: 1
29 resource_type: 'Environment' 29 resource_type: 'Environment'
test/functional/admin_panel_controller_test.rb
@@ -6,12 +6,12 @@ class AdminPanelController; def rescue_action(e) raise e end; end @@ -6,12 +6,12 @@ class AdminPanelController; def rescue_action(e) raise e end; end
6 6
7 class AdminPanelControllerTest < Test::Unit::TestCase 7 class AdminPanelControllerTest < Test::Unit::TestCase
8 8
9 - fixtures :environments  
10 - 9 + all_fixtures
11 def setup 10 def setup
12 @controller = AdminPanelController.new 11 @controller = AdminPanelController.new
13 @request = ActionController::TestRequest.new 12 @request = ActionController::TestRequest.new
14 @response = ActionController::TestResponse.new 13 @response = ActionController::TestResponse.new
  14 + login_as(:ze)
15 end 15 end
16 16
17 def test_index 17 def test_index
test/functional/categories_controller_test.rb
@@ -15,6 +15,7 @@ class CategoriesControllerTest &lt; Test::Unit::TestCase @@ -15,6 +15,7 @@ class CategoriesControllerTest &lt; Test::Unit::TestCase
15 Environment.stubs(:default).returns(env) 15 Environment.stubs(:default).returns(env)
16 assert (@cat1 = env.categories.create(:name => 'a test category')) 16 assert (@cat1 = env.categories.create(:name => 'a test category'))
17 assert (@cat1 = env.categories.create(:name => 'another category')) 17 assert (@cat1 = env.categories.create(:name => 'another category'))
  18 + login_as(:ze)
18 end 19 end
19 attr_reader :env, :cat1, :cat2 20 attr_reader :env, :cat1, :cat2
20 21
test/functional/role_controller_test.rb
@@ -9,11 +9,13 @@ class RoleControllerTest &lt; Test::Unit::TestCase @@ -9,11 +9,13 @@ class RoleControllerTest &lt; Test::Unit::TestCase
9 @controller = RoleController.new 9 @controller = RoleController.new
10 @request = ActionController::TestRequest.new 10 @request = ActionController::TestRequest.new
11 @response = ActionController::TestResponse.new 11 @response = ActionController::TestResponse.new
  12 + login_as(:ze)
12 end 13 end
13 all_fixtures 14 all_fixtures
14 15
15 def test_index_should_get_roles 16 def test_index_should_get_roles
16 get 'index' 17 get 'index'
  18 + assert_response :success
17 assert assigns(:roles) 19 assert assigns(:roles)
18 end 20 end
19 21
test/test_helper.rb
@@ -28,12 +28,13 @@ class Test::Unit::TestCase @@ -28,12 +28,13 @@ class Test::Unit::TestCase
28 # Add more helper methods to be used by all tests here... 28 # Add more helper methods to be used by all tests here...
29 29
30 include AuthenticatedTestHelper 30 include AuthenticatedTestHelper
31 - 31 +
32 def self.all_fixtures 32 def self.all_fixtures
33 Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.yml')).each do |item| 33 Dir.glob(File.join(RAILS_ROOT, 'test', 'fixtures', '*.yml')).each do |item|
34 fixtures File.basename(item).sub(/\.yml$/, '').to_s 34 fixtures File.basename(item).sub(/\.yml$/, '').to_s
35 end 35 end
36 end 36 end
  37 + all_fixtures
37 38
38 def self.should(name, &block) 39 def self.should(name, &block)
39 @shoulds ||= [] 40 @shoulds ||= []