annotate test/functional/custom_fields_controller_test.rb @ 1469:c77ab1edff6b bug_563

Close obsolete branch bug_563
author Chris Cannam
date Wed, 23 Jan 2013 14:12:47 +0000
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@0 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@119 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'custom_fields_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class CustomFieldsController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class CustomFieldsControllerTest < ActionController::TestCase
Chris@909 25 fixtures :custom_fields, :custom_values, :trackers, :users
Chris@909 26
Chris@0 27 def setup
Chris@0 28 @controller = CustomFieldsController.new
Chris@0 29 @request = ActionController::TestRequest.new
Chris@0 30 @response = ActionController::TestResponse.new
Chris@0 31 @request.session[:user_id] = 1
Chris@0 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@441 40 def test_get_new_issue_custom_field
Chris@441 41 get :new, :type => 'IssueCustomField'
Chris@441 42 assert_response :success
Chris@441 43 assert_template 'new'
Chris@441 44 assert_tag :select,
Chris@441 45 :attributes => {:name => 'custom_field[field_format]'},
Chris@441 46 :child => {
Chris@441 47 :tag => 'option',
Chris@441 48 :attributes => {:value => 'user'},
Chris@441 49 :content => 'User'
Chris@441 50 }
Chris@441 51 assert_tag :select,
Chris@441 52 :attributes => {:name => 'custom_field[field_format]'},
Chris@441 53 :child => {
Chris@441 54 :tag => 'option',
Chris@441 55 :attributes => {:value => 'version'},
Chris@441 56 :content => 'Version'
Chris@441 57 }
Chris@441 58 end
Chris@909 59
Chris@441 60 def test_get_new_with_invalid_custom_field_class_should_redirect_to_list
Chris@441 61 get :new, :type => 'UnknownCustomField'
Chris@441 62 assert_redirected_to '/custom_fields'
Chris@441 63 end
Chris@909 64
Chris@0 65 def test_post_new_list_custom_field
Chris@0 66 assert_difference 'CustomField.count' do
Chris@0 67 post :new, :type => "IssueCustomField",
Chris@0 68 :custom_field => {:name => "test_post_new_list",
Chris@0 69 :default_value => "",
Chris@0 70 :min_length => "0",
Chris@0 71 :searchable => "0",
Chris@0 72 :regexp => "",
Chris@0 73 :is_for_all => "1",
Chris@0 74 :possible_values => "0.1\n0.2\n",
Chris@0 75 :max_length => "0",
Chris@0 76 :is_filter => "0",
Chris@0 77 :is_required =>"0",
Chris@0 78 :field_format => "list",
Chris@0 79 :tracker_ids => ["1", ""]}
Chris@909 80 end
Chris@0 81 assert_redirected_to '/custom_fields?tab=IssueCustomField'
Chris@0 82 field = IssueCustomField.find_by_name('test_post_new_list')
Chris@0 83 assert_not_nil field
Chris@0 84 assert_equal ["0.1", "0.2"], field.possible_values
Chris@0 85 assert_equal 1, field.trackers.size
Chris@0 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@0 117 end