- get message_path(:id => 99999)
- assert_response :not_found
- assert_template "no_such_message"
- end
-
- ##
- # test the inbox action
- def test_inbox
- user = create(:user)
- read_message = create(:message, :read, :recipient => user)
- # Check that the inbox page requires us to login
- get inbox_messages_path
- assert_redirected_to login_path(:referer => inbox_messages_path)
-
- # Login
- session_for(user)
-
- # Check that we can view our inbox when logged in
- get inbox_messages_path
- assert_response :success
- assert_template "inbox"
- assert_select ".content-inner > table", :count => 1 do
- assert_select "tr", :count => 2
- assert_select "tr#inbox-#{read_message.id}.inbox-row", :count => 1
- end
- end
-
- ##
- # test the outbox action
- def test_outbox
- user = create(:user)
- create(:message, :sender => user)
-
- # Check that the outbox page requires us to login
- get outbox_messages_path
- assert_redirected_to login_path(:referer => outbox_messages_path)
-
- # Login
- session_for(user)
-
- # Check that we can view our outbox when logged in
- get outbox_messages_path
- assert_response :success
- assert_template "outbox"
- assert_select ".content-inner > table", :count => 1 do
- assert_select "tr", :count => 2
- assert_select "tr.inbox-row", :count => 1
- end
- end
-
- ##
- # test the mark action
- def test_mark
- user = create(:user)
- recipient_user = create(:user)
- other_user = create(:user)
- unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
-
- # Check that the marking a message requires us to login
- post message_mark_path(:message_id => unread_message)
- assert_response :forbidden
-
- # Login as a user with no messages
- session_for(other_user)
-
- # Check that marking a message we didn't send or receive fails
- post message_mark_path(:message_id => unread_message)
- assert_response :not_found
- assert_template "no_such_message"
-
- # Login as the message recipient_user
- session_for(recipient_user)
-
- # Check that the marking a message read works
- post message_mark_path(:message_id => unread_message, :mark => "read")
- assert_redirected_to inbox_messages_path
- assert Message.find(unread_message.id).message_read
-
- # Check that the marking a message unread works
- post message_mark_path(:message_id => unread_message, :mark => "unread")
- assert_redirected_to inbox_messages_path
- assert_not Message.find(unread_message.id).message_read
-
- # Check that the marking a message read via XHR works
- post message_mark_path(:message_id => unread_message, :mark => "read"), :xhr => true
- assert_response :success
- assert_template "mark"
- assert Message.find(unread_message.id).message_read
-
- # Check that the marking a message unread via XHR works
- post message_mark_path(:message_id => unread_message, :mark => "unread"), :xhr => true
- assert_response :success
- assert_template "mark"
- assert_not Message.find(unread_message.id).message_read
-
- # Asking to mark a message with no ID should fail
- post message_mark_path
- assert_response :redirect
- assert_redirected_to inbox_messages_path
-
- # Asking to mark a message with a bogus ID should fail
- post message_mark_path(:message_id => 99999)