File tree 4 files changed +32
-6
lines changed
4 files changed +32
-6
lines changed Original file line number Diff line number Diff line change 1
1
rvm :
2
- - 1.9.3
3
2
- 2.0.0
4
3
- 2.1.0
5
4
- ruby-head
6
5
- jruby-19mode
7
6
- jruby-head
8
- - rbx-2.2.10
7
+ - rbx-2
9
8
10
9
matrix :
11
10
allow_failures :
12
11
- rvm : jruby-19mode
13
12
- rvm : jruby-head
14
13
- rvm : ruby-head
14
+ - rvm : rbx-2
Original file line number Diff line number Diff line change 1
1
#### Next
2
2
3
+ * Fix template caching for multiple formats. [ #43 ] ( https://github.com/ruby-grape/grape-rabl/pull/43 ) [ @kushkella ] ( https://github.com/kushkella )
3
4
* Your contribution here.
4
5
5
6
#### v0.4.1
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ def set_view_root
67
67
68
68
def tilt_template ( template )
69
69
if Grape ::Rabl . configuration . cache_template_loading
70
- Grape ::Rabl ::Formatter . tilt_cache . fetch ( template ) { ::Tilt . new ( view_path ( template ) , tilt_options ) }
70
+ Grape ::Rabl ::Formatter . tilt_cache . fetch ( tilt_cache_key ( template ) ) { ::Tilt . new ( view_path ( template ) , tilt_options ) }
71
71
else
72
72
::Tilt . new ( view_path ( template ) , tilt_options )
73
73
end
@@ -80,11 +80,15 @@ def tilt_options
80
80
def layout_template
81
81
layout_path = view_path ( env [ 'api.tilt.layout' ] || 'layouts/application' )
82
82
if Grape ::Rabl . configuration . cache_template_loading
83
- Grape ::Rabl ::Formatter . tilt_cache . fetch ( layout_path ) { ::Tilt . new ( layout_path , tilt_options ) if File . exist? ( layout_path ) }
83
+ Grape ::Rabl ::Formatter . tilt_cache . fetch ( tilt_cache_key ( layout_path ) ) { ::Tilt . new ( layout_path , tilt_options ) if File . exist? ( layout_path ) }
84
84
else
85
85
::Tilt . new ( layout_path , tilt_options ) if File . exist? ( layout_path )
86
86
end
87
87
end
88
+
89
+ def tilt_cache_key ( path )
90
+ Digest ::MD5 . hexdigest ( "#{ path } #{ tilt_options } " )
91
+ end
88
92
end
89
93
end
90
94
end
Original file line number Diff line number Diff line change 6
6
end
7
7
8
8
before do
9
- subject . format :json
9
+ subject . default_format :json
10
10
subject . formatter :json , Grape ::Formatter ::Rabl
11
+ subject . formatter :xml , Grape ::Formatter ::Rabl
11
12
subject . helpers MyHelper
12
13
end
13
14
@@ -166,7 +167,27 @@ def app
166
167
old_response . should == new_response
167
168
end
168
169
169
- it 'should serve new template if cache_template_loading' do
170
+ it 'should maintain different cached templates for different formats' do
171
+ Grape ::Rabl . configure do |config |
172
+ config . cache_template_loading = true
173
+ end
174
+ get '/home'
175
+ last_response . status . should be == 200
176
+ json_response = last_response . body
177
+ get '/home.xml'
178
+ last_response . status . should be == 200
179
+ xml_response = last_response . body
180
+ json_response . should_not be == xml_response
181
+ open ( @template , 'a' ) { |f | f << 'node(:test) { "test" }' }
182
+ get '/home.xml'
183
+ last_response . status . should be == 200
184
+ last_response . body . should be == xml_response
185
+ get '/home.json'
186
+ last_response . status . should be == 200
187
+ last_response . body . should be == json_response
188
+ end
189
+
190
+ it 'should serve new template unless cache_template_loading' do
170
191
get '/home'
171
192
last_response . status . should be == 200
172
193
old_response = last_response . body
You can’t perform that action at this time.
0 commit comments