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
test/fixtures/affiliations.yml
test/fixtures/organization_infos.yml
test/fixtures/profiles.yml
| ... | ... | @@ -47,4 +47,12 @@ colivre: |
| 47 | 47 | flexible_template_template: 'default' |
| 48 | 48 | flexible_template_icon_theme: 'default' |
| 49 | 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 | 13 | @response = ActionController::TestResponse.new |
| 14 | 14 | end |
| 15 | 15 | |
| 16 | - def test_logged_index | |
| 16 | + def test_logged_with_one_enterprise_index | |
| 17 | 17 | login_as 'ze' |
| 18 | 18 | get :index |
| 19 | 19 | assert_response :redirect |
| ... | ... | @@ -22,10 +22,18 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
| 22 | 22 | assert_kind_of Array, assigns(:my_pending_enterprises) |
| 23 | 23 | end |
| 24 | 24 | |
| 25 | - def test_not_logged_index | |
| 25 | + def test_logged_with_two_enterprises_index | |
| 26 | + login_as 'johndoe' | |
| 26 | 27 | get :index |
| 27 | 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 | 37 | assert_redirected_to :controller => 'account' |
| 30 | 38 | end |
| 31 | 39 | |
| ... | ... | @@ -36,6 +44,20 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
| 36 | 44 | assert_kind_of Array, assigns(:my_enterprises) |
| 37 | 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 | 61 | def test_register_form |
| 40 | 62 | login_as 'ze' |
| 41 | 63 | get :register_form |
| ... | ... | @@ -46,9 +68,7 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
| 46 | 68 | login_as 'ze' |
| 47 | 69 | post :register, :enterprise => {:name => 'register_test', :identifier => 'register_test'} |
| 48 | 70 | assert_not_nil assigns(:enterprise) |
| 49 | - | |
| 50 | 71 | assert_response :redirect |
| 51 | - | |
| 52 | 72 | assert_redirected_to :action => 'index' |
| 53 | 73 | end |
| 54 | 74 | |
| ... | ... | @@ -57,7 +77,56 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
| 57 | 77 | post :register, :enterprise => {:name => ''} |
| 58 | 78 | assert_response :success |
| 59 | 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 | 131 | end |
| 62 | - | |
| 63 | 132 | end | ... | ... |