- 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.messages-table > tbody", :count => 1 do
- assert_select "tr", :count => 1
- assert_select "tr#inbox-#{read_message.id}", :count => 1 do
- assert_select "a[href='#{user_path read_message.sender}']", :text => read_message.sender.display_name
- assert_select "a[href='#{message_path read_message}']", :text => read_message.title
- end
- end
- end
-
- ##
- # test the outbox action
- def test_outbox
- user = create(:user)
- message = 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.messages-table > tbody", :count => 1 do
- assert_select "tr", :count => 1
- assert_select "tr#outbox-#{message.id}", :count => 1 do
- assert_select "a[href='#{user_path message.recipient}']", :text => message.recipient.display_name
- assert_select "a[href='#{message_path message}']", :text => message.title
- end
- end
- end
-
- ##
- # test the mark action
- def test_mark
- user = create(:user)
- recipient_user = create(:user)
- other_user = create(:user)
- 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 => 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 => 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 => message, :mark => "read")
- assert_redirected_to inbox_messages_path
- assert Message.find(message.id).message_read
-
- # Check that the marking a message unread works
- post message_mark_path(:message_id => message, :mark => "unread")
- assert_redirected_to inbox_messages_path
- assert_not Message.find(message.id).message_read
-
- # Check that the marking a message read works and redirects to inbox from the message page
- post message_mark_path(:message_id => message, :mark => "read"), :headers => { :referer => message_path(message) }
- assert_redirected_to inbox_messages_path
- assert Message.find(message.id).message_read
-
- # Check that the marking a message unread works and redirects to inbox from the message page
- post message_mark_path(:message_id => message, :mark => "unread"), :headers => { :referer => message_path(message) }
- assert_redirected_to inbox_messages_path
- assert_not Message.find(message.id).message_read
-
- # Asking to mark a message with no ID should fail
- post message_mark_path
- assert_redirected_to inbox_messages_path
-
- # Asking to mark a message with a bogus ID should fail
- post message_mark_path(:message_id => 99999)