- # Removing the image should work
- post :account, :params => { :display_name => user.display_name, :avatar_action => "delete", :user => user.attributes }, :session => { :user => user }
- assert_response :success
- assert_template :account
- assert_select "div#errorExplanation", false
- assert_select ".notice", /^User information updated successfully/
- assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked]", false
-
- # 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/#{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)
- post :account, :params => { :display_name => user.display_name, :user => new_attributes }, :session => { :user => user }
- assert_response :success
- assert_template :account
- assert_select ".notice", false
- assert_select "div#errorExplanation"
- assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_display_name"
-
- # Changing name to one that exists should fail, regardless of case
- new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name.upcase)
- post :account, :params => { :display_name => user.display_name, :user => new_attributes }, :session => { :user => user }
- assert_response :success
- assert_template :account
- assert_select ".notice", false
- assert_select "div#errorExplanation"
- assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_display_name"
-
- # Changing name to one that doesn't exist should work
- new_attributes = user.attributes.dup.merge(:display_name => "new tester")
- post :account, :params => { :display_name => user.display_name, :user => new_attributes }, :session => { :user => user }
- assert_response :success
- assert_template :account
- assert_select "div#errorExplanation", false
- assert_select ".notice", /^User information updated successfully/
- assert_select "form#accountForm > fieldset > div.standard-form-row > input#user_display_name[value=?]", "new tester"
-
- # Record the change of name
- user.display_name = "new tester"
-
- # Changing email to one that exists should fail
- user.new_email = create(:user).email
- assert_no_difference "ActionMailer::Base.deliveries.size" do
- perform_enqueued_jobs do
- post :account, :params => { :display_name => user.display_name, :user => user.attributes }, :session => { :user => user }
- end
- end
- assert_response :success
- assert_template :account
- assert_select ".notice", false
- assert_select "div#errorExplanation"
- assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_new_email"
-
- # Changing email to one that exists should fail, regardless of case
- user.new_email = create(:user).email.upcase
- assert_no_difference "ActionMailer::Base.deliveries.size" do
- perform_enqueued_jobs do
- post :account, :params => { :display_name => user.display_name, :user => user.attributes }, :session => { :user => user }
- end
- end
- assert_response :success
- assert_template :account
- assert_select ".notice", false
- assert_select "div#errorExplanation"
- assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_new_email"
-
- # Changing email to one that doesn't exist should work
- user.new_email = "new_tester@example.com"
- assert_difference "ActionMailer::Base.deliveries.size", 1 do
- perform_enqueued_jobs do
- post :account, :params => { :display_name => user.display_name, :user => user.attributes }, :session => { :user => user }
- end
- 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.standard-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