Skip to content

Commit

Permalink
Merge process2 into process to people's regular tests run :P
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehuda Katz + Carl Lerche committed Jun 16, 2009
1 parent 1fbfa3e commit 18c3b77
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 115 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/testing/integration.rb
Expand Up @@ -245,7 +245,7 @@ def process(method, path, parameters = nil, rack_environment = nil)
path = location.query ? "#{location.path}?#{location.query}" : location.path
end

[ControllerCapture, ActionController::ProcessWithTest].each do |mod|
[ControllerCapture, ActionController::Testing].each do |mod|
unless ActionController::Base < mod
ActionController::Base.class_eval { include mod }
end
Expand Down
51 changes: 11 additions & 40 deletions actionpack/lib/action_controller/testing/process.rb
Expand Up @@ -124,30 +124,24 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =

@request.recycle!
@response.recycle!
@controller.response_body = nil
@controller.formats = nil
@controller.params = nil

@html_document = nil
@request.request_method = http_method
@request.env['REQUEST_METHOD'] = http_method

parameters ||= {}
@request.assign_parameters(@controller.class.controller_path, action.to_s, parameters)

@request.session = ActionController::TestSession.new(session) unless session.nil?
@request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash
build_request_uri(action, parameters)

Base.class_eval { include ProcessWithTest } unless Base < ProcessWithTest

env = @request.env
app = @controller

# TODO: Enable Lint
# app = Rack::Lint.new(app)

status, headers, body = app.action(action, env)
response = Rack::MockResponse.new(status, headers, body)

@response.request, @response.template = @request, @controller.template
@response.status, @response.headers, @response.body = response.status, response.headers, response.body
@controller.request = @request
@controller.params.merge!(parameters)
build_request_uri(action, parameters)
Base.class_eval { include Testing }
@controller.process_with_new_base_test(@request, @response)
@response
end

Expand All @@ -167,7 +161,7 @@ def assigns(key = nil)
next if ActionController::Base.protected_instance_variables.include?(ivar)
assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar)
end

key.nil? ? assigns : assigns[key.to_s]
end

Expand Down Expand Up @@ -263,27 +257,4 @@ def with_routing
ActionController::Routing.const_set(:Routes, real_routes) if real_routes
end
end

module ProcessWithTest #:nodoc:
def self.included(base)
base.class_eval {
attr_reader :assigns
alias_method_chain :process, :test
}
end

def process_with_test(*args)
process_without_test(*args).tap { set_test_assigns }
end

private
def set_test_assigns
@assigns = {}
(instance_variable_names - self.class.protected_instance_variables).each do |var|
name, value = var[1..-1], instance_variable_get(var)
@assigns[name] = value
@template.assigns[name] = value if response
end
end
end
end
end
74 changes: 0 additions & 74 deletions actionpack/lib/action_controller/testing/process2.rb

This file was deleted.

0 comments on commit 18c3b77

Please sign in to comment.