Commit 9fd37c4cf06220d20637753977f277f88fbead8c
1 parent
80516055
Exists in
master
and in
22 other branches
ActionItem6: enterprise_controller covered by tests
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@332 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
91 additions
and
7 deletions
Show diff stats
lib/authenticated_test_helper.rb
| @@ -110,4 +110,4 @@ class XmlLoginProxy < BaseLoginProxy | @@ -110,4 +110,4 @@ class XmlLoginProxy < BaseLoginProxy | ||
| 110 | def check | 110 | def check |
| 111 | @controller.assert_response 401 | 111 | @controller.assert_response 401 |
| 112 | end | 112 | end |
| 113 | -end | ||
| 114 | \ No newline at end of file | 113 | \ No newline at end of file |
| 114 | +end |
test/fixtures/affiliations.yml
test/fixtures/organization_infos.yml
test/fixtures/profiles.yml
| @@ -47,4 +47,12 @@ colivre: | @@ -47,4 +47,12 @@ colivre: | ||
| 47 | flexible_template_template: 'default' | 47 | flexible_template_template: 'default' |
| 48 | flexible_template_icon_theme: 'default' | 48 | flexible_template_icon_theme: 'default' |
| 49 | flexible_template_theme: 'default' | 49 | flexible_template_theme: 'default' |
| 50 | - | 50 | +empreendimentoB: |
| 51 | + id: 6 | ||
| 52 | + name: "emp B" | ||
| 53 | + type: 'Enterprise' | ||
| 54 | + identifier: "empb" | ||
| 55 | + virtual_community_id: 1 | ||
| 56 | + flexible_template_template: 'default' | ||
| 57 | + flexible_template_icon_theme: 'default' | ||
| 58 | + flexible_template_theme: 'default' |
test/functional/enterprise_controller_test.rb
| @@ -13,7 +13,7 @@ class EnterpriseControllerTest < Test::Unit::TestCase | @@ -13,7 +13,7 @@ class EnterpriseControllerTest < Test::Unit::TestCase | ||
| 13 | @response = ActionController::TestResponse.new | 13 | @response = ActionController::TestResponse.new |
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | - def test_logged_index | 16 | + def test_logged_with_one_enterprise_index |
| 17 | login_as 'ze' | 17 | login_as 'ze' |
| 18 | get :index | 18 | get :index |
| 19 | assert_response :redirect | 19 | assert_response :redirect |
| @@ -22,10 +22,18 @@ class EnterpriseControllerTest < Test::Unit::TestCase | @@ -22,10 +22,18 @@ class EnterpriseControllerTest < Test::Unit::TestCase | ||
| 22 | assert_kind_of Array, assigns(:my_pending_enterprises) | 22 | assert_kind_of Array, assigns(:my_pending_enterprises) |
| 23 | end | 23 | end |
| 24 | 24 | ||
| 25 | - def test_not_logged_index | 25 | + def test_logged_with_two_enterprises_index |
| 26 | + login_as 'johndoe' | ||
| 26 | get :index | 27 | get :index |
| 27 | assert_response :redirect | 28 | assert_response :redirect |
| 29 | + assert_redirected_to :action => 'list' | ||
| 28 | 30 | ||
| 31 | + assert_kind_of Array, assigns(:my_pending_enterprises) | ||
| 32 | + end | ||
| 33 | + | ||
| 34 | + def test_not_logged_index | ||
| 35 | + get :index | ||
| 36 | + assert_response :redirect | ||
| 29 | assert_redirected_to :controller => 'account' | 37 | assert_redirected_to :controller => 'account' |
| 30 | end | 38 | end |
| 31 | 39 | ||
| @@ -36,6 +44,20 @@ class EnterpriseControllerTest < Test::Unit::TestCase | @@ -36,6 +44,20 @@ class EnterpriseControllerTest < Test::Unit::TestCase | ||
| 36 | assert_kind_of Array, assigns(:my_enterprises) | 44 | assert_kind_of Array, assigns(:my_enterprises) |
| 37 | end | 45 | end |
| 38 | 46 | ||
| 47 | + def test_enterprise_listing | ||
| 48 | + login_as 'ze' | ||
| 49 | + get :list | ||
| 50 | + assert_not_nil assigns(:enterprises) | ||
| 51 | + assert Array, assigns(:enterprises) | ||
| 52 | + end | ||
| 53 | + | ||
| 54 | + def test_enterprise_showing | ||
| 55 | + login_as 'ze' | ||
| 56 | + get :show, :id => 5 | ||
| 57 | + assert_not_nil assigns(:enterprise) | ||
| 58 | + assert_kind_of Enterprise, assigns(:enterprise) | ||
| 59 | + end | ||
| 60 | + | ||
| 39 | def test_register_form | 61 | def test_register_form |
| 40 | login_as 'ze' | 62 | login_as 'ze' |
| 41 | get :register_form | 63 | get :register_form |
| @@ -46,9 +68,7 @@ class EnterpriseControllerTest < Test::Unit::TestCase | @@ -46,9 +68,7 @@ class EnterpriseControllerTest < Test::Unit::TestCase | ||
| 46 | login_as 'ze' | 68 | login_as 'ze' |
| 47 | post :register, :enterprise => {:name => 'register_test', :identifier => 'register_test'} | 69 | post :register, :enterprise => {:name => 'register_test', :identifier => 'register_test'} |
| 48 | assert_not_nil assigns(:enterprise) | 70 | assert_not_nil assigns(:enterprise) |
| 49 | - | ||
| 50 | assert_response :redirect | 71 | assert_response :redirect |
| 51 | - | ||
| 52 | assert_redirected_to :action => 'index' | 72 | assert_redirected_to :action => 'index' |
| 53 | end | 73 | end |
| 54 | 74 | ||
| @@ -57,7 +77,56 @@ class EnterpriseControllerTest < Test::Unit::TestCase | @@ -57,7 +77,56 @@ class EnterpriseControllerTest < Test::Unit::TestCase | ||
| 57 | post :register, :enterprise => {:name => ''} | 77 | post :register, :enterprise => {:name => ''} |
| 58 | assert_response :success | 78 | assert_response :success |
| 59 | assert !assigns(:enterprise).valid? | 79 | assert !assigns(:enterprise).valid? |
| 80 | + end | ||
| 60 | 81 | ||
| 82 | + def test_enterprise_editing | ||
| 83 | + login_as 'ze' | ||
| 84 | + get :edit, :id => 5 | ||
| 85 | + assert_not_nil assigns(:enterprise) | ||
| 86 | + assert_kind_of Enterprise, assigns(:enterprise) | ||
| 87 | + end | ||
| 88 | + | ||
| 89 | + def test_enterprise_updating | ||
| 90 | + login_as 'ze' | ||
| 91 | + post :update, :id => 5, :enterprise => {:name => 'colivre'} | ||
| 92 | + assert_not_nil assigns(:enterprise) | ||
| 93 | + assert_kind_of Enterprise, assigns(:enterprise) | ||
| 94 | + assert_response :redirect | ||
| 95 | + assert_redirected_to :action => 'index' | ||
| 96 | + end | ||
| 97 | + | ||
| 98 | + def test_enterprise_updating_wrong | ||
| 99 | + login_as 'ze' | ||
| 100 | + post :update, :id => 5, :enterprise => {:name => ''} # name can't be blank | ||
| 101 | + assert_not_nil assigns(:enterprise) | ||
| 102 | + assert_kind_of Enterprise, assigns(:enterprise) | ||
| 103 | + assert_response :success | ||
| 104 | + assert_template 'edit' | ||
| 105 | + end | ||
| 106 | + | ||
| 107 | + def test_affiliate | ||
| 108 | + login_as 'ze' | ||
| 109 | + post :affiliate, :id => 6 | ||
| 110 | + assert assigns(:enterprise) | ||
| 111 | + assert assigns(:enterprise).people.include?(assigns(:person)) | ||
| 112 | + assert assigns(:person).enterprises.include?(assigns(:enterprise)) | ||
| 113 | + end | ||
| 114 | + | ||
| 115 | + def test_destroy | ||
| 116 | + login_as 'ze' | ||
| 117 | + c = Enterprise.count | ||
| 118 | + assert_nothing_raised { Enterprise.find(5) } | ||
| 119 | + post :destroy, :id => 5 | ||
| 120 | + assert_raise ActiveRecord::RecordNotFound do | ||
| 121 | + Enterprise.find(5) | ||
| 122 | + end | ||
| 123 | + assert_equal c - 1, Enterprise.count | ||
| 124 | + end | ||
| 125 | + | ||
| 126 | + def test_search | ||
| 127 | + login_as 'ze' | ||
| 128 | + get :search, :query => 'bla' | ||
| 129 | + assert assigns(:tagged_enterprises) | ||
| 130 | + assert_kind_of Array, assigns(:tagged_enterprises) | ||
| 61 | end | 131 | end |
| 62 | - | ||
| 63 | end | 132 | end |