To edit pages or tickets please login with username/password: aaf/aaf

Changeset 228

Show
Ignore:
Timestamp:
08/27/07 19:38:06 (10 months ago)
Author:
jk
Message:

rest done right

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo/app/controllers/contents_controller.rb

    r223 r228  
    1 class ContentController < ApplicationController 
     1class ContentsController < ApplicationController 
    22  before_filter :find_content, :only => [ :show, :edit, :update, :destroy ] 
    33 
  • trunk/demo/app/controllers/searches_controller.rb

    r223 r228  
    1 class SearchController < ApplicationController 
     1class SearchesController < ApplicationController 
    22 
    3   def show 
     3  def search 
    44    @search = Search.new params[:q], params[:page] 
    55    @results = @search.run if @search.valid? 
  • trunk/demo/app/views/contents/_form.rhtml

    r5 r228  
    33<!--[form:content]--> 
    44<p><label for="content_title">Title</label><br/> 
    5 <%= text_field 'content', 'title'  %></p> 
     5<%= form.text_field 'title'  %></p> 
    66 
    77<p><label for="content_description">Description</label><br/> 
    8 <%= text_area 'content', 'description'  %></p> 
     8<%= form.text_area 'description'  %></p> 
    99<!--[eoform:content]--> 
    1010 
  • trunk/demo/app/views/contents/edit.rhtml

    r135 r228  
    22 
    33<% form_tag :action => 'update', :id => @content do %> 
    4   <%= render :partial => 'form' %> 
     4  <%= render :partial => 'form', :object => f %> 
    55  <%= submit_tag 'Edit' %> 
    66<% end %> 
  • trunk/demo/app/views/contents/new.rhtml

    r135 r228  
    11<h1>New content</h1> 
    22 
    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 %> 
    55  <%= submit_tag "Create" %> 
    66<% end %> 
  • trunk/demo/app/views/layouts/application.html.erb

    r5 r228  
    11<html> 
    22<head> 
    3   <title>Content: <%= controller.action_name %></title> 
     3  <title>acts_as_ferret demo application</title> 
    44  <%= stylesheet_link_tag 'scaffold' %> 
    55</head> 
    66<body> 
     7  <ul> 
     8    <li><%= link_to 'Contents', contents_path %></li> 
     9    <li><%= link_to 'Search', search_path %></li> 
     10  </ul> 
    711 
    8 <p style="color: green"><%= flash[:notice] %></p> 
     12  <p style="color: green"><%= flash[:notice] %></p> 
    913 
    10 <%= @content_for_layout %> 
     14<%= yield %> 
    1115 
    1216</body> 
  • trunk/demo/app/views/searches/show.html.erb

    r223 r228  
    11<h1>Search</h1> 
    2 <% form_for :search, @search, search_path, :method => :get do |f| %> 
     2<% form_for :search, @search, search_path, :html => { :method => :post } do |f| %> 
    33  <fieldset> 
    44    <legend>Search</legend> 
  • trunk/demo/config/environment.rb

    r5 r228  
    1010Rails::Initializer.run do |config| 
    1111  # Settings in config/environments/* take precedence those specified here 
     12   
     13  config.action_controller.session = { :session_key => "_demo_session", :secret => "some secret phrase" } 
    1214   
    1315  # Skip frameworks you're not going to use 
  • trunk/demo/config/routes.rb

    r223 r228  
    11ActionController::Routing::Routes.draw do |map| 
    22 
    3   map.resources :content 
    4   map.resource :search 
     3  map.resources :contents 
     4  map.search 'search', :controller => 'searches', :action => 'search' 
    55 
    66 
  • trunk/demo/test/functional/contents_controller_test.rb

    r223 r228  
    11require File.dirname(__FILE__) + '/../test_helper' 
    2 require 'content_controller' 
     2require 'contents_controller' 
    33 
    44# Re-raise errors caught by the controller. 
    5 class ContentController; def rescue_action(e) raise e end; end 
     5class ContentsController; def rescue_action(e) raise e end; end 
    66 
    7 class ContentControllerTest < Test::Unit::TestCase 
     7class ContentsControllerTest < Test::Unit::TestCase 
    88  fixtures :contents 
    99 
  • trunk/demo/test/functional/searches_controller_test.rb

    r223 r228  
    11require File.dirname(__FILE__) + '/../test_helper' 
    2 require 'search_controller' 
     2require 'searches_controller' 
    33 
    44# Re-raise errors caught by the controller. 
    5 class SearchController; def rescue_action(e) raise e end; end 
     5class SearchesController; def rescue_action(e) raise e end; end 
    66 
    7 class SearchControllerTest < Test::Unit::TestCase 
     7class SearchesControllerTest < Test::Unit::TestCase 
    88  fixtures :contents 
    99 
     
    1616 
    1717  def test_show 
    18     get :show 
     18    get :search 
    1919    assert_template 'show' 
    2020    assert_response :success 
     
    2323 
    2424  def test_search 
    25     get :show, :q => 'title' 
     25    get :search, :q => 'title' 
    2626    assert_template 'show' 
    2727    assert_equal 1, assigns(:results).total_hits 
    2828    assert_equal 1, assigns(:results).size 
    2929     
    30     get :show, :q => 'monkey' 
     30    get :search, :q => 'monkey' 
    3131    assert_template 'show' 
    3232    assert assigns(:results).empty? 
     
    3838    sleep 1 
    3939    Content.create :title => 'another content object', :description => 'description goes hers' 
    40     get :show, :q => 'another' 
     40    get :search, :q => 'another' 
    4141    assert_template 'show' 
    4242    assert_equal 1, assigns(:results).total_hits 
     
    5050      Content.create! :title => "title of Content #{i}", :description => "#{i}" 
    5151    end 
    52     get :show, :q => 'title' 
     52    get :search, :q => 'title' 
    5353    r = assigns(:results) 
    5454    assert_equal 30, r.total_hits 
     
    5959    assert_equal 3, r.page_count 
    6060 
    61     get :show, :q => 'title', :page => 2 
     61    get :search, :q => 'title', :page => 2 
    6262    r = assigns(:results) 
    6363    assert_equal 30, r.total_hits 
  • trunk/demo/test/unit/comment_test.rb

    r227 r228  
    187187  end 
    188188 
    189   def test_pagination 
    190     more_contents 
    191  
    192     r = Content.find_with_ferret 'title', :page => 1, :per_page => 10, :sort => 'title' 
    193     assert_equal 30, r.total_hits 
    194     assert_equal 10, r.size 
    195     assert_equal "0", r.first.description 
    196     assert_equal "9", r.last.description 
    197     assert_equal 1, r.current_page 
    198     assert_equal 3, r.page_count 
    199  
    200     r = Content.find_with_ferret 'title', :page => 2, :per_page => 10, :sort => 'title' 
    201     assert_equal 30, r.total_hits 
    202     assert_equal 10, r.size 
    203     assert_equal "10", r.first.description 
    204     assert_equal "19", r.last.description 
    205     assert_equal 2, r.current_page 
    206     assert_equal 3, r.page_count 
    207  
    208     r = Content.find_with_ferret 'title', :page => 4, :per_page => 10, :sort => 'title' 
    209     assert_equal 30, r.total_hits 
    210     assert_equal 0, r.size 
    211   end 
    212  
    213   def test_pagination_with_ar_conditions 
    214     more_contents 
    215  
    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_hits 
    219     assert_equal 10, r.size 
    220     assert_equal "1", r.first.description 
    221     assert_equal "10", r.last.description 
    222     assert_equal 1, r.current_page 
    223     assert_equal 3, r.page_count 
    224  
    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_hits 
    228     assert_equal 9, r.size 
    229     assert_equal "21", r.first.description 
    230     assert_equal "29", r.last.description 
    231     assert_equal 3, r.current_page 
    232     assert_equal 3, r.page_count 
    233   end 
    234  
    235   def test_pagination_with_more_conditions 
    236     more_contents 
    237  
    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_hits 
    241     assert_equal 10, r.size 
    242     assert_equal "1", r.first.description 
    243     assert_equal "11", r.last.description 
    244     assert_equal 1, r.current_page 
    245     assert_equal 3, r.page_count 
    246   end 
    247  
    248   protected 
    249   def more_contents 
    250     Content.destroy_all 
    251     30.times do |i| 
    252       Content.create! :title => sprintf("title of Content %02d", i), :description => "#{i}" 
    253     end 
    254   end 
    255189 
    256190end 
  • trunk/demo/test/unit/content_test.rb

    r200 r228  
    592592    assert_equal @another_content.id, contents_from_ferret.first.id  
    593593      
    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 
    595662end 

To edit pages or tickets please login with username/password: aaf/aaf