Skip to content
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.
Permalink
Browse files
DRY via modules.
  • Loading branch information
steveklabnik committed Jan 14, 2013
1 parent fdcf40e commit 744c9d0faa3966a34a092f2794460bd63edc26c8
Showing 1 changed file with 50 additions and 80 deletions.
@@ -1,51 +1,60 @@
require 'test_helper'

class PostsControllerTest < ActionController::TestCase
setup do
@post = posts(:one)
end

test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:posts)
end

test "should get new" do
get :new
assert_response :success
end

test "should create post" do
assert_difference('Post.count') do
post :create, post: { body: @post.body, private: @post.private, title: @post.title }
module PostsControllerBehavior
def self.included(controller)
controller.instance_eval do
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:posts)
end

test "should get new" do
get :new
assert_response :success
end

test "should create post" do
assert_difference('Post.count') do
post :create, post: { body: @post.body, private: @post.private, title: @post.title }
end

assert_redirected_to post_path(assigns(:post))
end

test "should show post" do
get :show, id: @post
assert_response :success
end

test "should get edit" do
get :edit, id: @post
assert_response :success
end

test "should update post" do
put :update, id: @post, post: { body: @post.body, private: @post.private, title: @post.title }
assert_redirected_to post_path(assigns(:post))
end

test "should destroy post" do
assert_difference('Post.count', -1) do
delete :destroy, id: @post
end

assert_redirected_to posts_path
end
end

assert_redirected_to post_path(assigns(:post))
end

test "should show post" do
get :show, id: @post
assert_response :success
end

test "should get edit" do
get :edit, id: @post
assert_response :success
end
end

test "should update post" do
put :update, id: @post, post: { body: @post.body, private: @post.private, title: @post.title }
assert_redirected_to post_path(assigns(:post))
class PostsControllerTest < ActionController::TestCase
setup do
@post = posts(:one)
end

test "should destroy post" do
assert_difference('Post.count', -1) do
delete :destroy, id: @post
end
include PostsControllerBehavior

assert_redirected_to posts_path
end
end

class PrivatePostsControllerTest < ActionController::TestCase
@@ -56,45 +65,6 @@ class PrivatePostsControllerTest < ActionController::TestCase
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials("foo","bar")
end

test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:posts)
end

test "should get new" do
get :new
assert_response :success
end

test "should create post" do
assert_difference('Post.count') do
post :create, post: { body: @post.body, private: @post.private, title: @post.title }
end

assert_redirected_to post_path(assigns(:post))
end

test "should show post" do
get :show, id: @post
assert_response :success
end
include PostsControllerBehavior

test "should get edit" do
get :edit, id: @post
assert_response :success
end

test "should update post" do
put :update, id: @post, post: { body: @post.body, private: @post.private, title: @post.title }
assert_redirected_to post_path(assigns(:post))
end

test "should destroy post" do
assert_difference('Post.count', -1) do
delete :destroy, id: @post
end

assert_redirected_to posts_path
end
end

0 comments on commit 744c9d0

Please sign in to comment.