Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Always specify the path to render to

  • Loading branch information...
commit 25b590cbb2d344dacca812322d8bf0ea16188bbd 1 parent 595c915
Joe Ferris and Mike Burns authored jferris committed
View
4 lib/turning/controller.rb
@@ -6,8 +6,8 @@ def initialize(renderer = nil)
private
- def render(template_name, assigns = {})
- @renderer.render_to_file(template_name, assigns)
+ def render(template_name, path, assigns = {})
+ @renderer.render_to_file(template_name, path, assigns)
end
def default_renderer
View
2  lib/turning/file_storage.rb
@@ -22,7 +22,7 @@ def get(file_path)
private
def resolve(file_path)
- File.join(@root_path, file_path)
+ File.join(@root_path, "#{file_path}_contents")
end
def parent_directory(file_path)
View
4 lib/turning/renderer.rb
@@ -44,10 +44,10 @@ def self.name
@renderable.controller_path = @controller_path
end
- def render_to_file(template_name, assigns)
+ def render_to_file(template_name, path, assigns)
@renderable.view_assigns = assigns
contents = @renderable.render_to_string(action: template_name)
- @storage.put("#{@controller_path}/#{template_name}", contents)
+ @storage.put(path, contents)
end
end
end
View
12 spec/turning/controller_spec.rb
@@ -18,34 +18,34 @@
it 'renders' do
concrete_controller = Class.new(Turning::Controller) do
def do_it
- render 'index', greeting: 'hello'
+ render 'index', 'hello-index', greeting: 'hello'
end
end
renderer = mock_renderer
concrete_controller.new(renderer).do_it
- renderer.should have_rendered('index', greeting: 'hello')
+ renderer.should have_rendered('index', 'hello-index', greeting: 'hello')
end
it 'renders without assigns' do
concrete_controller = Class.new(Turning::Controller) do
def do_it
- render 'index'
+ render 'index', 'index-unassigned'
end
end
renderer = mock_renderer
concrete_controller.new(renderer).do_it
- renderer.should have_rendered('index', {})
+ renderer.should have_rendered('index', 'index-unassigned', {})
end
def mock_renderer
stub('mock renderer', render_to_file: nil)
end
- def have_rendered(template_name, assigns)
- have_received(:render_to_file).with(template_name, assigns)
+ def have_rendered(template_name, path, assigns)
+ have_received(:render_to_file).with(template_name, path, assigns)
end
end
View
10 spec/turning/file_storage_spec.rb
@@ -13,6 +13,16 @@
results.should == 'awesome!'
end
+ it 'caches a file at the root' do
+ root = Rails.root.join('public', 'static')
+ storage = Turning::FileStorage.new(root)
+
+ storage.put('/', 'awesome!')
+ results = storage.get('/')
+
+ results.should == 'awesome!'
+ end
+
it 'returns nil for a file that does not exist' do
root = Rails.root.join('public', 'static')
getter = Turning::FileStorage.new(root)
View
4 spec/turning/integration_spec.rb
@@ -17,7 +17,7 @@ def self.name
def listen
@model.on_update do
- render 'index', greeting: 'Hello'
+ render 'index', '/', greeting: 'Hello'
end
end
end
@@ -40,7 +40,7 @@ def trigger_update
controller.listen
model.trigger_update
- get '/examples/index'
+ get '/'
last_response.body.should == 'Hello'
end
View
18 spec/turning/renderer_spec.rb
@@ -6,18 +6,18 @@
create_view('examples/say_hello.html.erb', '<%= @greeting %>')
storage = mock_storage
renderer = Turning::Renderer.new('examples', storage)
- renderer.render_to_file('say_hello', greeting: 'Hello')
+ renderer.render_to_file('say_hello', '/result', greeting: 'Hello')
- storage.should have_static_view('examples/say_hello', 'Hello')
+ storage.should have_static_view('/result', 'Hello')
end
it 'supplies built-in helpers' do
create_view('examples/go_home.html.erb', '<%= link_to "go home", root_path %>')
storage = mock_storage
renderer = Turning::Renderer.new('examples', storage)
- renderer.render_to_file('go_home', {})
+ renderer.render_to_file('go_home', '/result', {})
- storage.should have_static_view('examples/go_home', %{<a href="/">go home</a>})
+ storage.should have_static_view('/result', %{<a href="/">go home</a>})
end
it 'supplies custom helpers' do
@@ -31,15 +31,15 @@ def greet
create_view('examples/greet_hello.html.erb', '<%= greet %>')
storage = mock_storage
renderer = Turning::Renderer.new('examples', storage)
- renderer.render_to_file('greet_hello', {})
+ renderer.render_to_file('greet_hello', '/examples/greet_hello', {})
- storage.should have_static_view('examples/greet_hello', 'Hello')
+ storage.should have_static_view('/examples/greet_hello', 'Hello')
end
it 'disables forgery protection for static forms' do
create_view('examples/form.html.erb', "<%= form_tag '/' do %><% end %>")
renderer = Turning::Renderer.new('examples', mock_storage)
- expect { renderer.render_to_file('form', {}) }.not_to raise_error
+ expect { renderer.render_to_file('form', '/form', {}) }.not_to raise_error
end
it 'renders with a layout' do
@@ -47,9 +47,9 @@ def greet
create_view('layouts/static.html.erb', 'Check this: <%= yield %>')
storage = mock_storage
renderer = Turning::Renderer.new('examples', storage)
- renderer.render_to_file('simple', {})
+ renderer.render_to_file('simple', '/examples/simple', {})
- storage.should have_static_view('examples/simple', 'Check this: Hello')
+ storage.should have_static_view('/examples/simple', 'Check this: Hello')
end
def mock_storage
Please sign in to comment.
Something went wrong with that request. Please try again.