end
end
+ def test_new_view_logged_in
+ session[:user] = users(:normal_user).id
+
+ get :new
+ assert_response :redirect
+ assert_redirected_to user_new_path(:cookie_test => "true")
+ get :new, :cookie_test => "true"
+ assert_response :redirect
+ assert_redirected_to root_path
+
+ get :new, :referer => "/test"
+ assert_response :redirect
+ assert_redirected_to user_new_path(:referer => "/test", :cookie_test => "true")
+ get :new, :referer => "/test", :cookie_test => "true"
+ assert_response :redirect
+ assert_redirected_to "/test"
+ end
+
def test_new_success
user = new_user
assert_redirected_to "/test"
end
+ def test_logout_with_token
+ token = users(:normal_user).tokens.create
+
+ session[:token] = token.token
+
+ get :logout
+ assert_response :success
+ assert_template :logout
+ assert_select "input[name=referer][value=?]", ""
+ assert_equal token.token, session[:token]
+ assert_not_nil UserToken.where(:id => token.id).first
+
+ session_id = assert_select("input[name=session]").first["value"]
+
+ get :logout, :session => session_id
+ assert_response :redirect
+ assert_redirected_to root_path
+ assert_nil session[:token]
+ assert_nil UserToken.where(:id => token.id).first
+ end
+
def test_confirm_get
user = users(:inactive_user)
confirm_string = user.tokens.create.token
end
def test_confirm_resend_success
+ session[:token] = users(:inactive_user).tokens.create.token
+
assert_difference "ActionMailer::Base.deliveries.size", 1 do
get :confirm_resend, :display_name => users(:inactive_user).display_name
end
ActionMailer::Base.deliveries.clear
end
- def test_confirm_resend_failure
+ def test_confirm_resend_no_token
+ assert_no_difference "ActionMailer::Base.deliveries.size" do
+ get :confirm_resend, :display_name => users(:inactive_user).display_name
+ end
+
+ assert_response :redirect
+ assert_redirected_to login_path
+ assert_match "User Inactive User not found.", flash[:error]
+ end
+
+ def test_confirm_resend_unknown_user
assert_no_difference "ActionMailer::Base.deliveries.size" do
get :confirm_resend, :display_name => "No Such User"
end
def test_terms_seen
user = users(:normal_user)
- get :terms, {}, { :user => user }
+ session[:user] = user.id
+
+ get :terms
+ assert_response :redirect
+ assert_redirected_to :action => :account, :display_name => user.display_name
+ end
+
+ def test_terms_not_seen_without_referer
+ user = users(:terms_not_seen_user)
+
+ session[:user] = user.id
+
+ get :terms
+ assert_response :success
+ assert_template :terms
+
+ post :save, :user => { :consider_pd => true }
assert_response :redirect
assert_redirected_to :action => :account, :display_name => user.display_name
+ assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
+
+ user.reload
+
+ assert_equal true, user.consider_pd
+ assert_not_nil user.terms_agreed
+ assert_equal true, user.terms_seen
end
- def test_terms_not_seen
+ def test_terms_not_seen_with_referer
user = users(:terms_not_seen_user)
- get :terms, {}, { :user => user }
+ session[:user] = user.id
+
+ get :terms, :referer => "/test"
assert_response :success
assert_template :terms
+
+ post :save, :user => { :consider_pd => true }, :referer => "/test"
+ assert_response :redirect
+ assert_redirected_to "/test"
+ assert_equal "Thanks for accepting the new contributor terms!", flash[:notice]
+
+ user.reload
+
+ assert_equal true, user.consider_pd
+ assert_not_nil user.terms_agreed
+ assert_equal true, user.terms_seen
end
def test_go_public
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > fieldset > div.form-row.accountImage input[name=image_action][checked]", false
+ # Adding external authentication should redirect to the auth provider
+ post :account, { :display_name => user.display_name, :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }, { :user => user.id }
+ assert_response :redirect
+ assert_redirected_to auth_path(:provider => "openid", :openid_url => "https://www.google.com/accounts/o8/id", :origin => "/user/#{user.display_name}/account")
+
# Changing name to one that exists should fail
new_attributes = user.attributes.dup.merge(:display_name => users(:public_user).display_name)
post :account, { :display_name => user.display_name, :user => new_attributes }, { :user => user.id }
get :list, :page => 3
assert_response :success
assert_template :list
- assert_select "table#user_list tr", :count => 19
+ assert_select "table#user_list tr", :count => 22
end
def test_list_post_confirm