| @@ -0,0 +1,175 @@ |
| | 1 | require 'test_helper' |
| | 2 | require 'rack/test' |
| | 3 | require 'app' |
| | 4 | |
| | 5 | class AppTest < MiniTest::Spec |
| | 6 | include Rack::Test::Methods |
| | 7 | |
| | 8 | def app |
| | 9 | App |
| | 10 | end |
| | 11 | |
| | 12 | describe "/" do |
| | 13 | it "works" do |
| | 14 | get '/' |
| | 15 | assert last_response.ok? |
| | 16 | end |
| | 17 | |
| | 18 | it "redirects without the query string" do |
| | 19 | get '/', foo: 'bar' |
| | 20 | assert last_response.redirect? |
| | 21 | assert_equal 'http://example.org/', last_response['Location'] |
| | 22 | end |
| | 23 | end |
| | 24 | |
| | 25 | describe "/[static-page]" do |
| | 26 | it "redirects to /#/[static-page]" do |
| | 27 | %w(offline about news help).each do |page| |
| | 28 | get "/#{page}" |
| | 29 | assert last_response.redirect? |
| | 30 | assert_equal "http://example.org/#/#{page}", last_response['Location'] |
| | 31 | end |
| | 32 | end |
| | 33 | end |
| | 34 | |
| | 35 | describe "/search" do |
| | 36 | it "redirects to /#q=" do |
| | 37 | get '/search' |
| | 38 | assert last_response.redirect? |
| | 39 | assert_equal 'http://example.org/#q=', last_response['Location'] |
| | 40 | |
| | 41 | get '/search', q: 'foo' |
| | 42 | assert last_response.redirect? |
| | 43 | assert_equal 'http://example.org/#q=foo', last_response['Location'] |
| | 44 | end |
| | 45 | end |
| | 46 | |
| | 47 | describe "/manifest.appcache" do |
| | 48 | it "works" do |
| | 49 | get '/manifest.appcache' |
| | 50 | assert last_response.ok? |
| | 51 | end |
| | 52 | |
| | 53 | it "works with cookie" do |
| | 54 | set_cookie('docs=css/html') |
| | 55 | get '/manifest.appcache' |
| | 56 | assert last_response.ok? |
| | 57 | assert_includes last_response.body, '/css/index.json' |
| | 58 | assert_includes last_response.body, '/html/index.json' |
| | 59 | end |
| | 60 | end |
| | 61 | |
| | 62 | describe "/[doc]" do |
| | 63 | it "works when the doc exists" do |
| | 64 | get '/html/' |
| | 65 | assert last_response.ok? |
| | 66 | end |
| | 67 | |
| | 68 | it "returns 404 when the doc doesn't exist" do |
| | 69 | get '/foo/' |
| | 70 | assert last_response.not_found? |
| | 71 | end |
| | 72 | |
| | 73 | it "redirects with trailing slash" do |
| | 74 | get '/html' |
| | 75 | assert last_response.redirect? |
| | 76 | assert_equal 'http://example.org/html/', last_response['Location'] |
| | 77 | |
| | 78 | get '/html', bar: 'baz' |
| | 79 | assert last_response.redirect? |
| | 80 | assert_equal 'http://example.org/html/?bar=baz', last_response['Location'] |
| | 81 | end |
| | 82 | end |
| | 83 | |
| | 84 | describe "/[doc]-[type]" do |
| | 85 | it "works when the doc exists" do |
| | 86 | get '/html-foo-bar_42/' |
| | 87 | assert last_response.ok? |
| | 88 | end |
| | 89 | |
| | 90 | it "returns 404 when the type is blank" do |
| | 91 | get '/html-/' |
| | 92 | assert last_response.not_found? |
| | 93 | end |
| | 94 | |
| | 95 | it "returns 404 when the type is not alpha-numeric" do |
| | 96 | get '/html-foo:bar/' |
| | 97 | assert last_response.not_found? |
| | 98 | end |
| | 99 | |
| | 100 | it "returns 404 when the doc doesn't exist" do |
| | 101 | get '/foo-bar/' |
| | 102 | assert last_response.not_found? |
| | 103 | end |
| | 104 | |
| | 105 | it "redirects with trailing slash" do |
| | 106 | get '/html-foo' |
| | 107 | assert last_response.redirect? |
| | 108 | assert_equal 'http://example.org/html-foo/', last_response['Location'] |
| | 109 | |
| | 110 | get '/html-foo', bar: 'baz' |
| | 111 | assert last_response.redirect? |
| | 112 | assert_equal 'http://example.org/html-foo/?bar=baz', last_response['Location'] |
| | 113 | end |
| | 114 | end |
| | 115 | |
| | 116 | describe "/[doc+type]/[path]" do |
| | 117 | it "works when the doc exists" do |
| | 118 | get '/html/foo' |
| | 119 | assert last_response.ok? |
| | 120 | |
| | 121 | get '/html-bar/foo' |
| | 122 | assert last_response.ok? |
| | 123 | end |
| | 124 | |
| | 125 | it "returns 404 when the doc doesn't exist" do |
| | 126 | get '/foo/bar' |
| | 127 | assert last_response.not_found? |
| | 128 | end |
| | 129 | |
| | 130 | it "redirects without trailing slash" do |
| | 131 | get '/html/foo/' |
| | 132 | assert last_response.redirect? |
| | 133 | assert_equal 'http://example.org/html/foo', last_response['Location'] |
| | 134 | |
| | 135 | get '/html/foo/', bar: 'baz' |
| | 136 | assert last_response.redirect? |
| | 137 | assert_equal 'http://example.org/html/foo?bar=baz', last_response['Location'] |
| | 138 | end |
| | 139 | end |
| | 140 | |
| | 141 | describe "/feed" do |
| | 142 | it "returns an atom feed" do |
| | 143 | get '/feed' |
| | 144 | assert last_response.ok? |
| | 145 | assert_equal 'application/atom+xml', last_response['Content-Type'] |
| | 146 | |
| | 147 | get '/feed.atom' |
| | 148 | assert last_response.ok? |
| | 149 | assert_equal 'application/atom+xml', last_response['Content-Type'] |
| | 150 | end |
| | 151 | end |
| | 152 | |
| | 153 | describe "/s/[link]" do |
| | 154 | it "redirects" do |
| | 155 | %w(maxcdn shopify tw fb re).each do |link| |
| | 156 | get "/s/#{link}" |
| | 157 | assert last_response.redirect? |
| | 158 | end |
| | 159 | end |
| | 160 | end |
| | 161 | |
| | 162 | describe "/ping" do |
| | 163 | it "works" do |
| | 164 | get '/ping' |
| | 165 | assert last_response.ok? |
| | 166 | end |
| | 167 | end |
| | 168 | |
| | 169 | describe "404" do |
| | 170 | it "works" do |
| | 171 | get '/foo' |
| | 172 | assert last_response.not_found? |
| | 173 | end |
| | 174 | end |
| | 175 | end |