diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-03-13 10:03:59 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2012-03-14 12:46:25 -0300 |
commit | 570cc89bad00a0df20e11196fa34d3119327a7d6 (patch) | |
tree | dcec69b0a6fa60bdde8a3cb5a5b5375c93a6be7a /railties/lib/rails/generators/test_unit/scaffold | |
parent | 3e138df9776985de8ab367dcd9757b404c53435e (diff) | |
download | rails-570cc89bad00a0df20e11196fa34d3119327a7d6.tar.gz rails-570cc89bad00a0df20e11196fa34d3119327a7d6.tar.bz2 rails-570cc89bad00a0df20e11196fa34d3119327a7d6.zip |
Generate special controller and functional test templates for http apps
The main goal is to not generate the format.html block in scaffold
controller, and to generate a different functional test as we don't rely
on redirects anymore, we should test for http responses.
In addition to that, the :edit action is removed from the http
controller and the edit route is not generated by default, as they
usually do not make sense in this scenario.
[Carlos Antonio da Silva & Santiago Pastorino]
Diffstat (limited to 'railties/lib/rails/generators/test_unit/scaffold')
-rw-r--r-- | railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/generators/test_unit/scaffold/templates/http_functional_test.rb | 50 |
2 files changed, 56 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb index 37b9f7ef7d..e875c81340 100644 --- a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -10,8 +10,13 @@ module TestUnit argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" + class_option :http, :type => :boolean, :default => false, + :desc => "Generate functional test with HTTP actions only" + def create_test_files - template 'functional_test.rb', + template_file = options.http? ? "http_functional_test.rb" : "functional_test.rb" + + template template_file, File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb") end diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/http_functional_test.rb b/railties/lib/rails/generators/test_unit/scaffold/templates/http_functional_test.rb new file mode 100644 index 0000000000..5bb61cb263 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/scaffold/templates/http_functional_test.rb @@ -0,0 +1,50 @@ +require 'test_helper' + +<% module_namespacing do -%> +class <%= controller_class_name %>ControllerTest < ActionController::TestCase + setup do + @<%= singular_table_name %> = <%= table_name %>(:one) + @request.accept = "application/json" + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:<%= table_name %>) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create <%= singular_table_name %>" do + assert_difference('<%= class_name %>.count') do + post :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %> + end + + assert_response 201 + assert_not_nil assigns(:<%= singular_table_name %>) + end + + test "should show <%= singular_table_name %>" do + get :show, id: @<%= singular_table_name %> + assert_response :success + end + + test "should update <%= singular_table_name %>" do + put :update, id: @<%= singular_table_name %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %> + assert_response 204 + assert_not_nil assigns(:<%= singular_table_name %>) + end + + test "should destroy <%= singular_table_name %>" do + assert_difference('<%= class_name %>.count', -1) do + delete :destroy, id: @<%= singular_table_name %> + end + + assert_response 204 + assert_not_nil assigns(:<%= singular_table_name %>) + end +end +<% end -%> |