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
Léo-Paul Géneau
gitlab-ce
Commits
f4810647
Commit
f4810647
authored
May 12, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RedisCacheable specs for memoization correctness
parent
b1fcac85
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
7 deletions
+19
-7
spec/models/concerns/redis_cacheable_spec.rb
spec/models/concerns/redis_cacheable_spec.rb
+19
-7
No files found.
spec/models/concerns/redis_cacheable_spec.rb
View file @
f4810647
...
@@ -9,7 +9,7 @@ describe RedisCacheable do
...
@@ -9,7 +9,7 @@ describe RedisCacheable do
end
end
end
end
let
(
:payload
)
{
{
name:
'value'
}
}
let
(
:payload
)
{
{
name:
'value'
,
time:
Time
.
zone
.
now
}
}
let
(
:instance
)
{
model
.
new
(
1
,
payload
)
}
let
(
:instance
)
{
model
.
new
(
1
,
payload
)
}
let
(
:cache_key
)
{
instance
.
__send__
(
:cache_attribute_key
)
}
let
(
:cache_key
)
{
instance
.
__send__
(
:cache_attribute_key
)
}
...
@@ -50,9 +50,7 @@ describe RedisCacheable do
...
@@ -50,9 +50,7 @@ describe RedisCacheable do
end
end
context
'when there is no cached value'
do
context
'when there is no cached value'
do
it
'checks the cached value first then reads the attribute'
do
it
'reads the attribute'
do
expect
(
instance
).
to
receive
(
:read_attribute
).
and_return
(
payload
[
:name
])
expect
(
subject
).
to
eq
(
payload
[
:name
])
expect
(
subject
).
to
eq
(
payload
[
:name
])
end
end
end
end
...
@@ -64,6 +62,14 @@ describe RedisCacheable do
...
@@ -64,6 +62,14 @@ describe RedisCacheable do
expect
(
subject
).
to
eq
(
payload
[
:name
])
expect
(
subject
).
to
eq
(
payload
[
:name
])
end
end
end
end
it
'always returns the latest values'
do
expect
(
instance
.
name
).
to
eq
(
payload
[
:name
])
instance
.
cache_attributes
(
name:
'new_value'
)
expect
(
instance
.
name
).
to
eq
(
'new_value'
)
end
end
end
describe
'#cached_attr_time_reader'
,
:clean_gitlab_redis_shared_state
do
describe
'#cached_attr_time_reader'
,
:clean_gitlab_redis_shared_state
do
...
@@ -74,9 +80,7 @@ describe RedisCacheable do
...
@@ -74,9 +80,7 @@ describe RedisCacheable do
end
end
context
'when there is no cached value'
do
context
'when there is no cached value'
do
it
'checks the cached value first then reads the attribute'
do
it
'reads the attribute'
do
expect
(
instance
).
to
receive
(
:read_attribute
).
and_return
(
Time
.
zone
.
now
)
expect
(
subject
).
to
be_instance_of
(
ActiveSupport
::
TimeWithZone
)
expect
(
subject
).
to
be_instance_of
(
ActiveSupport
::
TimeWithZone
)
expect
(
subject
).
to
be_within
(
1
.
minute
).
of
(
Time
.
zone
.
now
)
expect
(
subject
).
to
be_within
(
1
.
minute
).
of
(
Time
.
zone
.
now
)
end
end
...
@@ -90,5 +94,13 @@ describe RedisCacheable do
...
@@ -90,5 +94,13 @@ describe RedisCacheable do
expect
(
subject
).
to
be_within
(
1
.
minute
).
of
(
Time
.
zone
.
now
)
expect
(
subject
).
to
be_within
(
1
.
minute
).
of
(
Time
.
zone
.
now
)
end
end
end
end
it
'always returns the latest values'
do
expect
(
instance
.
time
).
to
be_within
(
1
.
minute
).
of
(
Time
.
zone
.
now
)
instance
.
cache_attributes
(
time:
1
.
hour
.
ago
)
expect
(
instance
.
time
).
to
be_within
(
1
.
minute
).
of
(
1
.
hour
.
ago
)
end
end
end
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