Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8521: test_superclasses.diff

File test_superclasses.diff, 11.2 kB (added by csshsh, 1 year ago)
  • actionmailer/lib/action_mailer/mailer_test.rb

    old new  
     1require 'rails_test' 
     2 
     3module ActionMailer 
     4  class MailerTest < ::RailsTest #:nodoc: 
     5    include ActionController::UrlWriter 
     6    include ActionMailer::Quoting 
     7     
     8    CHARSET = "utf-8" 
     9     
     10    def setup_with_mailer_initialisation 
     11      setup_without_mailer_initialisation 
     12       
     13      ActionMailer::Base.delivery_method = :test 
     14      ActionMailer::Base.perform_deliveries = true 
     15      ActionMailer::Base.deliveries = [] 
     16 
     17      @expected = TMail::Mail.new 
     18      @expected.set_content_type "text", "plain", { "charset" => CHARSET } 
     19      @expected.mime_version = '1.0' 
     20    end 
     21 
     22    alias_method_chain :setup, :mailer_initialisation 
     23     
     24    def self.method_added(method) 
     25      if method.to_s == 'setup' && !method_defined?(:user_defined_setup) 
     26        alias_method :user_defined_setup, :setup 
     27        define_method(:setup) do 
     28          rails_internal_setup 
     29          user_defined_setup 
     30        end 
     31      end 
     32       
     33      super(method) 
     34    end 
     35   
     36    protected 
     37      def read_fixture(action) 
     38        IO.readlines("#{self.class.fixture_path}#{self.class.to_s.gsub("Test", "").underscore}/#{action}") 
     39      end 
     40 
     41      def encode(subject) 
     42        quoted_printable(subject, CHARSET) 
     43      end 
     44  end 
     45end 
  • actionpack/lib/action_controller/controller_test.rb

    old new  
     1require 'rails_test' 
     2 
     3module ActionController 
     4  class ControllerTest < ::RailsTest #:nodoc: 
     5    def setup 
     6      @controller = self.class.controller_class.new 
     7      @request    = ActionController::TestRequest.new 
     8      @response   = ActionController::TestResponse.new 
     9    end 
     10     
     11    alias_method :rails_internal_setup, :setup 
     12           
     13    class << self 
     14      def method_added(method) 
     15        if method.to_s == 'setup' && !method_defined?(:user_defined_setup) 
     16          alias_method :user_defined_setup, :setup 
     17          define_method(:setup) do 
     18            rails_internal_setup 
     19            user_defined_setup 
     20          end 
     21        end 
     22 
     23        super(method) 
     24      end 
     25       
     26      def controller_class 
     27        return @controller_class if @controller_class 
     28 
     29        @controller_class = case @controller_class_or_symbol 
     30          when nil then controller_class_from_test_class_name 
     31          when Symbol then controller_class_from_symbol 
     32          else @controller_class_or_symbol 
     33        end 
     34         
     35        @controller_class.send(:define_method, :rescue_action) { |e| raise e } 
     36        @controller_class 
     37      end 
     38 
     39      def controller_class_from_symbol 
     40        "#{@controller_class_or_symbol}Controller".camelize.constantize 
     41      end 
     42 
     43      def controller_class_from_test_class_name 
     44        self.to_s.gsub("Test", "").constantize 
     45      end 
     46       
     47      def controller(controller_class_or_symbol) 
     48        @controller_class_or_symbol = controller_class_or_symbol 
     49      end 
     50    end 
     51  end 
     52end 
  • actionpack/lib/action_controller/integration.rb

    old new  
    22require 'stringio' 
    33require 'uri' 
    44require 'action_controller/test_process' 
     5require 'rails_test' 
    56 
    67module ActionController 
    78  module Integration #:nodoc: 
     
    444445  #         end 
    445446  #       end 
    446447  #   end 
    447   class IntegrationTest < Test::Unit::TestCase 
    448     # Work around a bug in test/unit caused by the default test being named 
    449     # as a symbol (:default_test), which causes regex test filters 
    450     # (like "ruby test.rb -n /foo/") to fail because =~ doesn't work on 
    451     # symbols. 
    452     def initialize(name) #:nodoc: 
    453       super(name.to_s) 
    454     end 
    455  
    456     # Work around test/unit's requirement that every subclass of TestCase have 
    457     # at least one test method. Note that this implementation extends to all 
    458     # subclasses, as well, so subclasses of IntegrationTest may also exist 
    459     # without any test methods. 
    460     def run(*args) #:nodoc: 
    461       return if @method_name == "default_test" 
    462       super 
    463     end 
    464  
    465     # Because of how use_instantiated_fixtures and use_transactional_fixtures 
    466     # are defined, we need to treat them as special cases. Otherwise, users 
    467     # would potentially have to set their values for both Test::Unit::TestCase 
    468     # ActionController::IntegrationTest, since by the time the value is set on 
    469     # TestCase, IntegrationTest has already been defined and cannot inherit 
    470     # changes to those variables. So, we make those two attributes copy-on-write. 
    471  
    472     class << self 
    473       def use_transactional_fixtures=(flag) #:nodoc: 
    474         @_use_transactional_fixtures = true 
    475         @use_transactional_fixtures = flag 
    476       end 
    477  
    478       def use_instantiated_fixtures=(flag) #:nodoc: 
    479         @_use_instantiated_fixtures = true 
    480         @use_instantiated_fixtures = flag 
    481       end 
    482  
    483       def use_transactional_fixtures #:nodoc: 
    484         @_use_transactional_fixtures ? 
    485           @use_transactional_fixtures : 
    486           superclass.use_transactional_fixtures 
    487       end 
    488  
    489       def use_instantiated_fixtures #:nodoc: 
    490         @_use_instantiated_fixtures ? 
    491           @use_instantiated_fixtures : 
    492           superclass.use_instantiated_fixtures 
    493       end 
    494     end 
    495  
     448  class IntegrationTest < RailsTest 
    496449    # Reset the current session. This is useful for testing multiple sessions 
    497450    # in a single test case. 
    498451    def reset! 
  • railties/lib/rails_generator/generators/components/controller/templates/functional_test.rb

    old new  
    11require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper' 
    2 require '<%= file_path %>_controller' 
    32 
    4 # Re-raise errors caught by the controller. 
    5 class <%= class_name %>Controller; def rescue_action(e) raise e end; end 
    6  
    7 class <%= class_name %>ControllerTest < Test::Unit::TestCase 
    8   def setup 
    9     @controller = <%= class_name %>Controller.new 
    10     @request    = ActionController::TestRequest.new 
    11     @response   = ActionController::TestResponse.new 
    12   end 
    13  
     3class <%= class_name %>ControllerTest < ActionController::ControllerTest 
    144  # Replace this with your real tests. 
    155  def test_truth 
    166    assert true 
  • railties/lib/rails_generator/generators/components/mailer/templates/unit_test.rb

    old new  
    11require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper' 
    22 
    3 class <%= class_name %>Test < Test::Unit::TestCase 
    4   FIXTURES_PATH = File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../fixtures' 
    5   CHARSET = "utf-8" 
    6  
    7   include ActionMailer::Quoting 
    8  
    9   def setup 
    10     ActionMailer::Base.delivery_method = :test 
    11     ActionMailer::Base.perform_deliveries = true 
    12     ActionMailer::Base.deliveries = [] 
    13  
    14     @expected = TMail::Mail.new 
    15     @expected.set_content_type "text", "plain", { "charset" => CHARSET } 
    16     @expected.mime_version = '1.0' 
    17   end 
    18  
     3class <%= class_name %>Test < ActionMailer::MailerTest 
    194<% for action in actions -%> 
    205  def test_<%= action %> 
    216    @expected.subject = '<%= class_name %>#<%= action %>' 
     
    2611  end 
    2712 
    2813<% end -%> 
    29   private 
    30     def read_fixture(action) 
    31       IO.readlines("#{FIXTURES_PATH}/<%= file_path %>/#{action}") 
    32     end 
    33  
    34     def encode(subject) 
    35       quoted_printable(subject, CHARSET) 
    36     end 
    3714end 
  • railties/lib/test_help.rb

    old new  
    77require 'test/unit' 
    88require 'active_record/fixtures' 
    99require 'action_controller/test_process' 
     10require 'rails_test' 
     11require 'action_mailer/mailer_test' 
     12require 'action_controller/controller_test' 
    1013require 'action_controller/integration' 
    1114 
    1215Test::Unit::TestCase.fixture_path = RAILS_ROOT + "/test/fixtures/" 
    13 ActionController::IntegrationTest.fixture_path = Test::Unit::TestCase.fixture_path 
    1416 
    1517def create_fixtures(*table_names) 
    1618  Fixtures.create_fixtures(RAILS_ROOT + "/test/fixtures", table_names) 
  • railties/lib/rails_test.rb

    old new  
     1class RailsTest < Test::Unit::TestCase #:nodoc: 
     2  # Work around a bug in test/unit caused by the default test being named 
     3  # as a symbol (:default_test), which causes regex test filters 
     4  # (like "ruby test.rb -n /foo/") to fail because =~ doesn't work on 
     5  # symbols. 
     6  def initialize(name) #:nodoc: 
     7    super(name.to_s) 
     8  end 
     9 
     10  # Work around test/unit's requirement that every subclass of TestCase have 
     11  # at least one test method. Note that this implementation extends to all 
     12  # subclasses, as well, so subclasses of RailsTest may also exist 
     13  # without any test methods. 
     14  def run(*args) #:nodoc: 
     15    return if @method_name == "default_test" 
     16    super    
     17  end 
     18   
     19  # Because of how use_instantiated_fixtures, use_transactional_fixtures 
     20  # and fixture_path are defined, we need to treat them as special cases.  
     21  # Otherwise, users would potentially have to set their values for  
     22  # Test::Unit::TestCase and all its subclasses, since by the time the  
     23  # value is set on TestCase, its subclasses have already been defined  
     24  # and cannot inherit changes to those variables. So, we make those three  
     25  # attributes copy-on-write. 
     26  class << self     
     27    def use_transactional_fixtures=(flag) #:nodoc: 
     28      @_use_transactional_fixtures = true 
     29      @use_transactional_fixtures = flag 
     30    end 
     31 
     32    def use_instantiated_fixtures=(flag) #:nodoc: 
     33      @_use_instantiated_fixtures = true 
     34      @use_instantiated_fixtures = flag 
     35    end 
     36     
     37    def fixture_path=(flag) #:nodoc: 
     38      @_fixture_path = true 
     39      @fixture_path = flag 
     40    end 
     41         
     42    def use_transactional_fixtures #:nodoc: 
     43      @_use_transactional_fixtures ? 
     44        @use_transactional_fixtures : 
     45        superclass.use_transactional_fixtures 
     46    end 
     47 
     48    def use_instantiated_fixtures #:nodoc: 
     49      @_use_instantiated_fixtures ? 
     50        @use_instantiated_fixtures : 
     51        superclass.use_instantiated_fixtures 
     52    end 
     53 
     54    def fixture_path #:nodoc: 
     55      @_fixture_path ? 
     56        @fixture_path : 
     57        superclass.fixture_path 
     58    end 
     59  end 
     60end