Changeset 228
- Timestamp:
- 08/27/07 19:38:06 (10 months ago)
- Files:
-
- trunk/demo/app/controllers/contents_controller.rb (moved) (moved from trunk/demo/app/controllers/content_controller.rb) (1 diff)
- trunk/demo/app/controllers/searches_controller.rb (moved) (moved from trunk/demo/app/controllers/search_controller.rb) (1 diff)
- trunk/demo/app/views/contents (moved) (moved from trunk/demo/app/views/content)
- trunk/demo/app/views/contents/_form.rhtml (modified) (1 diff)
- trunk/demo/app/views/contents/edit.rhtml (modified) (1 diff)
- trunk/demo/app/views/contents/new.rhtml (modified) (1 diff)
- trunk/demo/app/views/layouts/application.html.erb (moved) (moved from trunk/demo/app/views/layouts/content.rhtml) (1 diff)
- trunk/demo/app/views/searches (moved) (moved from trunk/demo/app/views/search)
- trunk/demo/app/views/searches/show.html.erb (modified) (1 diff)
- trunk/demo/config/environment.rb (modified) (1 diff)
- trunk/demo/config/routes.rb (modified) (1 diff)
- trunk/demo/test/functional/contents_controller_test.rb (moved) (moved from trunk/demo/test/functional/content_controller_test.rb) (1 diff)
- trunk/demo/test/functional/searches_controller_test.rb (moved) (moved from trunk/demo/test/functional/search_controller_test.rb) (6 diffs)
- trunk/demo/test/unit/comment_test.rb (modified) (1 diff)
- trunk/demo/test/unit/content_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/controllers/contents_controller.rb
r223 r228 1 class Content Controller < ApplicationController1 class ContentsController < ApplicationController 2 2 before_filter :find_content, :only => [ :show, :edit, :update, :destroy ] 3 3 trunk/demo/app/controllers/searches_controller.rb
r223 r228 1 class Search Controller < ApplicationController1 class SearchesController < ApplicationController 2 2 3 def s how3 def search 4 4 @search = Search.new params[:q], params[:page] 5 5 @results = @search.run if @search.valid? trunk/demo/app/views/contents/_form.rhtml
r5 r228 3 3 <!--[form:content]--> 4 4 <p><label for="content_title">Title</label><br/> 5 <%= text_field 'content','title' %></p>5 <%= form.text_field 'title' %></p> 6 6 7 7 <p><label for="content_description">Description</label><br/> 8 <%= text_area 'content','description' %></p>8 <%= form.text_area 'description' %></p> 9 9 <!--[eoform:content]--> 10 10 trunk/demo/app/views/contents/edit.rhtml
r135 r228 2 2 3 3 <% form_tag :action => 'update', :id => @content do %> 4 <%= render :partial => 'form' %>4 <%= render :partial => 'form', :object => f %> 5 5 <%= submit_tag 'Edit' %> 6 6 <% end %> trunk/demo/app/views/contents/new.rhtml
r135 r228 1 1 <h1>New content</h1> 2 2 3 <% form_ tag :action => 'create' do%>4 <%= render :partial => 'form' %>3 <% form_for :content, @content, contents_path, :html => { :method => :post } do |f| %> 4 <%= render :partial => 'form', :object => f %> 5 5 <%= submit_tag "Create" %> 6 6 <% end %> trunk/demo/app/views/layouts/application.html.erb
r5 r228 1 1 <html> 2 2 <head> 3 <title> Content: <%= controller.action_name %></title>3 <title>acts_as_ferret demo application</title> 4 4 <%= stylesheet_link_tag 'scaffold' %> 5 5 </head> 6 6 <body> 7 <ul> 8 <li><%= link_to 'Contents', contents_path %></li> 9 <li><%= link_to 'Search', search_path %></li> 10 </ul> 7 11 8 <p style="color: green"><%= flash[:notice] %></p>12 <p style="color: green"><%= flash[:notice] %></p> 9 13 10 <%= @content_for_layout%>14 <%= yield %> 11 15 12 16 </body> trunk/demo/app/views/searches/show.html.erb
r223 r228 1 1 <h1>Search</h1> 2 <% form_for :search, @search, search_path, : method => :getdo |f| %>2 <% form_for :search, @search, search_path, :html => { :method => :post } do |f| %> 3 3 <fieldset> 4 4 <legend>Search</legend> trunk/demo/config/environment.rb
r5 r228 10 10 Rails::Initializer.run do |config| 11 11 # Settings in config/environments/* take precedence those specified here 12 13 config.action_controller.session = { :session_key => "_demo_session", :secret => "some secret phrase" } 12 14 13 15 # Skip frameworks you're not going to use trunk/demo/config/routes.rb
r223 r228 1 1 ActionController::Routing::Routes.draw do |map| 2 2 3 map.resources :content 4 map. resource :search3 map.resources :contents 4 map.search 'search', :controller => 'searches', :action => 'search' 5 5 6 6 trunk/demo/test/functional/contents_controller_test.rb
r223 r228 1 1 require File.dirname(__FILE__) + '/../test_helper' 2 require 'content _controller'2 require 'contents_controller' 3 3 4 4 # Re-raise errors caught by the controller. 5 class Content Controller; def rescue_action(e) raise e end; end5 class ContentsController; def rescue_action(e) raise e end; end 6 6 7 class Content ControllerTest < Test::Unit::TestCase7 class ContentsControllerTest < Test::Unit::TestCase 8 8 fixtures :contents 9 9 trunk/demo/test/functional/searches_controller_test.rb
r223 r228 1 1 require File.dirname(__FILE__) + '/../test_helper' 2 require 'search _controller'2 require 'searches_controller' 3 3 4 4 # Re-raise errors caught by the controller. 5 class Search Controller; def rescue_action(e) raise e end; end5 class SearchesController; def rescue_action(e) raise e end; end 6 6 7 class Search ControllerTest < Test::Unit::TestCase7 class SearchesControllerTest < Test::Unit::TestCase 8 8 fixtures :contents 9 9 … … 16 16 17 17 def test_show 18 get :s how18 get :search 19 19 assert_template 'show' 20 20 assert_response :success … … 23 23 24 24 def test_search 25 get :s how, :q => 'title'25 get :search, :q => 'title' 26 26 assert_template 'show' 27 27 assert_equal 1, assigns(:results).total_hits 28 28 assert_equal 1, assigns(:results).size 29 29 30 get :s how, :q => 'monkey'30 get :search, :q => 'monkey' 31 31 assert_template 'show' 32 32 assert assigns(:results).empty? … … 38 38 sleep 1 39 39 Content.create :title => 'another content object', :description => 'description goes hers' 40 get :s how, :q => 'another'40 get :search, :q => 'another' 41 41 assert_template 'show' 42 42 assert_equal 1, assigns(:results).total_hits … … 50 50 Content.create! :title => "title of Content #{i}", :description => "#{i}" 51 51 end 52 get :s how, :q => 'title'52 get :search, :q => 'title' 53 53 r = assigns(:results) 54 54 assert_equal 30, r.total_hits … … 59 59 assert_equal 3, r.page_count 60 60 61 get :s how, :q => 'title', :page => 261 get :search, :q => 'title', :page => 2 62 62 r = assigns(:results) 63 63 assert_equal 30, r.total_hits trunk/demo/test/unit/comment_test.rb
r227 r228 187 187 end 188 188 189 def test_pagination190 more_contents191 192 r = Content.find_with_ferret 'title', :page => 1, :per_page => 10, :sort => 'title'193 assert_equal 30, r.total_hits194 assert_equal 10, r.size195 assert_equal "0", r.first.description196 assert_equal "9", r.last.description197 assert_equal 1, r.current_page198 assert_equal 3, r.page_count199 200 r = Content.find_with_ferret 'title', :page => 2, :per_page => 10, :sort => 'title'201 assert_equal 30, r.total_hits202 assert_equal 10, r.size203 assert_equal "10", r.first.description204 assert_equal "19", r.last.description205 assert_equal 2, r.current_page206 assert_equal 3, r.page_count207 208 r = Content.find_with_ferret 'title', :page => 4, :per_page => 10, :sort => 'title'209 assert_equal 30, r.total_hits210 assert_equal 0, r.size211 end212 213 def test_pagination_with_ar_conditions214 more_contents215 216 r = Content.find_with_ferret 'title', { :page => 1, :per_page => 10 },217 { :conditions => "description != '0'", :order => 'title ASC' }218 assert_equal 29, r.total_hits219 assert_equal 10, r.size220 assert_equal "1", r.first.description221 assert_equal "10", r.last.description222 assert_equal 1, r.current_page223 assert_equal 3, r.page_count224 225 r = Content.find_with_ferret 'title', { :page => 3, :per_page => 10 },226 { :conditions => "description != '0'", :order => 'title ASC' }227 assert_equal 29, r.total_hits228 assert_equal 9, r.size229 assert_equal "21", r.first.description230 assert_equal "29", r.last.description231 assert_equal 3, r.current_page232 assert_equal 3, r.page_count233 end234 235 def test_pagination_with_more_conditions236 more_contents237 238 r = Content.find_with_ferret 'title -description:0', { :page => 1, :per_page => 10 },239 { :conditions => "description != '9'", :order => 'title ASC' }240 assert_equal 28, r.total_hits241 assert_equal 10, r.size242 assert_equal "1", r.first.description243 assert_equal "11", r.last.description244 assert_equal 1, r.current_page245 assert_equal 3, r.page_count246 end247 248 protected249 def more_contents250 Content.destroy_all251 30.times do |i|252 Content.create! :title => sprintf("title of Content %02d", i), :description => "#{i}"253 end254 end255 189 256 190 end trunk/demo/test/unit/content_test.rb
r200 r228 592 592 assert_equal @another_content.id, contents_from_ferret.first.id 593 593 594 end 594 end 595 596 def test_pagination 597 more_contents 598 599 r = Content.find_with_ferret 'title', :page => 1, :per_page => 10, :sort => 'title' 600 assert_equal 30, r.total_hits 601 assert_equal 10, r.size 602 assert_equal "0", r.first.description 603 assert_equal "9", r.last.description 604 assert_equal 1, r.current_page 605 assert_equal 3, r.page_count 606 607 r = Content.find_with_ferret 'title', :page => 2, :per_page => 10, :sort => 'title' 608 assert_equal 30, r.total_hits 609 assert_equal 10, r.size 610 assert_equal "10", r.first.description 611 assert_equal "19", r.last.description 612 assert_equal 2, r.current_page 613 assert_equal 3, r.page_count 614 615 r = Content.find_with_ferret 'title', :page => 4, :per_page => 10, :sort => 'title' 616 assert_equal 30, r.total_hits 617 assert_equal 0, r.size 618 end 619 620 def test_pagination_with_ar_conditions 621 more_contents 622 623 r = Content.find_with_ferret 'title', { :page => 1, :per_page => 10 }, 624 { :conditions => "description != '0'", :order => 'title ASC' } 625 assert_equal 29, r.total_hits 626 assert_equal 10, r.size 627 assert_equal "1", r.first.description 628 assert_equal "10", r.last.description 629 assert_equal 1, r.current_page 630 assert_equal 3, r.page_count 631 632 r = Content.find_with_ferret 'title', { :page => 3, :per_page => 10 }, 633 { :conditions => "description != '0'", :order => 'title ASC' } 634 assert_equal 29, r.total_hits 635 assert_equal 9, r.size 636 assert_equal "21", r.first.description 637 assert_equal "29", r.last.description 638 assert_equal 3, r.current_page 639 assert_equal 3, r.page_count 640 end 641 642 def test_pagination_with_more_conditions 643 more_contents 644 645 r = Content.find_with_ferret 'title -description:0', { :page => 1, :per_page => 10 }, 646 { :conditions => "description != '9'", :order => 'title ASC' } 647 assert_equal 28, r.total_hits 648 assert_equal 10, r.size 649 assert_equal "1", r.first.description 650 assert_equal "11", r.last.description 651 assert_equal 1, r.current_page 652 assert_equal 3, r.page_count 653 end 654 655 protected 656 def more_contents 657 Content.destroy_all 658 30.times do |i| 659 Content.create! :title => sprintf("title of Content %02d", i), :description => "#{i}" 660 end 661 end 595 662 end
