Commit fa8d321693e983ec61974057aa5162c2636df434
1 parent
de0aceaa
Exists in
master
and in
29 other branches
rails3: fix search_controller tests
Showing
3 changed files
with
17 additions
and
14 deletions
Show diff stats
app/models/category.rb
1 | class Category < ActiveRecord::Base | 1 | class Category < ActiveRecord::Base |
2 | 2 | ||
3 | - attr_accessible :name, :parent_id, :display_color, :display_in_menu, :image_builder | 3 | + attr_accessible :name, :parent_id, :display_color, :display_in_menu, :image_builder, :environment |
4 | 4 | ||
5 | SEARCHABLE_FIELDS = { | 5 | SEARCHABLE_FIELDS = { |
6 | :name => 10, | 6 | :name => 10, |
app/views/search/_search_form.html.erb
1 | <div class='search-form'> | 1 | <div class='search-form'> |
2 | 2 | ||
3 | - <%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.explode_path : [] ) }, | 3 | + <%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.path : nil ) }, |
4 | :method => 'get', :class => 'search_form' ) do %> | 4 | :method => 'get', :class => 'search_form' ) do %> |
5 | 5 | ||
6 | <%= hidden_field_tag :display, params[:display] %> | 6 | <%= hidden_field_tag :display, params[:display] %> |
test/functional/search_controller_test.rb
@@ -13,7 +13,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -13,7 +13,7 @@ class SearchControllerTest < ActionController::TestCase | ||
13 | @request.stubs(:ssl?).returns(false) | 13 | @request.stubs(:ssl?).returns(false) |
14 | @response = ActionController::TestResponse.new | 14 | @response = ActionController::TestResponse.new |
15 | 15 | ||
16 | - @category = create(Category, :name => 'my category', :environment => Environment.default) | 16 | + @category = Category.create!(:name => 'my-category', :environment => Environment.default) |
17 | 17 | ||
18 | env = Environment.default | 18 | env = Environment.default |
19 | domain = env.domains.first | 19 | domain = env.domains.first |
@@ -33,6 +33,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -33,6 +33,7 @@ class SearchControllerTest < ActionController::TestCase | ||
33 | user.stubs(:valid?).returns(true) | 33 | user.stubs(:valid?).returns(true) |
34 | user.stubs(:email).returns('some@test.com') | 34 | user.stubs(:email).returns('some@test.com') |
35 | user.stubs(:save!).returns(true) | 35 | user.stubs(:save!).returns(true) |
36 | + user.stubs(:marked_for_destruction?).returns(false) | ||
36 | Person.any_instance.stubs(:user).returns(user) | 37 | Person.any_instance.stubs(:user).returns(user) |
37 | end | 38 | end |
38 | 39 | ||
@@ -113,7 +114,9 @@ class SearchControllerTest < ActionController::TestCase | @@ -113,7 +114,9 @@ class SearchControllerTest < ActionController::TestCase | ||
113 | end | 114 | end |
114 | 115 | ||
115 | should 'search for people' do | 116 | should 'search for people' do |
116 | - p1 = create_user('people_1').person; p1.name = 'a beautiful person'; p1.save! | 117 | + p1 = create_user('people_1').person; |
118 | + p1.name = 'a beautiful person'; | ||
119 | + p1.save! | ||
117 | get :people, :query => 'beautiful' | 120 | get :people, :query => 'beautiful' |
118 | assert_includes assigns(:searches)[:people][:results], p1 | 121 | assert_includes assigns(:searches)[:people][:results], p1 |
119 | end | 122 | end |
@@ -246,8 +249,8 @@ class SearchControllerTest < ActionController::TestCase | @@ -246,8 +249,8 @@ class SearchControllerTest < ActionController::TestCase | ||
246 | end | 249 | end |
247 | 250 | ||
248 | should 'search in category hierachy' do | 251 | should 'search in category hierachy' do |
249 | - parent = create(Category, :name => 'Parent Category', :environment => Environment.default) | ||
250 | - child = create(Category, :name => 'Child Category', :environment => Environment.default, :parent => parent) | 252 | + parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) |
253 | + child = Category.create!(:name => 'Child Category', :environment => Environment.default, :parent_id => parent.id) | ||
251 | 254 | ||
252 | p = create_profile_with_optional_category(Person, 'test_profile', child) | 255 | p = create_profile_with_optional_category(Person, 'test_profile', child) |
253 | 256 | ||
@@ -282,7 +285,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -282,7 +285,7 @@ class SearchControllerTest < ActionController::TestCase | ||
282 | art = create(Article, :name => 'test article', :profile_id => fast_create(Person).id) | 285 | art = create(Article, :name => 'test article', :profile_id => fast_create(Person).id) |
283 | per = create(Person, :name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id) | 286 | per = create(Person, :name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id) |
284 | com = Community.create!(:name => 'test community') | 287 | com = Community.create!(:name => 'test community') |
285 | - eve = Event.create!(:name => 'test event', :profile_id => fast_create(Person).id) | 288 | + eve = create(Event, :name => 'test event', :profile_id => fast_create(Person).id) |
286 | 289 | ||
287 | get :index, :query => 'test' | 290 | get :index, :query => 'test' |
288 | 291 | ||
@@ -294,13 +297,13 @@ class SearchControllerTest < ActionController::TestCase | @@ -294,13 +297,13 @@ class SearchControllerTest < ActionController::TestCase | ||
294 | end | 297 | end |
295 | 298 | ||
296 | should 'display category image while in directory' do | 299 | should 'display category image while in directory' do |
297 | - parent = create(Category, :name => 'category1', :environment => Environment.default) | ||
298 | - cat = create(Category, :name => 'category2', :environment => Environment.default, :parent => parent, | 300 | + parent = Category.create!(:name => 'category1', :environment => Environment.default) |
301 | + cat = Category.create!(:name => 'category2', :environment => Environment.default, :parent_id => parent.id, | ||
299 | :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} | 302 | :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} |
300 | ) | 303 | ) |
301 | 304 | ||
302 | process_delayed_job_queue | 305 | process_delayed_job_queue |
303 | - get :category_index, :category_path => [ 'category1', 'category2' ], :query => 'teste' | 306 | + get :category_index, :category_path => 'category1/category2', :query => 'teste' |
304 | assert_tag :tag => 'img', :attributes => { :src => /rails_thumb\.png/ } | 307 | assert_tag :tag => 'img', :attributes => { :src => /rails_thumb\.png/ } |
305 | end | 308 | end |
306 | 309 | ||
@@ -618,10 +621,10 @@ class SearchControllerTest < ActionController::TestCase | @@ -618,10 +621,10 @@ class SearchControllerTest < ActionController::TestCase | ||
618 | 621 | ||
619 | should 'not show assets from other environments' do | 622 | should 'not show assets from other environments' do |
620 | other_env = Environment.create!(:name => 'Another environment') | 623 | other_env = Environment.create!(:name => 'Another environment') |
621 | - p1 = Person.create!(:name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id) | ||
622 | - p2 = Person.create!(:name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id) | ||
623 | - art1 = Article.create!(:name => 'my article', :profile_id => p1.id) | ||
624 | - art2 = Article.create!(:name => 'my article', :profile_id => p2.id) | 624 | + p1 = create(Person, :name => 'Hildebrando', :identifier => 'hild', :user_id => fast_create(User).id, :environment_id => other_env.id) |
625 | + p2 = create(Person, :name => 'Adamastor', :identifier => 'adam', :user_id => fast_create(User).id) | ||
626 | + art1 = create(Article, :name => 'my article', :profile_id => p1.id) | ||
627 | + art2 = create(Article, :name => 'my article', :profile_id => p2.id) | ||
625 | 628 | ||
626 | get :articles, :query => 'my article' | 629 | get :articles, :query => 'my article' |
627 | 630 |