99 lines
2.7 KiB
Ruby
99 lines
2.7 KiB
Ruby
require "test_helper"
|
|
|
|
class BoardsControllerTest < ActionDispatch::IntegrationTest
|
|
setup do
|
|
sign_in_as :kevin
|
|
end
|
|
|
|
test "new" do
|
|
get new_board_path
|
|
assert_response :success
|
|
end
|
|
|
|
test "show" do
|
|
get board_path(boards(:writebook))
|
|
assert_response :success
|
|
end
|
|
|
|
test "create" do
|
|
assert_difference -> { Board.count }, +1 do
|
|
post boards_path, params: { board: { name: "Remodel Punch List" } }
|
|
end
|
|
|
|
board = Board.last
|
|
assert_redirected_to board_path(board)
|
|
assert_includes board.users, users(:kevin)
|
|
assert_equal "Remodel Punch List", board.name
|
|
end
|
|
|
|
test "edit" do
|
|
get edit_board_path(boards(:writebook))
|
|
assert_response :success
|
|
end
|
|
|
|
test "update" do
|
|
patch board_path(boards(:writebook)), params: {
|
|
board: {
|
|
name: "Writebook bugs",
|
|
all_access: false,
|
|
auto_postpone_period: 1.day
|
|
},
|
|
user_ids: users(:kevin, :jz).pluck(:id)
|
|
}
|
|
|
|
assert_redirected_to edit_board_path(boards(:writebook))
|
|
assert_equal "Writebook bugs", boards(:writebook).reload.name
|
|
assert_equal users(:kevin, :jz).sort, boards(:writebook).users.sort
|
|
assert_equal 1.day, entropies(:writebook_board).auto_postpone_period
|
|
assert_not boards(:writebook).all_access?
|
|
end
|
|
|
|
test "update redirects to root when user removes themselves from board" do
|
|
board = boards(:writebook)
|
|
|
|
patch board_path(board), params: {
|
|
board: { name: "Updated name", all_access: false },
|
|
user_ids: users(:david, :jz).pluck(:id)
|
|
}
|
|
|
|
assert_redirected_to root_path
|
|
assert_not board.reload.users.include?(users(:kevin))
|
|
end
|
|
|
|
test "update board with granular permissions, submitting no user ids" do
|
|
assert_not boards(:private).all_access?
|
|
|
|
boards(:private).users = [ users(:kevin) ]
|
|
boards(:private).save!
|
|
|
|
patch board_path(boards(:private)), params: {
|
|
board: { name: "Renamed" }
|
|
}
|
|
|
|
assert_redirected_to edit_board_path(boards(:private))
|
|
assert_equal "Renamed", boards(:private).reload.name
|
|
assert_equal [ users(:kevin) ], boards(:private).users
|
|
assert_not boards(:private).all_access?
|
|
end
|
|
|
|
test "update all access" do
|
|
board = Current.set(session: sessions(:kevin)) do
|
|
Board.create! name: "New board", all_access: false
|
|
end
|
|
assert_equal [ users(:kevin) ], board.users
|
|
|
|
patch board_path(board), params: { board: { name: "Bugs", all_access: true } }
|
|
|
|
assert_redirected_to edit_board_path(board)
|
|
assert board.reload.all_access?
|
|
assert_equal User.active.sort, board.users.sort
|
|
end
|
|
|
|
test "destroy" do
|
|
board = boards(:writebook)
|
|
delete board_path(board)
|
|
assert_redirected_to root_path
|
|
assert_raises(ActiveRecord::RecordNotFound) { board.reload }
|
|
end
|
|
end
|