diff options
author | José Valim <jose.valim@gmail.com> | 2009-10-17 15:56:44 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-10-17 15:56:44 -0300 |
commit | 1f9d234a6b567e68d97e71da6f19bd126e7f7058 (patch) | |
tree | 601ea9ceba21bb3f90173c38b81578aa5920eb86 /railties/test/generators | |
parent | 03c5a0e5c4c9888c54265d6ef97136854e0ff9e4 (diff) | |
download | rails-1f9d234a6b567e68d97e71da6f19bd126e7f7058.tar.gz rails-1f9d234a6b567e68d97e71da6f19bd126e7f7058.tar.bz2 rails-1f9d234a6b567e68d97e71da6f19bd126e7f7058.zip |
By default use ActiveModel API in controller generators, unless otherwise specified [#3123 status:resolved]
Diffstat (limited to 'railties/test/generators')
-rw-r--r-- | railties/test/generators/scaffold_controller_generator_test.rb | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index f555725eb8..02155c295c 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -2,6 +2,11 @@ require 'abstract_unit' require 'generators/generators_test_helper' require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' +module Unknown + module Generators + end +end + class ScaffoldControllerGeneratorTest < GeneratorsTestCase def test_controller_skeleton_is_created @@ -97,10 +102,38 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase assert_no_file "app/views/layouts/users.html.erb" end - def test_error_is_shown_if_orm_does_not_provide_interface - error = capture(:stderr){ run_generator ["User", "--orm=unknown"] } - assert_equal "Could not load Unknown::Generators::ActiveModel, skipping controller. " << - "Error: no such file to load -- rails/generators/unknown.\n", error + def test_default_orm_is_used + run_generator ["User", "--orm=unknown"] + + assert_file "app/controllers/users_controller.rb" do |content| + assert_match /class UsersController < ApplicationController/, content + + assert_instance_method content, :index do |m| + assert_match /@users = User\.all/, m + end + end + end + + def test_customized_orm_is_used + klass = Class.new(Rails::Generators::ActiveModel) do + def self.all(klass) + "#{klass}.find(:all)" + end + end + + Unknown::Generators.const_set(:ActiveModel, klass) + run_generator ["User", "--orm=unknown"] + + assert_file "app/controllers/users_controller.rb" do |content| + assert_match /class UsersController < ApplicationController/, content + + assert_instance_method content, :index do |m| + assert_match /@users = User\.find\(:all\)/, m + assert_no_match /@users = User\.all/, m + end + end + ensure + Unknown::Generators.send :remove_const, :ActiveModel end protected |