Commit 2eb3df9888358960cc4e1858029659e16177e7d5

Authored by Antonio Terceiro
1 parent d36492d6

Speeding up tests some tests

This time:

    * test/functional/search_controller_test.rb
    * test/functional/profile_editor_controller_test.rb

The time gain was small, so perhaps we need to formulate another strategy
for functional tests. The way we are doing them, they always require
hitting the database.
test/factories.rb
@@ -163,7 +163,7 @@ module Noosfero::Factory @@ -163,7 +163,7 @@ module Noosfero::Factory
163 end 163 end
164 164
165 ############################################### 165 ###############################################
166 - # Enterprise 166 + # Community
167 ############################################### 167 ###############################################
168 168
169 def defaults_for_community 169 def defaults_for_community
@@ -172,6 +172,15 @@ module Noosfero::Factory @@ -172,6 +172,15 @@ module Noosfero::Factory
172 end 172 end
173 173
174 ############################################### 174 ###############################################
  175 + # Person
  176 + ###############################################
  177 +
  178 + def defaults_for_person
  179 + n = factory_num_seq.to_s
  180 + defaults_for_profile.merge({ :identifier => "person-" + n, :name => 'Person ' + n })
  181 + end
  182 +
  183 + ###############################################
175 # Profile 184 # Profile
176 ############################################### 185 ###############################################
177 186
@@ -181,6 +190,15 @@ module Noosfero::Factory @@ -181,6 +190,15 @@ module Noosfero::Factory
181 end 190 end
182 191
183 ############################################### 192 ###############################################
  193 + # Organization
  194 + ###############################################
  195 +
  196 + def defaults_for_organization
  197 + n = factory_num_seq.to_s
  198 + defaults_for_profile.merge({:identifier => 'organization-' + n, :name => 'Organization ' + n})
  199 + end
  200 +
  201 + ###############################################
184 # Article 202 # Article
185 ############################################### 203 ###############################################
186 204
test/functional/profile_editor_controller_test.rb
@@ -27,13 +27,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase @@ -27,13 +27,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
27 end 27 end
28 28
29 def test_index 29 def test_index
30 - person = create_user('test_profile').person  
31 - person.name = 'a test profile'  
32 - person.address = 'my address'  
33 - person.contact_information = 'my contact information'  
34 - person.save!  
35 -  
36 - get :index, :profile => person.identifier 30 + get :index, :profile => profile.identifier
37 assert_template 'index' 31 assert_template 'index'
38 assert_response :success 32 assert_response :success
39 assert_not_nil assigns(:profile) 33 assert_not_nil assigns(:profile)
@@ -53,15 +47,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase @@ -53,15 +47,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
53 end 47 end
54 48
55 def test_edit_person_info 49 def test_edit_person_info
56 - person = create_user('test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person  
57 - get :edit, :profile => person.identifier 50 + get :edit, :profile => profile.identifier
58 assert_response :success 51 assert_response :success
59 assert_template 'edit' 52 assert_template 'edit'
60 end 53 end
61 54
62 should 'saving profile info' do 55 should 'saving profile info' do
63 - person = create_user('test_profile').person  
64 - post :edit, :profile => 'test_profile', :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address', 'sex' => 'female' } 56 + person = profile
  57 + post :edit, :profile => profile.identifier, :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address', 'sex' => 'female' }
65 assert_redirected_to :action => 'index' 58 assert_redirected_to :action => 'index'
66 person = Person.find(person.id) 59 person = Person.find(person.id)
67 assert_equal 'new person', person.name 60 assert_equal 'new person', person.name
@@ -72,15 +65,15 @@ class ProfileEditorControllerTest < Test::Unit::TestCase @@ -72,15 +65,15 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
72 65
73 should 'not permmit if not logged' do 66 should 'not permmit if not logged' do
74 logout 67 logout
75 - person = create_user('test_user')  
76 - get :index, :profile => 'test_user' 68 + get :index, :profile => profile.identifier
  69 + assert_response 302
77 end 70 end
78 71
79 should 'display categories to choose to associate profile' do 72 should 'display categories to choose to associate profile' do
80 cat1 = Environment.default.categories.build(:display_in_menu => true, :name => 'top category'); cat1.save! 73 cat1 = Environment.default.categories.build(:display_in_menu => true, :name => 'top category'); cat1.save!
81 cat2 = Environment.default.categories.build(:display_in_menu => true, :name => 'sub category', :parent => cat1); cat2.save! 74 cat2 = Environment.default.categories.build(:display_in_menu => true, :name => 'sub category', :parent => cat1); cat2.save!
82 - person = create_user('test_user').person  
83 - get :edit, :profile => 'test_user' 75 + person = profile
  76 + get :edit, :profile => profile.identifier
84 assert_response :success 77 assert_response :success
85 assert_template 'edit' 78 assert_template 'edit'
86 assert_tag :tag => 'input', :attributes => {:name => 'profile_data[category_ids][]', :value => cat2.id} 79 assert_tag :tag => 'input', :attributes => {:name => 'profile_data[category_ids][]', :value => cat2.id}
@@ -89,114 +82,95 @@ class ProfileEditorControllerTest < Test::Unit::TestCase @@ -89,114 +82,95 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
89 should 'save categorization of profile' do 82 should 'save categorization of profile' do
90 cat1 = Environment.default.categories.build(:name => 'top category'); cat1.save! 83 cat1 = Environment.default.categories.build(:name => 'top category'); cat1.save!
91 cat2 = Environment.default.categories.build(:name => 'sub category', :parent => cat1); cat2.save! 84 cat2 = Environment.default.categories.build(:name => 'sub category', :parent => cat1); cat2.save!
92 - person = create_user('test_user').person  
93 - post :edit, :profile => 'test_user', :profile_data => {:category_ids => [cat2.id]} 85 + person = profile
  86 + post :edit, :profile => profile.identifier, :profile_data => {:category_ids => [cat2.id]}
94 assert_response :redirect 87 assert_response :redirect
95 assert_redirected_to :action => 'index' 88 assert_redirected_to :action => 'index'
96 assert_includes person.categories, cat2 89 assert_includes person.categories, cat2
97 end 90 end
98 91
99 - should 'filter html from name when edit person_info' do  
100 - person = create_user('test_profile').person 92 + should 'filter html from person name' do
101 name = "name <strong id='name_html_test'>with</strong> html" 93 name = "name <strong id='name_html_test'>with</strong> html"
102 - post :edit, :profile => person.identifier, :profile_data => { :name => name } 94 + post :edit, :profile => profile.identifier, :profile_data => { :name => name }
103 assert_sanitized assigns(:profile).name 95 assert_sanitized assigns(:profile).name
104 end 96 end
105 97
106 - should 'filter html from contact_person to organization' do  
107 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) 98 + should 'filter html from organization fields' do
  99 + org = fast_create(Organization)
108 contact = "name <strong id='name_html_test'>with</strong> html" 100 contact = "name <strong id='name_html_test'>with</strong> html"
109 - post :edit, :profile => org.identifier, :profile_data => { :contact_person => contact }  
110 - assert_sanitized assigns(:profile).contact_person  
111 - end 101 + acronym = "name <strong id='name_html_test'>with</strong> html"
  102 + legal_form = "name <strong id='name_html_test'>with</strong> html"
  103 + economic_activity = "name <strong id='name_html_test'>with</strong> html"
  104 + management_information = "name <strong id='name_html_test'>with</strong> html"
112 105
113 - should 'filter html from acronym organization' do  
114 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default)  
115 - value = "name <strong id='name_html_test'>with</strong> html"  
116 - post :edit, :profile => org.identifier, :profile_data => { :acronym => value }  
117 - assert_sanitized assigns(:profile).acronym  
118 - end 106 + post :edit, :profile => org.identifier, :profile_data => { :name => name, :contact_person => contact, :acronym => acronym, :legal_form => legal_form, :economic_activity => economic_activity, :management_information => management_information}
119 107
120 - should 'filter html from legal_form organization' do  
121 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default)  
122 - value = "name <strong id='name_html_test'>with</strong> html"  
123 - post :edit, :profile => org.identifier, :profile_data => { :legal_form => value } 108 + assert_sanitized assigns(:profile).contact_person
  109 + assert_sanitized assigns(:profile).acronym
124 assert_sanitized assigns(:profile).legal_form 110 assert_sanitized assigns(:profile).legal_form
125 - end  
126 -  
127 - should 'filter html from economic_activity organization' do  
128 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default)  
129 - value = "name <strong id='name_html_test'>with</strong> html"  
130 - post :edit, :profile => org.identifier, :profile_data => { :economic_activity => value }  
131 assert_sanitized assigns(:profile).economic_activity 111 assert_sanitized assigns(:profile).economic_activity
132 - end  
133 -  
134 - should 'filter html from management_information organization' do  
135 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default)  
136 - value = "name <strong id='name_html_test'>with</strong> html"  
137 - post :edit, :profile => org.identifier, :profile_data => { :management_information => value }  
138 assert_sanitized assigns(:profile).management_information 112 assert_sanitized assigns(:profile).management_information
139 end 113 end
140 114
141 should 'saving profile organization_info' do 115 should 'saving profile organization_info' do
142 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default)  
143 - post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'contact person' } 116 + org = fast_create(Organization)
  117 + post :edit, :profile => org.identifier, :profile_data => { :contact_person => 'contact person' }
