phorsfall-tidy_rack 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/tidy_rack.rb +1 -1
- data/test/tidy_rack_test.rb +9 -2
- metadata +1 -1
    
        data/VERSION.yml
    CHANGED
    
    
    
        data/lib/tidy_rack.rb
    CHANGED
    
    | @@ -7,7 +7,7 @@ class TidyRack | |
| 7 7 |  | 
| 8 8 | 
             
              def call(env)
         | 
| 9 9 | 
             
                status, headers, response = @app.call(env)
         | 
| 10 | 
            -
                if headers['Content-Type'] | 
| 10 | 
            +
                if /text\/html/o.match(headers['Content-Type'])
         | 
| 11 11 | 
             
                  response = tidy(response)
         | 
| 12 12 | 
             
                  headers['Content-Length'] = response.size.to_s
         | 
| 13 13 | 
             
                end
         | 
    
        data/test/tidy_rack_test.rb
    CHANGED
    
    | @@ -12,17 +12,24 @@ class TidyRackTest < Test::Unit::TestCase | |
| 12 12 | 
             
                eof
         | 
| 13 13 | 
             
              end
         | 
| 14 14 |  | 
| 15 | 
            -
              should " | 
| 15 | 
            +
              should "tidy html responses" do
         | 
| 16 16 | 
             
                app = lambda { |env| [200, { 'Content-Type' => 'text/html' }, html] }
         | 
| 17 17 | 
             
                status, headers, response = TidyRack.new(app).call({})
         | 
| 18 18 | 
             
                doc = Hpricot(response)
         | 
| 19 19 | 
             
                assert doc.at('meta[@content*="HTML Tidy"]')
         | 
| 20 20 | 
             
              end
         | 
| 21 21 |  | 
| 22 | 
            -
              should " | 
| 22 | 
            +
              should "not tidy plain text responses" do
         | 
| 23 23 | 
             
                app = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, html] }
         | 
| 24 24 | 
             
                status, headers, response = TidyRack.new(app).call({})
         | 
| 25 25 | 
             
                doc = Hpricot(response)
         | 
| 26 26 | 
             
                assert_nil doc.at('meta[@content*="HTML Tidy"]')
         | 
| 27 27 | 
             
              end
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
              should "not die when content-type is nil" do
         | 
| 30 | 
            +
                app = lambda { |env| [200, {}, html] }
         | 
| 31 | 
            +
                status, headers, response = TidyRack.new(app).call({})
         | 
| 32 | 
            +
                doc = Hpricot(response)
         | 
| 33 | 
            +
                assert_nil doc.at('meta[@content*="HTML Tidy"]')
         | 
| 34 | 
            +
              end
         | 
| 28 35 | 
             
            end
         |