diff test/functional/custom_fields_controller_test.rb @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 433d4f72a19b
children e248c7af89ec
line wrap: on
line diff
--- a/test/functional/custom_fields_controller_test.rb	Fri Jun 14 09:05:06 2013 +0100
+++ b/test/functional/custom_fields_controller_test.rb	Tue Jan 14 14:37:42 2014 +0000
@@ -1,5 +1,5 @@
 # Redmine - project management software
-# Copyright (C) 2006-2012  Jean-Philippe Lang
+# Copyright (C) 2006-2013  Jean-Philippe Lang
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -18,7 +18,7 @@
 require File.expand_path('../../test_helper', __FILE__)
 
 class CustomFieldsControllerTest < ActionController::TestCase
-  fixtures :custom_fields, :custom_values, :trackers, :users
+  fixtures :custom_fields, :custom_values, :trackers, :users, :projects
 
   def setup
     @request.session[:user_id] = 1
@@ -52,10 +52,46 @@
         assert_select 'option[value=user]', :text => 'User'
         assert_select 'option[value=version]', :text => 'Version'
       end
+      assert_select 'input[type=checkbox][name=?]', 'custom_field[project_ids][]', Project.count
+      assert_select 'input[type=hidden][name=?]', 'custom_field[project_ids][]', 1
       assert_select 'input[type=hidden][name=type][value=IssueCustomField]'
     end
   end
 
+  def test_new_time_entry_custom_field_should_not_show_trackers_and_projects
+    get :new, :type => 'TimeEntryCustomField'
+    assert_response :success
+    assert_template 'new'
+    assert_select 'form#custom_field_form' do
+      assert_select 'input[name=?]', 'custom_field[tracker_ids][]', 0
+      assert_select 'input[name=?]', 'custom_field[project_ids][]', 0
+    end
+  end
+
+  def test_default_value_should_be_an_input_for_string_custom_field
+    get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'string'}
+    assert_response :success
+    assert_select 'input[name=?]', 'custom_field[default_value]'
+  end
+
+  def test_default_value_should_be_a_textarea_for_text_custom_field
+    get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'text'}
+    assert_response :success
+    assert_select 'textarea[name=?]', 'custom_field[default_value]'
+  end
+
+  def test_default_value_should_be_a_checkbox_for_bool_custom_field
+    get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'bool'}
+    assert_response :success
+    assert_select 'input[name=?][type=checkbox]', 'custom_field[default_value]'
+  end
+
+  def test_default_value_should_not_be_present_for_user_custom_field
+    get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'user'}
+    assert_response :success
+    assert_select '[name=?]', 'custom_field[default_value]', 0
+  end
+
   def test_new_js
     get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'list'}, :format => 'js'
     assert_response :success
@@ -94,6 +130,17 @@
     assert_equal 1, field.trackers.size
   end
 
+  def test_create_with_project_ids
+    assert_difference 'CustomField.count' do
+      post :create, :type => "IssueCustomField", :custom_field => {
+        :name => "foo", :field_format => "string", :is_for_all => "0", :project_ids => ["1", "3", ""]
+      }
+      assert_response 302
+    end
+    field = IssueCustomField.order("id desc").first
+    assert_equal [1, 3], field.projects.map(&:id).sort
+  end
+
   def test_create_with_failure
     assert_no_difference 'CustomField.count' do
       post :create, :type => "IssueCustomField", :custom_field => {:name => ''}
@@ -129,7 +176,7 @@
   end
 
   def test_destroy
-    custom_values_count = CustomValue.count(:conditions => {:custom_field_id => 1})
+    custom_values_count = CustomValue.where(:custom_field_id => 1).count
     assert custom_values_count > 0
 
     assert_difference 'CustomField.count', -1 do