stub_gravatar_request(user.new_email, 200)
confirm_string = user.tokens.create.token
# precondition gravatar should be turned off
- assert !user.image_use_gravatar
+ assert_not user.image_use_gravatar
post :confirm_email, :params => { :confirm_string => confirm_string }
assert_response :redirect
assert_redirected_to :action => :account, :display_name => user.display_name
assert_redirected_to :action => :account, :display_name => user.display_name
assert_match /Confirmed your change of email address/, flash[:notice]
# gravatar use should now be disabled
- assert !User.find(user.id).image_use_gravatar
+ assert_not User.find(user.id).image_use_gravatar
end
def test_terms_new_user
assert_response :success
assert_template :reset_password
+ # Test that errors are reported for erroneous submissions
+ post :reset_password, :params => { :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "different_password" } }
+ assert_response :success
+ assert_template :reset_password
+ assert_select "div#errorExplanation"
+
# Test setting a new password
post :reset_password, :params => { :token => token.token, :user => { :pass_crypt => "new_password", :pass_crypt_confirmation => "new_password" } }
assert_response :redirect
# you are not logged in
get :account, :params => { :display_name => user.display_name }
assert_response :redirect
- assert_redirected_to :controller => :user, :action => "login", :referer => "/user/#{URI.encode(user.display_name)}/account"
+ assert_redirected_to :controller => :user, :action => "login", :referer => "/user/#{ERB::Util.u(user.display_name)}/account"
# Make sure that you are blocked when not logged in as the right user
get :account, :params => { :display_name => user.display_name }, :session => { :user => create(:user) }
get :account, :params => { :display_name => user.display_name }, :session => { :user => user }
assert_response :success
assert_template :account
+ assert_select "form#accountForm" do |form|
+ assert_equal "post", form.attr("method").to_s
+ assert_select "input[name='_method']", false
+ assert_equal "/user/#{ERB::Util.u(user.display_name)}/account", form.attr("action").to_s
+ end
# Updating the description should work
user.description = "new description"
+ user.preferred_editor = "default"
post :account, :params => { :display_name => user.display_name, :user => user.attributes }, :session => { :user => user }
assert_response :success
assert_template :account
# Adding external authentication should redirect to the auth provider
post :account, :params => { :display_name => user.display_name, :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }, :session => { :user => user }
assert_response :redirect
- assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{URI.encode(user.display_name)}/account")
+ assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{ERB::Util.u(user.display_name)}/account")
# Changing name to one that exists should fail
new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name)
get :view, :params => { :display_name => user.display_name }
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^='/user/#{URI.encode(user.display_name)}/history']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/traces']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/diary']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/diary/comments']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/account']", 0
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/blocks']", 0
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/blocks_by']", 0
- assert_select "a[href='/blocks/new/#{URI.encode(user.display_name)}']", 0
+ assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/traces']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 0
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0
+ assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 0
end
# Test a user who has been blocked
get :view, :params => { :display_name => blocked_user.display_name }
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^='/user/#{URI.encode(blocked_user.display_name)}/history']", 1
- assert_select "a[href='/user/#{URI.encode(blocked_user.display_name)}/traces']", 1
- assert_select "a[href='/user/#{URI.encode(blocked_user.display_name)}/diary']", 1
- assert_select "a[href='/user/#{URI.encode(blocked_user.display_name)}/diary/comments']", 1
- assert_select "a[href='/user/#{URI.encode(blocked_user.display_name)}/account']", 0
- assert_select "a[href='/user/#{URI.encode(blocked_user.display_name)}/blocks']", 1
- assert_select "a[href='/user/#{URI.encode(blocked_user.display_name)}/blocks_by']", 0
- assert_select "a[href='/blocks/new/#{URI.encode(blocked_user.display_name)}']", 0
+ assert_select "a[href^='/user/#{ERB::Util.u(blocked_user.display_name)}/history']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/traces']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/diary']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/diary/comments']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/account']", 0
+ assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/blocks']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(blocked_user.display_name)}/blocks_by']", 0
+ assert_select "a[href='/blocks/new/#{ERB::Util.u(blocked_user.display_name)}']", 0
end
# Test a moderator who has applied blocks
get :view, :params => { :display_name => moderator_user.display_name }
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^='/user/#{URI.encode(moderator_user.display_name)}/history']", 1
- assert_select "a[href='/user/#{URI.encode(moderator_user.display_name)}/traces']", 1
- assert_select "a[href='/user/#{URI.encode(moderator_user.display_name)}/diary']", 1
- assert_select "a[href='/user/#{URI.encode(moderator_user.display_name)}/diary/comments']", 1
- assert_select "a[href='/user/#{URI.encode(moderator_user.display_name)}/account']", 0
- assert_select "a[href='/user/#{URI.encode(moderator_user.display_name)}/blocks']", 0
- assert_select "a[href='/user/#{URI.encode(moderator_user.display_name)}/blocks_by']", 1
- assert_select "a[href='/blocks/new/#{URI.encode(moderator_user.display_name)}']", 0
+ assert_select "a[href^='/user/#{ERB::Util.u(moderator_user.display_name)}/history']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/traces']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/diary']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/diary/comments']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/account']", 0
+ assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/blocks']", 0
+ assert_select "a[href='/user/#{ERB::Util.u(moderator_user.display_name)}/blocks_by']", 1
+ assert_select "a[href='/blocks/new/#{ERB::Util.u(moderator_user.display_name)}']", 0
end
# Login as a normal user
get :view, :params => { :display_name => user.display_name }
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^='/user/#{URI.encode(user.display_name)}/history']", 1
+ assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1
assert_select "a[href='/traces/mine']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/diary']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/diary/comments']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/account']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/blocks']", 0
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/blocks_by']", 0
- assert_select "a[href='/blocks/new/#{URI.encode(user.display_name)}']", 0
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0
+ assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 0
end
# Login as a moderator
get :view, :params => { :display_name => user.display_name }
assert_response :success
assert_select "div#userinformation" do
- assert_select "a[href^='/user/#{URI.encode(user.display_name)}/history']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/traces']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/diary']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/diary/comments']", 1
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/account']", 0
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/blocks']", 0
- assert_select "a[href='/user/#{URI.encode(user.display_name)}/blocks_by']", 0
- assert_select "a[href='/blocks/new/#{URI.encode(user.display_name)}']", 1
+ assert_select "a[href^='/user/#{ERB::Util.u(user.display_name)}/history']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/traces']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/diary/comments']", 1
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/account']", 0
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks']", 0
+ assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/blocks_by']", 0
+ assert_select "a[href='/blocks/new/#{ERB::Util.u(user.display_name)}']", 1
+ end
+ end
+
+ # Test whether information about contributor terms is shown for users who haven't agreed
+ def test_terms_not_agreed
+ agreed_user = create(:user, :terms_agreed => 3.days.ago)
+ seen_user = create(:user, :terms_seen => true)
+ not_seen_user = create(:user, :terms_seen => false)
+
+ get :view, :params => { :display_name => agreed_user.display_name }
+ assert_response :success
+ assert_select "div#userinformation" do
+ assert_select "p", :count => 0, :text => /Contributor terms/
+ end
+
+ get :view, :params => { :display_name => seen_user.display_name }
+ assert_response :success
+ # put @response.body
+ assert_select "div#userinformation" do
+ assert_select "p", :count => 1, :text => /Contributor terms/
+ assert_select "p", /Declined/
+ end
+
+ get :view, :params => { :display_name => not_seen_user.display_name }
+ assert_response :success
+ assert_select "div#userinformation" do
+ assert_select "p", :count => 1, :text => /Contributor terms/
+ assert_select "p", /Undecided/
end
end
assert_response :unauthorized
# check that we get a response when logged in
- basic_authorization(user.email, "test")
+ basic_authorization user.email, "test"
get :api_details
assert_response :success
assert_equal "text/xml", response.content_type
assert_response :unauthorized
# check that we get a response when logged in
- basic_authorization(user.email, "test")
+ basic_authorization user.email, "test"
get :api_gpx_files
assert_response :success
assert_equal "application/xml", response.content_type
post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
end
assert_response :redirect
- assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
+ assert_redirected_to :action => :login, :referer => users_path
assert_equal "pending", inactive_user.reload.status
assert_equal "suspended", suspended_user.reload.status
post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
end
assert_response :redirect
- assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
+ assert_redirected_to :action => :login, :referer => users_path
assert_equal "pending", inactive_user.reload.status
assert_equal "suspended", suspended_user.reload.status
post :list, :params => { :confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 } }
end
assert_response :redirect
- assert_redirected_to :action => :login, :referer => users_path(:confirm => 1, :user => { inactive_user.id => 1, suspended_user.id => 1 })
+ assert_redirected_to :action => :login, :referer => users_path
assert_equal "pending", inactive_user.reload.status
assert_equal "suspended", suspended_user.reload.status
post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
end
assert_response :redirect
- assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
+ assert_redirected_to :action => :login, :referer => users_path
assert_equal "active", normal_user.reload.status
assert_equal "confirmed", confirmed_user.reload.status
post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
end
assert_response :redirect
- assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
+ assert_redirected_to :action => :login, :referer => users_path
assert_equal "active", normal_user.reload.status
assert_equal "confirmed", confirmed_user.reload.status
post :list, :params => { :hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 } }
end
assert_response :redirect
- assert_redirected_to :action => :login, :referer => users_path(:hide => 1, :user => { normal_user.id => 1, confirmed_user.id => 1 })
+ assert_redirected_to :action => :login, :referer => users_path
assert_equal "active", normal_user.reload.status
assert_equal "confirmed", confirmed_user.reload.status