Commit fa8d321693e983ec61974057aa5162c2636df434
1 parent
de0aceaa
Exists in
master
and in
22 other branches
rails3: fix search_controller tests
Showing
3 changed files
with
17 additions
and
14 deletions
Show diff stats
app/models/category.rb
app/views/search/_search_form.html.erb
| 1 | 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 | 4 | :method => 'get', :class => 'search_form' ) do %> |
| 5 | 5 | |
| 6 | 6 | <%= hidden_field_tag :display, params[:display] %> | ... | ... |
test/functional/search_controller_test.rb
| ... | ... | @@ -13,7 +13,7 @@ class SearchControllerTest < ActionController::TestCase |
| 13 | 13 | @request.stubs(:ssl?).returns(false) |
| 14 | 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 | 18 | env = Environment.default |
| 19 | 19 | domain = env.domains.first |
| ... | ... | @@ -33,6 +33,7 @@ class SearchControllerTest < ActionController::TestCase |
| 33 | 33 | user.stubs(:valid?).returns(true) |
| 34 | 34 | user.stubs(:email).returns('some@test.com') |
| 35 | 35 | user.stubs(:save!).returns(true) |
| 36 | + user.stubs(:marked_for_destruction?).returns(false) | |
| 36 | 37 | Person.any_instance.stubs(:user).returns(user) |
| 37 | 38 | end |
| 38 | 39 | |
| ... | ... | @@ -113,7 +114,9 @@ class SearchControllerTest < ActionController::TestCase |
| 113 | 114 | end |
| 114 | 115 | |
| 115 | 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 | 120 | get :people, :query => 'beautiful' |
| 118 | 121 | assert_includes assigns(:searches)[:people][:results], p1 |
| 119 | 122 | end |
| ... | ... | @@ -246,8 +249,8 @@ class SearchControllerTest < ActionController::TestCase |
| 246 | 249 | end |
| 247 | 250 | |
| 248 | 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 | 255 | p = create_profile_with_optional_category(Person, 'test_profile', child) |
| 253 | 256 | |
| ... | ... | @@ -282,7 +285,7 @@ class SearchControllerTest < ActionController::TestCase |
| 282 | 285 | art = create(Article, :name => 'test article', :profile_id => fast_create(Person).id) |
| 283 | 286 | per = create(Person, :name => 'test person', :identifier => 'test-person', :user_id => fast_create(User).id) |
| 284 | 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 | 290 | get :index, :query => 'test' |
| 288 | 291 | |
| ... | ... | @@ -294,13 +297,13 @@ class SearchControllerTest < ActionController::TestCase |
| 294 | 297 | end |
| 295 | 298 | |
| 296 | 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 | 302 | :image_builder => {:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')} |
| 300 | 303 | ) |
| 301 | 304 | |
| 302 | 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 | 307 | assert_tag :tag => 'img', :attributes => { :src => /rails_thumb\.png/ } |
| 305 | 308 | end |
| 306 | 309 | |
| ... | ... | @@ -618,10 +621,10 @@ class SearchControllerTest < ActionController::TestCase |
| 618 | 621 | |
| 619 | 622 | should 'not show assets from other environments' do |
| 620 | 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 | 629 | get :articles, :query => 'my article' |
| 627 | 630 | ... | ... |