messages_controller_test.rb 828 B

12345678910111213141516171819202122232425
  1. require 'test_helper'
  2. class MessagesControllerTest < ActionDispatch::IntegrationTest
  3. def setup
  4. @user = users(:daniel)
  5. @conversation = conversations(:one)
  6. @unallowed_conversation = conversations(:two)
  7. log_in_as @user
  8. end
  9. test "should create valid message" do
  10. get conversation_path(@conversation)
  11. assert_response :success
  12. assert_difference '@user.messages.count', 1 do
  13. post messages_path, params: { message: { content: "Content" },
  14. conversation_id: @conversation.id }
  15. end
  16. end
  17. test "should redirect create message in unallowed conversation" do
  18. post messages_path, params: { message: { content: "Message content" },
  19. conversation_id: @unallowed_conversation.id }
  20. assert_redirected_to root_path
  21. end
  22. end