Merge remote-tracking branch 'upstream/pull/5424'
This commit is contained in:
commit
e41814d139
1 changed files with 17 additions and 17 deletions
|
@ -165,19 +165,19 @@ module Api
|
||||||
msg = create(:message, :unread, :sender => sender, :recipient => recipient)
|
msg = create(:message, :unread, :sender => sender, :recipient => recipient)
|
||||||
|
|
||||||
# fail if not authorized
|
# fail if not authorized
|
||||||
get api_message_path(:id => msg.id)
|
get api_message_path(msg)
|
||||||
assert_response :unauthorized
|
assert_response :unauthorized
|
||||||
|
|
||||||
# only recipient and sender can read the message
|
# only recipient and sender can read the message
|
||||||
get api_message_path(:id => msg.id), :headers => user3_auth
|
get api_message_path(msg), :headers => user3_auth
|
||||||
assert_response :forbidden
|
assert_response :forbidden
|
||||||
|
|
||||||
# message does not exist
|
# message does not exist
|
||||||
get api_message_path(:id => 99999), :headers => user3_auth
|
get api_message_path(99999), :headers => user3_auth
|
||||||
assert_response :not_found
|
assert_response :not_found
|
||||||
|
|
||||||
# verify xml output
|
# verify xml output
|
||||||
get api_message_path(:id => msg.id), :headers => recipient_auth
|
get api_message_path(msg), :headers => recipient_auth
|
||||||
assert_equal "application/xml", response.media_type
|
assert_equal "application/xml", response.media_type
|
||||||
assert_select "message", :count => 1 do
|
assert_select "message", :count => 1 do
|
||||||
assert_select "[id='#{msg.id}']"
|
assert_select "[id='#{msg.id}']"
|
||||||
|
@ -194,7 +194,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
# verify json output
|
# verify json output
|
||||||
get api_message_path(:id => msg.id, :format => "json"), :headers => recipient_auth
|
get api_message_path(msg, :format => "json"), :headers => recipient_auth
|
||||||
assert_equal "application/json", response.media_type
|
assert_equal "application/json", response.media_type
|
||||||
js = ActiveSupport::JSON.decode(@response.body)
|
js = ActiveSupport::JSON.decode(@response.body)
|
||||||
jsm = js["message"]
|
jsm = js["message"]
|
||||||
|
@ -211,7 +211,7 @@ module Api
|
||||||
assert_equal "markdown", jsm["body_format"]
|
assert_equal "markdown", jsm["body_format"]
|
||||||
assert_equal msg.body, jsm["body"]
|
assert_equal msg.body, jsm["body"]
|
||||||
|
|
||||||
get api_message_path(:id => msg.id), :headers => sender_auth
|
get api_message_path(msg), :headers => sender_auth
|
||||||
assert_equal "application/xml", response.media_type
|
assert_equal "application/xml", response.media_type
|
||||||
assert_select "message", :count => 1 do
|
assert_select "message", :count => 1 do
|
||||||
assert_select "[id='#{msg.id}']"
|
assert_select "[id='#{msg.id}']"
|
||||||
|
@ -228,7 +228,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
# verify json output
|
# verify json output
|
||||||
get api_message_path(:id => msg.id, :format => "json"), :headers => sender_auth
|
get api_message_path(msg, :format => "json"), :headers => sender_auth
|
||||||
assert_equal "application/json", response.media_type
|
assert_equal "application/json", response.media_type
|
||||||
js = ActiveSupport::JSON.decode(@response.body)
|
js = ActiveSupport::JSON.decode(@response.body)
|
||||||
jsm = js["message"]
|
jsm = js["message"]
|
||||||
|
@ -257,25 +257,25 @@ module Api
|
||||||
msg = create(:message, :unread, :sender => sender, :recipient => recipient)
|
msg = create(:message, :unread, :sender => sender, :recipient => recipient)
|
||||||
|
|
||||||
# attempt to mark message as read by recipient, not authenticated
|
# attempt to mark message as read by recipient, not authenticated
|
||||||
put api_message_path(:id => msg.id), :params => { :read_status => true }
|
put api_message_path(msg), :params => { :read_status => true }
|
||||||
assert_response :unauthorized
|
assert_response :unauthorized
|
||||||
|
|
||||||
# attempt to mark message as read by recipient, not allowed
|
# attempt to mark message as read by recipient, not allowed
|
||||||
put api_message_path(:id => msg.id), :params => { :read_status => true }, :headers => user3_auth
|
put api_message_path(msg), :params => { :read_status => true }, :headers => user3_auth
|
||||||
assert_response :forbidden
|
assert_response :forbidden
|
||||||
|
|
||||||
# missing parameter
|
# missing parameter
|
||||||
put api_message_path(:id => msg.id), :headers => recipient_auth
|
put api_message_path(msg), :headers => recipient_auth
|
||||||
assert_response :bad_request
|
assert_response :bad_request
|
||||||
|
|
||||||
# wrong type of parameter
|
# wrong type of parameter
|
||||||
put api_message_path(:id => msg.id),
|
put api_message_path(msg),
|
||||||
:params => { :read_status => "not a boolean" },
|
:params => { :read_status => "not a boolean" },
|
||||||
:headers => recipient_auth
|
:headers => recipient_auth
|
||||||
assert_response :bad_request
|
assert_response :bad_request
|
||||||
|
|
||||||
# mark message as read by recipient
|
# mark message as read by recipient
|
||||||
put api_message_path(:id => msg.id, :format => "json"),
|
put api_message_path(msg, :format => "json"),
|
||||||
:params => { :read_status => true },
|
:params => { :read_status => true },
|
||||||
:headers => recipient_auth
|
:headers => recipient_auth
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
@ -296,7 +296,7 @@ module Api
|
||||||
assert_equal msg.body, jsm["body"]
|
assert_equal msg.body, jsm["body"]
|
||||||
|
|
||||||
# mark message as unread by recipient
|
# mark message as unread by recipient
|
||||||
put api_message_path(:id => msg.id, :format => "json"),
|
put api_message_path(msg, :format => "json"),
|
||||||
:params => { :read_status => false },
|
:params => { :read_status => false },
|
||||||
:headers => recipient_auth
|
:headers => recipient_auth
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
@ -330,15 +330,15 @@ module Api
|
||||||
msg = create(:message, :read, :sender => sender, :recipient => recipient)
|
msg = create(:message, :read, :sender => sender, :recipient => recipient)
|
||||||
|
|
||||||
# attempt to delete message, not authenticated
|
# attempt to delete message, not authenticated
|
||||||
delete api_message_path(:id => msg.id)
|
delete api_message_path(msg)
|
||||||
assert_response :unauthorized
|
assert_response :unauthorized
|
||||||
|
|
||||||
# attempt to delete message, by user3
|
# attempt to delete message, by user3
|
||||||
delete api_message_path(:id => msg.id), :headers => user3_auth
|
delete api_message_path(msg), :headers => user3_auth
|
||||||
assert_response :forbidden
|
assert_response :forbidden
|
||||||
|
|
||||||
# delete message by recipient
|
# delete message by recipient
|
||||||
delete api_message_path(:id => msg.id, :format => "json"), :headers => recipient_auth
|
delete api_message_path(msg, :format => "json"), :headers => recipient_auth
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal "application/json", response.media_type
|
assert_equal "application/json", response.media_type
|
||||||
js = ActiveSupport::JSON.decode(@response.body)
|
js = ActiveSupport::JSON.decode(@response.body)
|
||||||
|
@ -357,7 +357,7 @@ module Api
|
||||||
assert_equal msg.body, jsm["body"]
|
assert_equal msg.body, jsm["body"]
|
||||||
|
|
||||||
# delete message by sender
|
# delete message by sender
|
||||||
delete api_message_path(:id => msg.id, :format => "json"), :headers => sender_auth
|
delete api_message_path(msg, :format => "json"), :headers => sender_auth
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal "application/json", response.media_type
|
assert_equal "application/json", response.media_type
|
||||||
js = ActiveSupport::JSON.decode(@response.body)
|
js = ActiveSupport::JSON.decode(@response.body)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue