Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First, very early, AbstractController code. More to come
- Loading branch information
Showing
6 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
module AbstractController | |||
class Base | |||
|
|||
attr_internal :response_body | |||
attr_internal :response_obj | |||
cattr_accessor :logger | |||
|
|||
def self.process(action) | |||
new.process(action) | |||
end | |||
|
|||
def initialize | |||
self.response_obj = {} | |||
end | |||
|
|||
def process(action) | |||
send(action) | |||
self.response_obj[:body] = self.response_body | |||
self | |||
end | |||
|
|||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
module AbstractController | |||
module Renderer | |||
|
|||
def self.included(klass) | |||
klass.extend ClassMethods | |||
klass.extlib_inheritable_accessor :view_paths | |||
klass.view_paths ||= ActionView::PathSet.new | |||
end | |||
|
|||
def _action_view | |||
@_action_view ||= ActionView::Base.new(self.class.view_paths, {}, self) | |||
end | |||
|
|||
def render(template) | |||
tmp = view_paths.find_by_parts(template) | |||
self.response_body = _action_view._render_template_with_layout(tmp) | |||
end | |||
|
|||
module ClassMethods | |||
def append_view_path(path) | |||
self.view_paths << path | |||
end | |||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
actionpack/test/abstract_controller/abstract_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,60 @@ | |||
$:.unshift(File.dirname(__FILE__) + '/../../lib') | |||
$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib') | |||
|
|||
require 'test/unit' | |||
require 'active_support' | |||
require 'active_support/test_case' | |||
require 'action_controller' | |||
|
|||
begin | |||
require 'ruby-debug' | |||
Debugger.settings[:autoeval] = true | |||
Debugger.start | |||
rescue LoadError | |||
# Debugging disabled. `gem install ruby-debug` to enable. | |||
end | |||
|
|||
require 'action_controller/abstract/base' | |||
require 'action_controller/abstract/renderer' | |||
|
|||
module AbstractController | |||
module Testing | |||
|
|||
class SimpleController < AbstractController::Base | |||
end | |||
|
|||
class Me < SimpleController | |||
def index | |||
self.response_body = "Hello world" | |||
"Something else" | |||
end | |||
end | |||
|
|||
class TestBasic < ActiveSupport::TestCase | |||
test "dispatching works" do | |||
result = Me.process(:index) | |||
assert_equal "Hello world", result.response_obj[:body] | |||
end | |||
end | |||
|
|||
class RenderingController < AbstractController::Base | |||
include Renderer | |||
|
|||
append_view_path File.expand_path(File.join(File.dirname(__FILE__), "views")) | |||
end | |||
|
|||
class Me2 < RenderingController | |||
def index | |||
render "index.erb" | |||
end | |||
end | |||
|
|||
class TestRenderer < ActiveSupport::TestCase | |||
test "rendering templates works" do | |||
result = Me2.process(:index) | |||
assert_equal "Hello from index.erb", result.response_obj[:body] | |||
end | |||
end | |||
|
|||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
Hello from index.erb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters