diff test/functional/users_controller_test.rb @ 38:33d69fee1d99 cannam

* Merge SVN update from default branch
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Fri, 19 Nov 2010 13:41:40 +0000
parents 94944d00e43c
children af80e5618e9b
line wrap: on
line diff
--- a/test/functional/users_controller_test.rb	Fri Oct 01 15:33:14 2010 +0100
+++ b/test/functional/users_controller_test.rb	Fri Nov 19 13:41:40 2010 +0000
@@ -24,7 +24,7 @@
 class UsersControllerTest < ActionController::TestCase
   include Redmine::I18n
   
-  fixtures :users, :projects, :members, :member_roles, :roles
+  fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values
   
   def setup
     @controller = UsersController.new
@@ -65,6 +65,19 @@
     assert_response :success
     assert_template 'show'
     assert_not_nil assigns(:user)
+    
+    assert_tag 'li', :content => /Phone number/
+  end
+  
+  def test_show_should_not_display_hidden_custom_fields
+    @request.session[:user_id] = nil
+    UserCustomField.find_by_name('Phone number').update_attribute :visible, false
+    get :show, :id => 2
+    assert_response :success
+    assert_template 'show'
+    assert_not_nil assigns(:user)
+    
+    assert_no_tag 'li', :content => /Phone number/
   end
 
   def test_show_should_not_fail_when_custom_values_are_nil
@@ -107,14 +120,65 @@
     assert project_ids.include?(2) #private project admin can see
   end
 
-  def test_edit
+  context "GET :new" do
+    setup do
+      get :new
+    end
+
+    should_assign_to :user
+    should_respond_with :success
+    should_render_template :new
+  end
+
+  context "POST :create" do
+    context "when successful" do
+      setup do
+        post :create, :user => {
+          :firstname => 'John',
+          :lastname => 'Doe',
+          :login => 'jdoe',
+          :password => 'test',
+          :password_confirmation => 'test',
+          :mail => 'jdoe@gmail.com'
+        },
+        :notification_option => 'none'
+      end
+
+      should_assign_to :user
+      should_respond_with :redirect
+      should_redirect_to('user edit') { {:controller => 'users', :action => 'edit', :id => User.find_by_login('jdoe')}}
+
+      should 'set the users mail notification' do
+        user = User.last
+        assert_equal 'none', user.mail_notification
+      end
+    end
+
+    context "when unsuccessful" do
+      setup do
+        post :create, :user => {}
+      end
+
+      should_assign_to :user
+      should_respond_with :success
+      should_render_template :new
+    end
+
+  end
+
+  def test_update
     ActionMailer::Base.deliveries.clear
-    post :edit, :id => 2, :user => {:firstname => 'Changed'}
-    assert_equal 'Changed', User.find(2).firstname
+    put :update, :id => 2, :user => {:firstname => 'Changed'}, :notification_option => 'all', :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
+
+    user = User.find(2)
+    assert_equal 'Changed', user.firstname
+    assert_equal 'all', user.mail_notification
+    assert_equal true, user.pref[:hide_mail]
+    assert_equal 'desc', user.pref[:comments_sorting]
     assert ActionMailer::Base.deliveries.empty?
   end
   
-  def test_edit_with_activation_should_send_a_notification
+  def test_update_with_activation_should_send_a_notification
     u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
     u.login = 'foo'
     u.status = User::STATUS_REGISTERED
@@ -122,7 +186,7 @@
     ActionMailer::Base.deliveries.clear
     Setting.bcc_recipients = '1'
     
-    post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
+    put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
     assert u.reload.active?
     mail = ActionMailer::Base.deliveries.last
     assert_not_nil mail
@@ -130,12 +194,12 @@
     assert mail.body.include?(ll('fr', :notice_account_activated))
   end
   
-  def test_edit_with_password_change_should_send_a_notification
+  def test_updat_with_password_change_should_send_a_notification
     ActionMailer::Base.deliveries.clear
     Setting.bcc_recipients = '1'
     
     u = User.find(2)
-    post :edit, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1'
+    put :update, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1'
     assert_equal User.hash_password('newpass'), u.reload.hashed_password 
     
     mail = ActionMailer::Base.deliveries.last
@@ -144,13 +208,13 @@
     assert mail.body.include?('newpass')
   end
 
-  test "POST :edit with a password change to an AuthSource user switching to Internal authentication" do
+  test "put :update with a password change to an AuthSource user switching to Internal authentication" do
     # Configure as auth source
     u = User.find(2)
     u.auth_source = AuthSource.find(1)
     u.save!
 
-    post :edit, :id => u.id, :user => {:auth_source_id => ''}, :password => 'newpass', :password_confirmation => 'newpass'
+    put :update, :id => u.id, :user => {:auth_source_id => ''}, :password => 'newpass', :password_confirmation => 'newpass'
 
     assert_equal nil, u.reload.auth_source
     assert_equal User.hash_password('newpass'), u.reload.hashed_password