spec/plugin/view_options_spec.rb in roda-2.29.0 vs spec/plugin/view_options_spec.rb in roda-3.0.0
- old
+ new
@@ -1,6 +1,6 @@
-require File.expand_path("spec_helper", File.dirname(File.dirname(__FILE__)))
+require_relative "../spec_helper"
begin
require 'tilt/erb'
rescue LoadError
warn "tilt not installed, skipping view_options plugin test"
@@ -43,10 +43,25 @@
body("/path").strip.must_equal "<h1>Path</h1>"
end
end
describe "view_options plugin" do
+ it "should not use :views view option for layout" do
+ app(:bare) do
+ plugin :render, :views=>'spec/views', :allowed_paths=>['spec/views']
+ plugin :view_options
+
+ route do
+ set_view_options :views=>'spec/views/about'
+ set_layout_options :template=>'layout-alternative'
+ view('_test', :locals=>{:title=>'About Roda'}, :layout_opts=>{:locals=>{:title=>'Home'}})
+ end
+ end
+
+ body.strip.must_equal "<title>Alternative Layout: Home</title>\n<h1>Subdir: About Roda</h1>"
+ end
+
it "should set view and layout options to use" do
app(:bare) do
plugin :render, :allowed_paths=>['spec/views']
plugin :view_options
plugin :render_locals, :render=>{:title=>'About Roda'}, :layout=>{:title=>'Home'}
@@ -77,117 +92,8 @@
view('multiple')
end
end
body.strip.must_equal "About Roda:A::Home:B"
- end
-
- deprecated "should set view and layout options and locals to use" do
- app(:view_options) do
- set_view_options :views=>'spec/views'
- set_view_locals :title=>'About Roda'
- set_layout_options :views=>'spec/views', :template=>'layout-alternative'
- set_layout_locals :title=>'Home'
- view('about')
- end
-
- body.strip.must_equal "<title>Alternative Layout: Home</title>\n<h1>About Roda</h1>"
- end
-
- deprecated "should merge multiple calls to set view and layout options and locals" do
- app(:view_options) do
- set_layout_options :views=>'spec/views', :template=>'multiple-layout', :engine=>'str'
- set_view_options :views=>'spec/views', :engine=>'str'
- set_layout_locals :title=>'About Roda'
- set_view_locals :title=>'Home'
-
- set_layout_options :engine=>'erb'
- set_view_options :engine=>'erb'
- set_layout_locals :a=>'A'
- set_view_locals :b=>'B'
-
- view('multiple')
- end
-
- body.strip.must_equal "About Roda:A::Home:B"
- end
-
- deprecated "should have set_view_locals have more precedence than plugin options, but less than view/render method options" do
- app(:bare) do
- plugin :render, :views=>"./spec/views", :locals=>{:title=>'Home', :b=>'B'}, :layout_opts=>{:template=>'multiple-layout', :locals=>{:title=>'About Roda', :a=>'A'}}
- plugin :view_options
-
- route do |r|
- r.is 'c' do
- view(:multiple)
- end
-
- set_view_locals :b=>'BB'
- set_layout_locals :a=>'AA'
-
- r.on 'b' do
- set_view_locals :title=>'About'
- set_layout_locals :title=>'Roda'
-
- r.is 'a' do
- view(:multiple)
- end
-
- view("multiple", :locals=>{:b => "BBB"}, :layout_opts=>{:locals=>{:a=>'AAA'}})
- end
-
- r.is 'a' do
- view(:multiple)
- end
-
- view("multiple", :locals=>{:b => "BBB"}, :layout_opts=>{:locals=>{:a=>'AAA'}})
- end
- end
-
- body('/c').strip.must_equal "About Roda:A::Home:B"
- body('/b/a').strip.must_equal "Roda:AA::About:BB"
- body('/b').strip.must_equal "Roda:AAA::About:BBB"
- body('/a').strip.must_equal "About Roda:AA::Home:BB"
- body.strip.must_equal "About Roda:AAA::Home:BBB"
- end
-
- deprecated "should have set_view_locals have more precedence than plugin options, but less than view/render method options" do
- app(:bare) do
- plugin :render, :views=>"./spec/views", :layout_opts=>{:template=>'multiple-layout'}
- plugin :render_locals, :render=>{:title=>'Home', :b=>'B'}, :layout=>{:title=>'About Roda', :a=>'A'}
- plugin :view_options
-
- route do |r|
- r.is 'c' do
- view(:multiple)
- end
-
- set_view_locals :b=>'BB'
- set_layout_locals :a=>'AA'
-
- r.on 'b' do
- set_view_locals :title=>'About'
- set_layout_locals :title=>'Roda'
-
- r.is 'a' do
- view(:multiple)
- end
-
- view("multiple", :locals=>{:b => "BBB"}, :layout_opts=>{:locals=>{:a=>'AAA'}})
- end
-
- r.is 'a' do
- view(:multiple)
- end
-
- view("multiple", :locals=>{:b => "BBB"}, :layout_opts=>{:locals=>{:a=>'AAA'}})
- end
- end
-
- body('/c').strip.must_equal "About Roda:A::Home:B"
- body('/b/a').strip.must_equal "Roda:AA::About:BB"
- body('/b').strip.must_equal "Roda:AAA::About:BBB"
- body('/a').strip.must_equal "About Roda:AA::Home:BB"
- body.strip.must_equal "About Roda:AAA::Home:BBB"
end
end
end