diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2015-06-11 17:44:06 -0300 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2015-06-11 17:44:06 -0300 |
commit | 21f7bcbaa7709ed072bb2e1273d25c09eeaa26d9 (patch) | |
tree | 14b91132cbe37e1b3bc6c8af41a8804b8163edac /railties/test/generators/scaffold_controller_generator_test.rb | |
parent | ed7d787e120347ebc97647014a5e1fef7a34c19c (diff) | |
parent | 51d5d6252ee093d3fa004abec79319ae8b4c42c4 (diff) | |
download | rails-21f7bcbaa7709ed072bb2e1273d25c09eeaa26d9.tar.gz rails-21f7bcbaa7709ed072bb2e1273d25c09eeaa26d9.tar.bz2 rails-21f7bcbaa7709ed072bb2e1273d25c09eeaa26d9.zip |
Merge pull request #19832 from spastorino/rails-api
Rails api
Diffstat (limited to 'railties/test/generators/scaffold_controller_generator_test.rb')
-rw-r--r-- | railties/test/generators/scaffold_controller_generator_test.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 7c282377d7..5dae36b65e 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -185,4 +185,51 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase assert_match(/2 runs, 2 assertions, 0 failures, 0 errors/, `bundle exec rake test 2>&1`) end end + + def test_api_only_generates_a_proper_api_controller + run_generator ["User", "--api"] + + assert_file "app/controllers/users_controller.rb" do |content| + assert_match(/class UsersController < ApplicationController/, content) + assert_no_match(/respond_to/, content) + + assert_match(/before_action :set_user, only: \[:show, :update, :destroy\]/, content) + + assert_instance_method :index, content do |m| + assert_match(/@users = User\.all/, m) + assert_match(/render json: @users/, m) + end + + assert_instance_method :show, content do |m| + assert_match(/render json: @user/, m) + end + + assert_instance_method :create, content do |m| + assert_match(/@user = User\.new\(user_params\)/, m) + assert_match(/@user\.save/, m) + assert_match(/@user\.errors/, m) + end + + assert_instance_method :update, content do |m| + assert_match(/@user\.update\(user_params\)/, m) + assert_match(/@user\.errors/, m) + end + + assert_instance_method :destroy, content do |m| + assert_match(/@user\.destroy/, m) + end + end + end + + def test_api_controller_tests + run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}", "--api"] + + assert_file "test/controllers/users_controller_test.rb" do |content| + assert_match(/class UsersControllerTest < ActionController::TestCase/, content) + assert_match(/test "should get index"/, content) + assert_match(/post :create, params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content) + assert_match(/patch :update, params: \{ id: @user, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/, content) + assert_no_match(/assert_redirected_to/, content) + end + end end |