From f0dd77c6be6a86fe384bb0015151e0a497973d39 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 24 Sep 2009 14:01:31 -0700 Subject: Move railties/lib/* into railties/lib/* --- .../test_unit/controller/controller_generator.rb | 14 +++++++ .../controller/templates/functional_test.rb | 8 ++++ .../test_unit/helper/helper_generator.rb | 13 ++++++ .../test_unit/helper/templates/helper_test.rb | 4 ++ .../test_unit/integration/integration_generator.rb | 13 ++++++ .../integration/templates/integration_test.rb | 10 +++++ .../test_unit/mailer/mailer_generator.rb | 21 ++++++++++ .../generators/test_unit/mailer/templates/fixture | 3 ++ .../test_unit/mailer/templates/unit_test.rb | 20 +++++++++ .../generators/test_unit/model/model_generator.rb | 24 +++++++++++ .../test_unit/model/templates/fixtures.yml | 19 +++++++++ .../test_unit/model/templates/unit_test.rb | 8 ++++ .../test_unit/observer/observer_generator.rb | 13 ++++++ .../test_unit/observer/templates/unit_test.rb | 8 ++++ .../test_unit/performance/performance_generator.rb | 13 ++++++ .../performance/templates/performance_test.rb | 9 +++++ .../test_unit/plugin/plugin_generator.rb | 13 ++++++ .../plugin/templates/%file_name%_test.rb.tt | 8 ++++ .../test_unit/plugin/templates/test_helper.rb | 5 +++ .../test_unit/scaffold/scaffold_generator.rb | 18 +++++++++ .../scaffold/templates/functional_test.rb | 47 ++++++++++++++++++++++ 21 files changed, 291 insertions(+) create mode 100644 railties/lib/rails/generators/test_unit/controller/controller_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb create mode 100644 railties/lib/rails/generators/test_unit/helper/helper_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/helper/templates/helper_test.rb create mode 100644 railties/lib/rails/generators/test_unit/integration/integration_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb create mode 100644 railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/mailer/templates/fixture create mode 100644 railties/lib/rails/generators/test_unit/mailer/templates/unit_test.rb create mode 100644 railties/lib/rails/generators/test_unit/model/model_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/model/templates/fixtures.yml create mode 100644 railties/lib/rails/generators/test_unit/model/templates/unit_test.rb create mode 100644 railties/lib/rails/generators/test_unit/observer/observer_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/observer/templates/unit_test.rb create mode 100644 railties/lib/rails/generators/test_unit/performance/performance_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb create mode 100644 railties/lib/rails/generators/test_unit/plugin/plugin_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt create mode 100644 railties/lib/rails/generators/test_unit/plugin/templates/test_helper.rb create mode 100644 railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb create mode 100644 railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb (limited to 'railties/lib/rails/generators/test_unit') diff --git a/railties/lib/rails/generators/test_unit/controller/controller_generator.rb b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb new file mode 100644 index 0000000000..39816d9990 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/controller/controller_generator.rb @@ -0,0 +1,14 @@ +require 'rails/generators/test_unit' + +module TestUnit + module Generators + class ControllerGenerator < Base + check_class_collision :suffix => "ControllerTest" + + def create_test_files + template 'functional_test.rb', + File.join('test/functional', class_path, "#{file_name}_controller_test.rb") + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb new file mode 100644 index 0000000000..62fa5d86fd --- /dev/null +++ b/railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class <%= class_name %>ControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/railties/lib/rails/generators/test_unit/helper/helper_generator.rb b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb new file mode 100644 index 0000000000..4ea80bf7be --- /dev/null +++ b/railties/lib/rails/generators/test_unit/helper/helper_generator.rb @@ -0,0 +1,13 @@ +require 'rails/generators/test_unit' + +module TestUnit + module Generators + class HelperGenerator < Base + check_class_collision :suffix => "HelperTest" + + def create_helper_files + template 'helper_test.rb', File.join('test/unit/helpers', class_path, "#{file_name}_helper_test.rb") + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/helper/templates/helper_test.rb b/railties/lib/rails/generators/test_unit/helper/templates/helper_test.rb new file mode 100644 index 0000000000..591e40900e --- /dev/null +++ b/railties/lib/rails/generators/test_unit/helper/templates/helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class <%= class_name %>HelperTest < ActionView::TestCase +end diff --git a/railties/lib/rails/generators/test_unit/integration/integration_generator.rb b/railties/lib/rails/generators/test_unit/integration/integration_generator.rb new file mode 100644 index 0000000000..32d0fac029 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/integration/integration_generator.rb @@ -0,0 +1,13 @@ +require 'rails/generators/test_unit' + +module TestUnit + module Generators + class IntegrationGenerator < Base + check_class_collision :suffix => "Test" + + def create_test_files + template 'integration_test.rb', File.join('test/integration', class_path, "#{file_name}_test.rb") + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb new file mode 100644 index 0000000000..2c57158b1c --- /dev/null +++ b/railties/lib/rails/generators/test_unit/integration/templates/integration_test.rb @@ -0,0 +1,10 @@ +require 'test_helper' + +class <%= class_name %>Test < ActionController::IntegrationTest + fixtures :all + + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb new file mode 100644 index 0000000000..7353e5d61a --- /dev/null +++ b/railties/lib/rails/generators/test_unit/mailer/mailer_generator.rb @@ -0,0 +1,21 @@ +require 'rails/generators/test_unit' + +module TestUnit + module Generators + class MailerGenerator < Base + argument :actions, :type => :array, :default => [], :banner => "method method" + check_class_collision :suffix => "Test" + + def create_test_files + template "unit_test.rb", File.join('test/unit', class_path, "#{file_name}_test.rb") + end + + def create_fixtures_files + actions.each do |action| + @action, @path = action, File.join(file_path, action) + template "fixture", File.join("test/fixtures", @path) + end + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/mailer/templates/fixture b/railties/lib/rails/generators/test_unit/mailer/templates/fixture new file mode 100644 index 0000000000..fcce7bd805 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/mailer/templates/fixture @@ -0,0 +1,3 @@ +<%= class_name %>#<%= @action %> + +Find me in app/views/<%= @path %> diff --git a/railties/lib/rails/generators/test_unit/mailer/templates/unit_test.rb b/railties/lib/rails/generators/test_unit/mailer/templates/unit_test.rb new file mode 100644 index 0000000000..4de94076e9 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/mailer/templates/unit_test.rb @@ -0,0 +1,20 @@ +require 'test_helper' + +class <%= class_name %>Test < ActionMailer::TestCase +<% for action in actions -%> + test "<%= action %>" do + @expected.subject = '<%= class_name %>#<%= action %>' + @expected.body = read_fixture('<%= action %>') + @expected.date = Time.now + + assert_equal @expected.encoded, <%= class_name %>.create_<%= action %>(@expected.date).encoded + end + +<% end -%> +<% if actions.blank? -%> + # replace this with your real tests + test "the truth" do + assert true + end +<% end -%> +end diff --git a/railties/lib/rails/generators/test_unit/model/model_generator.rb b/railties/lib/rails/generators/test_unit/model/model_generator.rb new file mode 100644 index 0000000000..609b815683 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/model/model_generator.rb @@ -0,0 +1,24 @@ +require 'rails/generators/test_unit' + +module TestUnit + module Generators + class ModelGenerator < Base + argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" + class_option :fixture, :type => :boolean + + check_class_collision :suffix => "Test" + + def create_test_file + template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb") + end + + hook_for :fixture_replacement + + def create_fixture_file + if options[:fixture] && options[:fixture_replacement].nil? + template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml") + end + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml new file mode 100644 index 0000000000..c21035113e --- /dev/null +++ b/railties/lib/rails/generators/test_unit/model/templates/fixtures.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +<% unless attributes.empty? -%> +one: +<% for attribute in attributes -%> + <%= attribute.name %>: <%= attribute.default %> +<% end -%> + +two: +<% for attribute in attributes -%> + <%= attribute.name %>: <%= attribute.default %> +<% end -%> +<% else -%> +# one: +# column: value +# +# two: +# column: value +<% end -%> diff --git a/railties/lib/rails/generators/test_unit/model/templates/unit_test.rb b/railties/lib/rails/generators/test_unit/model/templates/unit_test.rb new file mode 100644 index 0000000000..3e0bc29d3a --- /dev/null +++ b/railties/lib/rails/generators/test_unit/model/templates/unit_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class <%= class_name %>Test < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/railties/lib/rails/generators/test_unit/observer/observer_generator.rb b/railties/lib/rails/generators/test_unit/observer/observer_generator.rb new file mode 100644 index 0000000000..6cc1158c21 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/observer/observer_generator.rb @@ -0,0 +1,13 @@ +require 'rails/generators/test_unit' + +module TestUnit + module Generators + class ObserverGenerator < Base + check_class_collision :suffix => "ObserverTest" + + def create_test_files + template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb") + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/observer/templates/unit_test.rb b/railties/lib/rails/generators/test_unit/observer/templates/unit_test.rb new file mode 100644 index 0000000000..03f6d5666e --- /dev/null +++ b/railties/lib/rails/generators/test_unit/observer/templates/unit_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class <%= class_name %>ObserverTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/railties/lib/rails/generators/test_unit/performance/performance_generator.rb b/railties/lib/rails/generators/test_unit/performance/performance_generator.rb new file mode 100644 index 0000000000..99edda5461 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/performance/performance_generator.rb @@ -0,0 +1,13 @@ +require 'rails/generators/test_unit' + +module TestUnit + module Generators + class PerformanceGenerator < Base + check_class_collision :suffix => "Test" + + def create_test_files + template 'performance_test.rb', File.join('test/performance', class_path, "#{file_name}_test.rb") + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb new file mode 100644 index 0000000000..27c91b0fca --- /dev/null +++ b/railties/lib/rails/generators/test_unit/performance/templates/performance_test.rb @@ -0,0 +1,9 @@ +require 'test_helper' +require 'performance_test_help' + +class <%= class_name %>Test < ActionController::PerformanceTest + # Replace this with your real tests. + def test_homepage + get '/' + end +end diff --git a/railties/lib/rails/generators/test_unit/plugin/plugin_generator.rb b/railties/lib/rails/generators/test_unit/plugin/plugin_generator.rb new file mode 100644 index 0000000000..4d65cd7d89 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/plugin/plugin_generator.rb @@ -0,0 +1,13 @@ +require 'rails/generators/test_unit' + +module TestUnit + module Generators + class PluginGenerator < Base + check_class_collision :suffix => "Test" + + def create_test_files + directory '.', 'test' + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt b/railties/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt new file mode 100644 index 0000000000..3e0bc29d3a --- /dev/null +++ b/railties/lib/rails/generators/test_unit/plugin/templates/%file_name%_test.rb.tt @@ -0,0 +1,8 @@ +require 'test_helper' + +class <%= class_name %>Test < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/railties/lib/rails/generators/test_unit/plugin/templates/test_helper.rb b/railties/lib/rails/generators/test_unit/plugin/templates/test_helper.rb new file mode 100644 index 0000000000..348ec33582 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/plugin/templates/test_helper.rb @@ -0,0 +1,5 @@ +require 'rubygems' +require 'test/unit' +require 'active_support' +require 'active_support/test_case' + diff --git a/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb new file mode 100644 index 0000000000..c0315c7fe6 --- /dev/null +++ b/railties/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb @@ -0,0 +1,18 @@ +require 'rails/generators/test_unit' +require 'rails/generators/resource_helpers' + +module TestUnit + module Generators + class ScaffoldGenerator < Base + include Rails::Generators::ResourceHelpers + + class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller" + check_class_collision :suffix => "ControllerTest" + + def create_test_files + template 'functional_test.rb', + File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb") + end + end + end +end diff --git a/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb new file mode 100644 index 0000000000..e4bf4035da --- /dev/null +++ b/railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb @@ -0,0 +1,47 @@ +require 'test_helper' + +class <%= controller_class_name %>ControllerTest < ActionController::TestCase +<% unless options[:singleton] -%> + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:<%= table_name %>) + end +<% end -%> + + test "should get new" do + get :new + assert_response :success + end + + test "should create <%= file_name %>" do + assert_difference('<%= class_name %>.count') do + post :create, :<%= file_name %> => { } + end + + assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>)) + end + + test "should show <%= file_name %>" do + get :show, :id => <%= table_name %>(:one).to_param + assert_response :success + end + + test "should get edit" do + get :edit, :id => <%= table_name %>(:one).to_param + assert_response :success + end + + test "should update <%= file_name %>" do + put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { } + assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>)) + end + + test "should destroy <%= file_name %>" do + assert_difference('<%= class_name %>.count', -1) do + delete :destroy, :id => <%= table_name %>(:one).to_param + end + + assert_redirected_to <%= table_name %>_path + end +end -- cgit v1.2.3