]> source.dussan.org Git - redmine.git/commitdiff
Adds a few tests.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 3 Dec 2014 20:21:03 +0000 (20:21 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 3 Dec 2014 20:21:03 +0000 (20:21 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13695 e93f8b46-1217-0410-a6f0-8f06a7374b81

test/functional/issues_controller_test.rb
test/functional/projects_controller_test.rb
test/functional/users_controller_test.rb
test/functional/wiki_controller_test.rb
test/functional/workflows_controller_test.rb
test/integration/api_test/users_test.rb
test/unit/group_test.rb
test/unit/project_test.rb
test/unit/version_test.rb

index 2eccb90745c9e780e6bcfc7e530afd6aa559eb9e..876a63732cdf1a72272784dde44b3b3e0c1f7949 100644 (file)
@@ -1741,6 +1741,12 @@ class IssuesControllerTest < ActionController::TestCase
     assert_select_error /No tracker/
   end
 
+  def test_new_with_invalid_project_id
+    @request.session[:user_id] = 1
+    get :new, :project_id => 'invalid'
+    assert_response 404
+  end
+
   def test_update_form_for_new_issue
     @request.session[:user_id] = 2
     xhr :post, :update_form, :project_id => 1,
@@ -4032,6 +4038,19 @@ class IssuesControllerTest < ActionController::TestCase
     assert_equal 2, TimeEntry.find(2).issue_id
   end
 
+  def test_destroy_issues_and_reassign_time_entries_to_an_invalid_issue_should_fail
+    @request.session[:user_id] = 2
+
+    assert_no_difference 'Issue.count' do
+      assert_no_difference 'TimeEntry.count' do
+        # try to reassign time to an issue of another project
+        delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 4
+      end
+    end
+    assert_response :success
+    assert_template 'destroy'
+  end
+
   def test_destroy_issues_from_different_projects
     @request.session[:user_id] = 2
 
index 4a7f0d498ea8308aad34cfd3d7f110aede991e95..83fcf160ed3cc57bda026a14d44cd2c3319c8223 100644 (file)
@@ -75,6 +75,14 @@ class ProjectsControllerTest < ActionController::TestCase
     assert_select 'a[href=?]', '/time_entries', 0
   end
 
+  test "#index by non-admin user with permission should show add project link" do
+    Role.find(1).add_permission! :add_project
+    @request.session[:user_id] = 2
+    get :index
+    assert_template 'index'
+    assert_select 'a[href=?]', '/projects/new'
+  end
+
   test "#new by admin user should accept get" do
     @request.session[:user_id] = 1
 
index 3306e2fadb7318740b2705242e85c7371e4e486c..56a0292f607252d041ac5bedf1a348cc84aa2e63 100644 (file)
@@ -239,6 +239,17 @@ class UsersControllerTest < ActionController::TestCase
     assert user.check_password?(password)
   end
 
+  def test_create_and_continue
+    post :create, :user => {
+        :login => 'randompass',
+        :firstname => 'Random',
+        :lastname => 'Pass',
+        :mail => 'randompass@example.net',
+        :generate_password => '1'
+      }, :continue => '1'
+    assert_redirected_to '/users/new?user%5Bgenerate_password%5D=1'
+  end
+
   def test_create_with_failure
     assert_no_difference 'User.count' do
       post :create, :user => {}
index ebebf343d29e5d4abf9c265e794aefdc63326165..5e1b190341c96782a5b2915ca2d9402b4aeaaa43 100644 (file)
@@ -320,12 +320,14 @@ class WikiControllerTest < ActionController::TestCase
             :id => 'Another_page',
             :content => {
               :comments => 'a' * 300,  # failure here, comment is too long
-              :text => 'edited',
-              :version => 1
+              :text => 'edited'
+            },
+            :wiki_page => {
+              :parent_id => ""
             }
-          end
         end
       end
+    end
     assert_response :success
     assert_template 'edit'
 
index 10d68bf159c53c0d1a5cef9241fdd45975ded7c7..7a21972cbdcb1388397a67e1ea2458fc51d2d650 100644 (file)
@@ -61,6 +61,13 @@ class WorkflowsControllerTest < ActionController::TestCase
     assert_select 'input[type=checkbox][name=?]', 'transitions[1][1][always]', 0
   end
 
+  def test_get_edit_with_all_roles_and_all_trackers
+    get :edit, :role_id => 'all', :tracker_id => 'all'
+    assert_response :success
+    assert_equal Role.sorted.to_a, assigns(:roles)
+    assert_equal Tracker.sorted.to_a, assigns(:trackers)
+  end
+
   def test_get_edit_with_role_and_tracker_and_all_statuses
     WorkflowTransition.delete_all
 
index 22b6abeff3087846e50c2ad4730f55caabba8617..beadc54c61ce4265fddd18a40e9542b4a3fb3c42 100644 (file)
@@ -20,6 +20,26 @@ require File.expand_path('../../../test_helper', __FILE__)
 class Redmine::ApiTest::UsersTest < Redmine::ApiTest::Base
   fixtures :users, :members, :member_roles, :roles, :projects
 
+  test "GET /users.xml should return users" do
+    get '/users.xml', {}, credentials('admin')
+
+    assert_response :success
+    assert_equal 'application/xml', response.content_type
+    assert_select 'users' do
+      assert_select 'user', assigns(:users).size
+    end
+  end
+
+  test "GET /users.json should return users" do
+    get '/users.json', {}, credentials('admin')
+
+    assert_response :success
+    assert_equal 'application/json', response.content_type
+    json = ActiveSupport::JSON.decode(response.body)
+    assert json.key?('users')
+    assert_equal assigns(:users).size, json['users'].size
+  end
+
   test "GET /users/:id.xml should return the user" do
     get '/users/2.xml'
 
index d2f09f9a73d5e9c792e229b0f5c1b1d6654c8f80..6989680ec42c92d45b45220e8aa040a8f2f2e2dc 100644 (file)
@@ -132,4 +132,30 @@ class GroupTest < ActiveSupport::TestCase
 
     assert_equal nil, Issue.find(1).assigned_to_id
   end
+
+  def test_builtin_groups_should_be_created_if_missing
+    Group.delete_all
+
+    assert_difference 'Group.count', 2 do
+      group = Group.anonymous
+      assert_equal GroupAnonymous, group.class
+
+      group = Group.non_member
+      assert_equal GroupNonMember, group.class
+    end
+  end
+
+  def test_builtin_in_group_should_be_uniq
+    group = GroupAnonymous.new
+    group.name = 'Foo'
+    assert !group.save
+  end
+
+  def test_builtin_in_group_should_not_accept_users
+    group = Group.anonymous
+    assert_raise RuntimeError do
+      group.users << User.find(1)
+    end
+    assert_equal 0, group.reload.users.count
+  end
 end
index 4723b4638c26ca4eccc35d0699e4e7e724a2f3fa..02bcfccbddb297c291d99b6ec17b1eaca28321f0 100644 (file)
@@ -647,6 +647,12 @@ class ProjectTest < ActiveSupport::TestCase
     end
   end
 
+  def test_enabled_modules_names_with_nil_should_clear_modules
+    p = Project.find(1)
+    p.enabled_module_names = nil
+    assert_equal [], p.enabled_modules
+  end
+
   test "enabled_modules should define module by names and preserve ids" do
     @project = Project.find(1)
     # Remove one module
@@ -947,4 +953,23 @@ class ProjectTest < ActiveSupport::TestCase
     assert_equal [Role.anonymous], project.override_roles(Role.anonymous)
     assert_equal [Role.non_member], project.override_roles(Role.non_member)
   end
+
+  def test_css_classes
+    p = Project.new
+    assert_kind_of String, p.css_classes
+    assert_not_include 'archived', p.css_classes.split
+    assert_not_include 'closed', p.css_classes.split
+  end
+
+  def test_css_classes_for_archived_project
+    p = Project.new
+    p.status = Project::STATUS_ARCHIVED
+    assert_include 'archived', p.css_classes.split
+  end
+
+  def test_css_classes_for_closed_project
+    p = Project.new
+    p.status = Project::STATUS_CLOSED
+    assert_include 'closed', p.css_classes.split
+  end
 end
index a1dddd905598e28c247d50f0d9d640111c24fc41..85c1079d56be9e290a25993a3763496d6c12c38b 100644 (file)
@@ -127,6 +127,12 @@ class VersionTest < ActiveSupport::TestCase
     assert_equal [v5, v3, v1, v2, v4], Version.sorted.to_a
   end
 
+  def test_should_sort_versions_with_same_date_by_name
+    v1 = Version.new(:effective_date => '2014-12-03', :name => 'v2')
+    v2 = Version.new(:effective_date => '2014-12-03', :name => 'v1')
+    assert_equal [v2, v1], [v1, v2].sort
+  end
+
   def test_completed_should_be_false_when_due_today
     version = Version.create!(:project_id => 1, :effective_date => Date.today, :name => 'Due today')
     assert_equal false, version.completed?