5 class OutboxesControllerTest < ActionDispatch::IntegrationTest
7 # test all routes which lead to this controller
10 { :path => "/api/0.6/user/messages/outbox", :method => :get },
11 { :controller => "api/messages/outboxes", :action => "show" }
14 { :path => "/api/0.6/user/messages/outbox.xml", :method => :get },
15 { :controller => "api/messages/outboxes", :action => "show", :format => "xml" }
18 { :path => "/api/0.6/user/messages/outbox.json", :method => :get },
19 { :controller => "api/messages/outboxes", :action => "show", :format => "json" }
25 user1_auth = bearer_authorization_header(user1, :scopes => %w[send_messages consume_messages])
28 user2_auth = bearer_authorization_header(user2, :scopes => %w[send_messages consume_messages])
31 user3_auth = bearer_authorization_header(user3, :scopes => %w[send_messages consume_messages])
33 # create some messages between users
34 # user | inbox | outbox
38 create(:message, :unread, :sender => user1, :recipient => user2)
39 create(:message, :unread, :sender => user1, :recipient => user2)
40 create(:message, :unread, :sender => user1, :recipient => user3)
41 create(:message, :unread, :sender => user2, :recipient => user3)
43 # only authorized users
44 get api_messages_outbox_path
45 assert_response :unauthorized
47 # 3 messages in user1.outbox
48 get api_messages_outbox_path, :headers => user1_auth
49 assert_response :success
50 assert_equal "application/xml", response.media_type
51 assert_select "message", :count => 3 do
52 assert_select "[from_user_id='#{user1.id}']"
53 assert_select "[from_display_name='#{user1.display_name}']"
54 assert_select "[to_user_id]"
55 assert_select "[to_display_name]"
56 assert_select "[sent_on]"
57 assert_select "[message_read]", 0
58 assert_select "[deleted='false']"
59 assert_select "[body_format]"
60 assert_select "body", false
64 # 1 message in user2.outbox
65 get api_messages_outbox_path, :headers => user2_auth
66 assert_response :success
67 assert_equal "application/xml", response.media_type
68 assert_select "message", :count => 1 do
69 assert_select "[from_user_id='#{user2.id}']"
70 assert_select "[from_display_name='#{user2.display_name}']"
71 assert_select "[to_user_id]"
72 assert_select "[to_display_name]"
73 assert_select "[sent_on]"
74 assert_select "[deleted='false']"
75 assert_select "[message_read]", 0
76 assert_select "[body_format]"
77 assert_select "body", false
81 # 0 messages in user3.outbox
82 get api_messages_outbox_path, :headers => user3_auth
83 assert_response :success
84 assert_equal "application/xml", response.media_type
85 assert_select "message", :count => 0