To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / b9 / b9c79e5fb4d089dbf3a1ba6662defed5de839aa8.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (4.05 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
require File.expand_path('../../test_helper', __FILE__)
19
require 'custom_fields_controller'
20

    
21
# Re-raise errors caught by the controller.
22
class CustomFieldsController; def rescue_action(e) raise e end; end
23

    
24
class CustomFieldsControllerTest < ActionController::TestCase
25
  fixtures :custom_fields, :custom_values, :trackers, :users
26

    
27
  def setup
28
    @controller = CustomFieldsController.new
29
    @request    = ActionController::TestRequest.new
30
    @response   = ActionController::TestResponse.new
31
    @request.session[:user_id] = 1
32
  end
33

    
34
  def test_index
35
    get :index
36
    assert_response :success
37
    assert_template 'index'
38
  end
39

    
40
  def test_get_new_issue_custom_field
41
    get :new, :type => 'IssueCustomField'
42
    assert_response :success
43
    assert_template 'new'
44
    assert_tag :select,
45
      :attributes => {:name => 'custom_field[field_format]'},
46
      :child => {
47
        :tag => 'option',
48
        :attributes => {:value => 'user'},
49
        :content => 'User'
50
      }
51
    assert_tag :select,
52
      :attributes => {:name => 'custom_field[field_format]'},
53
      :child => {
54
        :tag => 'option',
55
        :attributes => {:value => 'version'},
56
        :content => 'Version'
57
      }
58
  end
59

    
60
  def test_get_new_with_invalid_custom_field_class_should_redirect_to_list
61
    get :new, :type => 'UnknownCustomField'
62
    assert_redirected_to '/custom_fields'
63
  end
64

    
65
  def test_post_new_list_custom_field
66
    assert_difference 'CustomField.count' do
67
      post :new, :type => "IssueCustomField",
68
                 :custom_field => {:name => "test_post_new_list",
69
                                   :default_value => "",
70
                                   :min_length => "0",
71
                                   :searchable => "0",
72
                                   :regexp => "",
73
                                   :is_for_all => "1",
74
                                   :possible_values => "0.1\n0.2\n",
75
                                   :max_length => "0",
76
                                   :is_filter => "0",
77
                                   :is_required =>"0",
78
                                   :field_format => "list",
79
                                   :tracker_ids => ["1", ""]}
80
    end
81
    assert_redirected_to '/custom_fields?tab=IssueCustomField'
82
    field = IssueCustomField.find_by_name('test_post_new_list')
83
    assert_not_nil field
84
    assert_equal ["0.1", "0.2"], field.possible_values
85
    assert_equal 1, field.trackers.size
86
  end
87

    
88
  def test_get_edit
89
    get :edit, :id => 1
90
    assert_response :success
91
    assert_template 'edit'
92
    assert_tag 'input', :attributes => {:name => 'custom_field[name]', :value => 'Database'}
93
  end
94

    
95
  def test_post_edit
96
    post :edit, :id => 1, :custom_field => {:name => 'New name'}
97
    assert_redirected_to '/custom_fields?tab=IssueCustomField'
98

    
99
    field = CustomField.find(1)
100
    assert_equal 'New name', field.name
101
  end
102

    
103
  def test_destroy
104
    custom_values_count = CustomValue.count(:conditions => {:custom_field_id => 1})
105
    assert custom_values_count > 0
106

    
107
    assert_difference 'CustomField.count', -1 do
108
      assert_difference 'CustomValue.count', - custom_values_count do
109
        post :destroy, :id => 1
110
      end
111
    end
112

    
113
    assert_redirected_to '/custom_fields?tab=IssueCustomField'
114
    assert_nil CustomField.find_by_id(1)
115
    assert_nil CustomValue.find_by_custom_field_id(1)
116
  end
117
end