don't cache the identity menu when masquerading
we would need a separate cache for each [@current_user, @real_current_user] combination because the authenticity token is included in the html here -- it's not really worth it, just skip the cache when masquerading. Change-Id: Ie1440a6e592ef96649467e06006520d176438a70 Reviewed-on: https://gerrit.instructure.com/6385 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
2b72c47b6e
commit
51f6535b57
|
@ -558,4 +558,12 @@ var I18n = I18n || {};
|
|||
].any?{ |e| e.respond_to?(:count) && e.count > 0 }
|
||||
end
|
||||
|
||||
def cache_if(cond, *args)
|
||||
if cond
|
||||
cache(*args) { yield }
|
||||
else
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
<% if (identity = yield :identity) %>
|
||||
<%= identity %>
|
||||
<% else %>
|
||||
<%- cache([@current_user || 'nobody', (@real_current_user && @real_current_user != @current_user ? 'm' : 'a'), 'identity-15m'], :expires_in => 15.minutes) do -%>
|
||||
<%- cache_if(!@real_current_user, [@current_user || 'nobody', 'identity-15m'], :expires_in => 15.minutes) do -%>
|
||||
<%= render(:partial => 'shared/identity') %>
|
||||
<%- end -%>
|
||||
<% end %>
|
||||
|
|
|
@ -107,4 +107,20 @@ describe ApplicationHelper do
|
|||
tomorrow_at_midnight.should > now
|
||||
end
|
||||
end
|
||||
|
||||
describe "cache_if" do
|
||||
it "should cache the fragment if the condition is true" do
|
||||
enable_cache do
|
||||
cache_if(true, "t1", :expires_in => 15.minutes, :no_locale => true) { output_buffer.concat "blargh" }
|
||||
@controller.read_fragment("t1").should == "blargh"
|
||||
end
|
||||
end
|
||||
|
||||
it "should not cache if the condition is false" do
|
||||
enable_cache do
|
||||
cache_if(false, "t1", :expires_in => 15.minutes, :no_locale => true) { output_buffer.concat "blargh" }
|
||||
@controller.read_fragment("t1").should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -386,10 +386,16 @@ Spec::Runner.configure do |config|
|
|||
|
||||
def enable_cache
|
||||
old_cache = RAILS_CACHE
|
||||
silence_warnings { Object.const_set(:RAILS_CACHE, ActiveSupport::Cache::MemoryStore.new) }
|
||||
new_cache = ActiveSupport::Cache::MemoryStore.new
|
||||
ActionController::Base.cache_store = new_cache
|
||||
silence_warnings { Object.const_set(:RAILS_CACHE, new_cache) }
|
||||
old_perform_caching = ActionController::Base.perform_caching
|
||||
ActionController::Base.perform_caching = true
|
||||
yield
|
||||
ensure
|
||||
silence_warnings { Object.const_set(:RAILS_CACHE, old_cache) }
|
||||
ActionController::Base.cache_store = old_cache
|
||||
ActionController::Base.perform_caching = old_perform_caching
|
||||
end
|
||||
|
||||
# enforce forgery protection, so we can verify usage of the authenticity token
|
||||
|
|
Loading…
Reference in New Issue