app_test.rb 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. it "includes has the word 'light' by default" do
  52. get '/manifest.appcache'
  53. assert_includes last_response.body, '# light'
  54. refute_includes last_response.body, '# dark'
  55. end
  56. it "includes has the word 'dark' when the cookie is set" do
  57. set_cookie('dark=1')
  58. get '/manifest.appcache'
  59. assert_includes last_response.body, '# dark'
  60. refute_includes last_response.body, '# light'
  61. end
  62. end
  63. describe "/[doc]" do
  64. it "works when the doc exists" do
  65. get '/html/'
  66. assert last_response.ok?
  67. end
  68. it "returns 404 when the doc doesn't exist" do
  69. get '/foo/'
  70. assert last_response.not_found?
  71. end
  72. it "redirects with trailing slash" do
  73. get '/html'
  74. assert last_response.redirect?
  75. assert_equal 'http://example.org/html/', last_response['Location']
  76. get '/html', bar: 'baz'
  77. assert last_response.redirect?
  78. assert_equal 'http://example.org/html/?bar=baz', last_response['Location']
  79. end
  80. end
  81. describe "/[doc]-[type]" do
  82. it "works when the doc exists" do
  83. get '/html-foo-bar_42/'
  84. assert last_response.ok?
  85. end
  86. it "returns 404 when the type is blank" do
  87. get '/html-/'
  88. assert last_response.not_found?
  89. end
  90. it "returns 404 when the type is not alpha-numeric" do
  91. get '/html-foo:bar/'
  92. assert last_response.not_found?
  93. end
  94. it "returns 404 when the doc doesn't exist" do
  95. get '/foo-bar/'
  96. assert last_response.not_found?
  97. end
  98. it "redirects with trailing slash" do
  99. get '/html-foo'
  100. assert last_response.redirect?
  101. assert_equal 'http://example.org/html-foo/', last_response['Location']
  102. get '/html-foo', bar: 'baz'
  103. assert last_response.redirect?
  104. assert_equal 'http://example.org/html-foo/?bar=baz', last_response['Location']
  105. end
  106. end
  107. describe "/[doc+type]/[path]" do
  108. it "works when the doc exists" do
  109. get '/html/foo'
  110. assert last_response.ok?
  111. get '/html-bar/foo'
  112. assert last_response.ok?
  113. end
  114. it "returns 404 when the doc doesn't exist" do
  115. get '/foo/bar'
  116. assert last_response.not_found?
  117. end
  118. it "redirects without trailing slash" do
  119. get '/html/foo/'
  120. assert last_response.redirect?
  121. assert_equal 'http://example.org/html/foo', last_response['Location']
  122. get '/html/foo/', bar: 'baz'
  123. assert last_response.redirect?
  124. assert_equal 'http://example.org/html/foo?bar=baz', last_response['Location']
  125. end
  126. end
  127. describe "/feed" do
  128. it "returns an atom feed" do
  129. get '/feed'
  130. assert last_response.ok?
  131. assert_equal 'application/atom+xml', last_response['Content-Type']
  132. get '/feed.atom'
  133. assert last_response.ok?
  134. assert_equal 'application/atom+xml', last_response['Content-Type']
  135. end
  136. end
  137. describe "/s/[link]" do
  138. it "redirects" do
  139. %w(maxcdn shopify tw fb re).each do |link|
  140. get "/s/#{link}"
  141. assert last_response.redirect?
  142. end
  143. end
  144. end
  145. describe "/ping" do
  146. it "works" do
  147. get '/ping'
  148. assert last_response.ok?
  149. end
  150. end
  151. describe "404" do
  152. it "works" do
  153. get '/foo'
  154. assert last_response.not_found?
  155. end
  156. end
  157. end