route_spec.rb 7.7 KB

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