From 0db68fd1408e52b1edc62b18756ba2662f9b5b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 16 Mar 2010 16:53:54 +0100 Subject: Change functional tests to make use of a setup block. --- .../test_unit/scaffold/templates/functional_test.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'railties') diff --git a/railties/lib/generators/test_unit/scaffold/templates/functional_test.rb b/railties/lib/generators/test_unit/scaffold/templates/functional_test.rb index 9380aa49b6..4f8ddbffcf 100644 --- a/railties/lib/generators/test_unit/scaffold/templates/functional_test.rb +++ b/railties/lib/generators/test_unit/scaffold/templates/functional_test.rb @@ -1,6 +1,10 @@ require 'test_helper' class <%= controller_class_name %>ControllerTest < ActionController::TestCase + setup do + @<%= file_name %> = <%= table_name %>(:one) + end + <% unless options[:singleton] -%> test "should get index" do get :index @@ -16,30 +20,30 @@ class <%= controller_class_name %>ControllerTest < ActionController::TestCase test "should create <%= file_name %>" do assert_difference('<%= class_name %>.count') do - post :create, :<%= file_name %> => <%= table_name %>(:one).attributes + post :create, :<%= file_name %> => @<%= file_name %>.attributes end assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>)) end test "should show <%= file_name %>" do - get :show, :id => <%= table_name %>(:one).to_param + get :show, :id => @<%= file_name %>.to_param assert_response :success end test "should get edit" do - get :edit, :id => <%= table_name %>(:one).to_param + get :edit, :id => @<%= file_name %>.to_param assert_response :success end test "should update <%= file_name %>" do - put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => <%= table_name %>(:one).attributes + put :update, :id => @<%= file_name %>.to_param, :<%= file_name %> => @<%= file_name %>.attributes assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>)) end test "should destroy <%= file_name %>" do assert_difference('<%= class_name %>.count', -1) do - delete :destroy, :id => <%= table_name %>(:one).to_param + delete :destroy, :id => @<%= file_name %>.to_param end assert_redirected_to <%= table_name %>_path -- cgit v1.2.3