Skip to content

Commit c2b6b14

Browse files
committed
Fix and update specs
1 parent 72a5331 commit c2b6b14

File tree

3 files changed

+88
-30
lines changed

3 files changed

+88
-30
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Empty template
1+
Static template named 'foo.html'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Empty template
1+
Static template named 'bar.html'

example_app_generator/spec/verify_custom_renderers_spec.rb

Lines changed: 86 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,107 @@
11
require 'rails_helper'
22

33
RSpec.describe "template rendering", :type => :controller do
4-
context 'with the standard renderers' do
5-
controller do
6-
def index
7-
render :template => 'foo'
4+
context "without render_views" do
5+
context "with the standard renderers" do
6+
controller do
7+
def index
8+
render :template => 'foo', :layout => false
9+
end
810
end
9-
end
1011

11-
it "renders the 'foo' template" do
12-
get :index
12+
it "renders the 'foo' template" do
13+
get :index
1314

14-
expect(response).to render_template(:foo)
15+
expect(response).to render_template(:foo)
16+
expect(response.body).to eq("")
17+
end
1518
end
16-
end
1719

18-
context 'with a String path prepended to the view path' do
19-
controller do
20-
def index
21-
prepend_view_path('app/views/some_templates')
20+
context "with a String path prepended to the view path" do
21+
controller do
22+
def index
23+
prepend_view_path('app/views/some_templates')
24+
25+
render :template => 'bar', :layout => false
26+
end
27+
end
28+
29+
it "renders the 'bar' template" do
30+
get :index
2231

23-
render :template => 'bar'
32+
expect(response).to render_template(:bar)
33+
expect(response.body).to eq("")
2434
end
2535
end
2636

27-
it "renders the 'bar' template" do
28-
get :index
37+
context "with a custom renderer prepended to the view path" do
38+
controller do
39+
def index
40+
prepend_view_path(MyResolver.new)
2941

30-
expect(response).to render_template(:bar)
42+
render :template => 'baz', :layout => false
43+
end
44+
end
45+
46+
it "renders the 'baz' template" do
47+
get :index
48+
49+
expect(response).to render_template(:baz)
50+
expect(response.body).to eq("")
51+
end
3152
end
3253
end
3354

34-
context 'with a custom renderer prepended to the view path' do
35-
controller do
36-
def index
37-
prepend_view_path(MyResolver.new)
55+
context "with render_views enabled" do
56+
render_views
57+
58+
context "with the standard renderers" do
59+
controller do
60+
def index
61+
render :template => 'foo', :layout => false
62+
end
63+
end
64+
65+
it "renders the 'foo' template" do
66+
get :index
67+
68+
expect(response).to render_template(:foo)
69+
expect(response.body).to include("Static template named 'foo.html'")
70+
end
71+
end
72+
73+
context "with a String path prepended to the view path" do
74+
controller do
75+
def index
76+
prepend_view_path('app/views/some_templates')
77+
78+
render :template => 'bar', :layout => false
79+
end
80+
end
81+
82+
it "renders the 'bar' template" do
83+
get :index
3884

39-
render :template => 'baz'
85+
expect(response).to render_template(:bar)
86+
expect(response.body).to include("Static template named 'bar.html'")
4087
end
4188
end
4289

43-
it "renders the 'baz' template" do
44-
get :index
90+
context "with a custom renderer prepended to the view path" do
91+
controller do
92+
def index
93+
prepend_view_path(MyResolver.new)
94+
95+
render :template => 'baz', :layout => false
96+
end
97+
end
98+
99+
it "renders the 'baz' template" do
100+
get :index
45101

46-
expect(response).to render_template(:baz)
102+
expect(response).to render_template(:baz)
103+
expect(response.body).to eq("Dynamic template with path '/baz'")
104+
end
47105
end
48106
end
49107

@@ -56,11 +114,11 @@ def find_all_anywhere(*args)
56114
find_templates(*args)
57115
end
58116

59-
private
117+
private
60118

61119
def find_templates(name, prefix = nil, partial = false, details = {}, key = nil, locals = [])
62120
name.prepend("_") if partial
63-
path = [prefix, name].compact.join("/")
121+
path = [prefix, name].join("/")
64122
template = find_template(name, path)
65123

66124
[template]
@@ -70,7 +128,7 @@ def find_template(name, path)
70128
ActionView::Template.new(
71129
"",
72130
name,
73-
lambda { |_template| %("") },
131+
lambda { |_template| %("Dynamic template with path '#{_template.virtual_path}'") },
74132
:virtual_path => path,
75133
:format => :html
76134
)

0 commit comments

Comments
 (0)