144 assert_equal 'contact person', Organization.find(org.id).contact_person 118 assert_equal 'contact person', Organization.find(org.id).contact_person
145 end 119 end
146 120
147 should 'show contact_phone field on edit enterprise' do 121 should 'show contact_phone field on edit enterprise' do
148 - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) 122 + org = fast_create(Enterprise)
149 Enterprise.any_instance.expects(:active_fields).returns(['contact_phone']).at_least_once 123 Enterprise.any_instance.expects(:active_fields).returns(['contact_phone']).at_least_once
150 get :edit, :profile => org.identifier 124 get :edit, :profile => org.identifier
151 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } 125 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' }
152 end 126 end
153 127
154 should 'save community description' do 128 should 'save community description' do
155 - org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default)  
156 - post :edit, :profile => 'testorg', :profile_data => { :description => 'my description' } 129 + org = fast_create(Community)
  130 + post :edit, :profile => org.identifier, :profile_data => { :description => 'my description' }
157 assert_equal 'my description', Organization.find(org.id).description 131 assert_equal 'my description', Organization.find(org.id).description
158 end 132 end
159 133
160 should 'show community description' do 134 should 'show community description' do
161 - org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) 135 + org = fast_create(Community)
162 Community.any_instance.expects(:active_fields).returns(['description']).at_least_once 136 Community.any_instance.expects(:active_fields).returns(['description']).at_least_once
163 - get :edit, :profile => 'testorg' 137 + get :edit, :profile => org.identifier
164 assert_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } 138 assert_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' }
165 end 139 end
166 140
167 should 'not show enterprise description' do 141 should 'not show enterprise description' do
168 - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default)  
169 - get :edit, :profile => 'testorg' 142 + org = fast_create(Enterprise)
  143 + get :edit, :profile => org.identifier
170 assert_no_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } 144 assert_no_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' }
171 end 145 end
172 146
173 should 'save organization contact_person' do 147 should 'save organization contact_person' do
174 - org = Organization.create!(:name => 'test org', :identifier => 'testorg')  
175 - post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' } 148 + org = fast_create(Organization)
  149 + post :edit, :profile => org.identifier, :profile_data => { :contact_person => 'my contact' }
176 assert_equal 'my contact', Organization.find(org.id).contact_person 150 assert_equal 'my contact', Organization.find(org.id).contact_person
177 end 151 end
178 152
179 should 'save enterprise contact_person' do 153 should 'save enterprise contact_person' do
180 - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default)  
181 - post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' } 154 + org = fast_create(Enterprise)
  155 + post :edit, :profile => org.identifier, :profile_data => { :contact_person => 'my contact' }
182 assert_equal 'my contact', Enterprise.find(org.id).contact_person 156 assert_equal 'my contact', Enterprise.find(org.id).contact_person
183 end 157 end
184 158
185 should 'show field values on edit community info' do 159 should 'show field values on edit community info' do
186 Community.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once 160 Community.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once
187 - org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) 161 + org = fast_create(Community)
188 org.contact_person = 'my contact' 162 org.contact_person = 'my contact'
189 org.save! 163 org.save!
190 - get :edit, :profile => 'testorg' 164 + get :edit, :profile => org.identifier
191 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } 165 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' }
192 end 166 end
193 167
194 should 'show field values on edit enterprise info' do 168 should 'show field values on edit enterprise info' do
195 Enterprise.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once 169 Enterprise.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once
196 - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) 170 + org = fast_create(Enterprise)
197 org.contact_person = 'my contact' 171 org.contact_person = 'my contact'
198 org.save! 172 org.save!
199 - get :edit, :profile => 'testorg' 173 + get :edit, :profile => org.identifier
200 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } 174 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' }
201 end 175 end
202 176
@@ -225,40 +199,38 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -225,40 +199,38 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
225 end 199 end
226 200
227 should 'show error messages for invalid foundation_year' do 201 should 'show error messages for invalid foundation_year' do
228 - org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default)  
229 - post :edit, :profile => 'testorg', :profile_data => { :foundation_year => 'aaa' } 202 + org = fast_create(Community)
  203 + post :edit, :profile => org.identifier, :profile_data => { :foundation_year => 'aaa' }
230 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' } 204 assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' }
231 end 205 end
232 206
233 should 'edit enterprise' do 207 should 'edit enterprise' do
234 - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :environment => Environment.default)  
235 - get :edit, :profile => 'testent' 208 + ent = fast_create(Enterprise)
  209 + get :edit, :profile => ent.identifier
236 assert_response :success 210 assert_response :success
237 end 211 end
238 212
239 should 'back when update community info fail' do 213 should 'back when update community info fail' do
240 - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) 214 + org = fast_create(Community)
241 Community.any_instance.stubs(:update_attributes!).returns(false) 215 Community.any_instance.stubs(:update_attributes!).returns(false)
242 - post :edit, :profile => 'testorg' 216 + post :edit, :profile => org.identifier
243 assert_template 'edit' 217 assert_template 'edit'
244 end 218 end
245 219
246 should 'back when update enterprise info fail' do 220 should 'back when update enterprise info fail' do
247 - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) 221 + org = fast_create(Enterprise)
248 Enterprise.any_instance.stubs(:update_attributes!).returns(false) 222 Enterprise.any_instance.stubs(:update_attributes!).returns(false)
249 - post :edit, :profile => 'testorg' 223 + post :edit, :profile => org.identifier
250 assert_template 'edit' 224 assert_template 'edit'
251 end 225 end
252 226
253 should 'show edit profile button' do 227 should 'show edit profile button' do
254 - person = create_user('testuser').person  
255 - get :index, :profile => 'testuser'  
256 - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testuser/profile_editor/edit' } 228 + get :index, :profile => profile.identifier
  229 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/profile_editor/edit" }
257 end 230 end
258 231
259 should 'show image field on edit profile' do 232 should 'show image field on edit profile' do
260 - person = create_user('testuser').person  
261 - get :edit, :profile => 'testuser' 233 + get :edit, :profile => profile.identifier
262 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[image_builder][uploaded_data]' } 234 assert_tag :tag => 'input', :attributes => { :name => 'profile_data[image_builder][uploaded_data]' }
263 end 235 end
264 236
@@ -271,13 +243,12 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -271,13 +243,12 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
271 end 243 end
272 244
273 should 'render edit template' do 245 should 'render edit template' do
274 - person = create_user('test_profile').person  
275 - get :edit, :profile => person.identifier 246 + get :edit, :profile => profile.identifier
276 assert_template 'edit' 247 assert_template 'edit'
277 end 248 end
278 249
279 should 'render person partial' do 250 should 'render person partial' do
280 - person = create_user('test_profile', :environment => Environment.default).person 251 + person = profile
281 Person.any_instance.expects(:active_fields).returns(['contact_phone', 'address']).at_least_once 252 Person.any_instance.expects(:active_fields).returns(['contact_phone', 'address']).at_least_once
282 get :edit, :profile => person.identifier 253 get :edit, :profile => person.identifier
283 person.active_fields.each do |field| 254 person.active_fields.each do |field|
@@ -287,70 +258,73 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -287,70 +258,73 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
287 258
288 should 'display only active person fields' do 259 should 'display only active person fields' do
289 Person.any_instance.expects(:active_fields).returns(['cell_phone']).at_least_once 260 Person.any_instance.expects(:active_fields).returns(['cell_phone']).at_least_once
290 - person = create_user('test_profile').person  
291 261
292 - get :edit, :profile => person.identifier 262 + get :edit, :profile => profile.identifier
293 263
294 assert_tag :tag => 'input', :attributes => { :name => "profile_data[cell_phone]" } 264 assert_tag :tag => 'input', :attributes => { :name => "profile_data[cell_phone]" }
295 assert_no_tag :tag => 'input', :attributes => { :name => "profile_data[comercial_phone]" } 265 assert_no_tag :tag => 'input', :attributes => { :name => "profile_data[comercial_phone]" }
296 end 266 end
297 267
298 should 'be able to upload an image' do 268 should 'be able to upload an image' do
299 - person = create_user('test_profile').person  
300 - assert_nil person.image  
301 - post :edit, :profile => 'test_profile', :profile_data => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } } 269 + assert_nil profile.image
  270 + post :edit, :profile => profile.identifier, :profile_data => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } }
302 assert_not_nil assigns(:profile).image 271 assert_not_nil assigns(:profile).image
303 end 272 end
304 273
305 should 'display closed attribute for communities when it is set' do 274 should 'display closed attribute for communities when it is set' do
306 - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true, :environment => Environment.default)  
307 - get :edit, :profile => 'testorg' 275 + org = fast_create(Community)
  276 + org.closed = true
  277 + org.save!
  278 +
  279 + get :edit, :profile => org.identifier
