/spec/acceptance/vote_for_proposals_spec.rb

https://github.com/tastytune/AgoraOnRails · Ruby · 196 lines · 176 code · 18 blank · 2 comment · 5 complexity · 539f4de1d2fb49777a082299d2c7bee0 MD5 · raw file

  1. # coding: utf-8
  2. require File.dirname(__FILE__) + '/acceptance_helper'
  3. feature "Vote for proposals", %q{
  4. In order to change the mother fucking world
  5. As a citizen
  6. I want to vote for/against proposals
  7. } do
  8. background do
  9. @user = create_user(:dni => "12345678A")
  10. @user2 = create_user(:dni => "12345678B")
  11. @user3 = create_user(:dni => "12345678C")
  12. end
  13. scenario "Vote for open proposals" do
  14. login_as @user
  15. [["no", I18n.t(:going_to_vote_against)],
  16. ["si", I18n.t(:going_to_vote_in_favor)],
  17. ["abstencion", I18n.t(:going_to_abstain)]].each do |vote, confirmation|
  18. proposal = create_proposal(:title => "Ley Sinde")
  19. visit proposal_path(proposal)
  20. click_button vote
  21. page.should have_content confirmation
  22. page.should_not have_content(I18n.t(:because))
  23. page.should_not have_content(I18n.t(:more_info))
  24. click_button I18n.t(:i_am_sure)
  25. page.should have_content(I18n.t(:vote_counted))
  26. page.should have_css(".share.fb-share iframe")
  27. page.should have_css(".share.twitter-share iframe")
  28. end
  29. end
  30. scenario "Add an optional explanation to your vote" do
  31. login_as @user
  32. proposal = create_proposal(:title => "Ley Sinde")
  33. explanation = "we don't want the ignorance in 'A Brave New World'"
  34. visit proposal_path(proposal)
  35. fill_in I18n.t(:explain), :with => explanation
  36. click_button I18n.t(:yes_option)
  37. page.should have_content(I18n.t(:because, :explanation => explanation))
  38. page.should_not have_content(I18n.t(:more_info))
  39. click_button I18n.t(:i_am_sure)
  40. @user.votes.last.explanation.should == explanation
  41. end
  42. scenario "Add an optional link to your vote" do
  43. login_as @user
  44. proposal = create_proposal(:title => "Ley Sinde")
  45. link = "http://en.wikipedia.org/wiki/Brave_New_World"
  46. visit proposal_path(proposal)
  47. fill_in "link", :with => link
  48. click_button I18n.t(:yes_option)
  49. page.should have_content("Más información #{link}")
  50. page.should_not have_content I18n.t(:because)
  51. click_button I18n.t(:i_am_sure)
  52. @user.votes.last.link.should == link
  53. end
  54. scenario "Can't vote if i'm not logged in" do
  55. proposal = create_proposal(:title => "Derogación del canon")
  56. visit proposal_path(proposal)
  57. click_button I18n.t(:yes_option)
  58. page.should have_content I18n.t(:dnie_auth_required)
  59. page.should_not have_css("button", :text => I18n.t(:i_am_sure))
  60. login_as @user
  61. page.should have_content("Vas a votar a favor de la iniciativa “Derogación del canon”")
  62. end
  63. scenario "Can't vote for closed proposals" do
  64. proposal = create_proposal(:closed_at => Date.yesterday, :official_resolution => "Derogada")
  65. login_as @user
  66. visit proposal_path(proposal)
  67. page.should have_content("La Propuesta fue Derogada en el Congreso")
  68. page.should_not have_css("button", :text => "Sí")
  69. page.should_not have_css("button", :text => "No")
  70. page.should_not have_css("button", :text => "Abstención")
  71. # Hacker-proof
  72. page.driver.post proposal_votes_path(proposal), :vote => {}
  73. Vote.count.should == 1
  74. end
  75. scenario "Can't vote twice for the same proposal" do
  76. proposal = create_proposal(:title => "Derogación del canon")
  77. login_as @user
  78. visit proposal_path(proposal)
  79. click_button I18n.t(:yes_option)
  80. click_button I18n.t(:i_am_sure)
  81. visit proposal_path(proposal)
  82. page.should have_content("Ya has votado esta propuesta")
  83. page.should_not have_css("button", :text => "Sí")
  84. page.should_not have_css("button", :text => "No")
  85. page.should_not have_css("button", :text => "Abstención")
  86. page.should have_css(".share.fb-share iframe")
  87. page.should have_css(".share.twitter-share iframe")
  88. # Hacker-proof
  89. page.driver.post proposal_votes_path(proposal), :vote => {}
  90. Vote.count.should == 1
  91. end
  92. scenario "Citizen vote results" do
  93. login_as @user
  94. proposal = create_proposal
  95. visit proposal_path(proposal)
  96. click_button I18n.t(:yes_option)
  97. click_button I18n.t(:i_am_sure)
  98. visit proposal_path(proposal)
  99. percentages_should_be(proposal, :in_favor => 100, :against => 0, :abstention => 0)
  100. number_of_votes_should_be(proposal, :in_favor => 1, :against => 0, :abstention => 0)
  101. login_as @user2
  102. visit proposal_path(proposal)
  103. click_button I18n.t(:no_option)
  104. click_button I18n.t(:i_am_sure)
  105. visit proposal_path(proposal)
  106. percentages_should_be(proposal, :in_favor => 50, :against => 50, :abstention => 0)
  107. number_of_votes_should_be(proposal, :in_favor => 1, :against => 1, :abstention => 0)
  108. login_as @user3
  109. visit proposal_path(proposal)
  110. click_button I18n.t(:abstention)
  111. click_button I18n.t(:i_am_sure)
  112. visit proposal_path(proposal)
  113. percentages_should_be(proposal, :in_favor => 33, :against => 33, :abstention => 33)
  114. number_of_votes_should_be(proposal, :in_favor => 1, :against => 1, :abstention => 1)
  115. page.should have_css(".in_favor", :text => "Sí")
  116. page.should have_css(".against", :text => "No")
  117. page.should have_css(".abstention", :text => "Abs")
  118. end
  119. scenario "Parlament vote results" do
  120. login_as @user
  121. proposal = create_proposal(:closed_at => Date.yesterday, :official_resolution => "Aceptada")
  122. visit proposal_path(proposal)
  123. page.should have_css(".official_resolution", :text => "Aceptada")
  124. end
  125. scenario "Concordance of voter's text and no votes" do
  126. create_proposal
  127. visit homepage
  128. page.should have_content("Sé el primero en votar")
  129. end
  130. scenario "Concordance of voter's text and one vote" do
  131. create_vote
  132. visit homepage
  133. page.should have_content("1 persona ya lo ha hecho")
  134. end
  135. scenario "Concordance of voter's text and two votes" do
  136. prop = create_proposal(:title => "Ley ffdsafdsafdsaf")
  137. create_vote(:user => @user, :proposal => prop)
  138. create_vote(:user => @user2, :proposal => prop)
  139. visit homepage
  140. page.should have_content("2 personas ya lo han hecho")
  141. end
  142. end