Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
3fd8e612
Commit
3fd8e612
authored
Mar 20, 2019
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to not exclude _html fields from attributes
parent
cc5095ed
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
8 deletions
+27
-8
app/models/concerns/cache_markdown_field.rb
app/models/concerns/cache_markdown_field.rb
+17
-4
spec/models/concerns/cache_markdown_field_spec.rb
spec/models/concerns/cache_markdown_field_spec.rb
+10
-4
No files found.
app/models/concerns/cache_markdown_field.rb
View file @
3fd8e612
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
# cache_markdown_field :foo
# cache_markdown_field :foo
# cache_markdown_field :bar
# cache_markdown_field :bar
# cache_markdown_field :baz, pipeline: :single_line
# cache_markdown_field :baz, pipeline: :single_line
# cache_markdown_field :baz, hidden: false
#
#
# Corresponding foo_html, bar_html and baz_html fields should exist.
# Corresponding foo_html, bar_html and baz_html fields should exist.
module
CacheMarkdownField
module
CacheMarkdownField
...
@@ -37,7 +38,15 @@ module CacheMarkdownField
...
@@ -37,7 +38,15 @@ module CacheMarkdownField
end
end
def
html_fields
def
html_fields
markdown_fields
.
map
{
|
field
|
html_field
(
field
)
}
markdown_fields
.
map
{
|
field
|
html_field
(
field
)
}
end
def
hidden_html_fields
markdown_fields
.
each_with_object
([])
do
|
field
,
fields
|
if
@data
[
field
].
fetch
(
:hidden
,
true
)
fields
<<
html_field
(
field
)
end
end
end
end
end
end
...
@@ -149,13 +158,17 @@ module CacheMarkdownField
...
@@ -149,13 +158,17 @@ module CacheMarkdownField
alias_method
:attributes_before_markdown_cache
,
:attributes
alias_method
:attributes_before_markdown_cache
,
:attributes
def
attributes
def
attributes
attrs
=
attributes_before_markdown_cache
attrs
=
attributes_before_markdown_cache
html_fields
=
cached_markdown_fields
.
html_fields
hidden_html_fields
=
cached_markdown_fields
.
hidden_html_fields
attrs
.
delete
(
'cached_markdown_version'
)
hidden_html_fields
.
each
do
|
field
|
cached_markdown_fields
.
html_fields
.
each
do
|
field
|
attrs
.
delete
(
field
)
attrs
.
delete
(
field
)
end
end
if
(
html_fields
-
hidden_html_fields
).
empty?
attrs
.
delete
(
'cached_markdown_version'
)
end
attrs
attrs
end
end
...
...
spec/models/concerns/cache_markdown_field_spec.rb
View file @
3fd8e612
...
@@ -23,6 +23,7 @@ describe CacheMarkdownField do
...
@@ -23,6 +23,7 @@ describe CacheMarkdownField do
include
CacheMarkdownField
include
CacheMarkdownField
cache_markdown_field
:foo
cache_markdown_field
:foo
cache_markdown_field
:baz
,
pipeline: :single_line
cache_markdown_field
:baz
,
pipeline: :single_line
cache_markdown_field
:zoo
,
hidden:
false
def
self
.
add_attr
(
name
)
def
self
.
add_attr
(
name
)
self
.
attribute_names
+=
[
name
]
self
.
attribute_names
+=
[
name
]
...
@@ -35,7 +36,7 @@ describe CacheMarkdownField do
...
@@ -35,7 +36,7 @@ describe CacheMarkdownField do
add_attr
:cached_markdown_version
add_attr
:cached_markdown_version
[
:foo
,
:foo_html
,
:bar
,
:baz
,
:baz_html
].
each
do
|
name
|
[
:foo
,
:foo_html
,
:bar
,
:baz
,
:baz_html
,
:zoo
,
:zoo_html
].
each
do
|
name
|
add_attr
(
name
)
add_attr
(
name
)
end
end
...
@@ -84,8 +85,8 @@ describe CacheMarkdownField do
...
@@ -84,8 +85,8 @@ describe CacheMarkdownField do
end
end
describe
'.attributes'
do
describe
'.attributes'
do
it
'excludes cache attributes'
do
it
'excludes cache attributes
that is hidden by default
'
do
expect
(
thing
.
attributes
.
keys
.
sort
).
to
eq
(
%w[bar baz
foo
]
)
expect
(
thing
.
attributes
.
keys
.
sort
).
to
eq
(
%w[bar baz
cached_markdown_version foo zoo zoo_html
]
)
end
end
end
end
...
@@ -297,7 +298,12 @@ describe CacheMarkdownField do
...
@@ -297,7 +298,12 @@ describe CacheMarkdownField do
it
'saves the changes using #update_columns'
do
it
'saves the changes using #update_columns'
do
expect
(
thing
).
to
receive
(
:persisted?
).
and_return
(
true
)
expect
(
thing
).
to
receive
(
:persisted?
).
and_return
(
true
)
expect
(
thing
).
to
receive
(
:update_columns
)
expect
(
thing
).
to
receive
(
:update_columns
)
.
with
(
"foo_html"
=>
updated_html
,
"baz_html"
=>
""
,
"cached_markdown_version"
=>
cache_version
)
.
with
(
"foo_html"
=>
updated_html
,
"baz_html"
=>
""
,
"zoo_html"
=>
""
,
"cached_markdown_version"
=>
cache_version
)
thing
.
refresh_markdown_cache!
thing
.
refresh_markdown_cache!
end
end
...
...
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