308 280
309 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } 281 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' }
310 assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } 282 assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' }
311 end 283 end
312 284
313 should 'display closed attribute for communities when it is set to false' do 285 should 'display closed attribute for communities when it is set to false' do
314 - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => false)  
315 - get :edit, :profile => 'testorg'  
316 - assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' }  
317 - assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' }  
318 - end  
319 -  
320 - should 'display closed attribute for communities when it is set to nothing at all' do  
321 - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => nil)  
322 - get :edit, :profile => 'testorg'  
323 - assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' }  
324 - assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } 286 + org = fast_create(Community)
  287 +
  288 + [false, nil].each do |value|
  289 + org.closed = value
  290 + org.save!
  291 + get :edit, :profile => org.identifier
  292 + assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' }
  293 + assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' }
  294 + end
325 end 295 end
326 296
327 should 'set closed attribute correctly' do 297 should 'set closed attribute correctly' do
328 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => false) 298 + org = fast_create(Organization)
  299 + org.closed = false
  300 + org.save!
329 301
330 - post :edit, :profile => 'testorg', :profile_data => { :closed => 'true' } 302 + post :edit, :profile => org.identifier, :profile_data => { :closed => 'true' }
331 org.reload 303 org.reload
332 assert org.closed 304 assert org.closed
333 end 305 end
334 306
335 should 'unset closed attribute correctly' do 307 should 'unset closed attribute correctly' do
336 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true) 308 + org = fast_create(Organization)
  309 + org.closed = true
  310 + org.save!
337 311
338 - post :edit, :profile => 'testorg', :profile_data => { :closed => 'false' } 312 + post :edit, :profile => org.identifier, :profile_data => { :closed => 'false' }
339 org.reload 313 org.reload
340 assert !org.closed 314 assert !org.closed
341 end 315 end
342 316
343 should 'not display option to close when it is enterprise' do 317 should 'not display option to close when it is enterprise' do
344 - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default)  
345 - get :edit, :profile => 'testorg' 318 + org = fast_create(Enterprise)
  319 + get :edit, :profile => org.identifier
346 320
347 assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true' } 321 assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true' }
348 assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false' } 322 assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false' }
349 end 323 end
350 324
351 should 'display option to close when it is community' do 325 should 'display option to close when it is community' do
352 - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default)  
353 - get :edit, :profile => 'testorg' 326 + org = fast_create(Community)
  327 + get :edit, :profile => org.identifier
354 328
355 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true' } 329 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true' }
356 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false' } 330 assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false' }
@@ -358,26 +332,26 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -358,26 +332,26 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
358 332
359 should 'display manage members options if has permission' do 333 should 'display manage members options if has permission' do
360 profile = Profile['ze'] 334 profile = Profile['ze']
361 - community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) 335 + community = fast_create(Community)
362 @controller.stubs(:user).returns(profile) 336 @controller.stubs(:user).returns(profile)
363 @controller.stubs(:profile).returns(community) 337 @controller.stubs(:profile).returns(community)
364 profile.stubs(:has_permission?).returns(true) 338 profile.stubs(:has_permission?).returns(true)
365 - get :index, :profile => 'testorg' 339 + get :index, :profile => community.identifier
366 assert_tag :tag => 'a', :content => 'Manage Members' 340 assert_tag :tag => 'a', :content => 'Manage Members'
367 end 341 end
368 342
369 should 'not display manage members options if has no permission' do 343 should 'not display manage members options if has no permission' do
370 profile = Profile['ze'] 344 profile = Profile['ze']
371 - community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) 345 + community = fast_create(Community)
372 @controller.stubs(:user).returns(profile) 346 @controller.stubs(:user).returns(profile)
373 @controller.stubs(:profile).returns(community) 347 @controller.stubs(:profile).returns(community)
374 profile.stubs(:has_permission?).returns(false) 348 profile.stubs(:has_permission?).returns(false)
375 - get :index, :profile => 'testorg' 349 + get :index, :profile => community.identifier
376 assert_no_tag :tag => 'a', :content => 'Manage Members' 350 assert_no_tag :tag => 'a', :content => 'Manage Members'
377 end 351 end
378 352
379 should 'render enterprise partial' do 353 should 'render enterprise partial' do
380 - ent = Enterprise.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) 354 + ent = fast_create(Enterprise)
381 Enterprise.any_instance.expects(:active_fields).returns(['contact_phone', 'contact_person', 'contact_email']).at_least_once 355 Enterprise.any_instance.expects(:active_fields).returns(['contact_phone', 'contact_person', 'contact_email']).at_least_once
382 get :edit, :profile => ent.identifier 356 get :edit, :profile => ent.identifier
383 ent.active_fields.each do |field| 357 ent.active_fields.each do |field|
@@ -386,7 +360,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -386,7 +360,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
386 end 360 end
387 361
388 should 'render community partial' do 362 should 'render community partial' do
389 - community = Community.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) 363 + community = fast_create(Community)
390 Community.any_instance.expects(:active_fields).returns(['contact_person', 'language']).at_least_once 364 Community.any_instance.expects(:active_fields).returns(['contact_person', 'language']).at_least_once
391 get :edit, :profile => community.identifier 365 get :edit, :profile => community.identifier
392 community.active_fields.each do |field| 366 community.active_fields.each do |field|
@@ -395,7 +369,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -395,7 +369,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
395 end 369 end
396 370
397 should 'show task if user has permission' do 371 should 'show task if user has permission' do
398 - user1 = create_user('userone').person 372 + user1 = profile
399 user2 = create_user('usertwo').person 373 user2 = create_user('usertwo').person
400 AddFriend.create!(:person => user1, :friend => user2) 374 AddFriend.create!(:person => user1, :friend => user2)
401 @controller.stubs(:user).returns(user2) 375 @controller.stubs(:user).returns(user2)
@@ -407,7 +381,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -407,7 +381,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
407 end 381 end
408 382
409 should 'not show task if user has no permission' do 383 should 'not show task if user has no permission' do
410 - user1 = create_user('userone').person 384 + user1 = profile
411 user2 = create_user('usertwo').person 385 user2 = create_user('usertwo').person
412 task = AddFriend.create!(:person => user1, :friend => user2) 386 task = AddFriend.create!(:person => user1, :friend => user2)
413 @controller.stubs(:user).returns(user2) 387 @controller.stubs(:user).returns(user2)
@@ -419,14 +393,13 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -419,14 +393,13 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
419 end 393 end
420 394
421 should 'show favorite enterprises button for person' do 395 should 'show favorite enterprises button for person' do
422 - person = create_user('testuser').person  
423 - get :index, :profile => 'testuser' 396 + get :index, :profile => profile.identifier
424 assert_tag :tag => 'a', :content => 'Favorite Enterprises' 397 assert_tag :tag => 'a', :content => 'Favorite Enterprises'
425 end 398 end
426 399
427 should 'not show favorite enterprises button for organization' do 400 should 'not show favorite enterprises button for organization' do
428 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact')  
429 - get :index, :profile => 'testorg' 401 + org = fast_create(Organization)
  402 + get :index, :profile => org.identifier
430 assert_no_tag :tag => 'a', :content => 'Favorite Enterprises' 403 assert_no_tag :tag => 'a', :content => 'Favorite Enterprises'
431 end 404 end
432 405
@@ -438,8 +411,8 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -438,8 +411,8 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
438 411
439 should 'not link to mailconf for organizations' do 412 should 'not link to mailconf for organizations' do
440 MailConf.stubs(:enabled?).returns(true).at_least_once 413 MailConf.stubs(:enabled?).returns(true).at_least_once
441 - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact')  
442 - get :index, :profile => 'testorg' 414 + org = fast_create(Organization)
  415 + get :index, :profile => org.identifier
443 assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testorg/mailconf' } 416 assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testorg/mailconf' }
444 end 417 end
445 418
@@ -450,50 +423,50 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -450,50 +423,50 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
450 end 423 end
451 424
452 should 'link to enable enterprise' do 425 should 'link to enable enterprise' do
453 - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default)  
454 - get :index, :profile => 'testent'  
455 - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/enable' } 426 + ent = fast_create(Enterprise, :enabled => false)
  427 + get :index, :profile => ent.identifier
  428 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{ent.identifier}/profile_editor/enable" }
456 end 429 end
457 430
458 should 'link to disable enterprise' do 431 should 'link to disable enterprise' do
459 - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default)  
460 - get :index, :profile => 'testent'  
461 - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/disable' } 432 + ent = fast_create(Enterprise, :enabled => true)
  433 + get :index, :profile => ent.identifier
  434 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{ent.identifier}/profile_editor/disable" }
462 end 435 end
463 436
464 should 'not link to enable/disable for non enterprises' do 437 should 'not link to enable/disable for non enterprises' do
465 - ent = Organization.create!(:name => 'test org', :identifier => 'testorg', :enabled => true)  
466 - get :index, :profile => 'testorg'  
467 - assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testorg/profile_editor/disable' } 438 + ent = fast_create(Organization, :enabled => true)
  439 + get :index, :profile => ent.identifier
  440 + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{ent.identifier}/profile_editor/disable" }
468 end 441 end
469 442
470 should 'request enable enterprise confirmation' do 443 should 'request enable enterprise confirmation' do
471 - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default)  
472 - get :enable, :profile => 'testent'  
473 - assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testent/profile_editor/enable', :method => 'post' } 444 + ent = fast_create(Enterprise, :enabled => false)
  445 + get :enable, :profile => ent.identifier
  446 + assert_tag :tag => 'form', :attributes => { :action => "/myprofile/#{ent.identifier}/profile_editor/enable", :method => 'post' }
