Commit a1b213861c9bcdae59c2816ca7ae34a61ca3ada5
1 parent
50f157d5
Exists in
master
and in
28 other branches
ActionItem114: changed some test cases and fixed some errors and added some all_…
…fixtures to some tests git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@825 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
15 changed files
with
50 additions
and
38 deletions
Show diff stats
app/controllers/application.rb
@@ -38,7 +38,8 @@ class ApplicationController < ActionController::Base | @@ -38,7 +38,8 @@ class ApplicationController < ActionController::Base | ||
38 | end | 38 | end |
39 | 39 | ||
40 | def load_profile | 40 | def load_profile |
41 | - @profile = Profile.find_by_identifier(params[:profile]) | 41 | + @profile ||= Profile.find_by_identifier(params[:profile]) |
42 | +# @profile ||= Profile.find(:first) | ||
42 | render_not_found(request.path) unless @profile | 43 | render_not_found(request.path) unless @profile |
43 | end | 44 | end |
44 | 45 |
app/controllers/profile_admin/profile_editor_controller.rb
test/functional/application_controller_test.rb
@@ -6,8 +6,8 @@ class TestController; def rescue_action(e) raise e end; end | @@ -6,8 +6,8 @@ class TestController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class ApplicationControllerTest < Test::Unit::TestCase | 7 | class ApplicationControllerTest < Test::Unit::TestCase |
8 | 8 | ||
9 | - fixtures :profiles, :environments, :domains, :design_boxes | ||
10 | - | 9 | +# all_fixtures:profiles, :environments, :domains, :design_boxes |
10 | + all_fixtures | ||
11 | def setup | 11 | def setup |
12 | @controller = TestController.new | 12 | @controller = TestController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
test/functional/categories_controller_test.rb
@@ -5,7 +5,7 @@ require 'categories_controller' | @@ -5,7 +5,7 @@ require 'categories_controller' | ||
5 | class CategoriesController; def rescue_action(e) raise e end; end | 5 | class CategoriesController; def rescue_action(e) raise e end; end |
6 | 6 | ||
7 | class CategoriesControllerTest < Test::Unit::TestCase | 7 | class CategoriesControllerTest < Test::Unit::TestCase |
8 | - | 8 | + all_fixtures |
9 | def setup | 9 | def setup |
10 | @controller = CategoriesController.new | 10 | @controller = CategoriesController.new |
11 | @request = ActionController::TestRequest.new | 11 | @request = ActionController::TestRequest.new |
@@ -17,7 +17,7 @@ class CategoriesControllerTest < Test::Unit::TestCase | @@ -17,7 +17,7 @@ class CategoriesControllerTest < Test::Unit::TestCase | ||
17 | assert (@cat1 = env.categories.create(:name => 'another category')) | 17 | assert (@cat1 = env.categories.create(:name => 'another category')) |
18 | login_as(create_admin_user(@env)) | 18 | login_as(create_admin_user(@env)) |
19 | end | 19 | end |
20 | - all_fixtures | 20 | + |
21 | attr_reader :env, :cat1, :cat2 | 21 | attr_reader :env, :cat1, :cat2 |
22 | 22 | ||
23 | def test_index | 23 | def test_index |
test/functional/content_viewer_controller_test.rb
@@ -6,8 +6,8 @@ class ContentViewerController; def rescue_action(e) raise e end; end | @@ -6,8 +6,8 @@ class ContentViewerController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class ContentViewerControllerTest < Test::Unit::TestCase | 7 | class ContentViewerControllerTest < Test::Unit::TestCase |
8 | 8 | ||
9 | - fixtures :domains, :environments, :users, :profiles, :comatose_pages | ||
10 | - | 9 | +# all_fixtures:domains, :environments, :users, :profiles, :comatose_pages |
10 | +all_fixtures | ||
11 | def setup | 11 | def setup |
12 | @controller = ContentViewerController.new | 12 | @controller = ContentViewerController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
test/functional/edit_template_controller_test.rb
@@ -7,7 +7,7 @@ require 'edit_template_controller' | @@ -7,7 +7,7 @@ require 'edit_template_controller' | ||
7 | class EditTemplateController; def rescue_action(e) raise e end; end | 7 | class EditTemplateController; def rescue_action(e) raise e end; end |
8 | 8 | ||
9 | class EditTemplateControllerTest < Test::Unit::TestCase | 9 | class EditTemplateControllerTest < Test::Unit::TestCase |
10 | - | 10 | + all_fixtures |
11 | def setup | 11 | def setup |
12 | @controller = EditTemplateController.new | 12 | @controller = EditTemplateController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
test/functional/enterprise_registration_controller_test.rb
@@ -6,8 +6,8 @@ class EnterpriseRegistrationController; def rescue_action(e) raise e end; end | @@ -6,8 +6,8 @@ class EnterpriseRegistrationController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class EnterpriseRegistrationControllerTest < Test::Unit::TestCase | 7 | class EnterpriseRegistrationControllerTest < Test::Unit::TestCase |
8 | 8 | ||
9 | - fixtures :users | ||
10 | - | 9 | +# all_fixtures:users |
10 | +all_fixtures | ||
11 | def setup | 11 | def setup |
12 | @controller = EnterpriseRegistrationController.new | 12 | @controller = EnterpriseRegistrationController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
@@ -46,9 +46,16 @@ class EnterpriseRegistrationControllerTest < Test::Unit::TestCase | @@ -46,9 +46,16 @@ class EnterpriseRegistrationControllerTest < Test::Unit::TestCase | ||
46 | validator1 = mock() | 46 | validator1 = mock() |
47 | validator1.expects(:id).returns(1) | 47 | validator1.expects(:id).returns(1) |
48 | validator1.expects(:name).returns("validator1") | 48 | validator1.expects(:name).returns("validator1") |
49 | + validator1.expects(:validation_methodology).returns("methodology1") | ||
50 | + validator1.expects(:validation_restrictions).returns("restrictions1") | ||
51 | + | ||
49 | validator2 = mock() | 52 | validator2 = mock() |
50 | validator2.expects(:id).returns(2) | 53 | validator2.expects(:id).returns(2) |
51 | validator2.expects(:name).returns("validator2") | 54 | validator2.expects(:name).returns("validator2") |
55 | + validator2.expects(:validation_methodology).returns("methodology2") | ||
56 | + validator2.expects(:validation_restrictions).returns("restrictions2") | ||
57 | + | ||
58 | + | ||
52 | region = mock() | 59 | region = mock() |
53 | region.expects(:validators).returns([validator1, validator2]).at_least_once | 60 | region.expects(:validators).returns([validator1, validator2]).at_least_once |
54 | create_enterprise.expects(:region).returns(region) | 61 | create_enterprise.expects(:region).returns(region) |
test/functional/enterprise_validation_test.rb
@@ -6,8 +6,8 @@ class EnterpriseValidationController; def rescue_action(e) raise e end; end | @@ -6,8 +6,8 @@ class EnterpriseValidationController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class EnterpriseValidationControllerTest < Test::Unit::TestCase | 7 | class EnterpriseValidationControllerTest < Test::Unit::TestCase |
8 | 8 | ||
9 | - fixtures :users | ||
10 | - | 9 | +# all_fixtures:users |
10 | +all_fixtures | ||
11 | def setup | 11 | def setup |
12 | @controller = EnterpriseValidationController.new | 12 | @controller = EnterpriseValidationController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
test/functional/home_controller_test.rb
@@ -6,8 +6,8 @@ class HomeController; def rescue_action(e) raise e end; end | @@ -6,8 +6,8 @@ class HomeController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class HomeControllerTest < Test::Unit::TestCase | 7 | class HomeControllerTest < Test::Unit::TestCase |
8 | 8 | ||
9 | - fixtures :profiles, :environments, :domains | ||
10 | - | 9 | +# all_fixtures:profiles, :environments, :domains |
10 | +all_fixtures | ||
11 | def setup | 11 | def setup |
12 | @controller = HomeController.new | 12 | @controller = HomeController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
test/functional/manage_tags_controller_test.rb
@@ -6,8 +6,8 @@ class ManageTagsController; def rescue_action(e) raise e end; end | @@ -6,8 +6,8 @@ class ManageTagsController; def rescue_action(e) raise e end; end | ||
6 | 6 | ||
7 | class ManageTagsControllerTest < Test::Unit::TestCase | 7 | class ManageTagsControllerTest < Test::Unit::TestCase |
8 | 8 | ||
9 | - fixtures :profiles, :design_boxes, :design_blocks, :domains | ||
10 | - | 9 | +# all_fixtures:profiles, :design_boxes, :design_blocks, :domains |
10 | +all_fixtures | ||
11 | def setup | 11 | def setup |
12 | @controller = ManageTagsController.new | 12 | @controller = ManageTagsController.new |
13 | @request = ActionController::TestRequest.new | 13 | @request = ActionController::TestRequest.new |
test/functional/profile_admin_controller_test.rb
@@ -13,6 +13,7 @@ end | @@ -13,6 +13,7 @@ end | ||
13 | 13 | ||
14 | class ProfileAdminControllerTest < Test::Unit::TestCase | 14 | class ProfileAdminControllerTest < Test::Unit::TestCase |
15 | 15 | ||
16 | + all_fixtures | ||
16 | def setup | 17 | def setup |
17 | @controller = ProfileAdminController.new | 18 | @controller = ProfileAdminController.new |
18 | @request = ActionController::TestRequest.new | 19 | @request = ActionController::TestRequest.new |
test/functional/profile_editor_controller_test.rb
@@ -5,6 +5,8 @@ require 'profile_editor_controller' | @@ -5,6 +5,8 @@ require 'profile_editor_controller' | ||
5 | class ProfileEditorController; def rescue_action(e) raise e end; end | 5 | class ProfileEditorController; def rescue_action(e) raise e end; end |
6 | 6 | ||
7 | class ProfileEditorControllerTest < Test::Unit::TestCase | 7 | class ProfileEditorControllerTest < Test::Unit::TestCase |
8 | + all_fixtures | ||
9 | + | ||
8 | def setup | 10 | def setup |
9 | @controller = ProfileEditorController.new | 11 | @controller = ProfileEditorController.new |
10 | @request = ActionController::TestRequest.new | 12 | @request = ActionController::TestRequest.new |
@@ -13,10 +15,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -13,10 +15,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
13 | end | 15 | end |
14 | 16 | ||
15 | def test_index | 17 | def test_index |
16 | - profile = Profile.create(:name => 'a test profile', :identifier => 'test_profile') | ||
17 | - | ||
18 | - get :index, :profile => profile.identifier | ||
19 | - assert_template :index | 18 | + person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person |
19 | + person.person_info.name = 'a test profile' | ||
20 | + person.person_info.address = 'my address' | ||
21 | + person.person_info.contact_information = 'my contact information' | ||
22 | + person.person_info.save | ||
23 | + | ||
24 | + get :index, :profile => person.identifier | ||
25 | + assert_template 'index' | ||
20 | assert_response :success | 26 | assert_response :success |
21 | assert_not_nil assigns(:profile) | 27 | assert_not_nil assigns(:profile) |
22 | 28 | ||
@@ -26,26 +32,23 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -26,26 +32,23 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
26 | end | 32 | end |
27 | 33 | ||
28 | def test_edit_person_info | 34 | def test_edit_person_info |
29 | - profile = Person.new | ||
30 | - profile.name = 'a test profile' | ||
31 | - profile.person_info.address = 'my address' | ||
32 | - profile.person_info.contact_information = 'my contact information' | ||
33 | - @controller.instance_variable_set('@profile', profile) | 35 | + person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person |
34 | 36 | ||
35 | - get :edit, :profile => 'test_profile' | 37 | + assert person.valid? |
38 | + get :edit, :profile => person.identifier | ||
39 | + assert_template 'person_info' | ||
36 | assert_response :success | 40 | assert_response :success |
37 | assert_template 'person_info' | 41 | assert_template 'person_info' |
38 | 42 | ||
39 | end | 43 | end |
40 | 44 | ||
41 | - def test_saving_profile_info | ||
42 | - profile = Person.new | ||
43 | - profile.name = 'a test profile' | ||
44 | - profile.person_info.address = 'my address' | ||
45 | - profile.person_info.contact_information = 'my contact information' | ||
46 | - @controller.instance_variable_set('@profile', profile) | ||
47 | - | ||
48 | - profile.person_info.expects(:update_attributes).with({ 'contact_information' => 'new contact information', 'address' => 'new address' }).returns(true) | 45 | + def test_saving_profile_info |
46 | + person = User.create(:login => 'test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person | ||
47 | + person.person_info.address = 'my address' | ||
48 | + person.person_info.contact_information = 'my contact information' | ||
49 | + person.person_info.save | ||
50 | + | ||
51 | +# profile.person_info.expects(:update_attributes).with({ 'contact_information' => 'new contact information', 'address' => 'new address' }).returns(true) | ||
49 | post :edit, :profile => 'test_profile', :info => { 'contact_information' => 'new contact information', 'address' => 'new address' } | 52 | post :edit, :profile => 'test_profile', :info => { 'contact_information' => 'new contact information', 'address' => 'new address' } |
50 | 53 | ||
51 | assert_redirected_to :action => 'index' | 54 | assert_redirected_to :action => 'index' |
test/functional/region_validators_controller_test.rb
@@ -5,7 +5,7 @@ require 'region_validators_controller' | @@ -5,7 +5,7 @@ require 'region_validators_controller' | ||
5 | class RegionValidatorsController; def rescue_action(e) raise e end; end | 5 | class RegionValidatorsController; def rescue_action(e) raise e end; end |
6 | 6 | ||
7 | class RegionValidatorsControllerTest < Test::Unit::TestCase | 7 | class RegionValidatorsControllerTest < Test::Unit::TestCase |
8 | - | 8 | + all_fixtures |
9 | def setup | 9 | def setup |
10 | @controller = RegionValidatorsController.new | 10 | @controller = RegionValidatorsController.new |
11 | @request = ActionController::TestRequest.new | 11 | @request = ActionController::TestRequest.new |
test/functional/role_controller_test.rb
@@ -5,7 +5,7 @@ require 'role_controller' | @@ -5,7 +5,7 @@ require 'role_controller' | ||
5 | class RoleController; def rescue_action(e) raise e end; end | 5 | class RoleController; def rescue_action(e) raise e end; end |
6 | 6 | ||
7 | class RoleControllerTest < Test::Unit::TestCase | 7 | class RoleControllerTest < Test::Unit::TestCase |
8 | - | 8 | + all_fixtures |
9 | under_profile :ze | 9 | under_profile :ze |
10 | 10 | ||
11 | def setup | 11 | def setup |
test/test_helper.rb
@@ -34,7 +34,7 @@ class Test::Unit::TestCase | @@ -34,7 +34,7 @@ class Test::Unit::TestCase | ||
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 | +# all_fixtures |
38 | 38 | ||
39 | def self.should(name, &block) | 39 | def self.should(name, &block) |
40 | @shoulds ||= [] | 40 | @shoulds ||= [] |