This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
/
posts_controller_test.rb
64 lines (52 loc) · 1.61 KB
/
posts_controller_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'test_helper'
class PostsControllerTest < ActionController::TestCase
test "should create post" do
Post.any_instance.expects(:save).returns(true)
post :create, :post => { }
assert_response :redirect
end
test "should handle failure to create post" do
Post.any_instance.expects(:save).returns(false)
post :create, :post => { }
assert_template "new"
end
test "should destroy post" do
Post.any_instance.expects(:destroy).returns(true)
delete :destroy, :id => posts(:one).to_param
assert_not_nil flash[:notice]
assert_response :redirect
end
test "should handle failure to destroy post" do
Post.any_instance.expects(:destroy).returns(false)
delete :destroy, :id => posts(:one).to_param
assert_not_nil flash[:error]
assert_response :redirect
end
test "should get edit for post" do
get :edit, :id => posts(:one).to_param
assert_response :success
end
test "should get index for posts" do
get :index
assert_response :success
assert_not_nil assigns(:posts)
end
test "should get new for post" do
get :new
assert_response :success
end
test "should get show for post" do
get :show, :id => posts(:one).to_param
assert_response :success
end
test "should update post" do
Post.any_instance.expects(:save).returns(true)
put :update, :id => posts(:one).to_param, :post => { }
assert_response :redirect
end
test "should handle failure to update post" do
Post.any_instance.expects(:save).returns(false)
put :update, :id => posts(:one).to_param, :post => { }
assert_template "edit"
end
end