474 end 447 end
475 448
476 should 'enable enterprise after confirmation' do 449 should 'enable enterprise after confirmation' do
477 - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default)  
478 - post :enable, :profile => 'testent', :confirmation => 1 450 + ent = fast_create(Enterprise, :enabled => false)
  451 + post :enable, :profile => ent.identifier, :confirmation => 1
479 assert assigns(:to_enable).enabled? 452 assert assigns(:to_enable).enabled?
480 end 453 end
481 454
482 should 'not enable enterprise without confirmation' do 455 should 'not enable enterprise without confirmation' do
483 - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default)  
484 - post :enable, :profile => 'testent' 456 + ent = fast_create(Enterprise, :enabled => false)
  457 + post :enable, :profile => ent.identifier
485 assert !assigns(:to_enable).enabled? 458 assert !assigns(:to_enable).enabled?
486 end 459 end
487 460
488 should 'disable enterprise after confirmation' do 461 should 'disable enterprise after confirmation' do
489 - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default)  
490 - post :disable, :profile => 'testent', :confirmation => 1 462 + ent = fast_create(Enterprise, :enabled => true)
  463 + post :disable, :profile => ent.identifier, :confirmation => 1
491 assert !assigns(:to_disable).enabled? 464 assert !assigns(:to_disable).enabled?
492 end 465 end
493 466
494 should 'not disable enterprise without confirmation' do 467 should 'not disable enterprise without confirmation' do
495 - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default)  
496 - post :disable, :profile => 'testent' 468 + ent = fast_create(Enterprise, :enabled => true)
  469 + post :disable, :profile => ent.identifier
497 assert assigns(:to_disable).enabled? 470 assert assigns(:to_disable).enabled?
498 end 471 end
499 472
@@ -509,45 +482,43 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -509,45 +482,43 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
509 end 482 end
510 483
511 should 'display manage my groups button for person' do 484 should 'display manage my groups button for person' do
512 - person = create_user('testuser').person  
513 - get :index, :profile => 'testuser' 485 + get :index, :profile => profile.identifier
514 assert_tag :tag => 'a', :content => 'Manage my groups' 486 assert_tag :tag => 'a', :content => 'Manage my groups'
515 end 487 end
516 488
517 should 'display footer edit screen' do 489 should 'display footer edit screen' do
518 490
519 - person = create_user('designtestuser').person 491 + person = profile
520 person.custom_header = 'my custom header' 492 person.custom_header = 'my custom header'
521 person.custom_footer = 'my custom footer' 493 person.custom_footer = 'my custom footer'
522 person.save! 494 person.save!
523 495
524 - get :header_footer, :profile => 'designtestuser' 496 + get :header_footer, :profile => profile.identifier
525 assert_tag :tag => 'textarea', :content => 'my custom header' 497 assert_tag :tag => 'textarea', :content => 'my custom header'
526 assert_tag :tag => 'textarea', :content => 'my custom footer' 498 assert_tag :tag => 'textarea', :content => 'my custom footer'
527 end 499 end
528 500
529 should 'save footer and header' do 501 should 'save footer and header' do
530 - person = create_user('designtestuser').person  
531 - post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' 502 + person = profile
  503 + post :header_footer, :profile => profile.identifier, :custom_header => 'new header', :custom_footer => 'new footer'
532 person = Person.find(person.id) 504 person = Person.find(person.id)
533 assert_equal 'new header', person.custom_header 505 assert_equal 'new header', person.custom_header
534 assert_equal 'new footer', person.custom_footer 506 assert_equal 'new footer', person.custom_footer
535 end 507 end
536 508
537 should 'save header and footer even if model is invalid' do 509 should 'save header and footer even if model is invalid' do
538 - person = create_user('designtestuser').person 510 + person = profile
539 person.sex = nil; person.save! 511 person.sex = nil; person.save!
540 person.environment.custom_person_fields = {'sex' => {'required' => 'true', 'active' => 'true'} }; person.environment.save! 512 person.environment.custom_person_fields = {'sex' => {'required' => 'true', 'active' => 'true'} }; person.environment.save!
541 513
542 - post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' 514 + post :header_footer, :profile => profile.identifier, :custom_header => 'new header', :custom_footer => 'new footer'
543 person = Person.find(person.id) 515 person = Person.find(person.id)
544 assert_equal 'new header', person.custom_header 516 assert_equal 'new header', person.custom_header
545 assert_equal 'new footer', person.custom_footer 517 assert_equal 'new footer', person.custom_footer
546 end 518 end
547 519
548 should 'go back to editor after saving header/footer' do 520 should 'go back to editor after saving header/footer' do
549 - person = create_user('designtestuser').person  
550 - post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' 521 + post :header_footer, :profile => profile.identifier, :custom_header => 'new header', :custom_footer => 'new footer'
551 assert_redirected_to :action => 'index' 522 assert_redirected_to :action => 'index'
552 end 523 end
553 524
@@ -561,13 +532,13 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -561,13 +532,13 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
561 env.enable('disable_header_and_footer') 532 env.enable('disable_header_and_footer')
562 env.save! 533 env.save!
563 534
564 - enterprise = Enterprise.create!(:name => 'Enterprise for test', :identifier => 'enterprise_for_test') 535 + enterprise = fast_create(Enterprise)
565 536
566 u = create_user_with_permission('test_user', 'edit_profile', enterprise) 537 u = create_user_with_permission('test_user', 'edit_profile', enterprise)
567 login_as('test_user') 538 login_as('test_user')
568 539
569 get :index, :profile => enterprise.identifier 540 get :index, :profile => enterprise.identifier
570 - assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/enterprise_for_test/profile_editor/header_footer" } 541 + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{enterprise.identifier}/profile_editor/header_footer" }
571 end 542 end
572 543
573 should 'display header/footer button to enterprises if the environment disabled it but user is admin' do 544 should 'display header/footer button to enterprises if the environment disabled it but user is admin' do
@@ -575,59 +546,55 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -575,59 +546,55 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
575 env.enable('disable_header_and_footer') 546 env.enable('disable_header_and_footer')
576 env.save! 547 env.save!
577 548
578 - enterprise = Enterprise.create!(:name => 'Enterprise for test', :identifier => 'enterprise_for_test') 549 + enterprise = fast_create(Enterprise)
579 550
580 Person.any_instance.expects(:is_admin?).returns(true).at_least_once 551 Person.any_instance.expects(:is_admin?).returns(true).at_least_once
581 552
582 get :index, :profile => enterprise.identifier 553 get :index, :profile => enterprise.identifier
583 - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/enterprise_for_test/profile_editor/header_footer" } 554 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{enterprise.identifier}/profile_editor/header_footer" }
584 end 555 end
585 556
586 should 'not list the manage products button if the environment disabled it' do 557 should 'not list the manage products button if the environment disabled it' do
587 env = Environment.default 558 env = Environment.default
588 env.enable('disable_products_for_enterprises') 559 env.enable('disable_products_for_enterprises')
589 env.save! 560 env.save!
590 - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :environment => env) 561 + ent = fast_create(Enterprise)
591 562
592 u = create_user_with_permission('test_user', 'edit_profile', ent) 563 u = create_user_with_permission('test_user', 'edit_profile', ent)
593 login_as('test_user') 564 login_as('test_user')
594 565
595 - get :index, :profile => 'test_ent' 566 + get :index, :profile => ent.identifier
596 567
597 assert_no_tag :tag => 'span', :content => 'Manage Products and Services' 568 assert_no_tag :tag => 'span', :content => 'Manage Products and Services'
598 end 569 end
599 570
600 should 'display categories if environment disable_categories disabled' do 571 should 'display categories if environment disable_categories disabled' do
601 Environment.any_instance.stubs(:enabled?).with(anything).returns(false) 572 Environment.any_instance.stubs(:enabled?).with(anything).returns(false)
602 - person = create_user('test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person  
603 - get :edit, :profile => person.identifier 573 + get :edit, :profile => profile.identifier
604 assert_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } 574 assert_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' }
605 end 575 end
606 576
607 should 'not display categories if environment disable_categories enabled' do 577 should 'not display categories if environment disable_categories enabled' do
608 Environment.any_instance.stubs(:enabled?).with(anything).returns(true) 578 Environment.any_instance.stubs(:enabled?).with(anything).returns(true)
609 - person = create_user('test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person  
610 - get :edit, :profile => person.identifier 579 + get :edit, :profile => profile.identifier
611 assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } 580 assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' }
612 end 581 end
613 582
614 should 'show a e-mail field in profile editor' do 583 should 'show a e-mail field in profile editor' do
615 - create_user('test_user', :email=>'teste_user@teste.com')  
616 - login_as('test_user')  
617 - get :edit, :profile => 'test_user' 584 + get :edit, :profile => profile.identifier
618 585
619 assert_tag :tag => 'input', 586 assert_tag :tag => 'input',
620 - :attributes => { :name=>'profile_data[email]', :value=>'teste_user@teste.com' } 587 + :attributes => { :name=>'profile_data[email]', :value => profile.email }
621 end 588 end
622 589
623 should 'display enable contact us for enterprise' do 590 should 'display enable contact us for enterprise' do
624 - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg')  
625 - get :edit, :profile => 'testorg' 591 + org = fast_create(Enterprise)
  592 + get :edit, :profile => org.identifier
