app_test.rb 4.2 KB

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