# test fetching new message page when not logged in
def test_new_no_login
# Check that the new message page requires us to login
# test fetching new message page when not logged in
def test_new_no_login
# Check that the new message page requires us to login
- get :new, :display_name => users(:public_user).display_name
- assert_redirected_to login_path(:referer => new_message_path(:display_name => users(:public_user).display_name))
+ user = create(:user)
+ get :new, :params => { :display_name => user.display_name }
+ assert_redirected_to login_path(:referer => new_message_path(:display_name => user.display_name))
- assert_select "title", "OpenStreetMap | Send message"
- assert_select "form[action='#{new_message_path(:display_name => users(:public_user).display_name)}']", :count => 1 do
+ assert_select "title", "Send message | OpenStreetMap"
+ assert_select "form[action='#{new_message_path(:display_name => recipient_user.display_name)}']", :count => 1 do
assert_select "input#message_title", :count => 1
assert_select "textarea#message_body", :count => 1
assert_select "input[type='submit'][value='Send']", :count => 1
assert_select "input#message_title", :count => 1
assert_select "textarea#message_body", :count => 1
assert_select "input[type='submit'][value='Send']", :count => 1
# Check that we can't send a message from a GET request
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
get :new,
# Check that we can't send a message from a GET request
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
get :new,
- :display_name => users(:public_user).display_name,
- :message => { :title => "Test Message", :body => "Test message body" }
+ :params => { :display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "Test message body" } }
- assert_select "title", "OpenStreetMap | Send message"
- assert_select "form[action='#{new_message_path(:display_name => users(:public_user).display_name)}']", :count => 1 do
+ assert_select "title", "Send message | OpenStreetMap"
+ assert_select "form[action='#{new_message_path(:display_name => recipient_user.display_name)}']", :count => 1 do
assert_select "input#message_title", :count => 1 do
assert_select "[value='Test Message']"
end
assert_select "input#message_title", :count => 1 do
assert_select "[value='Test Message']"
end
# Check that the subject is preserved over errors
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
post :new,
# Check that the subject is preserved over errors
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
post :new,
- :display_name => users(:public_user).display_name,
- :message => { :title => "Test Message", :body => "" }
+ :params => { :display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "" } }
- assert_select "title", "OpenStreetMap | Send message"
- assert_select "form[action='#{new_message_path(:display_name => users(:public_user).display_name)}']", :count => 1 do
+ assert_select "title", "Send message | OpenStreetMap"
+ assert_select "form[action='#{new_message_path(:display_name => recipient_user.display_name)}']", :count => 1 do
assert_select "input#message_title", :count => 1 do
assert_select "[value='Test Message']"
end
assert_select "input#message_title", :count => 1 do
assert_select "[value='Test Message']"
end
# Check that the body text is preserved over errors
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
post :new,
# Check that the body text is preserved over errors
assert_difference "ActionMailer::Base.deliveries.size", 0 do
assert_difference "Message.count", 0 do
post :new,
- :display_name => users(:public_user).display_name,
- :message => { :title => "", :body => "Test message body" }
+ :params => { :display_name => recipient_user.display_name,
+ :message => { :title => "", :body => "Test message body" } }
- assert_select "title", "OpenStreetMap | Send message"
- assert_select "form[action='#{new_message_path(:display_name => users(:public_user).display_name)}']", :count => 1 do
+ assert_select "title", "Send message | OpenStreetMap"
+ assert_select "form[action='#{new_message_path(:display_name => recipient_user.display_name)}']", :count => 1 do
assert_select "input#message_title", :count => 1 do
assert_select "[value='']"
end
assert_select "input#message_title", :count => 1 do
assert_select "[value='']"
end
# Check that sending a message works
assert_difference "ActionMailer::Base.deliveries.size", 1 do
assert_difference "Message.count", 1 do
post :new,
# Check that sending a message works
assert_difference "ActionMailer::Base.deliveries.size", 1 do
assert_difference "Message.count", 1 do
post :new,
- :display_name => users(:public_user).display_name,
- :message => { :title => "Test Message", :body => "Test message body" }
+ :params => { :display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "Test message body" } }
assert_equal "Message sent", flash[:notice]
e = ActionMailer::Base.deliveries.first
assert_equal "Message sent", flash[:notice]
e = ActionMailer::Base.deliveries.first
assert_equal "[OpenStreetMap] Test Message", e.subject
assert_match /Test message body/, e.text_part.decoded
assert_match /Test message body/, e.html_part.decoded
ActionMailer::Base.deliveries.clear
m = Message.last
assert_equal "[OpenStreetMap] Test Message", e.subject
assert_match /Test message body/, e.text_part.decoded
assert_match /Test message body/, e.html_part.decoded
ActionMailer::Base.deliveries.clear
m = Message.last
- assert_equal users(:normal_user).id, m.from_user_id
- assert_equal users(:public_user).id, m.to_user_id
+ assert_equal user.id, m.from_user_id
+ assert_equal recipient_user.id, m.to_user_id
assert_in_delta Time.now, m.sent_on, 2
assert_equal "Test Message", m.title
assert_equal "Test message body", m.body
assert_equal "markdown", m.body_format
# Asking to send a message with a bogus user name should fail
assert_in_delta Time.now, m.sent_on, 2
assert_equal "Test Message", m.title
assert_equal "Test message body", m.body
assert_equal "markdown", m.body_format
# Asking to send a message with a bogus user name should fail
assert_response :not_found
assert_template "user/no_such_user"
assert_select "h1", "The user non_existent_user does not exist"
assert_response :not_found
assert_template "user/no_such_user"
assert_select "h1", "The user non_existent_user does not exist"
# Check that sending a message fails when the message limit is hit
assert_no_difference "ActionMailer::Base.deliveries.size" do
assert_no_difference "Message.count" do
with_message_limit(0) do
post :new,
# Check that sending a message fails when the message limit is hit
assert_no_difference "ActionMailer::Base.deliveries.size" do
assert_no_difference "Message.count" do
with_message_limit(0) do
post :new,
- :display_name => users(:public_user).display_name,
- :message => { :title => "Test Message", :body => "Test message body" }
+ :params => { :display_name => recipient_user.display_name,
+ :message => { :title => "Test Message", :body => "Test message body" } }
- unread_message = create(:message, :unread, :sender => users(:normal_user), :recipient => users(:public_user))
+ user = create(:user)
+ recipient_user = create(:user)
+ other_user = create(:user)
+ unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
assert_redirected_to login_path(:referer => reply_message_path(:message_id => unread_message.id))
# Login as the wrong user
assert_redirected_to login_path(:referer => reply_message_path(:message_id => unread_message.id))
# Login as the wrong user
- assert_select "title", "OpenStreetMap | Re: #{unread_message.title}"
- assert_select "form[action='#{new_message_path(:display_name => users(:normal_user).display_name)}']", :count => 1 do
+ assert_select "title", "Re: #{unread_message.title} | OpenStreetMap"
+ assert_select "form[action='#{new_message_path(:display_name => user.display_name)}']", :count => 1 do
assert_select "input#message_title[value='Re: #{unread_message.title}']", :count => 1
assert_select "textarea#message_body", :count => 1
assert_select "input[type='submit'][value='Send']", :count => 1
assert_select "input#message_title[value='Re: #{unread_message.title}']", :count => 1
assert_select "textarea#message_body", :count => 1
assert_select "input[type='submit'][value='Send']", :count => 1
- unread_message = create(:message, :unread, :sender => users(:normal_user), :recipient => users(:public_user))
+ user = create(:user)
+ recipient_user = create(:user)
+ other_user = create(:user)
+ unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
assert_redirected_to login_path(:referer => read_message_path(:message_id => unread_message.id))
# Login as the wrong user
assert_redirected_to login_path(:referer => read_message_path(:message_id => unread_message.id))
# Login as the wrong user
- assert_equal "You are logged in as `pulibc_test2' but the message you have asked to read was not sent by or to that user. Please login as the correct user in order to read it.", flash[:notice]
+ assert_equal "You are logged in as `#{other_user.display_name}' but the message you have asked to read was not sent by or to that user. Please login as the correct user in order to read it.", flash[:notice]
assert_response :success
assert_template "read"
assert_equal false, Message.find(unread_message.id).message_read
# Login as the message recipient
assert_response :success
assert_template "read"
assert_equal false, Message.find(unread_message.id).message_read
# Login as the message recipient
- read_message = create(:message, :read, :recipient => users(:normal_user))
+ user = create(:user)
+ other_user = create(:user)
+ read_message = create(:message, :read, :recipient => user)
- get :inbox, :display_name => users(:normal_user).display_name
- assert_redirected_to login_path(:referer => inbox_path(:display_name => users(:normal_user).display_name))
+ get :inbox, :params => { :display_name => user.display_name }
+ assert_redirected_to login_path(:referer => inbox_path(:display_name => user.display_name))
- get :inbox, :display_name => users(:public_user).display_name
- assert_redirected_to inbox_path(:display_name => users(:normal_user).display_name)
+ get :inbox, :params => { :display_name => other_user.display_name }
+ assert_redirected_to inbox_path(:display_name => user.display_name)
- get :outbox, :display_name => users(:normal_user).display_name
- assert_redirected_to login_path(:referer => outbox_path(:display_name => users(:normal_user).display_name))
+ get :outbox, :params => { :display_name => user.display_name }
+ assert_redirected_to login_path(:referer => outbox_path(:display_name => user.display_name))
- get :outbox, :display_name => users(:public_user).display_name
- assert_redirected_to outbox_path(:display_name => users(:normal_user).display_name)
+ get :outbox, :params => { :display_name => other_user.display_name }
+ assert_redirected_to outbox_path(:display_name => user.display_name)
- unread_message = create(:message, :unread, :sender => users(:normal_user), :recipient => users(:public_user))
+ user = create(:user)
+ recipient_user = create(:user)
+ other_user = create(:user)
+ unread_message = create(:message, :unread, :sender => user, :recipient => recipient_user)
- post :mark, :message_id => unread_message.id, :mark => "read"
- assert_redirected_to inbox_path(:display_name => users(:public_user).display_name)
+ post :mark, :params => { :message_id => unread_message.id, :mark => "read" }
+ assert_redirected_to inbox_path(:display_name => recipient_user.display_name)
assert_equal true, Message.find(unread_message.id).message_read
# Check that the marking a message unread works
assert_equal true, Message.find(unread_message.id).message_read
# Check that the marking a message unread works
- post :mark, :message_id => unread_message.id, :mark => "unread"
- assert_redirected_to inbox_path(:display_name => users(:public_user).display_name)
+ post :mark, :params => { :message_id => unread_message.id, :mark => "unread" }
+ assert_redirected_to inbox_path(:display_name => recipient_user.display_name)
assert_equal false, Message.find(unread_message.id).message_read
# Check that the marking a message read via XHR works
assert_equal false, Message.find(unread_message.id).message_read
# Check that the marking a message read via XHR works
- xhr :post, :mark, :message_id => unread_message.id, :mark => "read"
+ post :mark, :xhr => true, :params => { :message_id => unread_message.id, :mark => "read" }
assert_response :success
assert_template "mark"
assert_equal true, Message.find(unread_message.id).message_read
# Check that the marking a message unread via XHR works
assert_response :success
assert_template "mark"
assert_equal true, Message.find(unread_message.id).message_read
# Check that the marking a message unread via XHR works
- xhr :post, :mark, :message_id => unread_message.id, :mark => "unread"
+ post :mark, :xhr => true, :params => { :message_id => unread_message.id, :mark => "unread" }
- read_message = create(:message, :read, :recipient => users(:normal_user), :sender => users(:public_user))
- sent_message = create(:message, :unread, :recipient => users(:public_user), :sender => users(:normal_user))
+ user = create(:user)
+ second_user = create(:user)
+ other_user = create(:user)
+ read_message = create(:message, :read, :recipient => user, :sender => second_user)
+ sent_message = create(:message, :unread, :recipient => second_user, :sender => user)
- post :delete, :message_id => read_message.id
- assert_redirected_to inbox_path(:display_name => users(:normal_user).display_name)
+ post :delete, :params => { :message_id => read_message.id }
+ assert_redirected_to inbox_path(:display_name => user.display_name)
assert_equal "Message deleted", flash[:notice]
m = Message.find(read_message.id)
assert_equal true, m.from_user_visible
assert_equal false, m.to_user_visible
# Check that the deleting a sent message works
assert_equal "Message deleted", flash[:notice]
m = Message.find(read_message.id)
assert_equal true, m.from_user_visible
assert_equal false, m.to_user_visible
# Check that the deleting a sent message works
- post :delete, :message_id => sent_message.id, :referer => outbox_path(:display_name => users(:normal_user).display_name)
- assert_redirected_to outbox_path(:display_name => users(:normal_user).display_name)
+ post :delete, :params => { :message_id => sent_message.id, :referer => outbox_path(:display_name => user.display_name) }
+ assert_redirected_to outbox_path(:display_name => user.display_name)
assert_equal "Message deleted", flash[:notice]
m = Message.find(sent_message.id)
assert_equal false, m.from_user_visible
assert_equal "Message deleted", flash[:notice]
m = Message.find(sent_message.id)
assert_equal false, m.from_user_visible