626 assert_tag :tag => 'input', :attributes => {:name => 'profile_data[enable_contact_us]', :type => 'checkbox'} 593 assert_tag :tag => 'input', :attributes => {:name => 'profile_data[enable_contact_us]', :type => 'checkbox'}
627 end 594 end
628 595
629 should 'display link to CMS' do 596 should 'display link to CMS' do
630 - get :index, :profile => 'default_user' 597 + get :index, :profile => profile.identifier
631 assert_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' } 598 assert_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' }
632 end 599 end
633 600
@@ -635,20 +602,20 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -635,20 +602,20 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
635 env = Environment.default 602 env = Environment.default
636 env.enable('disable_cms') 603 env.enable('disable_cms')
637 env.save! 604 env.save!
638 - get :index, :profile => 'default_user' 605 + get :index, :profile => profile.identifier
639 606
640 assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' } 607 assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' }
641 end 608 end
642 609
643 should 'offer to create blog in control panel' do 610 should 'offer to create blog in control panel' do
644 - get :index, :profile => 'default_user' 611 + get :index, :profile => profile.identifier
645 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/cms/new?type=Blog" } 612 assert_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/cms/new?type=Blog" }
646 end 613 end
647 614
648 should 'offer to config blog in control panel' do 615 should 'offer to config blog in control panel' do
649 profile.articles << Blog.new(:name => 'My blog', :profile => profile) 616 profile.articles << Blog.new(:name => 'My blog', :profile => profile)
650 get :index, :profile => profile.identifier 617 get :index, :profile => profile.identifier
651 - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/cms/edit/#{profile.blog.id}" } 618 + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/edit/#{profile.blog.id}" }
652 end 619 end
653 620
654 should 'not show select preferred domain if not enabled in environment' do 621 should 'not show select preferred domain if not enabled in environment' do
@@ -688,7 +655,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -688,7 +655,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
688 655
689 should 'not be able to upload an image bigger than max size' do 656 should 'not be able to upload an image bigger than max size' do
690 Image.any_instance.stubs(:size).returns(Image.attachment_options[:max_size] + 1024) 657 Image.any_instance.stubs(:size).returns(Image.attachment_options[:max_size] + 1024)
691 - person = create_user('test_profile').person 658 + person = profile
692 assert_nil person.image 659 assert_nil person.image
693 post :edit, :profile => person.identifier, :profile_data => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } } 660 post :edit, :profile => person.identifier, :profile_data => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } }
694 assert_nil person.image 661 assert_nil person.image
@@ -736,7 +703,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -736,7 +703,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
736 env.enable('enterprise_activation') 703 env.enable('enterprise_activation')
737 env.save! 704 env.save!
738 705
739 - enterprise = Enterprise.create!(:name => 'bli', :identifier => 'bli') 706 + enterprise = fast_create(Enterprise)
740 enterprise.add_admin(profile) 707 enterprise.add_admin(profile)
741 708
742 get :index, :profile => enterprise.identifier 709 get :index, :profile => enterprise.identifier
@@ -744,7 +711,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -744,7 +711,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
744 end 711 end
745 712
746 should 'have url field for identifier when environment allows' do 713 should 'have url field for identifier when environment allows' do
747 - c = Community.create!(:name => 'test community', :identifier => 'test_comm') 714 + c = fast_create(Community)
748 env = c.environment 715 env = c.environment
749 env.enable('enable_organization_url_change') 716 env.enable('enable_organization_url_change')
750 env.save! 717 env.save!
@@ -757,7 +724,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -757,7 +724,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
757 end 724 end
758 725
759 should 'not have url field for identifier when environment not allows' do 726 should 'not have url field for identifier when environment not allows' do
760 - c = Community.create!(:name => 'test community', :identifier => 'test_comm') 727 + c = fast_create(Community)
761 env = c.environment 728 env = c.environment
762 env.disable('enable_organization_url_change') 729 env.disable('enable_organization_url_change')
763 env.save! 730 env.save!
@@ -770,14 +737,14 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -770,14 +737,14 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
770 end 737 end
771 738
772 should 'redirect to new url when is changed' do 739 should 'redirect to new url when is changed' do
773 - c = Community.create!(:name => 'test community', :identifier => 'test_comm') 740 + c = fast_create(Community)
774 post :edit, :profile => c.identifier, :profile_data => {:identifier => 'new_address'} 741 post :edit, :profile => c.identifier, :profile_data => {:identifier => 'new_address'}
775 assert_response :redirect 742 assert_response :redirect
776 assert_redirected_to :action => 'index', :profile => 'new_address' 743 assert_redirected_to :action => 'index', :profile => 'new_address'
777 end 744 end
778 745
779 should 'not crash if identifier is left blank' do 746 should 'not crash if identifier is left blank' do
780 - c = Community.create!(:name => 'test community', :identifier => 'test_comm') 747 + c = fast_create(Community)
781 assert_nothing_raised do 748 assert_nothing_raised do
782 post :edit, :profile => c.identifier, :profile_data => c.attributes.merge('identifier' => '') 749 post :edit, :profile => c.identifier, :profile_data => c.attributes.merge('identifier' => '')
783 end 750 end
@@ -791,7 +758,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -791,7 +758,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
791 'contact_phone' => {'active' => 'true', 'required' => 'false'} 758 'contact_phone' => {'active' => 'true', 'required' => 'false'}
792 } 759 }
793 env.save! 760 env.save!
794 - community = Community.create(:name => 'test_profile') 761 + community = fast_create(Community)
795 762
796 get :edit, :profile => community.identifier 763 get :edit, :profile => community.identifier
797 764
@@ -807,7 +774,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -807,7 +774,7 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
807 'contact_phone' => {'active' => 'false', 'required' => 'false'} 774 'contact_phone' => {'active' => 'false', 'required' => 'false'}
808 } 775 }
809 env.save! 776 env.save!
810 - community = Community.create(:name => 'test_profile') 777 + community = fast_create(Community)
811 778
812 get :edit, :profile => community.identifier 779 get :edit, :profile => community.identifier
813 780
@@ -817,18 +784,17 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase @@ -817,18 +784,17 @@ class ProfileEditorControllerTest &lt; Test::Unit::TestCase
817 end 784 end
818 785
819 should 'show profile nickname on title' do 786 should 'show profile nickname on title' do
820 - person = create_user('testuser', {}, :nickname => 'my nick').person  
821 - get :index, :profile => 'testuser' 787 + profile.update_attributes(:nickname => 'my nick')
  788 + get :index, :profile => profile.identifier
822 assert_tag :tag => 'h1', :attributes => { :class => 'block-title'}, :descendant => { 789 assert_tag :tag => 'h1', :attributes => { :class => 'block-title'}, :descendant => {
823 :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => 'my nick' 790 :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => 'my nick'
824 } 791 }
825 end 792 end
826 793
827 should 'show profile name on title when no nickname' do 794 should 'show profile name on title when no nickname' do
828 - person = create_user('testuser').person  
829 - get :index, :profile => 'testuser' 795 + get :index, :profile => profile.identifier
830 assert_tag :tag => 'h1', :attributes => { :class => 'block-title'}, :descendant => { 796 assert_tag :tag => 'h1', :attributes => { :class => 'block-title'}, :descendant => {
831 - :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => 'testuser' 797 + :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => profile.identifier
832 } 798 }
833 end 799 end
834 800
test/functional/search_controller_test.rb
@@ -11,8 +11,20 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -11,8 +11,20 @@ class SearchControllerTest &lt; Test::Unit::TestCase
11 @response = ActionController::TestResponse.new 11 @response = ActionController::TestResponse.new
12 12
13 @category = Category.create!(:name => 'my category', :environment => Environment.default) 13 @category = Category.create!(:name => 'my category', :environment => Environment.default)
14 - Profile.rebuild_index  
15 - Article.rebuild_index 14 + end
  15 +
  16 + def create_article_with_optional_category(name, profile, category = nil)
  17 + article = fast_create(Article, :name => name, :profile_id => profile.id)
  18 + article.add_category(category) if category
  19 + article.ferret_create
  20 + article
  21 + end
  22 +
  23 + def create_profile_with_optional_category(klass, name, category = nil, data = {})
  24 + profile = fast_create(klass, { :name => name }.merge(data))
  25 + profile.add_category(category) if category
  26 + profile.ferret_create
  27 + profile
16 end 28 end
17 29
18 def test_local_files_reference 30 def test_local_files_reference
@@ -54,25 +66,20 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -54,25 +66,20 @@ class SearchControllerTest &lt; Test::Unit::TestCase
54 end 66 end
55 67
56 should 'search for articles' do 68 should 'search for articles' do
57 - person = create_user('teste').person  
58 - art = person.articles.build(:name => 'an article to be found'); art.save! 69 + person = fast_create(Person)
  70 + art = create_article_with_optional_category('an article to be found', person)
