Commit 411eb7b1bac36b6d94b1e4ea203cf5107c7f3b3a

Authored by MoisesMachado
1 parent a2ffa15c

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
app/controllers/enterprise_controller.rb
@@ -73,7 +73,11 @@ class EnterpriseController < ApplicationController @@ -73,7 +73,11 @@ class EnterpriseController < ApplicationController
73 # Elimitates the enterprise of the system 73 # Elimitates the enterprise of the system
74 def destroy 74 def destroy
75 @enterprise = @my_enterprises.find(params[:id]) 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 redirect_to :action => 'index' 81 redirect_to :action => 'index'
78 end 82 end
79 83
test/functional/enterprise_controller_test.rb
@@ -81,14 +81,16 @@ class EnterpriseControllerTest < Test::Unit::TestCase @@ -81,14 +81,16 @@ class EnterpriseControllerTest < Test::Unit::TestCase
81 81
82 def test_enterprise_editing 82 def test_enterprise_editing
83 login_as 'ze' 83 login_as 'ze'
84 - get :edit, :id => 5 84 + e = create_enterprise
  85 + get :edit, :id => e
85 assert_not_nil assigns(:enterprise) 86 assert_not_nil assigns(:enterprise)
86 assert_kind_of Enterprise, assigns(:enterprise) 87 assert_kind_of Enterprise, assigns(:enterprise)
87 end 88 end
88 89
89 def test_enterprise_updating 90 def test_enterprise_updating
90 login_as 'ze' 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 assert_not_nil assigns(:enterprise) 94 assert_not_nil assigns(:enterprise)
93 assert_kind_of Enterprise, assigns(:enterprise) 95 assert_kind_of Enterprise, assigns(:enterprise)
94 assert_response :redirect 96 assert_response :redirect
@@ -97,7 +99,8 @@ class EnterpriseControllerTest < Test::Unit::TestCase @@ -97,7 +99,8 @@ class EnterpriseControllerTest < Test::Unit::TestCase
97 99
98 def test_enterprise_updating_wrong 100 def test_enterprise_updating_wrong
99 login_as 'ze' 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 assert_not_nil assigns(:enterprise) 104 assert_not_nil assigns(:enterprise)
102 assert_kind_of Enterprise, assigns(:enterprise) 105 assert_kind_of Enterprise, assigns(:enterprise)
103 assert_response :success 106 assert_response :success
@@ -106,7 +109,8 @@ class EnterpriseControllerTest < Test::Unit::TestCase @@ -106,7 +109,8 @@ class EnterpriseControllerTest < Test::Unit::TestCase
106 109
107 def test_affiliate 110 def test_affiliate
108 login_as 'ze' 111 login_as 'ze'
109 - post :affiliate, :id => 6 112 + e = create_enterprise(:owner => 'johndoe', :user => 'ze')
  113 + post :affiliate, :id => e
110 assert assigns(:enterprise) 114 assert assigns(:enterprise)
111 assert assigns(:enterprise).people.include?(assigns(:person)) 115 assert assigns(:enterprise).people.include?(assigns(:person))
112 assert assigns(:person).enterprises.include?(assigns(:enterprise)) 116 assert assigns(:person).enterprises.include?(assigns(:enterprise))
@@ -114,17 +118,20 @@ class EnterpriseControllerTest < Test::Unit::TestCase @@ -114,17 +118,20 @@ class EnterpriseControllerTest < Test::Unit::TestCase
114 118
115 def test_destroy 119 def test_destroy
116 login_as 'ze' 120 login_as 'ze'
  121 + e = create_enterprise
117 c = Enterprise.count 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 assert_raise ActiveRecord::RecordNotFound do 126 assert_raise ActiveRecord::RecordNotFound do
121 - Enterprise.find(5) 127 + Enterprise.find(e)
122 end 128 end
123 assert_equal c - 1, Enterprise.count 129 assert_equal c - 1, Enterprise.count
124 end 130 end
125 131
126 def test_search 132 def test_search
127 login_as 'ze' 133 login_as 'ze'
  134 + e = create_enterprise(:tag_list => 'bla')
128 get :search, :query => 'bla' 135 get :search, :query => 'bla'
129 assert assigns(:tagged_enterprises) 136 assert assigns(:tagged_enterprises)
130 assert_kind_of Array, assigns(:tagged_enterprises) 137 assert_kind_of Array, assigns(:tagged_enterprises)
@@ -132,15 +139,29 @@ class EnterpriseControllerTest < Test::Unit::TestCase @@ -132,15 +139,29 @@ class EnterpriseControllerTest < Test::Unit::TestCase
132 139
133 def test_activate 140 def test_activate
134 login_as 'ze' 141 login_as 'ze'
135 - post :activate, :id => 5 142 + e = create_enterprise
  143 + post :activate, :id => e
136 assert assigns(:enterprise) 144 assert assigns(:enterprise)
137 assert_kind_of Enterprise, assigns(:enterprise) 145 assert_kind_of Enterprise, assigns(:enterprise)
138 assert assigns(:enterprise).active 146 assert assigns(:enterprise).active
139 end 147 end
140 148
141 def test_approve 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 end 166 end
146 end 167 end