diff options
| author | Emilio Tagua <miloops@gmail.com> | 2009-10-02 10:52:55 -0300 | 
|---|---|---|
| committer | Emilio Tagua <miloops@gmail.com> | 2009-10-02 10:52:55 -0300 | 
| commit | 29457a21c0d4451f5dbc66f72b8256baa02a55bd (patch) | |
| tree | 50aebb7b31b990b805871e816b852151df2833a1 /railties/lib/rails/generators/test_unit | |
| parent | 5f9540e4830ace3459b4018006573bad7fb30b53 (diff) | |
| parent | 420004e030e96f2ace6e27fd622c90ee9e986677 (diff) | |
| download | rails-29457a21c0d4451f5dbc66f72b8256baa02a55bd.tar.gz rails-29457a21c0d4451f5dbc66f72b8256baa02a55bd.tar.bz2 rails-29457a21c0d4451f5dbc66f72b8256baa02a55bd.zip | |
Merge commit 'rails/master'
Diffstat (limited to 'railties/lib/rails/generators/test_unit')
21 files changed, 291 insertions, 0 deletions
| 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 | 
