Commit bf921d08 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Invalidate cache for builds badge

Closes #13982
parent f8c4dc97
class Projects::BadgesController < Projects::ApplicationController class Projects::BadgesController < Projects::ApplicationController
before_action :set_no_cache
def build def build
respond_to do |format| respond_to do |format|
format.html { render_404 } format.html { render_404 }
...@@ -8,4 +10,15 @@ class Projects::BadgesController < Projects::ApplicationController ...@@ -8,4 +10,15 @@ class Projects::BadgesController < Projects::ApplicationController
end end
end 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 end
...@@ -20,3 +20,8 @@ Feature: Project Badges Build ...@@ -20,3 +20,8 @@ Feature: Project Badges Build
And project has another build that is running And project has another build that is running
When I display builds badge for a master branch When I display builds badge for a master branch
Then I should see a build running badge 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
...@@ -20,6 +20,10 @@ class Spinach::Features::ProjectBadgesBuild < Spinach::FeatureSteps ...@@ -20,6 +20,10 @@ class Spinach::Features::ProjectBadgesBuild < Spinach::FeatureSteps
expect_badge('running') expect_badge('running')
end 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) def expect_badge(status)
svg = Nokogiri::XML.parse(page.body) svg = Nokogiri::XML.parse(page.body)
expect(page.response_headers).to include('Content-Type' => 'image/svg+xml') expect(page.response_headers).to include('Content-Type' => 'image/svg+xml')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment