|
| 1 | +require "test_helper" |
| 2 | + |
| 3 | +class Retros::PhaseBacksControllerTest < ActionDispatch::IntegrationTest |
| 4 | + setup do |
| 5 | + @retro = retros(:one) |
| 6 | + @admin_user = users(:one) |
| 7 | + @member_user = users(:two) |
| 8 | + # Add member as participant (non-admin) |
| 9 | + @retro.add_participant(@member_user, role: :participant) |
| 10 | + end |
| 11 | + |
| 12 | + test "admin can go back from grouping to brainstorming" do |
| 13 | + sign_in_as :one |
| 14 | + @retro.update!(phase: :grouping) |
| 15 | + |
| 16 | + post retro_phase_back_path(@retro) |
| 17 | + |
| 18 | + assert_redirected_to retro_brainstorming_path(@retro) |
| 19 | + assert_equal "brainstorming", @retro.reload.phase |
| 20 | + end |
| 21 | + |
| 22 | + test "admin can go back from voting to grouping" do |
| 23 | + sign_in_as :one |
| 24 | + @retro.update!(phase: :voting) |
| 25 | + |
| 26 | + post retro_phase_back_path(@retro) |
| 27 | + |
| 28 | + assert_redirected_to retro_grouping_path(@retro) |
| 29 | + assert_equal "grouping", @retro.reload.phase |
| 30 | + end |
| 31 | + |
| 32 | + test "admin can go back from discussion to voting" do |
| 33 | + sign_in_as :one |
| 34 | + @retro.update!(phase: :discussion) |
| 35 | + |
| 36 | + post retro_phase_back_path(@retro) |
| 37 | + |
| 38 | + assert_redirected_to retro_voting_path(@retro) |
| 39 | + assert_equal "voting", @retro.reload.phase |
| 40 | + end |
| 41 | + |
| 42 | + test "admin can go back from complete to discussion" do |
| 43 | + sign_in_as :one |
| 44 | + @retro.update!(phase: :complete) |
| 45 | + |
| 46 | + post retro_phase_back_path(@retro) |
| 47 | + |
| 48 | + assert_redirected_to retro_discussion_path(@retro) |
| 49 | + assert_equal "discussion", @retro.reload.phase |
| 50 | + end |
| 51 | + |
| 52 | + test "non-admin participant cannot go back" do |
| 53 | + sign_in_as :two |
| 54 | + @retro.update!(phase: :grouping) |
| 55 | + |
| 56 | + post retro_phase_back_path(@retro) |
| 57 | + |
| 58 | + assert_redirected_to retros_path |
| 59 | + assert_equal "grouping", @retro.reload.phase |
| 60 | + end |
| 61 | + |
| 62 | + test "unauthenticated user cannot go back" do |
| 63 | + @retro.update!(phase: :grouping) |
| 64 | + |
| 65 | + post retro_phase_back_path(@retro, script_name: nil) |
| 66 | + |
| 67 | + assert_redirected_to session_menu_path(script_name: nil) |
| 68 | + assert_equal "grouping", @retro.reload.phase |
| 69 | + end |
| 70 | + |
| 71 | + test "going back does not change phase when already at brainstorming" do |
| 72 | + sign_in_as :one |
| 73 | + @retro.update!(phase: :brainstorming) |
| 74 | + |
| 75 | + post retro_phase_back_path(@retro) |
| 76 | + |
| 77 | + assert_redirected_to retro_brainstorming_path(@retro) |
| 78 | + assert_equal "brainstorming", @retro.reload.phase |
| 79 | + end |
| 80 | +end |
0 commit comments