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

Changeset 3840

Show
Ignore:
Timestamp:
03/12/06 00:08:26 (3 years ago)
Author:
minam
Message:

More integration testing tweaks

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/integration_test.rb

    r3836 r3840  
    462462    %w(get post cookies assigns).each do |method| 
    463463      define_method(method) do |*args| 
    464         @integration_session.send(method, *args) 
     464        reset! unless @integration_session 
     465        returning @integration_session.send(method, *args) do 
     466          copy_session_variables! 
     467        end 
    465468      end 
    466469    end 
     
    480483 
    481484      # delegate the fixture accessors back to the test instance 
    482       klass = class<<session; self; end 
    483       tests = self 
    484  
     485      extras = Module.new { attr_accessor :delegate, :test_result } 
    485486      self.class.fixture_table_names.each do |table_name| 
    486487        name = table_name.tr(".", "_") 
    487488        next unless respond_to?(name) 
    488         klass.send(:define_method, name) { |*args| tests.send(name, *args) } 
     489        extras.send(:define_method, name) { |*args| delegate.send(name, *args) } 
    489490      end 
    490491 
    491492      # delegate add_assertion to the test case 
    492       klass.send(:define_method, :add_assertion) { tests.add_assertion } 
     493      extras.send(:define_method, :add_assertion) { test_result.add_assertion } 
     494      session.extend(extras) 
     495      session.delegate = self 
     496      session.test_result = @_result 
    493497 
    494498      yield session if block_given? 
    495499      session 
     500    end 
     501 
     502    # Copy the instance variables from the current session instance into the 
     503    # test instance. 
     504    def copy_session_variables! #:nodoc: 
     505      return unless @integration_session 
     506      %w(controller response request).each do |var| 
     507        instance_variable_set("@#{var}", @integration_session.send(var)) 
     508      end 
    496509    end 
    497510 
     
    499512    def method_missing(sym, *args, &block) 
    500513      reset! unless @integration_session 
    501       @integration_session.send(sym, *args, &block) 
     514      returning @integration_session.send(sym, *args, &block) do 
     515        copy_session_variables! 
     516      end 
    502517    end 
    503518  end