Skip to content

Commit

Permalink
updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Croak committed Oct 30, 2008
1 parent bdd021e commit 4ac4349
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 49 deletions.
50 changes: 15 additions & 35 deletions README.textile
Expand Up @@ -6,12 +6,6 @@ h2. Install

script/plugin install git://github.com/dancroak/sortable_table.git

In test/test_helper.rb:

class Test::Unit::TestCase
include SortableTable::Test::TestHelper
end

In app/controllers/application_controller.rb:

class ApplicationController < ActionController::Base
Expand Down Expand Up @@ -45,45 +39,31 @@ order parameter for will paginate or named scope call.

end

Time-saving Shoulda macros for your tests:
h2. Test with shoulda macros:

class UsersControllerTest < ActionController::TestCase

context 'GET to index with sort and order params' do
setup do
5.times do |each|
Factory :user,
:name => "name #{each}",
:email => "email#{each}@example.com"
end
end
context "enough Users to sort" do
setup { 5.times { Factory :user } }

should_sort_by_attributes :name, :email
should_sort_by_attributes :name, :email, :age

context "GET to #index" do
setup { get :index }
should_display_sortable_table_header_for :name, :email, :age
end

end

If you need to test an action other than a simple "get :index," you can pass a
block to #should_sort_by_attributes:


class SearchesControllerTest < ActionController::TestCase

context 'GET to show with id, sort, and order params' do
setup do
5.times do |each|
Factory :user,
:name => "name #{each}",
:email => "email#{each}@example.com"
end
@search = Factory(:search, :name => 'name')
end
context 'GET to show with id, sort, and order params' do
setup do
5.times { Factory :user }
@search = Factory(:search, :name => 'name')
end

should_sort_by_attributes :name, :email do |sort, order|
get :show, :id => @search.to_param, :sort => sort, :order => order
end
should_sort_by_attributes :name, :email do |sort, order|
get :show, :id => @search.to_param, :sort => sort, :order => order
end

end

And some sugar for your views:
Expand Down
21 changes: 7 additions & 14 deletions test/rails_root/test/functional/users_controller_test.rb
Expand Up @@ -2,24 +2,17 @@

class UsersControllerTest < ActionController::TestCase

context "GET to #index with sort and order params" do
setup do
2.times { |each| Factory :user }
end

should_sort_by :name
should_sort_by_attributes :email, :age do |sort, order|
context "enough Users to sort" do
setup { 2.times { Factory :user } }

should_sort_by_attributes :name, :email, :age do |sort, order|
get :index, :sort => sort, :order => order
end
end

context "GET to #index" do
setup do
2.times { |each| Factory :user }
get :index
context "GET to #index" do
setup { get :index }
should_display_sortable_table_header_for :name, :email, :age
end

should_display_sortable_table_header_for :name, :email, :age
end

end

0 comments on commit 4ac4349

Please sign in to comment.