59 71
60 get 'index', :query => 'article found', :find_in => [ 'articles' ] 72 get 'index', :query => 'article found', :find_in => [ 'articles' ]
61 -  
62 assert_includes assigns(:results)[:articles], art 73 assert_includes assigns(:results)[:articles], art
63 end 74 end
64 75
65 should 'search for articles in a specific category' do 76 should 'search for articles in a specific category' do
66 - person = create_user('teste').person 77 + person = fast_create(Person)
67 78
68 # in category 79 # in category
69 - art1 = person.articles.build(:name => 'an article to be found')  
70 - art1.add_category @category  
71 - art1.save!  
72 - 80 + art1 = create_article_with_optional_category('an article to be found', person, @category)
73 # not in category 81 # not in category
74 - art2 = person.articles.build(:name => 'another article to be found')  
75 - art2.save! 82 + art2 = create_article_with_optional_category('another article to be found', person)
76 83
77 get :index, :category_path => [ 'my-category' ], :query => 'article found', :find_in => [ 'articles' ] 84 get :index, :category_path => [ 'my-category' ], :query => 'article found', :find_in => [ 'articles' ]
78 85
@@ -82,12 +89,10 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -82,12 +89,10 @@ class SearchControllerTest &lt; Test::Unit::TestCase
82 89
83 # 'assets' outside any category 90 # 'assets' outside any category
84 should 'list articles in general' do 91 should 'list articles in general' do
85 - person = create_user('testuser').person  
86 - person2 = create_user('anotheruser').person 92 + person = fast_create(Person)
87 93
88 - art1 = person.articles.create!(:name => 'one article', :category_ids => [@category.id])  
89 -  
90 - art2 = person2.articles.create!(:name => 'two article', :category_ids => [@category.id]) 94 + art1 = create_article_with_optional_category('one article', person, @category)
  95 + art2 = create_article_with_optional_category('two article', person, @category)
91 96
92 get :assets, :asset => 'articles' 97 get :assets, :asset => 'articles'
93 98
@@ -97,14 +102,13 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -97,14 +102,13 @@ class SearchControllerTest &lt; Test::Unit::TestCase
97 102
98 # 'assets' inside a category 103 # 'assets' inside a category
99 should 'list articles in a specific category' do 104 should 'list articles in a specific category' do
100 - person = create_user('testuser').person 105 + person = fast_create(Person)
101 106
102 # in category 107 # in category
103 - art1 = person.articles.create!(:name => 'one article', :category_ids => [@category.id])  
104 - art2 = person.articles.create!(:name => 'other article', :category_ids => [@category.id])  
105 - 108 + art1 = create_article_with_optional_category('one article', person, @category)
  109 + art2 = create_article_with_optional_category('two article', person, @category)
106 # not in category 110 # not in category
107 - art3 = person.articles.create!(:name => 'another article') 111 + art3 = create_article_with_optional_category('another article', person)
108 112
109 get :assets, :asset => 'articles', :category_path => ['my-category'] 113 get :assets, :asset => 'articles', :category_path => ['my-category']
110 114
@@ -114,7 +118,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -114,7 +118,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
114 end 118 end
115 119
116 should 'find enterprises' do 120 should 'find enterprises' do
117 - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') 121 + ent = create_profile_with_optional_category(Enterprise, 'teste')
118 get 'index', :query => 'teste', :find_in => [ 'enterprises' ] 122 get 'index', :query => 'teste', :find_in => [ 'enterprises' ]
119 assert_includes assigns(:results)[:enterprises], ent 123 assert_includes assigns(:results)[:enterprises], ent
120 end 124 end
@@ -122,10 +126,9 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -122,10 +126,9 @@ class SearchControllerTest &lt; Test::Unit::TestCase
122 should 'find enterprises in a specified category' do 126 should 'find enterprises in a specified category' do
123 127
124 # in category 128 # in category
125 - ent1 = Enterprise.create!(:name => 'testing enterprise 1', :identifier => 'test1', :category_ids => [@category.id])  
126 - 129 + ent1 = create_profile_with_optional_category(Enterprise, 'testing enterprise 1', @category)
127 # not in category 130 # not in category
128 - ent2 = Enterprise.create!(:name => 'testing enterprise 2', :identifier => 'test2') 131 + ent2 = create_profile_with_optional_category(Enterprise, 'testing enterprise 2')
129 132
130 get :index, :category_path => [ 'my-category' ], :query => 'testing', :find_in => [ 'enterprises' ] 133 get :index, :category_path => [ 'my-category' ], :query => 'testing', :find_in => [ 'enterprises' ]
131 134
@@ -134,8 +137,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -134,8 +137,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase
134 end 137 end
135 138
136 should 'list enterprises in general' do 139 should 'list enterprises in general' do
137 - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1')  
138 - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2') 140 + ent1 = create_profile_with_optional_category(Enterprise, 'teste 1')
  141 + ent2 = create_profile_with_optional_category(Enterprise, 'teste 2')
139 142
140 get :assets, :asset => 'enterprises' 143 get :assets, :asset => 'enterprises'
141 assert_includes assigns(:results)[:enterprises], ent1 144 assert_includes assigns(:results)[:enterprises], ent1
@@ -145,10 +148,9 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -145,10 +148,9 @@ class SearchControllerTest &lt; Test::Unit::TestCase
145 # 'assets' menu inside a category 148 # 'assets' menu inside a category
146 should 'list enterprises in a specified category' do 149 should 'list enterprises in a specified category' do
147 # in category 150 # in category
148 - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1', :category_ids => [@category.id])  
149 - 151 + ent1 = create_profile_with_optional_category(Enterprise, 'teste 1', @category)
150 # not in category 152 # not in category
151 - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2') 153 + ent2 = create_profile_with_optional_category(Enterprise, 'teste 2')
152 154
153 get :assets, :asset => 'enterprises', :category_path => [ 'my-category' ] 155 get :assets, :asset => 'enterprises', :category_path => [ 'my-category' ]
154 assert_includes assigns(:results)[:enterprises], ent1 156 assert_includes assigns(:results)[:enterprises], ent1
@@ -196,15 +198,14 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -196,15 +198,14 @@ class SearchControllerTest &lt; Test::Unit::TestCase
196 end 198 end
197 199
198 should 'find communities' do 200 should 'find communities' do
199 - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) 201 + c1 = create_profile_with_optional_category(Community, 'a beautiful community')
200 get :index, :query => 'beautiful', :find_in => [ 'communities' ] 202 get :index, :query => 'beautiful', :find_in => [ 'communities' ]
201 assert_includes assigns(:results)[:communities], c1 203 assert_includes assigns(:results)[:communities], c1
202 end 204 end
203 205
204 should 'find communities in a specified category' do 206 should 'find communities in a specified category' do
205 - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default)  
206 - c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default)  
207 - c1.add_category @category; c1.save! 207 + c1 = create_profile_with_optional_category(Community, 'a beautiful community', @category)
  208 + c2 = create_profile_with_optional_category(Community, 'another beautiful community')
208 get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'communities' ] 209 get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'communities' ]
209 assert_includes assigns(:results)[:communities], c1 210 assert_includes assigns(:results)[:communities], c1
210 assert_not_includes assigns(:results)[:communities], c2 211 assert_not_includes assigns(:results)[:communities], c2
@@ -212,8 +213,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -212,8 +213,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase
212 213
213 # 'assets' menu outside any category 214 # 'assets' menu outside any category
214 should 'list communities in general' do 215 should 'list communities in general' do
215 - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default)  
216 - c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default) 216 + c1 = create_profile_with_optional_category(Community, 'a beautiful community')
  217 + c2 = create_profile_with_optional_category(Community, 'another beautiful community')
217 218
218 get :assets, :asset => 'communities' 219 get :assets, :asset => 'communities'
219 assert_equivalent [c2, c1], assigns(:results)[:communities] 220 assert_equivalent [c2, c1], assigns(:results)[:communities]
@@ -223,15 +224,13 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -223,15 +224,13 @@ class SearchControllerTest &lt; Test::Unit::TestCase
223 should 'list communities in a specified category' do 224 should 'list communities in a specified category' do
224 225
225 # in category 226 # in category
226 - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default)  
227 - c1.add_category @category 227 + c1 = create_profile_with_optional_category(Community, 'a beautiful community', @category)
228 228
229 # not in category 229 # not in category
230 - c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default) 230 + c2 = create_profile_with_optional_category(Community, 'another beautiful community')
231 231
232 # in category 232 # in category
233 - c3 = Community.create!(:name => 'yet another beautiful community', :identifier => 'yet_an_bea_comm', :environment => Environment.default)  
234 - c3.add_category @category 233 + c3 = create_profile_with_optional_category(Community, 'yet another beautiful community', @category)
235 234
236 get :assets, :asset => 'communities', :category_path => [ 'my-category' ] 235 get :assets, :asset => 'communities', :category_path => [ 'my-category' ]
237 236
@@ -239,22 +238,22 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -239,22 +238,22 @@ class SearchControllerTest &lt; Test::Unit::TestCase
239 end 238 end
240 239
241 should 'find communities in signup wizard' do 240 should 'find communities in signup wizard' do
242 - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) 241 + c1 = create_profile_with_optional_category(Community, 'a beautiful community')
243 get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true 242 get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true
244 assert_includes assigns(:results)[:communities], c1 243 assert_includes assigns(:results)[:communities], c1
245 assert_equal 'layouts/wizard', @response.layout 244 assert_equal 'layouts/wizard', @response.layout
246 end 245 end
247 246
248 should 'find products' do 247 should 'find products' do
249 - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') 248 + ent = create_profile_with_optional_category(Enterprise, 'teste')
250 prod = ent.products.create!(:name => 'a beautiful product') 249 prod = ent.products.create!(:name => 'a beautiful product')
251 get 'index', :query => 'beautiful', :find_in => ['products'] 250 get 'index', :query => 'beautiful', :find_in => ['products']
252 assert_includes assigns(:results)[:products], prod 251 assert_includes assigns(:results)[:products], prod
253 end 252 end
254 253
255 should 'find products in a specific category' do 254 should 'find products in a specific category' do
256 - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id])  
257 - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') 255 + ent1 = create_profile_with_optional_category(Enterprise, 'teste1', @category)
  256 + ent2 = create_profile_with_optional_category(Enterprise, 'teste2')
