BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
cc752f24
Commit
cc752f24
authored
Jul 13, 2016
by
Paco Guzman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ObjectRenderer doesn't crash when no objects to cache with Rails.cache.read_multi
parent
5fea640e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
+21
-4
renderer.rb
lib/banzai/renderer.rb
+10
-4
object_renderer_spec.rb
spec/lib/banzai/object_renderer_spec.rb
+11
-0
No files found.
lib/banzai/renderer.rb
View file @
cc752f24
...
...
@@ -61,10 +61,16 @@ module Banzai
end
cacheable_items
,
non_cacheable_items
=
items_collection
.
partition
{
|
item
|
item
.
key?
(
:cache_key
)
}
items_in_cache
=
Rails
.
cache
.
read_multi
(
*
cacheable_items
.
map
{
|
item
|
item
[
:cache_key
]
})
items_not_in_cache
=
cacheable_items
.
reject
do
|
item
|
item
[
:rendered
]
=
items_in_cache
[
item
[
:cache_key
]]
items_in_cache
.
key?
(
item
[
:cache_key
])
items_in_cache
=
[]
items_not_in_cache
=
[]
unless
cacheable_items
.
empty?
items_in_cache
=
Rails
.
cache
.
read_multi
(
*
cacheable_items
.
map
{
|
item
|
item
[
:cache_key
]
})
items_not_in_cache
=
cacheable_items
.
reject
do
|
item
|
item
[
:rendered
]
=
items_in_cache
[
item
[
:cache_key
]]
items_in_cache
.
key?
(
item
[
:cache_key
])
end
end
(
items_not_in_cache
+
non_cacheable_items
).
each
do
|
item
|
...
...
spec/lib/banzai/object_renderer_spec.rb
View file @
cc752f24
...
...
@@ -109,6 +109,17 @@ describe Banzai::ObjectRenderer do
expect
(
docs
[
1
]).
to
be_an_instance_of
(
Nokogiri
::
HTML
::
DocumentFragment
)
expect
(
docs
[
1
].
to_html
).
to
eq
(
'<p>bye</p>'
)
end
it
'returns when no objects to render'
do
objects
=
[]
renderer
=
described_class
.
new
(
project
,
user
,
pipeline: :note
)
expect
(
Banzai
).
to
receive
(
:cache_collection_render
).
with
([]).
and_call_original
expect
(
renderer
.
render_attributes
(
objects
,
:note
)).
to
eq
([])
end
end
describe
'#base_context'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment