Ver código fonte

Add permanent URLs for JS and CSS asset bundles

Thibaut 10 anos atrás
pai
commit
4954dc688b
2 arquivos alterados com 22 adições e 2 exclusões
  1. 6 2
      lib/app.rb
  2. 16 0
      test/app_test.rb

+ 6 - 2
lib/app.rb

@@ -172,8 +172,12 @@ class App < Sinatra::Application
     200
   end
 
-  get '/docs.json' do
-    redirect asset_path('docs.json', protocol: 'http')
+  %w(docs.json application.js application.css).each do |asset|
+    class_eval <<-CODE, __FILE__, __LINE__ + 1
+      get '/#{asset}' do
+        redirect asset_path('#{asset}', protocol: 'http')
+      end
+    CODE
   end
 
   get '/s/maxcdn' do

+ 16 - 0
test/app_test.rb

@@ -181,6 +181,22 @@ class AppTest < MiniTest::Spec
     end
   end
 
+  describe "/application.js" do
+    it "returns to the asset path" do
+      get '/application.js'
+      assert last_response.redirect?
+      assert_equal 'http://example.org/assets/application.js', last_response['Location']
+    end
+  end
+
+  describe "/application.css" do
+    it "returns to the asset path" do
+      get '/application.css'
+      assert last_response.redirect?
+      assert_equal 'http://example.org/assets/application.css', last_response['Location']
+    end
+  end
+
   describe "/feed" do
     it "returns an atom feed" do
       get '/feed'