]> source.dussan.org Git - redmine.git/commitdiff
UsersController tests cleanup.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 12 Dec 2010 15:34:35 +0000 (15:34 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 12 Dec 2010 15:34:35 +0000 (15:34 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4501 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/functional/users_controller_test.rb

index d8493740d76d53d046fa5f3212368298c25db0d7..dbc4dba46fc0d6f2fbfda9d9cd3555706798a434 100644 (file)
@@ -119,55 +119,13 @@ class UsersControllerTest < ActionController::TestCase
     project_ids = memberships.map(&:project_id)
     assert project_ids.include?(2) #private project admin can see
   end
-
-  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',
-          :mail_notification => '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
-      
-      should 'set the password' do
-        user = User.first(:order => 'id DESC')
-        assert user.check_password?('test')
-      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
+  
+  def test_new
+    get :new
+    
+    assert_response :success
+    assert_template :new
+    assert assigns(:user)
   end
   
   def test_create
@@ -204,6 +162,23 @@ class UsersControllerTest < ActionController::TestCase
     assert_equal [user.mail], mail.bcc
     assert mail.body.include?('secret')
   end
+  
+  def test_create_with_failure
+    assert_no_difference 'User.count' do
+      post :create, :user => {}
+    end
+    
+    assert_response :success
+    assert_template 'new'
+  end
+
+  def test_edit
+    get :edit, :id => 2
+    
+    assert_response :success
+    assert_template 'edit'
+    assert_equal User.find(2), assigns(:user)
+  end
 
   def test_update
     ActionMailer::Base.deliveries.clear
@@ -216,6 +191,15 @@ class UsersControllerTest < ActionController::TestCase
     assert_equal 'desc', user.pref[:comments_sorting]
     assert ActionMailer::Base.deliveries.empty?
   end
+
+  def test_update_with_failure
+    assert_no_difference 'User.count' do
+      put :update, :id => 2, :user => {:firstname => ''}
+    end
+    
+    assert_response :success
+    assert_template 'edit'
+  end
   
   def test_update_with_group_ids_should_assign_groups
     put :update, :id => 2, :user => {:group_ids => ['10']}