annotate .svn/pristine/b9/b9c79e5fb4d089dbf3a1ba6662defed5de839aa8.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 # Redmine - project management software
Chris@909 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@909 3 #
Chris@909 4 # This program is free software; you can redistribute it and/or
Chris@909 5 # modify it under the terms of the GNU General Public License
Chris@909 6 # as published by the Free Software Foundation; either version 2
Chris@909 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@909 9 # This program is distributed in the hope that it will be useful,
Chris@909 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@909 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@909 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@909 14 # You should have received a copy of the GNU General Public License
Chris@909 15 # along with this program; if not, write to the Free Software
Chris@909 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@909 17
Chris@909 18 require File.expand_path('../../test_helper', __FILE__)
Chris@909 19 require 'custom_fields_controller'
Chris@909 20
Chris@909 21 # Re-raise errors caught by the controller.
Chris@909 22 class CustomFieldsController; def rescue_action(e) raise e end; end
Chris@909 23
Chris@909 24 class CustomFieldsControllerTest < ActionController::TestCase
Chris@909 25 fixtures :custom_fields, :custom_values, :trackers, :users
Chris@909 26
Chris@909 27 def setup
Chris@909 28 @controller = CustomFieldsController.new
Chris@909 29 @request = ActionController::TestRequest.new
Chris@909 30 @response = ActionController::TestResponse.new
Chris@909 31 @request.session[:user_id] = 1
Chris@909 32 end
Chris@909 33
Chris@909 34 def test_index
Chris@909 35 get :index
Chris@909 36 assert_response :success
Chris@909 37 assert_template 'index'
Chris@909 38 end
Chris@909 39
Chris@909 40 def test_get_new_issue_custom_field
Chris@909 41 get :new, :type => 'IssueCustomField'
Chris@909 42 assert_response :success
Chris@909 43 assert_template 'new'
Chris@909 44 assert_tag :select,
Chris@909 45 :attributes => {:name => 'custom_field[field_format]'},
Chris@909 46 :child => {
Chris@909 47 :tag => 'option',
Chris@909 48 :attributes => {:value => 'user'},
Chris@909 49 :content => 'User'
Chris@909 50 }
Chris@909 51 assert_tag :select,
Chris@909 52 :attributes => {:name => 'custom_field[field_format]'},
Chris@909 53 :child => {
Chris@909 54 :tag => 'option',
Chris@909 55 :attributes => {:value => 'version'},
Chris@909 56 :content => 'Version'
Chris@909 57 }
Chris@909 58 end
Chris@909 59
Chris@909 60 def test_get_new_with_invalid_custom_field_class_should_redirect_to_list
Chris@909 61 get :new, :type => 'UnknownCustomField'
Chris@909 62 assert_redirected_to '/custom_fields'
Chris@909 63 end
Chris@909 64
Chris@909 65 def test_post_new_list_custom_field
Chris@909 66 assert_difference 'CustomField.count' do
Chris@909 67 post :new, :type => "IssueCustomField",
Chris@909 68 :custom_field => {:name => "test_post_new_list",
Chris@909 69 :default_value => "",
Chris@909 70 :min_length => "0",
Chris@909 71 :searchable => "0",
Chris@909 72 :regexp => "",
Chris@909 73 :is_for_all => "1",
Chris@909 74 :possible_values => "0.1\n0.2\n",
Chris@909 75 :max_length => "0",
Chris@909 76 :is_filter => "0",
Chris@909 77 :is_required =>"0",
Chris@909 78 :field_format => "list",
Chris@909 79 :tracker_ids => ["1", ""]}
Chris@909 80 end
Chris@909 81 assert_redirected_to '/custom_fields?tab=IssueCustomField'
Chris@909 82 field = IssueCustomField.find_by_name('test_post_new_list')
Chris@909 83 assert_not_nil field
Chris@909 84 assert_equal ["0.1", "0.2"], field.possible_values
Chris@909 85 assert_equal 1, field.trackers.size
Chris@909 86 end
Chris@909 87
Chris@909 88 def test_get_edit
Chris@909 89 get :edit, :id => 1
Chris@909 90 assert_response :success
Chris@909 91 assert_template 'edit'
Chris@909 92 assert_tag 'input', :attributes => {:name => 'custom_field[name]', :value => 'Database'}
Chris@909 93 end
Chris@909 94
Chris@909 95 def test_post_edit
Chris@909 96 post :edit, :id => 1, :custom_field => {:name => 'New name'}
Chris@909 97 assert_redirected_to '/custom_fields?tab=IssueCustomField'
Chris@909 98
Chris@909 99 field = CustomField.find(1)
Chris@909 100 assert_equal 'New name', field.name
Chris@909 101 end
Chris@909 102
Chris@909 103 def test_destroy
Chris@909 104 custom_values_count = CustomValue.count(:conditions => {:custom_field_id => 1})
Chris@909 105 assert custom_values_count > 0
Chris@909 106
Chris@909 107 assert_difference 'CustomField.count', -1 do
Chris@909 108 assert_difference 'CustomValue.count', - custom_values_count do
Chris@909 109 post :destroy, :id => 1
Chris@909 110 end
Chris@909 111 end
Chris@909 112
Chris@909 113 assert_redirected_to '/custom_fields?tab=IssueCustomField'
Chris@909 114 assert_nil CustomField.find_by_id(1)
Chris@909 115 assert_nil CustomValue.find_by_custom_field_id(1)
Chris@909 116 end
Chris@909 117 end