Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OHR Support
Manage
Activity
Members
Labels
Plan
Issues
97
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Projects
OHR Support
Commits
637ca24a
Commit
637ca24a
authored
13 years ago
by
Holger Just
Browse files
Options
Downloads
Patches
Plain Diff
Completely disable the Rails cache for tests
Settings extension to handle cache behaviour by Gregor Schmidt.
parent
a938d582
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/setting.rb
+24
-1
24 additions, 1 deletion
app/models/setting.rb
test/test_helper.rb
+1
-0
1 addition, 0 deletions
test/test_helper.rb
with
25 additions
and
1 deletion
app/models/setting.rb
+
24
−
1
View file @
637ca24a
...
...
@@ -97,7 +97,11 @@ class Setting < ActiveRecord::Base
# Returns the value of the setting named name
def
self
.
[]
(
name
)
Marshal
.
load
(
Rails
.
cache
.
fetch
(
self
.
cache_key
(
name
))
{
Marshal
.
dump
(
find_or_default
(
name
).
value
)})
if
use_caching?
Marshal
.
load
(
Rails
.
cache
.
fetch
(
self
.
cache_key
(
name
))
{
Marshal
.
dump
(
find_or_default
(
name
).
value
)})
else
find_or_default
(
name
).
value
end
end
def
self
.
[]=
(
name
,
v
)
...
...
@@ -156,6 +160,25 @@ class Setting < ActiveRecord::Base
"only, you may use Setting.first.try(:touch)"
end
# Temporarily deactivate settings caching in the block scope
def
self
.
uncached
cache_setting
=
self
.
use_caching
self
.
use_caching
=
false
yield
ensure
self
.
use_caching
=
cache_setting
end
# Check if Setting caching should be performed
def
self
.
use_caching?
!
Thread
.
current
[
'chiliproject/settings/do_not_use_caching'
]
end
# Dis-/En-able Setting caching. This is mainly intended to be used in tests
def
self
.
use_caching
=
(
new_value
)
Thread
.
current
[
'chiliproject/settings/do_not_use_caching'
]
=
!
new_value
end
private
# Returns the Setting instance for the setting named name
# (record found in database or new record with default value)
...
...
This diff is collapsed.
Click to expand it.
test/test_helper.rb
+
1
−
0
View file @
637ca24a
...
...
@@ -47,6 +47,7 @@ class ActiveSupport::TestCase
# Add more helper methods to be used by all tests here...
def
setup
super
Setting
.
use_caching
=
false
Rails
.
cache
.
clear
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment