Mercurial > hg > soundsoftware-site
diff test/functional/custom_fields_controller_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | dffacf8a6908 |
children |
line wrap: on
line diff
--- a/test/functional/custom_fields_controller_test.rb Mon Mar 17 08:57:04 2014 +0000 +++ b/test/functional/custom_fields_controller_test.rb Thu Sep 11 12:46:20 2014 +0100 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2012 Jean-Philippe Lang +# Copyright (C) 2006-2014 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 @@ -30,19 +30,36 @@ assert_template 'index' end - def test_new + def test_new_without_type_should_render_select_type + get :new + assert_response :success + assert_template 'select_type' + assert_select 'input[name=type]', CustomField.subclasses.size + assert_select 'input[name=type][checked=checked]', 1 + end + + def test_new_should_work_for_each_customized_class_and_format custom_field_classes.each do |klass| - get :new, :type => klass.name - assert_response :success - assert_template 'new' - assert_kind_of klass, assigns(:custom_field) - assert_select 'form#custom_field_form' do - assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' - assert_select 'input[type=hidden][name=type][value=?]', klass.name + Redmine::FieldFormat.available_formats.each do |format_name| + get :new, :type => klass.name, :custom_field => {:field_format => format_name} + assert_response :success + assert_template 'new' + assert_kind_of klass, assigns(:custom_field) + assert_equal format_name, assigns(:custom_field).format.name + assert_select 'form#custom_field_form' do + assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' + assert_select 'input[type=hidden][name=type][value=?]', klass.name + end end end end + def test_new_should_have_string_default_format + get :new, :type => 'IssueCustomField' + assert_response :success + assert_equal 'string', assigns(:custom_field).format.name + end + def test_new_issue_custom_field get :new, :type => 'IssueCustomField' assert_response :success @@ -52,10 +69,48 @@ 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 'select[name=?]', 'custom_field[default_value]' do + assert_select 'option', 3 + end + 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 @@ -66,9 +121,10 @@ assert_equal 'list', field.field_format end - def test_new_with_invalid_custom_field_class_should_render_404 + def test_new_with_invalid_custom_field_class_should_render_select_type get :new, :type => 'UnknownCustomField' - assert_response 404 + assert_response :success + assert_template 'select_type' end def test_create_list_custom_field @@ -94,6 +150,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 => ''} @@ -102,6 +169,14 @@ assert_template 'new' end + def test_create_without_type_should_render_select_type + assert_no_difference 'CustomField.count' do + post :create, :custom_field => {:name => ''} + end + assert_response :success + assert_template 'select_type' + end + def test_edit get :edit, :id => 1 assert_response :success @@ -129,7 +204,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