Commit 2eb3df9888358960cc4e1858029659e16177e7d5
1 parent
d36492d6
Exists in
master
and in
29 other branches
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.
Showing
3 changed files
with
250 additions
and
272 deletions
Show diff stats
test/factories.rb
... | ... | @@ -163,7 +163,7 @@ module Noosfero::Factory |
163 | 163 | end |
164 | 164 | |
165 | 165 | ############################################### |
166 | - # Enterprise | |
166 | + # Community | |
167 | 167 | ############################################### |
168 | 168 | |
169 | 169 | def defaults_for_community |
... | ... | @@ -172,6 +172,15 @@ module Noosfero::Factory |
172 | 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 | 184 | # Profile |
176 | 185 | ############################################### |
177 | 186 | |
... | ... | @@ -181,6 +190,15 @@ module Noosfero::Factory |
181 | 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 | 202 | # Article |
185 | 203 | ############################################### |
186 | 204 | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -27,13 +27,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
27 | 27 | end |
28 | 28 | |
29 | 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 | 31 | assert_template 'index' |
38 | 32 | assert_response :success |
39 | 33 | assert_not_nil assigns(:profile) |
... | ... | @@ -53,15 +47,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
53 | 47 | end |
54 | 48 | |
55 | 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 | 51 | assert_response :success |
59 | 52 | assert_template 'edit' |
60 | 53 | end |
61 | 54 | |
62 | 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 | 58 | assert_redirected_to :action => 'index' |
66 | 59 | person = Person.find(person.id) |
67 | 60 | assert_equal 'new person', person.name |
... | ... | @@ -72,15 +65,15 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
72 | 65 | |
73 | 66 | should 'not permmit if not logged' do |
74 | 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 | 70 | end |
78 | 71 | |
79 | 72 | should 'display categories to choose to associate profile' do |
80 | 73 | cat1 = Environment.default.categories.build(:display_in_menu => true, :name => 'top category'); cat1.save! |
81 | 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 | 77 | assert_response :success |
85 | 78 | assert_template 'edit' |
86 | 79 | assert_tag :tag => 'input', :attributes => {:name => 'profile_data[category_ids][]', :value => cat2.id} |
... | ... | @@ -89,114 +82,95 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
89 | 82 | should 'save categorization of profile' do |
90 | 83 | cat1 = Environment.default.categories.build(:name => 'top category'); cat1.save! |
91 | 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 | 87 | assert_response :redirect |
95 | 88 | assert_redirected_to :action => 'index' |
96 | 89 | assert_includes person.categories, cat2 |
97 | 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 | 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 | 95 | assert_sanitized assigns(:profile).name |
104 | 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 | 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 | 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 | 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 | 112 | assert_sanitized assigns(:profile).management_information |
139 | 113 | end |
140 | 114 | |
141 | 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 | 118 | assert_equal 'contact person', Organization.find(org.id).contact_person |
145 | 119 | end |
146 | 120 | |
147 | 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 | 123 | Enterprise.any_instance.expects(:active_fields).returns(['contact_phone']).at_least_once |
150 | 124 | get :edit, :profile => org.identifier |
151 | 125 | assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } |
152 | 126 | end |
153 | 127 | |
154 | 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 | 131 | assert_equal 'my description', Organization.find(org.id).description |
158 | 132 | end |
159 | 133 | |
160 | 134 | should 'show community description' do |
161 | - org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) | |
135 | + org = fast_create(Community) | |
162 | 136 | Community.any_instance.expects(:active_fields).returns(['description']).at_least_once |
163 | - get :edit, :profile => 'testorg' | |
137 | + get :edit, :profile => org.identifier | |
164 | 138 | assert_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } |
165 | 139 | end |
166 | 140 | |
167 | 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 | 144 | assert_no_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } |
171 | 145 | end |
172 | 146 | |
173 | 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 | 150 | assert_equal 'my contact', Organization.find(org.id).contact_person |
177 | 151 | end |
178 | 152 | |
179 | 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 | 156 | assert_equal 'my contact', Enterprise.find(org.id).contact_person |
183 | 157 | end |
184 | 158 | |
185 | 159 | should 'show field values on edit community info' do |
186 | 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 | 162 | org.contact_person = 'my contact' |
189 | 163 | org.save! |
190 | - get :edit, :profile => 'testorg' | |
164 | + get :edit, :profile => org.identifier | |
191 | 165 | assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } |
192 | 166 | end |
193 | 167 | |
194 | 168 | should 'show field values on edit enterprise info' do |
195 | 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 | 171 | org.contact_person = 'my contact' |
198 | 172 | org.save! |
199 | - get :edit, :profile => 'testorg' | |
173 | + get :edit, :profile => org.identifier | |
200 | 174 | assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } |
201 | 175 | end |
202 | 176 | |
... | ... | @@ -225,40 +199,38 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
225 | 199 | end |
226 | 200 | |
227 | 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 | 204 | assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' } |
231 | 205 | end |
232 | 206 | |
233 | 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 | 210 | assert_response :success |
237 | 211 | end |
238 | 212 | |
239 | 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 | 215 | Community.any_instance.stubs(:update_attributes!).returns(false) |
242 | - post :edit, :profile => 'testorg' | |
216 | + post :edit, :profile => org.identifier | |
243 | 217 | assert_template 'edit' |
244 | 218 | end |
245 | 219 | |
246 | 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 | 222 | Enterprise.any_instance.stubs(:update_attributes!).returns(false) |
249 | - post :edit, :profile => 'testorg' | |
223 | + post :edit, :profile => org.identifier | |
250 | 224 | assert_template 'edit' |
251 | 225 | end |
252 | 226 | |
253 | 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 | 230 | end |
258 | 231 | |
259 | 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 | 234 | assert_tag :tag => 'input', :attributes => { :name => 'profile_data[image_builder][uploaded_data]' } |
263 | 235 | end |
264 | 236 | |
... | ... | @@ -271,13 +243,12 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
271 | 243 | end |
272 | 244 | |
273 | 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 | 247 | assert_template 'edit' |
277 | 248 | end |
278 | 249 | |
279 | 250 | should 'render person partial' do |
280 | - person = create_user('test_profile', :environment => Environment.default).person | |
251 | + person = profile | |
281 | 252 | Person.any_instance.expects(:active_fields).returns(['contact_phone', 'address']).at_least_once |
282 | 253 | get :edit, :profile => person.identifier |
283 | 254 | person.active_fields.each do |field| |
... | ... | @@ -287,70 +258,73 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
287 | 258 | |
288 | 259 | should 'display only active person fields' do |
289 | 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 | 264 | assert_tag :tag => 'input', :attributes => { :name => "profile_data[cell_phone]" } |
295 | 265 | assert_no_tag :tag => 'input', :attributes => { :name => "profile_data[comercial_phone]" } |
296 | 266 | end |
297 | 267 | |
298 | 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 | 271 | assert_not_nil assigns(:profile).image |
303 | 272 | end |
304 | 273 | |
305 | 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 | 281 | assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } |
310 | 282 | assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } |
311 | 283 | end |
312 | 284 | |
313 | 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 | 295 | end |
326 | 296 | |
327 | 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 | 303 | org.reload |
332 | 304 | assert org.closed |
333 | 305 | end |
334 | 306 | |
335 | 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 | 313 | org.reload |
340 | 314 | assert !org.closed |
341 | 315 | end |
342 | 316 | |
343 | 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 | 321 | assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true' } |
348 | 322 | assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false' } |
349 | 323 | end |
350 | 324 | |
351 | 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 | 329 | assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true' } |
356 | 330 | assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false' } |
... | ... | @@ -358,26 +332,26 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
358 | 332 | |
359 | 333 | should 'display manage members options if has permission' do |
360 | 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 | 336 | @controller.stubs(:user).returns(profile) |
363 | 337 | @controller.stubs(:profile).returns(community) |
364 | 338 | profile.stubs(:has_permission?).returns(true) |
365 | - get :index, :profile => 'testorg' | |
339 | + get :index, :profile => community.identifier | |
366 | 340 | assert_tag :tag => 'a', :content => 'Manage Members' |
367 | 341 | end |
368 | 342 | |
369 | 343 | should 'not display manage members options if has no permission' do |
370 | 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 | 346 | @controller.stubs(:user).returns(profile) |
373 | 347 | @controller.stubs(:profile).returns(community) |
374 | 348 | profile.stubs(:has_permission?).returns(false) |
375 | - get :index, :profile => 'testorg' | |
349 | + get :index, :profile => community.identifier | |
376 | 350 | assert_no_tag :tag => 'a', :content => 'Manage Members' |
377 | 351 | end |
378 | 352 | |
379 | 353 | should 'render enterprise partial' do |
380 | - ent = Enterprise.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) | |
354 | + ent = fast_create(Enterprise) | |
381 | 355 | Enterprise.any_instance.expects(:active_fields).returns(['contact_phone', 'contact_person', 'contact_email']).at_least_once |
382 | 356 | get :edit, :profile => ent.identifier |
383 | 357 | ent.active_fields.each do |field| |
... | ... | @@ -386,7 +360,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
386 | 360 | end |
387 | 361 | |
388 | 362 | should 'render community partial' do |
389 | - community = Community.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) | |
363 | + community = fast_create(Community) | |
390 | 364 | Community.any_instance.expects(:active_fields).returns(['contact_person', 'language']).at_least_once |
391 | 365 | get :edit, :profile => community.identifier |
392 | 366 | community.active_fields.each do |field| |
... | ... | @@ -395,7 +369,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
395 | 369 | end |
396 | 370 | |
397 | 371 | should 'show task if user has permission' do |
398 | - user1 = create_user('userone').person | |
372 | + user1 = profile | |
399 | 373 | user2 = create_user('usertwo').person |
400 | 374 | AddFriend.create!(:person => user1, :friend => user2) |
401 | 375 | @controller.stubs(:user).returns(user2) |
... | ... | @@ -407,7 +381,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
407 | 381 | end |
408 | 382 | |
409 | 383 | should 'not show task if user has no permission' do |
410 | - user1 = create_user('userone').person | |
384 | + user1 = profile | |
411 | 385 | user2 = create_user('usertwo').person |
412 | 386 | task = AddFriend.create!(:person => user1, :friend => user2) |
413 | 387 | @controller.stubs(:user).returns(user2) |
... | ... | @@ -419,14 +393,13 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
419 | 393 | end |
420 | 394 | |
421 | 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 | 397 | assert_tag :tag => 'a', :content => 'Favorite Enterprises' |
425 | 398 | end |
426 | 399 | |
427 | 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 | 403 | assert_no_tag :tag => 'a', :content => 'Favorite Enterprises' |
431 | 404 | end |
432 | 405 | |
... | ... | @@ -438,8 +411,8 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
438 | 411 | |
439 | 412 | should 'not link to mailconf for organizations' do |
440 | 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 | 416 | assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testorg/mailconf' } |
444 | 417 | end |
445 | 418 | |
... | ... | @@ -450,50 +423,50 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
450 | 423 | end |
451 | 424 | |
452 | 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 | 429 | end |
457 | 430 | |
458 | 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 | 435 | end |
463 | 436 | |
464 | 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 | 441 | end |
469 | 442 | |
470 | 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 | 447 | end |
475 | 448 | |
476 | 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 | 452 | assert assigns(:to_enable).enabled? |
480 | 453 | end |
481 | 454 | |
482 | 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 | 458 | assert !assigns(:to_enable).enabled? |
486 | 459 | end |
487 | 460 | |
488 | 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 | 464 | assert !assigns(:to_disable).enabled? |
492 | 465 | end |
493 | 466 | |
494 | 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 | 470 | assert assigns(:to_disable).enabled? |
498 | 471 | end |
499 | 472 | |
... | ... | @@ -509,45 +482,43 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
509 | 482 | end |
510 | 483 | |
511 | 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 | 486 | assert_tag :tag => 'a', :content => 'Manage my groups' |
515 | 487 | end |
516 | 488 | |
517 | 489 | should 'display footer edit screen' do |
518 | 490 | |
519 | - person = create_user('designtestuser').person | |
491 | + person = profile | |
520 | 492 | person.custom_header = 'my custom header' |
521 | 493 | person.custom_footer = 'my custom footer' |
522 | 494 | person.save! |
523 | 495 | |
524 | - get :header_footer, :profile => 'designtestuser' | |
496 | + get :header_footer, :profile => profile.identifier | |
525 | 497 | assert_tag :tag => 'textarea', :content => 'my custom header' |
526 | 498 | assert_tag :tag => 'textarea', :content => 'my custom footer' |
527 | 499 | end |
528 | 500 | |
529 | 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 | 504 | person = Person.find(person.id) |
533 | 505 | assert_equal 'new header', person.custom_header |
534 | 506 | assert_equal 'new footer', person.custom_footer |
535 | 507 | end |
536 | 508 | |
537 | 509 | should 'save header and footer even if model is invalid' do |
538 | - person = create_user('designtestuser').person | |
510 | + person = profile | |
539 | 511 | person.sex = nil; person.save! |
540 | 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 | 515 | person = Person.find(person.id) |
544 | 516 | assert_equal 'new header', person.custom_header |
545 | 517 | assert_equal 'new footer', person.custom_footer |
546 | 518 | end |
547 | 519 | |
548 | 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 | 522 | assert_redirected_to :action => 'index' |
552 | 523 | end |
553 | 524 | |
... | ... | @@ -561,13 +532,13 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
561 | 532 | env.enable('disable_header_and_footer') |
562 | 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 | 537 | u = create_user_with_permission('test_user', 'edit_profile', enterprise) |
567 | 538 | login_as('test_user') |
568 | 539 | |
569 | 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 | 542 | end |
572 | 543 | |
573 | 544 | should 'display header/footer button to enterprises if the environment disabled it but user is admin' do |
... | ... | @@ -575,59 +546,55 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
575 | 546 | env.enable('disable_header_and_footer') |
576 | 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 | 551 | Person.any_instance.expects(:is_admin?).returns(true).at_least_once |
581 | 552 | |
582 | 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 | 555 | end |
585 | 556 | |
586 | 557 | should 'not list the manage products button if the environment disabled it' do |
587 | 558 | env = Environment.default |
588 | 559 | env.enable('disable_products_for_enterprises') |
589 | 560 | env.save! |
590 | - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :environment => env) | |
561 | + ent = fast_create(Enterprise) | |
591 | 562 | |
592 | 563 | u = create_user_with_permission('test_user', 'edit_profile', ent) |
593 | 564 | login_as('test_user') |
594 | 565 | |
595 | - get :index, :profile => 'test_ent' | |
566 | + get :index, :profile => ent.identifier | |
596 | 567 | |
597 | 568 | assert_no_tag :tag => 'span', :content => 'Manage Products and Services' |
598 | 569 | end |
599 | 570 | |
600 | 571 | should 'display categories if environment disable_categories disabled' do |
601 | 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 | 574 | assert_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } |
605 | 575 | end |
606 | 576 | |
607 | 577 | should 'not display categories if environment disable_categories enabled' do |
608 | 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 | 580 | assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } |
612 | 581 | end |
613 | 582 | |
614 | 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 | 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 | 588 | end |
622 | 589 | |
623 | 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 | 593 | assert_tag :tag => 'input', :attributes => {:name => 'profile_data[enable_contact_us]', :type => 'checkbox'} |
627 | 594 | end |
628 | 595 | |
629 | 596 | should 'display link to CMS' do |
630 | - get :index, :profile => 'default_user' | |
597 | + get :index, :profile => profile.identifier | |
631 | 598 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' } |
632 | 599 | end |
633 | 600 | |
... | ... | @@ -635,20 +602,20 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
635 | 602 | env = Environment.default |
636 | 603 | env.enable('disable_cms') |
637 | 604 | env.save! |
638 | - get :index, :profile => 'default_user' | |
605 | + get :index, :profile => profile.identifier | |
639 | 606 | |
640 | 607 | assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' } |
641 | 608 | end |
642 | 609 | |
643 | 610 | should 'offer to create blog in control panel' do |
644 | - get :index, :profile => 'default_user' | |
611 | + get :index, :profile => profile.identifier | |
645 | 612 | assert_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/cms/new?type=Blog" } |
646 | 613 | end |
647 | 614 | |
648 | 615 | should 'offer to config blog in control panel' do |
649 | 616 | profile.articles << Blog.new(:name => 'My blog', :profile => profile) |
650 | 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 | 619 | end |
653 | 620 | |
654 | 621 | should 'not show select preferred domain if not enabled in environment' do |
... | ... | @@ -688,7 +655,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
688 | 655 | |
689 | 656 | should 'not be able to upload an image bigger than max size' do |
690 | 657 | Image.any_instance.stubs(:size).returns(Image.attachment_options[:max_size] + 1024) |
691 | - person = create_user('test_profile').person | |
658 | + person = profile | |
692 | 659 | assert_nil person.image |
693 | 660 | post :edit, :profile => person.identifier, :profile_data => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } } |
694 | 661 | assert_nil person.image |
... | ... | @@ -736,7 +703,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
736 | 703 | env.enable('enterprise_activation') |
737 | 704 | env.save! |
738 | 705 | |
739 | - enterprise = Enterprise.create!(:name => 'bli', :identifier => 'bli') | |
706 | + enterprise = fast_create(Enterprise) | |
740 | 707 | enterprise.add_admin(profile) |
741 | 708 | |
742 | 709 | get :index, :profile => enterprise.identifier |
... | ... | @@ -744,7 +711,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
744 | 711 | end |
745 | 712 | |
746 | 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 | 715 | env = c.environment |
749 | 716 | env.enable('enable_organization_url_change') |
750 | 717 | env.save! |
... | ... | @@ -757,7 +724,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
757 | 724 | end |
758 | 725 | |
759 | 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 | 728 | env = c.environment |
762 | 729 | env.disable('enable_organization_url_change') |
763 | 730 | env.save! |
... | ... | @@ -770,14 +737,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
770 | 737 | end |
771 | 738 | |
772 | 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 | 741 | post :edit, :profile => c.identifier, :profile_data => {:identifier => 'new_address'} |
775 | 742 | assert_response :redirect |
776 | 743 | assert_redirected_to :action => 'index', :profile => 'new_address' |
777 | 744 | end |
778 | 745 | |
779 | 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 | 748 | assert_nothing_raised do |
782 | 749 | post :edit, :profile => c.identifier, :profile_data => c.attributes.merge('identifier' => '') |
783 | 750 | end |
... | ... | @@ -791,7 +758,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
791 | 758 | 'contact_phone' => {'active' => 'true', 'required' => 'false'} |
792 | 759 | } |
793 | 760 | env.save! |
794 | - community = Community.create(:name => 'test_profile') | |
761 | + community = fast_create(Community) | |
795 | 762 | |
796 | 763 | get :edit, :profile => community.identifier |
797 | 764 | |
... | ... | @@ -807,7 +774,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
807 | 774 | 'contact_phone' => {'active' => 'false', 'required' => 'false'} |
808 | 775 | } |
809 | 776 | env.save! |
810 | - community = Community.create(:name => 'test_profile') | |
777 | + community = fast_create(Community) | |
811 | 778 | |
812 | 779 | get :edit, :profile => community.identifier |
813 | 780 | |
... | ... | @@ -817,18 +784,17 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
817 | 784 | end |
818 | 785 | |
819 | 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 | 789 | assert_tag :tag => 'h1', :attributes => { :class => 'block-title'}, :descendant => { |
823 | 790 | :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => 'my nick' |
824 | 791 | } |
825 | 792 | end |
826 | 793 | |
827 | 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 | 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 | 799 | end |
834 | 800 | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -11,8 +11,20 @@ class SearchControllerTest < Test::Unit::TestCase |
11 | 11 | @response = ActionController::TestResponse.new |
12 | 12 | |
13 | 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 | 28 | end |
17 | 29 | |
18 | 30 | def test_local_files_reference |
... | ... | @@ -54,25 +66,20 @@ class SearchControllerTest < Test::Unit::TestCase |
54 | 66 | end |
55 | 67 | |
56 | 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 | 72 | get 'index', :query => 'article found', :find_in => [ 'articles' ] |
61 | - | |
62 | 73 | assert_includes assigns(:results)[:articles], art |
63 | 74 | end |
64 | 75 | |
65 | 76 | should 'search for articles in a specific category' do |
66 | - person = create_user('teste').person | |
77 | + person = fast_create(Person) | |
67 | 78 | |
68 | 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 | 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 | 84 | get :index, :category_path => [ 'my-category' ], :query => 'article found', :find_in => [ 'articles' ] |
78 | 85 | |
... | ... | @@ -82,12 +89,10 @@ class SearchControllerTest < Test::Unit::TestCase |
82 | 89 | |
83 | 90 | # 'assets' outside any category |
84 | 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 | 97 | get :assets, :asset => 'articles' |
93 | 98 | |
... | ... | @@ -97,14 +102,13 @@ class SearchControllerTest < Test::Unit::TestCase |
97 | 102 | |
98 | 103 | # 'assets' inside a category |
99 | 104 | should 'list articles in a specific category' do |
100 | - person = create_user('testuser').person | |
105 | + person = fast_create(Person) | |
101 | 106 | |
102 | 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 | 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 | 113 | get :assets, :asset => 'articles', :category_path => ['my-category'] |
110 | 114 | |
... | ... | @@ -114,7 +118,7 @@ class SearchControllerTest < Test::Unit::TestCase |
114 | 118 | end |
115 | 119 | |
116 | 120 | should 'find enterprises' do |
117 | - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') | |
121 | + ent = create_profile_with_optional_category(Enterprise, 'teste') | |
118 | 122 | get 'index', :query => 'teste', :find_in => [ 'enterprises' ] |
119 | 123 | assert_includes assigns(:results)[:enterprises], ent |
120 | 124 | end |
... | ... | @@ -122,10 +126,9 @@ class SearchControllerTest < Test::Unit::TestCase |
122 | 126 | should 'find enterprises in a specified category' do |
123 | 127 | |
124 | 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 | 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 | 133 | get :index, :category_path => [ 'my-category' ], :query => 'testing', :find_in => [ 'enterprises' ] |
131 | 134 | |
... | ... | @@ -134,8 +137,8 @@ class SearchControllerTest < Test::Unit::TestCase |
134 | 137 | end |
135 | 138 | |
136 | 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 | 143 | get :assets, :asset => 'enterprises' |
141 | 144 | assert_includes assigns(:results)[:enterprises], ent1 |
... | ... | @@ -145,10 +148,9 @@ class SearchControllerTest < Test::Unit::TestCase |
145 | 148 | # 'assets' menu inside a category |
146 | 149 | should 'list enterprises in a specified category' do |
147 | 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 | 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 | 155 | get :assets, :asset => 'enterprises', :category_path => [ 'my-category' ] |
154 | 156 | assert_includes assigns(:results)[:enterprises], ent1 |
... | ... | @@ -196,15 +198,14 @@ class SearchControllerTest < Test::Unit::TestCase |
196 | 198 | end |
197 | 199 | |
198 | 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 | 202 | get :index, :query => 'beautiful', :find_in => [ 'communities' ] |
201 | 203 | assert_includes assigns(:results)[:communities], c1 |
202 | 204 | end |
203 | 205 | |
204 | 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 | 209 | get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'communities' ] |
209 | 210 | assert_includes assigns(:results)[:communities], c1 |
210 | 211 | assert_not_includes assigns(:results)[:communities], c2 |
... | ... | @@ -212,8 +213,8 @@ class SearchControllerTest < Test::Unit::TestCase |
212 | 213 | |
213 | 214 | # 'assets' menu outside any category |
214 | 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 | 219 | get :assets, :asset => 'communities' |
219 | 220 | assert_equivalent [c2, c1], assigns(:results)[:communities] |
... | ... | @@ -223,15 +224,13 @@ class SearchControllerTest < Test::Unit::TestCase |
223 | 224 | should 'list communities in a specified category' do |
224 | 225 | |
225 | 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 | 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 | 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 | 235 | get :assets, :asset => 'communities', :category_path => [ 'my-category' ] |
237 | 236 | |
... | ... | @@ -239,22 +238,22 @@ class SearchControllerTest < Test::Unit::TestCase |
239 | 238 | end |
240 | 239 | |
241 | 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 | 242 | get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true |
244 | 243 | assert_includes assigns(:results)[:communities], c1 |
245 | 244 | assert_equal 'layouts/wizard', @response.layout |
246 | 245 | end |
247 | 246 | |
248 | 247 | should 'find products' do |
249 | - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') | |
248 | + ent = create_profile_with_optional_category(Enterprise, 'teste') | |
250 | 249 | prod = ent.products.create!(:name => 'a beautiful product') |
251 | 250 | get 'index', :query => 'beautiful', :find_in => ['products'] |
252 | 251 | assert_includes assigns(:results)[:products], prod |
253 | 252 | end |
254 | 253 | |
255 | 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 | 257 | prod1 = ent1.products.create!(:name => 'a beautiful product') |
259 | 258 | prod2 = ent2.products.create!(:name => 'another beautiful product') |
260 | 259 | get :index, :category_path => @category.path.split('/'), :query => 'beautiful', :find_in => ['products'] |
... | ... | @@ -266,8 +265,8 @@ class SearchControllerTest < Test::Unit::TestCase |
266 | 265 | should 'list products in general' do |
267 | 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 | 270 | prod1 = ent1.products.create!(:name => 'a beautiful product') |
272 | 271 | prod2 = ent2.products.create!(:name => 'another beautiful product') |
273 | 272 | |
... | ... | @@ -280,11 +279,11 @@ class SearchControllerTest < Test::Unit::TestCase |
280 | 279 | Profile.delete_all |
281 | 280 | |
282 | 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 | 283 | prod1 = ent1.products.create!(:name => 'a beautiful product') |
285 | 284 | |
286 | 285 | # not in category |
287 | - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') | |
286 | + ent2 = create_profile_with_optional_category(Enterprise, 'teste2') | |
288 | 287 | prod2 = ent2.products.create!(:name => 'another beautiful product') |
289 | 288 | |
290 | 289 | get :assets, :asset => 'products', :category_path => [ 'my-category' ] |
... | ... | @@ -294,8 +293,8 @@ class SearchControllerTest < Test::Unit::TestCase |
294 | 293 | |
295 | 294 | should 'paginate enterprise listing' do |
296 | 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 | 299 | get :assets, :asset => 'enterprises', :page => '2' |
301 | 300 | |
... | ... | @@ -303,13 +302,13 @@ class SearchControllerTest < Test::Unit::TestCase |
303 | 302 | end |
304 | 303 | |
305 | 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 | 306 | product = ent.products.create!(:name => 'display product') |
308 | 307 | person = create_user('displayperson').person; person.name = 'display person'; person.save! |
309 | 308 | article = person.articles.create!(:name => 'display article') |
310 | 309 | event = Event.new(:name => 'display event', :start_date => Date.today); event.profile = person; event.save! |
311 | 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 | 313 | get :index, :query => 'display' |
315 | 314 | |
... | ... | @@ -320,8 +319,8 @@ class SearchControllerTest < Test::Unit::TestCase |
320 | 319 | :products => ['Products', product], |
321 | 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 | 324 | assert_tag :tag => 'div', :attributes => { :class => /search-results-#{thing}/ }, :descendant => { :tag => 'h3', :content => Regexp.new(description) } |
326 | 325 | assert_tag :tag => 'a', :content => object.respond_to?(:short_name) ? object.short_name : object.name |
327 | 326 | end |
... | ... | @@ -507,9 +506,7 @@ class SearchControllerTest < Test::Unit::TestCase |
507 | 506 | parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) |
508 | 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 | 511 | get :index, :category_path => ['parent-category'], :query => 'test_profile', :find_in => ['people'] |
515 | 512 | |
... | ... | @@ -526,11 +523,11 @@ class SearchControllerTest < Test::Unit::TestCase |
526 | 523 | end |
527 | 524 | |
528 | 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 | 527 | prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) |
531 | 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 | 532 | get :index, :query => prod_cat.name |
536 | 533 | |
... | ... | @@ -540,12 +537,11 @@ class SearchControllerTest < Test::Unit::TestCase |
540 | 537 | |
541 | 538 | should 'find profiles by radius and region' do |
542 | 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 | 546 | get :index, :city => city.id, :radius => 10, :query => 'test' |
551 | 547 | |
... | ... | @@ -732,7 +728,7 @@ class SearchControllerTest < Test::Unit::TestCase |
732 | 728 | should 'list only categories with products' do |
733 | 729 | cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default) |
734 | 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 | 733 | cat1.products.create!(:name => 'prod test 1', :enterprise => ent) |
738 | 734 | |
... | ... | @@ -744,7 +740,7 @@ class SearchControllerTest < Test::Unit::TestCase |
744 | 740 | |
745 | 741 | should 'display only within a product category when specified' do |
746 | 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 | 745 | p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent) |
750 | 746 | |
... | ... | @@ -757,7 +753,7 @@ class SearchControllerTest < Test::Unit::TestCase |
757 | 753 | cat = Category.create(:name => 'cat', :environment => Environment.default) |
758 | 754 | prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) |
759 | 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 | 758 | p = prod_cat2.products.create!(:name => 'prod test 1', :enterprise => ent) |
763 | 759 | |
... | ... | @@ -769,7 +765,7 @@ class SearchControllerTest < Test::Unit::TestCase |
769 | 765 | should 'display only top level product categories that has products when no product category filter is specified' do |
770 | 766 | cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) |
771 | 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 | 769 | p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent) |
774 | 770 | |
775 | 771 | get :index, :find_in => 'products' |
... | ... | @@ -782,7 +778,7 @@ class SearchControllerTest < Test::Unit::TestCase |
782 | 778 | cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) |
783 | 779 | cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) |
784 | 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 | 782 | p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) |
787 | 783 | |
788 | 784 | get :index, :find_in => 'products', :product_category => cat1.id |
... | ... | @@ -794,7 +790,7 @@ class SearchControllerTest < Test::Unit::TestCase |
794 | 790 | should 'list only product categories with enterprises' do |
795 | 791 | cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default) |
796 | 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 | 795 | cat1.products.create!(:name => 'prod test 1', :enterprise => ent) |
800 | 796 | |
... | ... | @@ -806,10 +802,10 @@ class SearchControllerTest < Test::Unit::TestCase |
806 | 802 | |
807 | 803 | should 'display only enterprises in the product category when its specified' do |
808 | 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 | 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 | 810 | get :index, :find_in => 'enterprises', :product_category => prod_cat.id |
815 | 811 | |
... | ... | @@ -821,10 +817,10 @@ class SearchControllerTest < Test::Unit::TestCase |
821 | 817 | cat = Category.create(:name => 'cat', :environment => Environment.default) |
822 | 818 | prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) |
823 | 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 | 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 | 825 | get :index, :find_in => 'enterprises', :category_path => cat.path.split('/'), :product_category => prod_cat1.id |
830 | 826 | |
... | ... | @@ -835,7 +831,7 @@ class SearchControllerTest < Test::Unit::TestCase |
835 | 831 | should 'display only top level product categories that has enterprises when no product category filter is specified' do |
836 | 832 | cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) |
837 | 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 | 835 | p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent) |
840 | 836 | |
841 | 837 | get :index, :find_in => 'enterprises' |
... | ... | @@ -848,7 +844,7 @@ class SearchControllerTest < Test::Unit::TestCase |
848 | 844 | cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) |
849 | 845 | cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) |
850 | 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 | 848 | p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) |
853 | 849 | |
854 | 850 | get :index, :find_in => 'enterprises', :product_category => cat1.id |
... | ... | @@ -861,7 +857,7 @@ class SearchControllerTest < Test::Unit::TestCase |
861 | 857 | cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) |
862 | 858 | cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) |
863 | 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 | 861 | p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) |
866 | 862 | |
867 | 863 | get :index, :find_in => 'enterprises' |
... | ... | @@ -924,12 +920,10 @@ class SearchControllerTest < Test::Unit::TestCase |
924 | 920 | |
925 | 921 | should 'search for products by origin and radius correctly' do |
926 | 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 | 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 | 926 | p2 = e2.products.create!(:name => 'test_product2') |
932 | - e2.save! | |
933 | 927 | |
934 | 928 | get :assets, :asset => 'products', :city => s.id, :radius => 15 |
935 | 929 | |
... | ... | @@ -956,7 +950,7 @@ class SearchControllerTest < Test::Unit::TestCase |
956 | 950 | should 'indicate more than page for total_entries' do |
957 | 951 | Enterprise.destroy_all |
958 | 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 | 954 | end |
961 | 955 | |
962 | 956 | get :index, :query => 'test' |
... | ... | @@ -979,7 +973,7 @@ class SearchControllerTest < Test::Unit::TestCase |
979 | 973 | end |
980 | 974 | |
981 | 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 | 977 | login_as('ze') |
984 | 978 | get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true |
985 | 979 | assert_equal 'layouts/wizard', @response.layout |
... | ... | @@ -987,14 +981,14 @@ class SearchControllerTest < Test::Unit::TestCase |
987 | 981 | end |
988 | 982 | |
989 | 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 | 985 | get :index, :query => 'beautiful', :find_in => [ 'communities' ] |
992 | 986 | assert_equal 'layouts/application', @response.layout |
993 | 987 | assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'} |
994 | 988 | end |
995 | 989 | |
996 | 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 | 992 | ent.domains << Domain.new(:name => 'testent.com'); ent.save! |
999 | 993 | prod = ent.products.create!(:name => 'a beautiful product') |
1000 | 994 | get 'index', :query => 'beautiful', :find_in => ['products'] | ... | ... |