end
assert_select "body", :count => 1 do
assert_select "div#content", :count => 1 do
- assert_select "form[action='/user/new'][method=post]", :count => 1 do
- assert_select "input[id=user_email]", :count => 1
- assert_select "input[id=user_email_confirmation]", :count => 1
- assert_select "input[id=user_display_name]", :count => 1
- assert_select "input[id=user_pass_crypt][type=password]", :count => 1
- assert_select "input[id=user_pass_crypt_confirmation][type=password]", :count => 1
- assert_select "input[type=submit][value=Sign Up]", :count => 1
+ assert_select "form[action='/user/new'][method='post']", :count => 1 do
+ assert_select "input[id='user_email']", :count => 1
+ assert_select "input[id='user_email_confirmation']", :count => 1
+ assert_select "input[id='user_display_name']", :count => 1
+ assert_select "input[id='user_pass_crypt'][type='password']", :count => 1
+ assert_select "input[id='user_pass_crypt_confirmation'][type='password']", :count => 1
+ assert_select "input[type='submit'][value='Sign Up']", :count => 1
end
end
end
def test_user_create_success
user = new_user
- assert_difference('User.count') do
- assert_difference('ActionMailer::Base.deliveries.size') do
+ assert_difference('User.count', 1) do
+ assert_difference('ActionMailer::Base.deliveries.size', 1) do
post :save, {}, {:new_user => user}
end
end
def test_user_save_referer_params
user = new_user
- post :save, {}, {:new_user => user,
- :referer => '/edit?editor=id#map=1/2/3'}
+ assert_difference('User.count', 1) do
+ assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ post :save, {}, {:new_user => user,
+ :referer => '/edit?editor=id#map=1/2/3'}
+ end
+ end
assert_equal welcome_path(:editor => 'id', :zoom => 1, :lat => 2, :lon => 3),
user.tokens.order("id DESC").first.referer
+
+ ActionMailer::Base.deliveries.clear
end
def test_user_confirm_expired_token
assert_response :redirect
assert_redirected_to :action => :login
assert_match /^Sorry you lost it/, flash[:notice]
- assert_equal users(:normal_user).email, ActionMailer::Base.deliveries.last.to[0]
+ email = ActionMailer::Base.deliveries.first
+ assert_equal 1, email.to.count
+ assert_equal users(:normal_user).email, email.to.first
+ ActionMailer::Base.deliveries.clear
# Test resetting using an address that matches a different user
# that has the same address in a different case
assert_response :redirect
assert_redirected_to :action => :login
assert_match /^Sorry you lost it/, flash[:notice]
- assert_equal users(:uppercase_user).email, ActionMailer::Base.deliveries.last.to[0]
+ email = ActionMailer::Base.deliveries.first
+ assert_equal 1, email.to.count
+ assert_equal users(:uppercase_user).email, email.to.first
+ ActionMailer::Base.deliveries.clear
# Test resetting using an address that is a case insensitive match
# for more than one user but not an exact match for either
assert_response :redirect
assert_redirected_to :action => :login
assert_match /^Sorry you lost it/, flash[:notice]
- assert_equal users(:public_user).email, ActionMailer::Base.deliveries.last.to[0]
+ email = ActionMailer::Base.deliveries.first
+ assert_equal 1, email.to.count
+ assert_equal users(:public_user).email, email.to.first
+ ActionMailer::Base.deliveries.clear
# Test resetting using an address that matches a user that has the
# same (case insensitively unique) address in a different case
assert_response :redirect
assert_redirected_to :action => :login
assert_match /^Sorry you lost it/, flash[:notice]
- assert_equal users(:public_user).email, ActionMailer::Base.deliveries.last.to[0]
+ email = ActionMailer::Base.deliveries.first
+ assert_equal 1, email.to.count
+ assert_equal users(:public_user).email, email.to.first
+ ActionMailer::Base.deliveries.clear
end
def test_reset_password
# Changing email to one that exists should fail
user.new_email = users(:public_user).email
- post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
+ assert_no_difference('ActionMailer::Base.deliveries.size') do
+ post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
+ end
assert_response :success
assert_template :account
assert_select ".notice", false
# Changing email to one that exists should fail, regardless of case
user.new_email = users(:public_user).email.upcase
- post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
+ assert_no_difference('ActionMailer::Base.deliveries.size') do
+ post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
+ end
assert_response :success
assert_template :account
assert_select ".notice", false
# Changing email to one that doesn't exist should work
user.new_email = "new_tester@example.com"
- post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
+ assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ post :account, { :display_name => user.display_name, :user => user.attributes }, { "user" => user.id }
+ end
assert_response :success
assert_template :account
assert_select "div#errorExplanation", false
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.form-row > input#user_new_email[value=?]", user.new_email
+ email = ActionMailer::Base.deliveries.first
+ assert_equal 1, email.to.count
+ assert_equal user.new_email, email.to.first
+ ActionMailer::Base.deliveries.clear
end
# Check that the user account page will display and contains some relevant
get :view, {:display_name => "test"}
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^=/user/test/history]", 1
- assert_select "a[href=/user/test/traces]", 1
- assert_select "a[href=/user/test/diary]", 1
- assert_select "a[href=/user/test/diary/comments]", 1
- assert_select "a[href=/user/test/account]", 0
- assert_select "a[href=/user/test/blocks]", 0
- assert_select "a[href=/user/test/blocks_by]", 0
- assert_select "a[href=/blocks/new/test]", 0
+ assert_select "a[href^='/user/test/history']", 1
+ assert_select "a[href='/user/test/traces']", 1
+ assert_select "a[href='/user/test/diary']", 1
+ assert_select "a[href='/user/test/diary/comments']", 1
+ assert_select "a[href='/user/test/account']", 0
+ assert_select "a[href='/user/test/blocks']", 0
+ assert_select "a[href='/user/test/blocks_by']", 0
+ assert_select "a[href='/blocks/new/test']", 0
end
# Test a user who has been blocked
get :view, {:display_name => "blocked"}
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^=/user/blocked/history]", 1
- assert_select "a[href=/user/blocked/traces]", 1
- assert_select "a[href=/user/blocked/diary]", 1
- assert_select "a[href=/user/blocked/diary/comments]", 1
- assert_select "a[href=/user/blocked/account]", 0
- assert_select "a[href=/user/blocked/blocks]", 1
- assert_select "a[href=/user/blocked/blocks_by]", 0
- assert_select "a[href=/blocks/new/blocked]", 0
+ assert_select "a[href^='/user/blocked/history']", 1
+ assert_select "a[href='/user/blocked/traces']", 1
+ assert_select "a[href='/user/blocked/diary']", 1
+ assert_select "a[href='/user/blocked/diary/comments']", 1
+ assert_select "a[href='/user/blocked/account']", 0
+ assert_select "a[href='/user/blocked/blocks']", 1
+ assert_select "a[href='/user/blocked/blocks_by']", 0
+ assert_select "a[href='/blocks/new/blocked']", 0
end
# Test a moderator who has applied blocks
get :view, {:display_name => "moderator"}
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^=/user/moderator/history]", 1
- assert_select "a[href=/user/moderator/traces]", 1
- assert_select "a[href=/user/moderator/diary]", 1
- assert_select "a[href=/user/moderator/diary/comments]", 1
- assert_select "a[href=/user/moderator/account]", 0
- assert_select "a[href=/user/moderator/blocks]", 0
- assert_select "a[href=/user/moderator/blocks_by]", 1
- assert_select "a[href=/blocks/new/moderator]", 0
+ assert_select "a[href^='/user/moderator/history']", 1
+ assert_select "a[href='/user/moderator/traces']", 1
+ assert_select "a[href='/user/moderator/diary']", 1
+ assert_select "a[href='/user/moderator/diary/comments']", 1
+ assert_select "a[href='/user/moderator/account']", 0
+ assert_select "a[href='/user/moderator/blocks']", 0
+ assert_select "a[href='/user/moderator/blocks_by']", 1
+ assert_select "a[href='/blocks/new/moderator']", 0
end
# Login as a normal user
get :view, {:display_name => "test"}
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^=/user/test/history]", 1
- assert_select "a[href=/traces/mine]", 1
- assert_select "a[href=/user/test/diary]", 1
- assert_select "a[href=/user/test/diary/comments]", 1
- assert_select "a[href=/user/test/account]", 1
- assert_select "a[href=/user/test/blocks]", 0
- assert_select "a[href=/user/test/blocks_by]", 0
- assert_select "a[href=/blocks/new/test]", 0
+ assert_select "a[href^='/user/test/history']", 1
+ assert_select "a[href='/traces/mine']", 1
+ assert_select "a[href='/user/test/diary']", 1
+ assert_select "a[href='/user/test/diary/comments']", 1
+ assert_select "a[href='/user/test/account']", 1
+ assert_select "a[href='/user/test/blocks']", 0
+ assert_select "a[href='/user/test/blocks_by']", 0
+ assert_select "a[href='/blocks/new/test']", 0
end
# Login as a moderator
get :view, {:display_name => "test"}
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^=/user/test/history]", 1
- assert_select "a[href=/user/test/traces]", 1
- assert_select "a[href=/user/test/diary]", 1
- assert_select "a[href=/user/test/diary/comments]", 1
- assert_select "a[href=/user/test/account]", 0
- assert_select "a[href=/user/test/blocks]", 0
- assert_select "a[href=/user/test/blocks_by]", 0
- assert_select "a[href=/blocks/new/test]", 1
+ assert_select "a[href^='/user/test/history']", 1
+ assert_select "a[href='/user/test/traces']", 1
+ assert_select "a[href='/user/test/diary']", 1
+ assert_select "a[href='/user/test/diary/comments']", 1
+ assert_select "a[href='/user/test/account']", 0
+ assert_select "a[href='/user/test/blocks']", 0
+ assert_select "a[href='/user/test/blocks_by']", 0
+ assert_select "a[href='/blocks/new/test']", 1
end
end
# check the data that is returned
assert_select "description", :count => 1, :text => "test"
assert_select "contributor-terms", :count => 1 do
- assert_select "[agreed=true]"
+ assert_select "[agreed='true']"
end
assert_select "img", :count => 1
assert_select "roles", :count => 1 do
assert_select "role", :count => 0
end
assert_select "changesets", :count => 1 do
- assert_select "[count=0]"
+ assert_select "[count='0']"
end
assert_select "traces", :count => 1 do
- assert_select "[count=0]"
+ assert_select "[count='0']"
end
assert_select "blocks", :count => 1 do
assert_select "received", :count => 1 do
- assert_select "[count=0][active=0]"
+ assert_select "[count='0'][active='0']"
end
assert_select "issued", :count => 0
end
# check the data that is returned
assert_select "description", :count => 1, :text => "test"
assert_select "contributor-terms", :count => 1 do
- assert_select "[agreed=true][pd=false]"
+ assert_select "[agreed='true'][pd='false']"
end
assert_select "img", :count => 1
assert_select "roles", :count => 1 do
assert_select "role", :count => 0
end
assert_select "changesets", :count => 1 do
- assert_select "[count=0]", :count => 1
+ assert_select "[count='0']", :count => 1
end
assert_select "traces", :count => 1 do
- assert_select "[count=0]", :count => 1
+ assert_select "[count='0']", :count => 1
end
assert_select "blocks", :count => 1 do
assert_select "received", :count => 1 do
- assert_select "[count=0][active=0]"
+ assert_select "[count='0'][active='0']"
end
assert_select "issued", :count => 0
end
assert_select "home", :count => 1 do
- assert_select "[lat=12.1][lon=12.1][zoom=3]"
+ assert_select "[lat='12.1'][lon='12.1'][zoom='3']"
end
assert_select "languages", :count => 1 do
assert_select "lang", :count => 1, :text => "en"
end
assert_select "messages", :count => 1 do
assert_select "received", :count => 1 do
- assert_select "[count=1][unread=0]"
+ assert_select "[count='1'][unread='0']"
end
assert_select "sent", :count => 1 do
- assert_select "[count=1]"
+ assert_select "[count='1']"
end
end
end
assert_response :success
assert_template :make_friend
assert_select "form" do
- assert_select "input[type=hidden][name=referer]", 0
- assert_select "input[type=submit]", 1
+ assert_select "input[type='hidden'][name='referer']", 0
+ assert_select "input[type='submit']", 1
end
assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
assert_response :success
assert_template :make_friend
assert_select "form" do
- assert_select "input[type=hidden][name=referer][value=/test]", 1
- assert_select "input[type=submit]", 1
+ assert_select "input[type='hidden'][name='referer'][value='/test']", 1
+ assert_select "input[type='submit']", 1
end
assert_nil Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
# When logged in a POST should add the friendship
- post :make_friend, {:display_name => friend.display_name}, {"user" => user}
+ assert_difference('ActionMailer::Base.deliveries.size', 1) do
+ post :make_friend, {:display_name => friend.display_name}, {"user" => user}
+ end
assert_redirected_to user_path(:display_name => friend.display_name)
assert_match /is now your friend/, flash[:notice]
assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
+ email = ActionMailer::Base.deliveries.first
+ assert_equal 1, email.to.count
+ assert_equal friend.email, email.to.first
+ ActionMailer::Base.deliveries.clear
# A second POST should report that the friendship already exists
- post :make_friend, {:display_name => friend.display_name}, {"user" => user}
+ assert_no_difference('ActionMailer::Base.deliveries.size') do
+ post :make_friend, {:display_name => friend.display_name}, {"user" => user}
+ end
assert_redirected_to user_path(:display_name => friend.display_name)
assert_match /You are already friends with/, flash[:warning]
assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
assert_response :success
assert_template :remove_friend
assert_select "form" do
- assert_select "input[type=hidden][name=referer]", 0
- assert_select "input[type=submit]", 1
+ assert_select "input[type='hidden'][name='referer']", 0
+ assert_select "input[type='submit']", 1
end
assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first
assert_response :success
assert_template :remove_friend
assert_select "form" do
- assert_select "input[type=hidden][name=referer][value=/test]", 1
- assert_select "input[type=submit]", 1
+ assert_select "input[type='hidden'][name='referer'][value='/test']", 1
+ assert_select "input[type='submit']", 1
end
assert Friend.where(:user_id => user.id, :friend_user_id => friend.id).first