Changeset 232
- Timestamp:
- 08/27/07 20:38:27 (1 year ago)
- Files:
-
- trunk/demo/app/models/search.rb (modified) (1 diff)
- trunk/demo/app/views/contents/edit.rhtml (modified) (1 diff)
- trunk/demo/app/views/searches/search.html.erb (modified) (1 diff)
- trunk/demo/test/functional/contents_controller_test.rb (modified) (1 diff)
- trunk/demo/test/functional/searches_controller_test.rb (modified) (4 diffs)
- trunk/demo/test/unit/content_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/search.rb
r223 r232 15 15 # run the search 16 16 def run 17 Content.find_with_ferret @query, :page => @page, :per_page => 10, :sort => 'title' 17 Content.find_with_ferret @query, :page => @page, :per_page => 10, :sort => 'title', :lazy => true 18 18 end 19 19 end trunk/demo/app/views/contents/edit.rhtml
r228 r232 1 1 <h1>Editing content</h1> 2 2 3 <% form_ tag :action => 'update', :id => @content do%>3 <% form_for :content, @content, content_path(@content), :html => { :method => :put } do |f| %> 4 4 <%= render :partial => 'form', :object => f %> 5 5 <%= submit_tag 'Edit' %> 6 6 <% end %> 7 7 8 <%= link_to 'Show', :action => 'show', :id => @content%> |9 <%= link_to 'Back', :action => 'list'%>8 <%= link_to 'Show', content_path(@content) %> | 9 <%= link_to 'Back', contents_path %> trunk/demo/app/views/searches/search.html.erb
r230 r232 1 1 <h1>Search</h1> 2 <% form_tag search_path do |f|%>2 <% form_tag search_path do %> 3 3 <fieldset> 4 4 <legend>Search</legend> trunk/demo/test/functional/contents_controller_test.rb
r228 r232 9 9 10 10 def setup 11 @controller = Content Controller.new11 @controller = ContentsController.new 12 12 @request = ActionController::TestRequest.new 13 13 @response = ActionController::TestResponse.new trunk/demo/test/functional/searches_controller_test.rb
r228 r232 9 9 10 10 def setup 11 @controller = Search Controller.new11 @controller = SearchesController.new 12 12 @request = ActionController::TestRequest.new 13 13 @response = ActionController::TestResponse.new … … 15 15 end 16 16 17 def test_s how17 def test_search 18 18 get :search 19 assert_template 's how'19 assert_template 'search' 20 20 assert_response :success 21 21 assert_nil assigns(:results) … … 24 24 def test_search 25 25 get :search, :q => 'title' 26 assert_template 's how'26 assert_template 'search' 27 27 assert_equal 1, assigns(:results).total_hits 28 28 assert_equal 1, assigns(:results).size 29 29 30 30 get :search, :q => 'monkey' 31 assert_template 's how'31 assert_template 'search' 32 32 assert assigns(:results).empty? 33 33 … … 39 39 Content.create :title => 'another content object', :description => 'description goes hers' 40 40 get :search, :q => 'another' 41 assert_template 's how'41 assert_template 'search' 42 42 assert_equal 1, assigns(:results).total_hits 43 43 assert_equal 1, assigns(:results).size trunk/demo/test/unit/content_test.rb
r228 r232 274 274 end 275 275 276 # TODO: Sort usage fails with drb 277 #def test_sort_class 278 # sorting = Ferret::Search::Sort.new(Ferret::Search::SortField.new(:id, :type => :string, :reverse => true)) 279 # result = Content.find_by_contents('comment_count:2 OR comment_count:1', :sort => sorting) 280 # assert result.size > 2 281 # result = Content.find_by_contents('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2) 282 # assert_equal 2, result.size 283 # assert result.first.id > result.last.id 284 #end 285 286 def test_sort_with_limit 287 sorting = [ Ferret::Search::SortField.new(:id, :type => :string, :reverse => true) ] 276 def test_sort_class 277 sorting = Ferret::Search::Sort.new(Ferret::Search::SortField.new(:id, :reverse => true)) 288 278 result = Content.find_by_contents('comment_count:2 OR comment_count:1', :sort => sorting) 289 279 assert result.size > 2 280 assert result.first.id > result.last.id 281 result = Content.find_by_contents('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2) 282 assert_equal 2, result.size 283 assert result.first.id > result.last.id 284 end 285 286 def test_sort_with_limit 287 sorting = [ Ferret::Search::SortField.new(:id) ] 288 result = Content.find_by_contents('comment_count:2 OR comment_count:1', :sort => sorting) 289 assert result.size > 2 290 assert result.first.id < result.last.id 291 result = Content.find_by_contents('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2) 292 assert_equal 2, result.size 293 assert result.first.id < result.last.id 294 295 sorting = [ Ferret::Search::SortField.new(:id, :reverse => true) ] 296 result = Content.find_by_contents('comment_count:2 OR comment_count:1', :sort => sorting) 297 assert result.size > 2 298 assert result.first.id > result.last.id 290 299 result = Content.find_by_contents('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2) 291 300 assert_equal 2, result.size