258 prod1 = ent1.products.create!(:name => 'a beautiful product') 257 prod1 = ent1.products.create!(:name => 'a beautiful product')
259 prod2 = ent2.products.create!(:name => 'another beautiful product') 258 prod2 = ent2.products.create!(:name => 'another beautiful product')
260 get :index, :category_path => @category.path.split('/'), :query => 'beautiful', :find_in => ['products'] 259 get :index, :category_path => @category.path.split('/'), :query => 'beautiful', :find_in => ['products']
@@ -266,8 +265,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -266,8 +265,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase
266 should 'list products in general' do 265 should 'list products in general' do
267 Profile.delete_all 266 Profile.delete_all
268 267
269 - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1')  
270 - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') 268 + ent1 = create_profile_with_optional_category(Enterprise, 'teste1')
  269 + ent2 = create_profile_with_optional_category(Enterprise, 'teste2')
271 prod1 = ent1.products.create!(:name => 'a beautiful product') 270 prod1 = ent1.products.create!(:name => 'a beautiful product')
272 prod2 = ent2.products.create!(:name => 'another beautiful product') 271 prod2 = ent2.products.create!(:name => 'another beautiful product')
273 272
@@ -280,11 +279,11 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -280,11 +279,11 @@ class SearchControllerTest &lt; Test::Unit::TestCase
280 Profile.delete_all 279 Profile.delete_all
281 280
282 # in category 281 # in category
283 - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.add_category @category 282 + ent1 = create_profile_with_optional_category(Enterprise, 'teste1', @category)
284 prod1 = ent1.products.create!(:name => 'a beautiful product') 283 prod1 = ent1.products.create!(:name => 'a beautiful product')
285 284
286 # not in category 285 # not in category
287 - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') 286 + ent2 = create_profile_with_optional_category(Enterprise, 'teste2')
288 prod2 = ent2.products.create!(:name => 'another beautiful product') 287 prod2 = ent2.products.create!(:name => 'another beautiful product')
289 288
290 get :assets, :asset => 'products', :category_path => [ 'my-category' ] 289 get :assets, :asset => 'products', :category_path => [ 'my-category' ]
@@ -294,8 +293,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -294,8 +293,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase
294 293
295 should 'paginate enterprise listing' do 294 should 'paginate enterprise listing' do
296 @controller.expects(:limit).returns(1) 295 @controller.expects(:limit).returns(1)
297 - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste_1')  
298 - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste_2') 296 + ent1 = create_profile_with_optional_category(Enterprise, 'teste 1')
  297 + ent2 = create_profile_with_optional_category(Enterprise, 'teste 2')
299 298
300 get :assets, :asset => 'enterprises', :page => '2' 299 get :assets, :asset => 'enterprises', :page => '2'
301 300
@@ -303,13 +302,13 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -303,13 +302,13 @@ class SearchControllerTest &lt; Test::Unit::TestCase
303 end 302 end
304 303
305 should 'display search results' do 304 should 'display search results' do
306 - ent = Enterprise.create!(:name => 'display enterprise', :identifier => 'teste1') 305 + ent = create_profile_with_optional_category(Enterprise, 'display enterprise')
307 product = ent.products.create!(:name => 'display product') 306 product = ent.products.create!(:name => 'display product')
308 person = create_user('displayperson').person; person.name = 'display person'; person.save! 307 person = create_user('displayperson').person; person.name = 'display person'; person.save!
309 article = person.articles.create!(:name => 'display article') 308 article = person.articles.create!(:name => 'display article')
310 event = Event.new(:name => 'display event', :start_date => Date.today); event.profile = person; event.save! 309 event = Event.new(:name => 'display event', :start_date => Date.today); event.profile = person; event.save!
311 comment = article.comments.create!(:title => 'display comment', :body => '...', :author => person) 310 comment = article.comments.create!(:title => 'display comment', :body => '...', :author => person)
312 - community = Community.create!(:name => 'display community', :identifier => 'an_bea_comm') 311 + community = create_profile_with_optional_category(Community, 'display community')
313 312
314 get :index, :query => 'display' 313 get :index, :query => 'display'
315 314
@@ -320,8 +319,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -320,8 +319,8 @@ class SearchControllerTest &lt; Test::Unit::TestCase
320 :products => ['Products', product], 319 :products => ['Products', product],
321 :events => ['Events', event], 320 :events => ['Events', event],
322 } 321 }
323 - names.each do |thing, description|  
324 - description, object = description 322 + names.each do |thing, pair|
  323 + description, object = pair
325 assert_tag :tag => 'div', :attributes => { :class => /search-results-#{thing}/ }, :descendant => { :tag => 'h3', :content => Regexp.new(description) } 324 assert_tag :tag => 'div', :attributes => { :class => /search-results-#{thing}/ }, :descendant => { :tag => 'h3', :content => Regexp.new(description) }
326 assert_tag :tag => 'a', :content => object.respond_to?(:short_name) ? object.short_name : object.name 325 assert_tag :tag => 'a', :content => object.respond_to?(:short_name) ? object.short_name : object.name
327 end 326 end
@@ -507,9 +506,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -507,9 +506,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
507 parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) 506 parent = Category.create!(:name => 'Parent Category', :environment => Environment.default)
508 child = Category.create!(:name => 'Child Category', :environment => Environment.default, :parent => parent) 507 child = Category.create!(:name => 'Child Category', :environment => Environment.default, :parent => parent)
509 508
510 - p = create_user('test_profile').person  
511 - p.add_category child  
512 - p.save! 509 + p = create_profile_with_optional_category(Person, 'test_profile', child)
513 510
514 get :index, :category_path => ['parent-category'], :query => 'test_profile', :find_in => ['people'] 511 get :index, :category_path => ['parent-category'], :query => 'test_profile', :find_in => ['people']
515 512
@@ -526,11 +523,11 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -526,11 +523,11 @@ class SearchControllerTest &lt; Test::Unit::TestCase
526 end 523 end
527 524
528 should 'find enterprise by product category' do 525 should 'find enterprise by product category' do
529 - ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1') 526 + ent1 = create_profile_with_optional_category(Enterprise, 'test1')
530 prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) 527 prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default)
531 prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) 528 prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat)
532 529
533 - ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2') 530 + ent2 = create_profile_with_optional_category(Enterprise, 'test2')
534 531
535 get :index, :query => prod_cat.name 532 get :index, :query => prod_cat.name
536 533
@@ -540,12 +537,11 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -540,12 +537,11 @@ class SearchControllerTest &lt; Test::Unit::TestCase
540 537
541 should 'find profiles by radius and region' do 538 should 'find profiles by radius and region' do
542 city = City.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) 539 city = City.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0)
543 - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0)  
544 - p1 = create_user('test2').person  
545 - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.save!  
546 - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0)  
547 - p2 = create_user('test4').person  
548 - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.save! 540 + ent1 = create_profile_with_optional_category(Enterprise, 'test 1', nil, :lat => 45.0, :lng => 45.0)
  541 + p1 = create_profile_with_optional_category(Person, 'test 2', nil, :lat => 45.0, :lng => 45.0)
  542 +
  543 + ent2 = create_profile_with_optional_category(Enterprise, 'test 1', nil, :lat => 30.0, :lng => 30.0)
  544 + p2 = create_profile_with_optional_category(Person, 'test 2', nil, :lat => 30.0, :lng => 30.0)
