aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/scaffold_controller_generator_test.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-03-13 10:03:59 -0300
committerSantiago Pastorino <santiago@wyeworks.com>2012-03-14 12:46:25 -0300
commit570cc89bad00a0df20e11196fa34d3119327a7d6 (patch)
treedcec69b0a6fa60bdde8a3cb5a5b5375c93a6be7a /railties/test/generators/scaffold_controller_generator_test.rb
parent3e138df9776985de8ab367dcd9757b404c53435e (diff)
downloadrails-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/test/generators/scaffold_controller_generator_test.rb')
-rw-r--r--railties/test/generators/scaffold_controller_generator_test.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb
index 1eea50b0d9..ed54ce43da 100644
--- a/railties/test/generators/scaffold_controller_generator_test.rb
+++ b/railties/test/generators/scaffold_controller_generator_test.rb
@@ -142,4 +142,41 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
assert_match(/\{ render action: "new" \}/, content)
end
end
+
+ def test_http_only_generates_controller_without_respond_to_block_and_html_format
+ run_generator ["User", "--http"]
+
+ assert_file "app/controllers/users_controller.rb" do |content|
+ assert_match(/render json: @user/, content)
+ assert_no_match(/respond_to/, content)
+ assert_no_match(/format\.html/, content)
+ end
+ end
+
+ def test_http_only_generates_functional_tests_with_json_format_and_http_status_assertions
+ run_generator ["User", "--http"]
+
+ assert_file "test/functional/users_controller_test.rb" do |content|
+ assert_match(/class UsersControllerTest < ActionController::TestCase/, content)
+ assert_match(/@request\.accept = "application\/json"/, content)
+ assert_match(/test "should get index"/, content)
+
+ assert_match(/assert_response 201/, content)
+ assert_no_match(/assert_redirected_to/, content)
+ end
+ end
+
+ def test_http_only_does_not_generate_edit_action
+ run_generator ["User", "--http"]
+
+ assert_file "app/controllers/users_controller.rb" do |content|
+ assert_match(/def index/, content)
+ assert_no_match(/def edit/, content)
+ end
+
+ assert_file "test/functional/users_controller_test.rb" do |content|
+ assert_match(/test "should get index"/, content)
+ assert_no_match(/test "should get edit"/, content)
+ end
+ end
end