1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

fix bug when reloading inline templates

This commit is contained in:
Gabriel Andretta 2011-04-13 22:16:22 -03:00
parent 7b1a65b347
commit 8a26f5bb57
2 changed files with 20 additions and 3 deletions

View file

@ -131,9 +131,9 @@ module Sinatra
end end
end end
def iniline_templates=(file=nil) def inline_templates=(file=nil)
file = (file.nil? || file == true) ? file = (file.nil? || file == true) ?
(caller_files.first || File.expand_path($0)) : file (caller_files[1] || File.expand_path($0)) : file
Watcher::List.for(self).watch_inline_templates(file) Watcher::List.for(self).watch_inline_templates(file)
super super
end end

View file

@ -87,13 +87,30 @@ describe Sinatra::Reloader do
get('/foo').status.should == 404 get('/foo').status.should == 404
end end
it "reloads inline templates" do it "reloads inline templates in the app file" do
update_app_file( update_app_file(
:routes => ['get("/foo") { erb :foo }'], :routes => ['get("/foo") { erb :foo }'],
:inline_templates => { :foo => 'bar' } :inline_templates => { :foo => 'bar' }
) )
get('/foo').body.should == 'bar' get('/foo').body.should == 'bar'
end end
it "reloads inline templates in other file" do
setup_example_app(:routes => ['get("/foo") { erb :foo }'])
template_file_path = File.join(tmp_dir, 'templates.rb')
File.open(template_file_path, 'w') do |f|
f.write "__END__\n\n@@foo\nfoo"
end
require template_file_path
app_const.inline_templates= template_file_path
get('/foo').body.should == 'foo'
update_file(template_file_path) do |path|
File.open(path, 'w') do |f|
f.write "__END__\n\n@@foo\nbar"
end
end
get('/foo').body.should == 'bar'
end
end end
describe ".dont_reload" do describe ".dont_reload" do