@@ -111,5 +111,42 @@ def app
111
111
last_response . body . should == '{"user":{"name":"LTe","email":"email@example.com","project":{"name":"First"}}}'
112
112
end
113
113
end
114
+
115
+ describe 'template cache' do
116
+ before do
117
+ @template = "#{ File . dirname ( __FILE__ ) } /views/user_cached.rabl"
118
+ FileUtils . cp ( "#{ File . dirname ( __FILE__ ) } /views/user.rabl" , @template )
119
+ subject . get ( '/home' , rabl : 'user_cached' ) do
120
+ @user = OpenStruct . new ( name : 'LTe' , email : 'email@example.com' )
121
+ @project = OpenStruct . new ( name : 'First' )
122
+ end
123
+ end
124
+
125
+ after do
126
+ Grape ::Rabl . reset_configuration!
127
+ FileUtils . rm ( @template )
128
+ end
129
+
130
+ it 'should serve from cache if cache_template_loading' do
131
+ Grape ::Rabl . configure do |config |
132
+ config . cache_template_loading = true
133
+ end
134
+ get '/home'
135
+ old_response = last_response . body
136
+ open ( @template , 'a' ) { |f | f << 'node(:test) { "test" }' }
137
+ get '/home'
138
+ new_response = last_response . body
139
+ old_response . should == new_response
140
+ end
141
+
142
+ it 'should serve new template if cache_template_loading' do
143
+ get '/home'
144
+ old_response = last_response . body
145
+ open ( @template , 'a' ) { |f | f << 'node(:test) { "test" }' }
146
+ get '/home'
147
+ new_response = last_response . body
148
+ old_response . should_not == new_response
149
+ end
150
+ end
114
151
end
115
152
end
0 commit comments