annotate .svn/pristine/14/1417ec7b1e59a18d042b1d9264d06470b6e7c6bf.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents dffacf8a6908
children
rev   line source
Chris@1517 1 # Redmine - project management software
Chris@1517 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1517 3 #
Chris@1517 4 # This program is free software; you can redistribute it and/or
Chris@1517 5 # modify it under the terms of the GNU General Public License
Chris@1517 6 # as published by the Free Software Foundation; either version 2
Chris@1517 7 # of the License, or (at your option) any later version.
Chris@1517 8 #
Chris@1517 9 # This program is distributed in the hope that it will be useful,
Chris@1517 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1517 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1517 12 # GNU General Public License for more details.
Chris@1517 13 #
Chris@1517 14 # You should have received a copy of the GNU General Public License
Chris@1517 15 # along with this program; if not, write to the Free Software
Chris@1517 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1517 17
Chris@1517 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1517 19
Chris@1517 20 class CustomFieldsControllerTest < ActionController::TestCase
Chris@1517 21 fixtures :custom_fields, :custom_values, :trackers, :users, :projects
Chris@1517 22
Chris@1517 23 def setup
Chris@1517 24 @request.session[:user_id] = 1
Chris@1517 25 end
Chris@1517 26
Chris@1517 27 def test_index
Chris@1517 28 get :index
Chris@1517 29 assert_response :success
Chris@1517 30 assert_template 'index'
Chris@1517 31 end
Chris@1517 32
Chris@1517 33 def test_new_without_type_should_render_select_type
Chris@1517 34 get :new
Chris@1517 35 assert_response :success
Chris@1517 36 assert_template 'select_type'
Chris@1517 37 assert_select 'input[name=type]', CustomField.subclasses.size
Chris@1517 38 assert_select 'input[name=type][checked=checked]', 1
Chris@1517 39 end
Chris@1517 40
Chris@1517 41 def test_new_should_work_for_each_customized_class_and_format
Chris@1517 42 custom_field_classes.each do |klass|
Chris@1517 43 Redmine::FieldFormat.available_formats.each do |format_name|
Chris@1517 44 get :new, :type => klass.name, :custom_field => {:field_format => format_name}
Chris@1517 45 assert_response :success
Chris@1517 46 assert_template 'new'
Chris@1517 47 assert_kind_of klass, assigns(:custom_field)
Chris@1517 48 assert_equal format_name, assigns(:custom_field).format.name
Chris@1517 49 assert_select 'form#custom_field_form' do
Chris@1517 50 assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]'
Chris@1517 51 assert_select 'input[type=hidden][name=type][value=?]', klass.name
Chris@1517 52 end
Chris@1517 53 end
Chris@1517 54 end
Chris@1517 55 end
Chris@1517 56
Chris@1517 57 def test_new_should_have_string_default_format
Chris@1517 58 get :new, :type => 'IssueCustomField'
Chris@1517 59 assert_response :success
Chris@1517 60 assert_equal 'string', assigns(:custom_field).format.name
Chris@1517 61 end
Chris@1517 62
Chris@1517 63 def test_new_issue_custom_field
Chris@1517 64 get :new, :type => 'IssueCustomField'
Chris@1517 65 assert_response :success
Chris@1517 66 assert_template 'new'
Chris@1517 67 assert_select 'form#custom_field_form' do
Chris@1517 68 assert_select 'select#custom_field_field_format[name=?]', 'custom_field[field_format]' do
Chris@1517 69 assert_select 'option[value=user]', :text => 'User'
Chris@1517 70 assert_select 'option[value=version]', :text => 'Version'
Chris@1517 71 end
Chris@1517 72 assert_select 'input[type=checkbox][name=?]', 'custom_field[project_ids][]', Project.count
Chris@1517 73 assert_select 'input[type=hidden][name=?]', 'custom_field[project_ids][]', 1
Chris@1517 74 assert_select 'input[type=hidden][name=type][value=IssueCustomField]'
Chris@1517 75 end
Chris@1517 76 end
Chris@1517 77
Chris@1517 78 def test_new_time_entry_custom_field_should_not_show_trackers_and_projects
Chris@1517 79 get :new, :type => 'TimeEntryCustomField'
Chris@1517 80 assert_response :success
Chris@1517 81 assert_template 'new'
Chris@1517 82 assert_select 'form#custom_field_form' do
Chris@1517 83 assert_select 'input[name=?]', 'custom_field[tracker_ids][]', 0
Chris@1517 84 assert_select 'input[name=?]', 'custom_field[project_ids][]', 0
Chris@1517 85 end
Chris@1517 86 end
Chris@1517 87
Chris@1517 88 def test_default_value_should_be_an_input_for_string_custom_field
Chris@1517 89 get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'string'}
Chris@1517 90 assert_response :success
Chris@1517 91 assert_select 'input[name=?]', 'custom_field[default_value]'
Chris@1517 92 end
Chris@1517 93
Chris@1517 94 def test_default_value_should_be_a_textarea_for_text_custom_field
Chris@1517 95 get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'text'}
Chris@1517 96 assert_response :success
Chris@1517 97 assert_select 'textarea[name=?]', 'custom_field[default_value]'
Chris@1517 98 end
Chris@1517 99
Chris@1517 100 def test_default_value_should_be_a_checkbox_for_bool_custom_field
Chris@1517 101 get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'bool'}
Chris@1517 102 assert_response :success
Chris@1517 103 assert_select 'select[name=?]', 'custom_field[default_value]' do
Chris@1517 104 assert_select 'option', 3
Chris@1517 105 end
Chris@1517 106 end
Chris@1517 107
Chris@1517 108 def test_default_value_should_not_be_present_for_user_custom_field
Chris@1517 109 get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'user'}
Chris@1517 110 assert_response :success
Chris@1517 111 assert_select '[name=?]', 'custom_field[default_value]', 0
Chris@1517 112 end
Chris@1517 113
Chris@1517 114 def test_new_js
Chris@1517 115 get :new, :type => 'IssueCustomField', :custom_field => {:field_format => 'list'}, :format => 'js'
Chris@1517 116 assert_response :success
Chris@1517 117 assert_template 'new'
Chris@1517 118 assert_equal 'text/javascript', response.content_type
Chris@1517 119
Chris@1517 120 field = assigns(:custom_field)
Chris@1517 121 assert_equal 'list', field.field_format
Chris@1517 122 end
Chris@1517 123
Chris@1517 124 def test_new_with_invalid_custom_field_class_should_render_select_type
Chris@1517 125 get :new, :type => 'UnknownCustomField'
Chris@1517 126 assert_response :success
Chris@1517 127 assert_template 'select_type'
Chris@1517 128 end
Chris@1517 129
Chris@1517 130 def test_create_list_custom_field
Chris@1517 131 assert_difference 'CustomField.count' do
Chris@1517 132 post :create, :type => "IssueCustomField",
Chris@1517 133 :custom_field => {:name => "test_post_new_list",
Chris@1517 134 :default_value => "",
Chris@1517 135 :min_length => "0",
Chris@1517 136 :searchable => "0",
Chris@1517 137 :regexp => "",
Chris@1517 138 :is_for_all => "1",
Chris@1517 139 :possible_values => "0.1\n0.2\n",
Chris@1517 140 :max_length => "0",
Chris@1517 141 :is_filter => "0",
Chris@1517 142 :is_required =>"0",
Chris@1517 143 :field_format => "list",
Chris@1517 144 :tracker_ids => ["1", ""]}
Chris@1517 145 end
Chris@1517 146 assert_redirected_to '/custom_fields?tab=IssueCustomField'
Chris@1517 147 field = IssueCustomField.find_by_name('test_post_new_list')
Chris@1517 148 assert_not_nil field
Chris@1517 149 assert_equal ["0.1", "0.2"], field.possible_values
Chris@1517 150 assert_equal 1, field.trackers.size
Chris@1517 151 end
Chris@1517 152
Chris@1517 153 def test_create_with_project_ids
Chris@1517 154 assert_difference 'CustomField.count' do
Chris@1517 155 post :create, :type => "IssueCustomField", :custom_field => {
Chris@1517 156 :name => "foo", :field_format => "string", :is_for_all => "0", :project_ids => ["1", "3", ""]
Chris@1517 157 }
Chris@1517 158 assert_response 302
Chris@1517 159 end
Chris@1517 160 field = IssueCustomField.order("id desc").first
Chris@1517 161 assert_equal [1, 3], field.projects.map(&:id).sort
Chris@1517 162 end
Chris@1517 163
Chris@1517 164 def test_create_with_failure
Chris@1517 165 assert_no_difference 'CustomField.count' do
Chris@1517 166 post :create, :type => "IssueCustomField", :custom_field => {:name => ''}
Chris@1517 167 end
Chris@1517 168 assert_response :success
Chris@1517 169 assert_template 'new'
Chris@1517 170 end
Chris@1517 171
Chris@1517 172 def test_create_without_type_should_render_select_type
Chris@1517 173 assert_no_difference 'CustomField.count' do
Chris@1517 174 post :create, :custom_field => {:name => ''}
Chris@1517 175 end
Chris@1517 176 assert_response :success
Chris@1517 177 assert_template 'select_type'
Chris@1517 178 end
Chris@1517 179
Chris@1517 180 def test_edit
Chris@1517 181 get :edit, :id => 1
Chris@1517 182 assert_response :success
Chris@1517 183 assert_template 'edit'
Chris@1517 184 assert_tag 'input', :attributes => {:name => 'custom_field[name]', :value => 'Database'}
Chris@1517 185 end
Chris@1517 186
Chris@1517 187 def test_edit_invalid_custom_field_should_render_404
Chris@1517 188 get :edit, :id => 99
Chris@1517 189 assert_response 404
Chris@1517 190 end
Chris@1517 191
Chris@1517 192 def test_update
Chris@1517 193 put :update, :id => 1, :custom_field => {:name => 'New name'}
Chris@1517 194 assert_redirected_to '/custom_fields?tab=IssueCustomField'
Chris@1517 195
Chris@1517 196 field = CustomField.find(1)
Chris@1517 197 assert_equal 'New name', field.name
Chris@1517 198 end
Chris@1517 199
Chris@1517 200 def test_update_with_failure
Chris@1517 201 put :update, :id => 1, :custom_field => {:name => ''}
Chris@1517 202 assert_response :success
Chris@1517 203 assert_template 'edit'
Chris@1517 204 end
Chris@1517 205
Chris@1517 206 def test_destroy
Chris@1517 207 custom_values_count = CustomValue.where(:custom_field_id => 1).count
Chris@1517 208 assert custom_values_count > 0
Chris@1517 209
Chris@1517 210 assert_difference 'CustomField.count', -1 do
Chris@1517 211 assert_difference 'CustomValue.count', - custom_values_count do
Chris@1517 212 delete :destroy, :id => 1
Chris@1517 213 end
Chris@1517 214 end
Chris@1517 215
Chris@1517 216 assert_redirected_to '/custom_fields?tab=IssueCustomField'
Chris@1517 217 assert_nil CustomField.find_by_id(1)
Chris@1517 218 assert_nil CustomValue.find_by_custom_field_id(1)
Chris@1517 219 end
Chris@1517 220
Chris@1517 221 def custom_field_classes
Chris@1517 222 files = Dir.glob(File.join(Rails.root, 'app/models/*_custom_field.rb')).map {|f| File.basename(f).sub(/\.rb$/, '') }
Chris@1517 223 classes = files.map(&:classify).map(&:constantize)
Chris@1517 224 assert classes.size > 0
Chris@1517 225 classes
Chris@1517 226 end
Chris@1517 227 end