Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add tests for redirect to index action in show not defined
  • Loading branch information
janisr authored and josevalim committed Dec 20, 2010
1 parent e11b02e commit e551600
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/customized_redirect_to_test.rb
@@ -0,0 +1,32 @@
require File.expand_path('test_helper', File.dirname(__FILE__))

class Post;
def self.human_name; 'Post'; end
end

class PostsController < InheritedResources::Base
actions :all, :except => [:show]
end

class RedirectToIndexWithoutShowTest < ActionController::TestCase
tests PostsController

def test_redirect_index_url_after_create
Post.stubs(:new).returns(mock_machine(:save => true))
assert !PostsController.respond_to?(:show)
post :create
assert_redirected_to 'http://test.host/posts'
end

def test_redirect_to_index_url_after_update
Post.stubs(:find).returns(mock_machine(:update_attributes => true))
assert !PostsController.respond_to?(:show)
put :update
assert_redirected_to 'http://test.host/posts'
end

protected
def mock_machine(stubs={})
@mock_machine ||= mock(stubs)
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Expand Up @@ -29,6 +29,7 @@ class ApplicationController < ActionController::Base; end
InheritedResources::Routes.draw do
match ':controller(/:action(/:id))'
match ':controller(/:action)'
resources 'posts'
end

ActionController::Base.send :include, InheritedResources::Routes.url_helpers
Expand Down

0 comments on commit e551600

Please sign in to comment.