conversations_controller_test.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. require 'test_helper'
  2. class ConversationsControllerTest < ActionDispatch::IntegrationTest
  3. def setup
  4. @user = users(:daniel)
  5. @other_user = users(:ben)
  6. log_in_as @user
  7. end
  8. test "should create valid conversation" do
  9. get new_conversation_path
  10. assert_response :success
  11. assert_difference '@user.conversations.count', 1 do
  12. post conversations_path, params: { conversation: {
  13. name: "Example conversation",
  14. user_ids: [@user.id, @other_user.id],
  15. messages_attributes: { "0" => { content: "Content" }}}}
  16. end
  17. end
  18. test "should redirect conversation which user is not participating in" do
  19. get conversation_path conversations(:two)
  20. assert_redirected_to root_path
  21. end
  22. test "last message should be shown in index and dropdown" do
  23. message = @user.messages.build(content: "Hello, world!",
  24. conversation: conversations(:one))
  25. message.save
  26. get conversations_path
  27. assert_select "tbody" do
  28. assert_select "tr:nth-child(1)", text: /#{message.content}/
  29. end
  30. assert_select ".dropdown-messages li:nth-child(1)", text: /#{message.content}/
  31. end
  32. end