549 545
550 get :index, :city => city.id, :radius => 10, :query => 'test' 546 get :index, :city => city.id, :radius => 10, :query => 'test'
551 547
@@ -732,7 +728,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -732,7 +728,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
732 should 'list only categories with products' do 728 should 'list only categories with products' do
733 cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default) 729 cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default)
734 cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default) 730 cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default)
735 - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') 731 + ent = create_profile_with_optional_category(Enterprise, 'test ent')
736 732
737 cat1.products.create!(:name => 'prod test 1', :enterprise => ent) 733 cat1.products.create!(:name => 'prod test 1', :enterprise => ent)
738 734
@@ -744,7 +740,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -744,7 +740,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
744 740
745 should 'display only within a product category when specified' do 741 should 'display only within a product category when specified' do
746 prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) 742 prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default)
747 - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') 743 + ent = create_profile_with_optional_category(Enterprise, 'test ent')
748 744
749 p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent) 745 p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent)
750 746
@@ -757,7 +753,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -757,7 +753,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
757 cat = Category.create(:name => 'cat', :environment => Environment.default) 753 cat = Category.create(:name => 'cat', :environment => Environment.default)
758 prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) 754 prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default)
759 prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) 755 prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1)
760 - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent', :category_ids => [cat.id]) 756 + ent = create_profile_with_optional_category(Enterprise, 'test ent', cat)
761 757
762 p = prod_cat2.products.create!(:name => 'prod test 1', :enterprise => ent) 758 p = prod_cat2.products.create!(:name => 'prod test 1', :enterprise => ent)
763 759
@@ -769,7 +765,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -769,7 +765,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
769 should 'display only top level product categories that has products when no product category filter is specified' do 765 should 'display only top level product categories that has products when no product category filter is specified' do
770 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) 766 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default)
771 cat2 = ProductCategory.create(:name => 'prod cat 2', :environment => Environment.default) 767 cat2 = ProductCategory.create(:name => 'prod cat 2', :environment => Environment.default)
772 - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') 768 + ent = create_profile_with_optional_category(Enterprise, 'test ent')
773 p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent) 769 p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent)
774 770
775 get :index, :find_in => 'products' 771 get :index, :find_in => 'products'
@@ -782,7 +778,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -782,7 +778,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
782 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) 778 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default)
783 cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) 779 cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1)
784 cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1) 780 cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1)
785 - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') 781 + ent = create_profile_with_optional_category(Enterprise, 'test ent')
786 p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) 782 p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent)
787 783
788 get :index, :find_in => 'products', :product_category => cat1.id 784 get :index, :find_in => 'products', :product_category => cat1.id
@@ -794,7 +790,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -794,7 +790,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
794 should 'list only product categories with enterprises' do 790 should 'list only product categories with enterprises' do
795 cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default) 791 cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default)
796 cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default) 792 cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default)
797 - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') 793 + ent = create_profile_with_optional_category(Enterprise, 'test ent')
798 794
799 cat1.products.create!(:name => 'prod test 1', :enterprise => ent) 795 cat1.products.create!(:name => 'prod test 1', :enterprise => ent)
800 796
@@ -806,10 +802,10 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -806,10 +802,10 @@ class SearchControllerTest &lt; Test::Unit::TestCase
806 802
807 should 'display only enterprises in the product category when its specified' do 803 should 'display only enterprises in the product category when its specified' do
808 prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) 804 prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default)
809 - ent1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1') 805 + ent1 = create_profile_with_optional_category(Enterprise, 'test_ent1')
810 p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent1) 806 p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent1)
811 807
812 - ent2 = Enterprise.create!(:name => 'test ent 2', :identifier => 'test_ent2') 808 + ent2 = create_profile_with_optional_category(Enterprise, 'test_ent2')
813 809
814 get :index, :find_in => 'enterprises', :product_category => prod_cat.id 810 get :index, :find_in => 'enterprises', :product_category => prod_cat.id
815 811
@@ -821,10 +817,10 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -821,10 +817,10 @@ class SearchControllerTest &lt; Test::Unit::TestCase
821 cat = Category.create(:name => 'cat', :environment => Environment.default) 817 cat = Category.create(:name => 'cat', :environment => Environment.default)
822 prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) 818 prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default)
823 prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) 819 prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1)
824 - ent1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1', :category_ids => [cat.id]) 820 + ent1 = create_profile_with_optional_category(Enterprise, 'test ent 1', cat)
825 p = prod_cat2.products.create!(:name => 'prod test 1', :enterprise => ent1) 821 p = prod_cat2.products.create!(:name => 'prod test 1', :enterprise => ent1)
826 822
827 - ent2 = Enterprise.create!(:name => 'test ent 2', :identifier => 'test_ent2', :category_ids => [cat.id]) 823 + ent2 = create_profile_with_optional_category(Enterprise, 'test ent 2', cat)
828 824
829 get :index, :find_in => 'enterprises', :category_path => cat.path.split('/'), :product_category => prod_cat1.id 825 get :index, :find_in => 'enterprises', :category_path => cat.path.split('/'), :product_category => prod_cat1.id
830 826
@@ -835,7 +831,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -835,7 +831,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
835 should 'display only top level product categories that has enterprises when no product category filter is specified' do 831 should 'display only top level product categories that has enterprises when no product category filter is specified' do
836 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) 832 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default)
837 cat2 = ProductCategory.create(:name => 'prod cat 2', :environment => Environment.default) 833 cat2 = ProductCategory.create(:name => 'prod cat 2', :environment => Environment.default)
838 - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') 834 + ent = create_profile_with_optional_category(Enterprise, 'test ent')
839 p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent) 835 p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent)
840 836
841 get :index, :find_in => 'enterprises' 837 get :index, :find_in => 'enterprises'
@@ -848,7 +844,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -848,7 +844,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
848 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) 844 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default)
849 cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) 845 cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1)
850 cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1) 846 cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1)
851 - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') 847 + ent = create_profile_with_optional_category(Enterprise, 'test ent')
852 p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) 848 p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent)
853 849
854 get :index, :find_in => 'enterprises', :product_category => cat1.id 850 get :index, :find_in => 'enterprises', :product_category => cat1.id
@@ -861,7 +857,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -861,7 +857,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
861 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) 857 cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default)
862 cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) 858 cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1)
863 cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1) 859 cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1)
864 - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') 860 + ent = create_profile_with_optional_category(Enterprise, 'test ent')
865 p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) 861 p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent)
866 862
867 get :index, :find_in => 'enterprises' 863 get :index, :find_in => 'enterprises'
@@ -924,12 +920,10 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -924,12 +920,10 @@ class SearchControllerTest &lt; Test::Unit::TestCase
924 920
925 should 'search for products by origin and radius correctly' do 921 should 'search for products by origin and radius correctly' do
926 s = City.create!(:name => 'Salvador', :lat => -12.97, :lng => -38.51, :environment => Environment.default) 922 s = City.create!(:name => 'Salvador', :lat => -12.97, :lng => -38.51, :environment => Environment.default)
927 - e1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1', :lat => -12.97, :lng => -38.51) 923 + e1 = create_profile_with_optional_category(Enterprise, 'test ent 1', nil, :lat => -12.97, :lng => -38.51)
928 p1 = e1.products.create!(:name => 'test_product1') 924 p1 = e1.products.create!(:name => 'test_product1')
929 - e1.save!  
930 - e2 = Enterprise.create!(:name => 'test ent 2', :identifier => 'test_ent2', :lat => -14.97, :lng => -40.51) 925 + e2 = create_profile_with_optional_category(Enterprise, 'test ent 2', nil, :lat => -14.97, :lng => -40.51)
931 p2 = e2.products.create!(:name => 'test_product2') 926 p2 = e2.products.create!(:name => 'test_product2')
932 - e2.save!  
933 927
934 get :assets, :asset => 'products', :city => s.id, :radius => 15 928 get :assets, :asset => 'products', :city => s.id, :radius => 15
935 929
@@ -956,7 +950,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -956,7 +950,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
956 should 'indicate more than page for total_entries' do 950 should 'indicate more than page for total_entries' do
957 Enterprise.destroy_all 951 Enterprise.destroy_all
958 ('1'..'20').each do |n| 952 ('1'..'20').each do |n|
959 - Enterprise.create!(:name => 'test ' + n, :identifier => 'test_' + n) 953 + create_profile_with_optional_category(Enterprise, 'test ' + n)
960 end 954 end
961 955
962 get :index, :query => 'test' 956 get :index, :query => 'test'
@@ -979,7 +973,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -979,7 +973,7 @@ class SearchControllerTest &lt; Test::Unit::TestCase
979 end 973 end
980 974
981 should 'display steps when searching on wizard' do 975 should 'display steps when searching on wizard' do
982 - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) 976 + c1 = create_profile_with_optional_category(Community, 'a beautiful community')
983 login_as('ze') 977 login_as('ze')
984 get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true 978 get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true
985 assert_equal 'layouts/wizard', @response.layout 979 assert_equal 'layouts/wizard', @response.layout
@@ -987,14 +981,14 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -987,14 +981,14 @@ class SearchControllerTest &lt; Test::Unit::TestCase
987 end 981 end
988 982
989 should 'not display steps when searching not on wizard' do 983 should 'not display steps when searching not on wizard' do
990 - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) 984 + c1 = create_profile_with_optional_category(Community, 'a beautiful community')
991 get :index, :query => 'beautiful', :find_in => [ 'communities' ] 985 get :index, :query => 'beautiful', :find_in => [ 'communities' ]
992 assert_equal 'layouts/application', @response.layout 986 assert_equal 'layouts/application', @response.layout
993 assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'} 987 assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'}
994 end 988 end
995 989
996 should 'find products when enterprises has own hostname' do 990 should 'find products when enterprises has own hostname' do
997 - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') 991 + ent = create_profile_with_optional_category(Enterprise, 'teste')
998 ent.domains << Domain.new(:name => 'testent.com'); ent.save! 992 ent.domains << Domain.new(:name => 'testent.com'); ent.save!
999 prod = ent.products.create!(:name => 'a beautiful product') 993 prod = ent.products.create!(:name => 'a beautiful product')
1000 get 'index', :query => 'beautiful', :find_in => ['products'] 994 get 'index', :query => 'beautiful', :find_in => ['products']