msg = create(:message, :unread, :sender => sender, :recipient => recipient)
# fail if not authorized
msg = create(:message, :unread, :sender => sender, :recipient => recipient)
# fail if not authorized
assert_equal "application/xml", response.media_type
assert_select "message", :count => 1 do
assert_select "[id='#{msg.id}']"
assert_equal "application/xml", response.media_type
assert_select "message", :count => 1 do
assert_select "[id='#{msg.id}']"
assert_equal "application/json", response.media_type
js = ActiveSupport::JSON.decode(@response.body)
jsm = js["message"]
assert_equal "application/json", response.media_type
js = ActiveSupport::JSON.decode(@response.body)
jsm = js["message"]
assert_equal "markdown", jsm["body_format"]
assert_equal msg.body, jsm["body"]
assert_equal "markdown", jsm["body_format"]
assert_equal msg.body, jsm["body"]
assert_equal "application/xml", response.media_type
assert_select "message", :count => 1 do
assert_select "[id='#{msg.id}']"
assert_equal "application/xml", response.media_type
assert_select "message", :count => 1 do
assert_select "[id='#{msg.id}']"
assert_equal "application/json", response.media_type
js = ActiveSupport::JSON.decode(@response.body)
jsm = js["message"]
assert_equal "application/json", response.media_type
js = ActiveSupport::JSON.decode(@response.body)
jsm = js["message"]
msg = create(:message, :unread, :sender => sender, :recipient => recipient)
# attempt to mark message as read by recipient, not authenticated
msg = create(:message, :unread, :sender => sender, :recipient => recipient)
# attempt to mark message as read by recipient, not authenticated
assert_response :unauthorized
# attempt to mark message as read by recipient, not allowed
assert_response :unauthorized
# attempt to mark message as read by recipient, not allowed
:params => { :read_status => "not a boolean" },
:headers => recipient_auth
assert_response :bad_request
# mark message as read by recipient
:params => { :read_status => "not a boolean" },
:headers => recipient_auth
assert_response :bad_request
# mark message as read by recipient
:params => { :read_status => true },
:headers => recipient_auth
assert_response :success
:params => { :read_status => true },
:headers => recipient_auth
assert_response :success
assert_equal msg.body, jsm["body"]
# mark message as unread by recipient
assert_equal msg.body, jsm["body"]
# mark message as unread by recipient
:params => { :read_status => false },
:headers => recipient_auth
assert_response :success
:params => { :read_status => false },
:headers => recipient_auth
assert_response :success
msg = create(:message, :read, :sender => sender, :recipient => recipient)
# attempt to delete message, not authenticated
msg = create(:message, :read, :sender => sender, :recipient => recipient)
# attempt to delete message, not authenticated
assert_response :unauthorized
# attempt to delete message, by user3
assert_response :unauthorized
# attempt to delete message, by user3
assert_response :success
assert_equal "application/json", response.media_type
js = ActiveSupport::JSON.decode(@response.body)
assert_response :success
assert_equal "application/json", response.media_type
js = ActiveSupport::JSON.decode(@response.body)
assert_equal msg.body, jsm["body"]
# delete message by sender
assert_equal msg.body, jsm["body"]
# delete message by sender
assert_response :success
assert_equal "application/json", response.media_type
js = ActiveSupport::JSON.decode(@response.body)
assert_response :success
assert_equal "application/json", response.media_type
js = ActiveSupport::JSON.decode(@response.body)