1
1
require 'rails_helper'
2
2
3
3
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
8
10
end
9
- end
10
11
11
- it "renders the 'foo' template" do
12
- get :index
12
+ it "renders the 'foo' template" do
13
+ get :index
13
14
14
- expect ( response ) . to render_template ( :foo )
15
+ expect ( response ) . to render_template ( :foo )
16
+ expect ( response . body ) . to eq ( "" )
17
+ end
15
18
end
16
- end
17
19
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
22
31
23
- render :template => 'bar'
32
+ expect ( response ) . to render_template ( :bar )
33
+ expect ( response . body ) . to eq ( "" )
24
34
end
25
35
end
26
36
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 )
29
41
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
31
52
end
32
53
end
33
54
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
38
84
39
- render :template => 'baz'
85
+ expect ( response ) . to render_template ( :bar )
86
+ expect ( response . body ) . to include ( "Static template named 'bar.html'" )
40
87
end
41
88
end
42
89
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
45
101
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
47
105
end
48
106
end
49
107
@@ -56,11 +114,11 @@ def find_all_anywhere(*args)
56
114
find_templates ( *args )
57
115
end
58
116
59
- private
117
+ private
60
118
61
119
def find_templates ( name , prefix = nil , partial = false , details = { } , key = nil , locals = [ ] )
62
120
name . prepend ( "_" ) if partial
63
- path = [ prefix , name ] . compact . join ( "/" )
121
+ path = [ prefix , name ] . join ( "/" )
64
122
template = find_template ( name , path )
65
123
66
124
[ template ]
@@ -70,7 +128,7 @@ def find_template(name, path)
70
128
ActionView ::Template . new (
71
129
"" ,
72
130
name ,
73
- lambda { |_template | %("") } ,
131
+ lambda { |_template | %("Dynamic template with path ' #{ _template . virtual_path } ' ") } ,
74
132
:virtual_path => path ,
75
133
:format => :html
76
134
)
0 commit comments