route_spec.rb 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. require "#{File.dirname(__FILE__)}/spec_helper"
  2. include SpecHelper
  3. describe "routes" do
  4. describe 'basic auth' do
  5. it "ohne auth" do
  6. get '/info'
  7. last_response.status.must_equal 401
  8. end
  9. it "falsche auth" do
  10. authorize 'oh', 'ah'
  11. get '/info'
  12. last_response.status.must_equal 401
  13. end
  14. it "korrekte auth" do
  15. authorize 'test', 'test'
  16. get '/info'
  17. last_response.status.must_equal 200
  18. end
  19. end
  20. describe "Views ok" do
  21. it "gibt home-view 200 zurück" do
  22. get '/'
  23. last_response.status.must_equal 200
  24. end
  25. end
  26. end
  27. describe "verlauf schüler" do
  28. before do
  29. Lehrer.create(:id => 1, :name => "Müller")
  30. Lehrer.create(:id => 2, :name => "Maier")
  31. Lehrer.create(:id => 3, :name => "Walter")
  32. end
  33. describe "schüler besucht seite zur aktiven Wahl" do
  34. before do
  35. Schueler.create(:hashid => "a", :vorname => "A", :klasse => "A1")
  36. Schueler.create(:hashid => "b", :vorname => "B", :klasse => "B1")
  37. end
  38. it "schüler gibt code auf startseite ein und wird umgeleitet" do
  39. Time.stub :now, Time.parse("Sep 21, 2016, 17:00") do
  40. post "/hashid", params={:hashid => "a"}
  41. follow_redirect!
  42. last_response.body.must_include "Hallo A,"
  43. end
  44. end
  45. it "schüler stellt sich auf als schuko" do
  46. Time.stub :now, Time.parse("Sep 21, 2016, 17:00") do
  47. post "/wahl", params={:hashid => "a",:schuko => "on"}
  48. a = Schueler["a"]
  49. a.schuko.must_equal true
  50. a.sprecher.must_be_nil
  51. end
  52. end
  53. it "schüler stellt sich auf als sprecher" do
  54. Time.stub :now, Time.parse("Sep 21, 2016, 17:00") do
  55. post "/wahl", params={:hashid => "a",:sprecher => "on"}
  56. a = Schueler["a"]
  57. a.sprecher.must_equal true
  58. a.schuko.must_be_nil
  59. end
  60. end
  61. it "schüler stellt sich auf als sprecher und ändert Daten" do
  62. Time.stub :now, Time.parse("Sep 21, 2016, 17:00") do
  63. post "/wahl", params={:hashid => "a",:sprecher => "on"}
  64. post "/wahl", params={:hashid => "a",:sprecher => "", :schuko => "on", :email => "xyz"}
  65. a = Schueler["a"]
  66. a.sprecher.must_be_nil
  67. a.schuko.must_equal true
  68. a.email.must_equal "xyz"
  69. end
  70. end
  71. it "schüler stellt sich auf als sprecher und schuko" do
  72. Time.stub :now, Time.parse("Sep 21, 2016, 17:00") do
  73. post "/wahl", params={:hashid => "a", :sprecher => "on", :schuko => "on"}
  74. a = Schueler["a"]
  75. a.schuko.must_equal true
  76. a.sprecher.must_equal true
  77. end
  78. end
  79. it "schüler stellt sich auf als schuko und gibt Infos" do
  80. Time.stub :now, Time.parse("Sep 21, 2016, 17:00") do
  81. post "/wahl", params={:hashid => "a",:schuko => "on", :nachname => "AA7", :info => "Bin hier"}
  82. get "/a"
  83. last_response.body.must_include "AA7"
  84. last_response.body.must_include "Bin hier"
  85. end
  86. end
  87. after do
  88. Schueler.dataset.destroy
  89. end
  90. end
  91. describe "schüler besucht seite zur passiven Wahl" do
  92. before do
  93. Schueler.create(:hashid => "a", :vorname => "A", :klasse => "A1", :schuko => true, :sprecher => true)
  94. Schueler.create(:hashid => "b", :vorname => "B", :klasse => "B1", :schuko => true, :sprecher => true)
  95. Schueler.create(:hashid => "c", :schuko => true)
  96. %w(d e f g h i j k l).each do |s|
  97. Schueler.create(:hashid => s, :sprecher => true)
  98. end
  99. end
  100. it "schüler gibt code auf startseite ein und wird umgeleitet" do
  101. Time.stub :now, Time.parse("Oct 1, 2016, 17:00") do
  102. post "/hashid", params={:hashid => "a"}
  103. follow_redirect!
  104. last_response.body.must_include "Hallo A,"
  105. end
  106. end
  107. it "schüler will sich als schuko aufstellen nach wahlbeginn" do
  108. Time.stub :now, Time.parse("Oct 1, 2016, 17:00") do
  109. post "/wahl", params={:hashid => "d",:schuko => "on"}
  110. a = Schueler["d"]
  111. a.sprecher.must_equal true
  112. a.schuko.must_be_nil
  113. follow_redirect!
  114. last_response.body.must_include "Wahl hat bereits begonnen"
  115. end
  116. end
  117. it "schüler wählt jeweils zwei" do
  118. Time.stub :now, Time.parse("Oct 1, 2016, 17:00") do
  119. post "/a", params={:sprecher => ["a", "b"], :schuko => ["a", "b"], :lehrer => [1,2]}
  120. a = Schueler["a"]
  121. a.gewaehlt.must_equal true
  122. Sprecher.count.must_equal 2
  123. Schuko.count.must_equal 2
  124. Verbindungslehrer.count.must_equal 2
  125. end
  126. end
  127. it "schüler wählt jeweils zwei und versucht es nochmal" do
  128. Time.stub :now, Time.parse("Oct 1, 2016, 17:00") do
  129. post "/a", params={:sprecher => ["a", "b"], :schuko => ["a", "b"], :lehrer => [1,2]}
  130. post "/a", params={:sprecher => ["d"]}
  131. a = Schueler["a"]
  132. a.gewaehlt.must_equal true
  133. Sprecher.count.must_equal 2
  134. Schuko.count.must_equal 2
  135. Verbindungslehrer.count.must_equal 2
  136. end
  137. end
  138. it "schüler wählt drei sprecher statt zwei" do
  139. Time.stub :now, Time.parse("Oct 1, 2016, 17:00") do
  140. post "/a", params={:sprecher => ["a", "b", "d"]}
  141. a = Schueler["a"]
  142. a.gewaehlt.must_be_nil
  143. Sprecher.count.must_equal 0
  144. end
  145. end
  146. it "schüler wählt neun schuko statt acht" do
  147. Time.stub :now, Time.parse("Oct 1, 2016, 17:00") do
  148. post "/a", params={:schuko => %w(d e f g h i j k l)}
  149. a = Schueler["a"]
  150. a.gewaehlt.must_be_nil
  151. Schuko.count.must_equal 0
  152. end
  153. end
  154. it "schüler wählt drei lehrer statt zwei" do
  155. Time.stub :now, Time.parse("Oct 1, 2016, 17:00") do
  156. post "/a", params={:lehrer => [1,2,3]}
  157. a = Schueler["a"]
  158. a.gewaehlt.must_be_nil
  159. Verbindungslehrer.count.must_equal 0
  160. end
  161. end
  162. it "schüler wählt nichtaufgestellten schuko" do
  163. Time.stub :now, Time.parse("Oct 1, 2016, 17:00") do
  164. post "/a", params={:schuko => %w(d)}
  165. a = Schueler["a"]
  166. a.gewaehlt.must_be_nil
  167. Schuko.count.must_equal 0
  168. end
  169. end
  170. after do
  171. Schueler.dataset.destroy
  172. Sprecher.dataset.destroy
  173. Schuko.dataset.destroy
  174. Verbindungslehrer.dataset.destroy
  175. end
  176. end
  177. describe "schüler besucht seite nach der wahl" do
  178. before do
  179. Schueler.create(:hashid => "a", :vorname => "A", :klasse => "A1", :schuko => true, :sprecher => true)
  180. Schueler.create(:hashid => "b", :vorname => "B", :klasse => "B1", :schuko => true, :sprecher => true)
  181. Schueler.create(:hashid => "c", :schuko => true)
  182. Schueler.create(:hashid => "d")
  183. end
  184. it "schüler gibt code auf startseite ein und wird umgeleitet" do
  185. Time.stub :now, Time.parse("Oct 3, 2016, 19:00") do
  186. post "/hashid", params={:hashid => "a"}
  187. follow_redirect!
  188. last_response.body.must_include "Hallo A,"
  189. end
  190. end
  191. it "schüler will sich als schuko aufstellen nach wahlbeginn" do
  192. Time.stub :now, Time.parse("Oct 3, 2016, 19:00") do
  193. post "/wahl", params={:hashid => "d",:schuko => "on"}
  194. a = Schueler["d"]
  195. a.sprecher.must_be_nil
  196. a.schuko.must_be_nil
  197. end
  198. end
  199. it "schüler wählt jeweils zwei und kann es nicht mehr" do
  200. Time.stub :now, Time.parse("Oct 3, 2016, 19:00") do
  201. post "/a", params={:sprecher => ["a", "b"], :schuko => ["a", "b"], :lehrer => [1,2]}
  202. a = Schueler["a"]
  203. a.gewaehlt.must_be_nil
  204. Sprecher.count.must_equal 0
  205. Schuko.count.must_equal 0
  206. Verbindungslehrer.count.must_equal 0
  207. end
  208. end
  209. after do
  210. Schueler.dataset.destroy
  211. Sprecher.dataset.destroy
  212. Schuko.dataset.destroy
  213. Verbindungslehrer.dataset.destroy
  214. end
  215. end
  216. after do
  217. Lehrer.dataset.destroy
  218. end
  219. end