rails_generators/qadmin/templates/functional_test.rb in quirkey-qadmin-0.1.1 vs rails_generators/qadmin/templates/functional_test.rb in quirkey-qadmin-0.2.0

- old
+ new

@@ -1,77 +1,114 @@ -require File.dirname(__FILE__) + '<%= '/..' * controller_class_nesting_depth %>/../test_helper' -require '<%= controller_file_path %>_controller' +require 'test_helper' -# Re-raise errors caught by the controller. -class <%= controller_class_name %>Controller; def rescue_action(e) raise e end; end +class <%= controller_class_name %>ControllerTest < ActionController::TestCase + + context "<%= controller_class_name %>" do + setup do + @<%= file_name %> = <%= table_name %>(!!FIXTURE_NAME) + @<%= file_name %>_params = { +<%= attributes.collect { |a| ":#{a.name} => '#{a.default}'" }.join(",\n\t") %> + } + end -class <%= controller_class_name %>ControllerTest < Test::Unit::TestCase - fixtures :<%= model_name.tableize %>#, :users + context "html" do + context "GET index" do + setup do + get :index + end - def setup - @controller = <%= controller_class_name %>Controller.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - #login_as(:aaron) - @<%= file_name %> = <%= model_name.tableize %>(!!FIXTURENAME) - end + should_respond_with :success - # def test_should_require_login - # logout - # get :index - # assert_redirected_to_login - # end + should "load paginated collection of <%= table_name %>" do + assert assigns(:<%= table_name %>) + assert assigns(:<%= table_name %>).respond_to?(:next_page) + end - def test_should_get_index - get :index - assert_response :success - assert assigns(:<%= model_name.tableize %>) - end + should "display <%= file_name %>" do + assert_select "#<%= file_name %>_#{@<%= file_name %>.id}" + end + end - def test_should_get_new - get :new - assert_response :success - assert_select 'form' - end - - def test_should_create_<%= file_name %> - assert_difference '<%= model_name %>.count' do - post :create, :<%= file_name %> => <%= file_name %>_params - assert_redirected_to <%= table_name.singularize %>_path(assigns(:<%= file_name %>)) - end - end + context "GET show" do + setup do + get :show, :id => @<%= file_name %>.id + end - def test_should_show_<%= file_name %> - get :show, :id => @<%= file_name %>.id - assert_response :success - assert assigns(:<%= file_name %>) - end + should_respond_with :success + should_assign_to :<%= file_name %> - def test_should_get_edit - get :edit, :id => @<%= file_name %>.id - assert_response :success - assert assigns(:<%= file_name %>) - assert_select 'form' - end - - def test_should_update_<%= file_name %> - assert_no_difference '<%= model_name %>.count' do - put :update, :id => @<%= file_name %>.id, :<%= file_name %> => <%= file_name %>_params - assert_redirected_to <%= table_name.singularize %>_path(assigns(:<%= file_name %>)) + should "load <%= file_name %>" do + assert_equal @<%= file_name %>, assigns(:<%= file_name %>) + end + + should "display <%= file_name %>" do + assert_select "#<%= file_name %>_#{@<%= file_name %>.id}" + end + end + + context "GET new" do + setup do + get :new + end + + should_respond_with :success + should_assign_to :<%= file_name %> + + should "display form" do + assert_select 'form' + end + end + + context "POST create with valid <%= file_name %>" do + setup do + post :create, :<%= file_name %> => @<%= file_name %>_params + end + + should_change '<%= model_name %>.count', :by => 1 + should_redirect_to "<%= file_name %>_path(@<%= file_name %>)" + should_assign_to :<%= file_name %> + end + + context "GET edit" do + setup do + get :edit, :id => @<%= file_name %>.id + end + + should_respond_with :success + should_assign_to :<%= file_name %> + + should "load <%= file_name %>" do + assert_equal @<%= file_name %>, assigns(:<%= file_name %>) + end + + should "display form" do + assert_select 'form' + end + end + + context "PUT update" do + setup do + put :update, :id => @<%= file_name %>.id, :<%= file_name %> => @<%= file_name %>_params + end + + should_not_change '<%= model_name %>.count' + should_redirect_to "<%= file_name %>_path(@<%= file_name %>)" + should_assign_to :<%= file_name %> + + should "load <%= file_name %>" do + assert_equal @<%= file_name %>, assigns(:<%= file_name %>) + end + end + + context "DELETE destroy" do + setup do + delete :destroy, :id => @<%= file_name %>.id + end + + should_change '<%= model_name %>.count', :by => -1 + should_redirect_to "<%= table_name %>_path" + should_assign_to :<%= file_name %> + end end end - def test_should_destroy_<%= file_name %> - assert_difference '<%= model_name %>.count', -1 do - delete :destroy, :id => @<%= file_name %>.id - assert_redirected_to <%= table_name %>_path - end - end - - - protected - def <%= file_name %>_params(options = {}) - { - <%= attributes.collect { |a| ":#{a.name} => #{a.default}" }.join(', ') %> - }.update(options) - end end