22
33class UrlsControllerTest < ActionController ::TestCase
44 setup do
5- @url = urls ( :one )
5+ @valid_url = urls :valid
6+ @invalid_url = urls :invalid
67 end
78
89 test "should get index" do
@@ -16,22 +17,36 @@ class UrlsControllerTest < ActionController::TestCase
1617 assert_response :success
1718 end
1819
19- test "should create url" do
20+ test "should create valid url" do
2021 assert_difference ( 'Url.count' ) do
21- post :create , url : { click_count : @url . click_count , long_url : @url . long_url , short_url : @url . short_url }
22+ post :create , url : { click_count : @valid_url . click_count , long_url : @valid_url . long_url , short_url : @valid_url . short_url }
2223 end
2324
24- assert_redirected_to url_path ( assigns ( :url ) )
25+ assert_redirected_to urls_url
2526 end
2627
27- test "should show url" do
28- get :show , id : @url
29- assert_response :success
28+ test "should not create invalid url" do
29+ assert_no_difference ( 'Url.count' ) do
30+ post :create , url : { click_count : @invalid_url . click_count , long_url : @invalid_url . long_url , short_url : @invalid_url . short_url }
31+ end
32+ end
33+
34+ test "should show valid url" do
35+ get :show , id : @valid_url
36+ assert_response :redirect
37+ assert_redirected_to @valid_url . long_url
38+ end
39+
40+ test "should not show nonexistent url" do
41+ assert_raise ActionController ::RoutingError do
42+ get :show , id : 'nonexistent'
43+ assert_response :missing
44+ end
3045 end
3146
32- test "should destroy url" do
47+ test "should destroy valid url" do
3348 assert_difference ( 'Url.count' , -1 ) do
34- delete :destroy , id : @url
49+ delete :destroy , id : @valid_url
3550 end
3651
3752 assert_redirected_to urls_path
0 commit comments