Skip to content

Commit

Permalink
Merge pull request zendesk#682 from zendesk/grosser/badge
Browse files Browse the repository at this point in the history
rediret to badge instead of caching it for speed
  • Loading branch information
grosser committed Dec 8, 2015
2 parents 8b9f969 + d03af25 commit 16f8f73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
7 changes: 1 addition & 6 deletions app/controllers/stages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ def show
else
"#{badge_safe(@stage.name)}-None-red"
end

if stale?(etag: badge)
expires_in 1.minute, public: true
image = open("https://img.shields.io/badge/#{badge}.svg").read
render text: image, content_type: Mime::SVG
end
redirect_to "https://img.shields.io/badge/#{badge}.svg"
end
end
end
Expand Down
12 changes: 3 additions & 9 deletions test/controllers/stages_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
let(:deploy) { deploys(:succeeded_test) }

it "renders" do
stub_request(:get, "https://img.shields.io/badge/Staging-staging-green.svg")
get :show, valid_params
assert_response :success
response.content_type.must_equal Mime::SVG
assert_redirected_to "https://img.shields.io/badge/Staging-staging-green.svg"
end

it "fails with invalid token" do
Expand All @@ -31,18 +29,14 @@

it "renders none without deploy" do
deploy.destroy!
stub_request(:get, "https://img.shields.io/badge/Staging-None-red.svg")
get :show, valid_params
assert_response :success
response.content_type.must_equal Mime::SVG
assert_redirected_to "https://img.shields.io/badge/Staging-None-red.svg"
end

it "renders strange characters" do
subject.update_column(:name, 'Foo & Bar 1-4')
stub_request(:get, "https://img.shields.io/badge/Foo%20%26%20Bar%201--4-staging-green.svg")
get :show, valid_params
assert_response :success
response.content_type.must_equal Mime::SVG
assert_redirected_to "https://img.shields.io/badge/Foo%20%26%20Bar%201--4-staging-green.svg"
end
end

Expand Down

0 comments on commit 16f8f73

Please sign in to comment.