Commit 411eb7b1bac36b6d94b1e4ea203cf5107c7f3b3a
1 parent
a2ffa15c
Exists in
master
and in
29 other branches
ActionItem16: fixed some tests about approving and activating an enterprise
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@414 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
37 additions
and
12 deletions
Show diff stats
app/controllers/enterprise_controller.rb
... | ... | @@ -73,7 +73,11 @@ class EnterpriseController < ApplicationController |
73 | 73 | # Elimitates the enterprise of the system |
74 | 74 | def destroy |
75 | 75 | @enterprise = @my_enterprises.find(params[:id]) |
76 | - @enterprise.destroy | |
76 | + if @enterprise | |
77 | + @enterprise.destroy | |
78 | + else | |
79 | + flash[:notice] = 'Can destroy only your enterprises' | |
80 | + end | |
77 | 81 | redirect_to :action => 'index' |
78 | 82 | end |
79 | 83 | ... | ... |
test/functional/enterprise_controller_test.rb
... | ... | @@ -81,14 +81,16 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
81 | 81 | |
82 | 82 | def test_enterprise_editing |
83 | 83 | login_as 'ze' |
84 | - get :edit, :id => 5 | |
84 | + e = create_enterprise | |
85 | + get :edit, :id => e | |
85 | 86 | assert_not_nil assigns(:enterprise) |
86 | 87 | assert_kind_of Enterprise, assigns(:enterprise) |
87 | 88 | end |
88 | 89 | |
89 | 90 | def test_enterprise_updating |
90 | 91 | login_as 'ze' |
91 | - post :update, :id => 5, :enterprise => {:name => 'colivre'} | |
92 | + e = create_enterprise | |
93 | + post :update, :id => e, :enterprise => {:name => 'colivre'} | |
92 | 94 | assert_not_nil assigns(:enterprise) |
93 | 95 | assert_kind_of Enterprise, assigns(:enterprise) |
94 | 96 | assert_response :redirect |
... | ... | @@ -97,7 +99,8 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
97 | 99 | |
98 | 100 | def test_enterprise_updating_wrong |
99 | 101 | login_as 'ze' |
100 | - post :update, :id => 5, :enterprise => {:name => ''} # name can't be blank | |
102 | + e = create_enterprise | |
103 | + post :update, :id => e, :enterprise => {:name => ''} # name can't be blank | |
101 | 104 | assert_not_nil assigns(:enterprise) |
102 | 105 | assert_kind_of Enterprise, assigns(:enterprise) |
103 | 106 | assert_response :success |
... | ... | @@ -106,7 +109,8 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
106 | 109 | |
107 | 110 | def test_affiliate |
108 | 111 | login_as 'ze' |
109 | - post :affiliate, :id => 6 | |
112 | + e = create_enterprise(:owner => 'johndoe', :user => 'ze') | |
113 | + post :affiliate, :id => e | |
110 | 114 | assert assigns(:enterprise) |
111 | 115 | assert assigns(:enterprise).people.include?(assigns(:person)) |
112 | 116 | assert assigns(:person).enterprises.include?(assigns(:enterprise)) |
... | ... | @@ -114,17 +118,20 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
114 | 118 | |
115 | 119 | def test_destroy |
116 | 120 | login_as 'ze' |
121 | + e = create_enterprise | |
117 | 122 | c = Enterprise.count |
118 | - assert_nothing_raised { Enterprise.find(5) } | |
119 | - post :destroy, :id => 5 | |
123 | + assert_nothing_raised { Enterprise.find(e) } | |
124 | + post :destroy, :id => e | |
125 | + assert assigns(:enterprise) | |
120 | 126 | assert_raise ActiveRecord::RecordNotFound do |
121 | - Enterprise.find(5) | |
127 | + Enterprise.find(e) | |
122 | 128 | end |
123 | 129 | assert_equal c - 1, Enterprise.count |
124 | 130 | end |
125 | 131 | |
126 | 132 | def test_search |
127 | 133 | login_as 'ze' |
134 | + e = create_enterprise(:tag_list => 'bla') | |
128 | 135 | get :search, :query => 'bla' |
129 | 136 | assert assigns(:tagged_enterprises) |
130 | 137 | assert_kind_of Array, assigns(:tagged_enterprises) |
... | ... | @@ -132,15 +139,29 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
132 | 139 | |
133 | 140 | def test_activate |
134 | 141 | login_as 'ze' |
135 | - post :activate, :id => 5 | |
142 | + e = create_enterprise | |
143 | + post :activate, :id => e | |
136 | 144 | assert assigns(:enterprise) |
137 | 145 | assert_kind_of Enterprise, assigns(:enterprise) |
138 | 146 | assert assigns(:enterprise).active |
139 | 147 | end |
140 | 148 | |
141 | 149 | def test_approve |
142 | - logins_as 'ze' | |
143 | - post :approve, :id => 5 | |
144 | - assert assigns(:em) | |
150 | + login_as 'ze' | |
151 | + e = create_enterprise | |
152 | + post :approve, :id => e | |
153 | + assert assigns(:enterprise) | |
154 | + end | |
155 | + | |
156 | + protected | |
157 | + | |
158 | + def create_enterprise(options = {}) | |
159 | + owner = options.delete(:owner) | |
160 | + user = options.delete(:user) | |
161 | + login_as owner if owner | |
162 | + post :register, :enterprise => {:identifier => 'enterprise_a', :name => 'Enterprise A'}.merge(options) | |
163 | + id = assigns(:enterprise).id | |
164 | + login_as user if user | |
165 | + id | |
145 | 166 | end |
146 | 167 | end | ... | ... |