Merge branch 'fix/invalidate-builds-badge-cache' into 'master'

Invalidate cache for builds badge

This fixes cache issue with badges (we should not cache badge images).

Closes #13982

See merge request !3086
This commit is contained in:
Rémy Coutable 2016-03-04 12:18:47 +00:00
commit b763c65eff
4 changed files with 25 additions and 0 deletions

View file

@ -13,6 +13,9 @@ v 8.6.0 (unreleased)
- Don't show Issues/MRs from archived projects in Groups view
- Increase the notes polling timeout over time (Roberto Dip)
v 8.5.4 (unreleased)
- Do not cache requests for badges (including builds badge)
v 8.5.3
- Flush repository caches before renaming projects

View file

@ -1,4 +1,6 @@
class Projects::BadgesController < Projects::ApplicationController
before_action :set_no_cache
def build
respond_to do |format|
format.html { render_404 }
@ -8,4 +10,15 @@ class Projects::BadgesController < Projects::ApplicationController
end
end
end
private
def set_no_cache
expires_now
# Add some deprecated headers for older agents
#
response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = 'Fri, 01 Jan 1990 00:00:00 GMT'
end
end

View file

@ -20,3 +20,8 @@ Feature: Project Badges Build
And project has another build that is running
When I display builds badge for a master branch
Then I should see a build running badge
Scenario: I want to see a fresh badge on each request
Given recent build is successful
When I display builds badge for a master branch
Then I should see a badge that has not been cached

View file

@ -20,6 +20,10 @@ class Spinach::Features::ProjectBadgesBuild < Spinach::FeatureSteps
expect_badge('running')
end
step 'I should see a badge that has not been cached' do
expect(page.response_headers).to include('Cache-Control' => 'no-cache')
end
def expect_badge(status)
svg = Nokogiri::XML.parse(page.body)
expect(page.response_headers).to include('Content-Type' => 'image/svg+xml')