@@ -1,84 +1,79 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class CustomFieldsController < ApplicationController |
|
18 | class CustomFieldsController < ApplicationController | |
19 | before_filter :require_admin |
|
19 | before_filter :require_admin | |
20 |
|
20 | |||
21 | def index |
|
21 | def index | |
22 | list |
|
22 | list | |
23 | render :action => 'list' unless request.xhr? |
|
23 | render :action => 'list' unless request.xhr? | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | def list |
|
26 | def list | |
27 | @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name } |
|
27 | @custom_fields_by_type = CustomField.find(:all).group_by {|f| f.class.name } | |
28 | @tab = params[:tab] || 'IssueCustomField' |
|
28 | @tab = params[:tab] || 'IssueCustomField' | |
29 | render :action => "list", :layout => false if request.xhr? |
|
29 | render :action => "list", :layout => false if request.xhr? | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | def new |
|
32 | def new | |
33 | case params[:type] |
|
33 | @custom_field = begin | |
34 | when "IssueCustomField" |
|
34 | if params[:type].to_s.match(/.+CustomField$/) | |
35 |
|
|
35 | params[:type].to_s.constantize.new(params[:custom_field]) | |
36 | when "UserCustomField" |
|
36 | end | |
37 | @custom_field = UserCustomField.new(params[:custom_field]) |
|
37 | rescue | |
38 | when "ProjectCustomField" |
|
38 | end | |
39 | @custom_field = ProjectCustomField.new(params[:custom_field]) |
|
39 | redirect_to(:action => 'list') and return unless @custom_field.is_a?(CustomField) | |
40 | when "TimeEntryCustomField" |
|
40 | ||
41 | @custom_field = TimeEntryCustomField.new(params[:custom_field]) |
|
|||
42 | else |
|
|||
43 | redirect_to :action => 'list' |
|
|||
44 | return |
|
|||
45 | end |
|
|||
46 | if request.post? and @custom_field.save |
|
41 | if request.post? and @custom_field.save | |
47 | flash[:notice] = l(:notice_successful_create) |
|
42 | flash[:notice] = l(:notice_successful_create) | |
48 | redirect_to :action => 'list', :tab => @custom_field.class.name |
|
43 | redirect_to :action => 'list', :tab => @custom_field.class.name | |
49 | end |
|
44 | end | |
50 | @trackers = Tracker.find(:all, :order => 'position') |
|
45 | @trackers = Tracker.find(:all, :order => 'position') | |
51 | end |
|
46 | end | |
52 |
|
47 | |||
53 | def edit |
|
48 | def edit | |
54 | @custom_field = CustomField.find(params[:id]) |
|
49 | @custom_field = CustomField.find(params[:id]) | |
55 | if request.post? and @custom_field.update_attributes(params[:custom_field]) |
|
50 | if request.post? and @custom_field.update_attributes(params[:custom_field]) | |
56 | flash[:notice] = l(:notice_successful_update) |
|
51 | flash[:notice] = l(:notice_successful_update) | |
57 | redirect_to :action => 'list', :tab => @custom_field.class.name |
|
52 | redirect_to :action => 'list', :tab => @custom_field.class.name | |
58 | end |
|
53 | end | |
59 | @trackers = Tracker.find(:all, :order => 'position') |
|
54 | @trackers = Tracker.find(:all, :order => 'position') | |
60 | end |
|
55 | end | |
61 |
|
56 | |||
62 | def move |
|
57 | def move | |
63 | @custom_field = CustomField.find(params[:id]) |
|
58 | @custom_field = CustomField.find(params[:id]) | |
64 | case params[:position] |
|
59 | case params[:position] | |
65 | when 'highest' |
|
60 | when 'highest' | |
66 | @custom_field.move_to_top |
|
61 | @custom_field.move_to_top | |
67 | when 'higher' |
|
62 | when 'higher' | |
68 | @custom_field.move_higher |
|
63 | @custom_field.move_higher | |
69 | when 'lower' |
|
64 | when 'lower' | |
70 | @custom_field.move_lower |
|
65 | @custom_field.move_lower | |
71 | when 'lowest' |
|
66 | when 'lowest' | |
72 | @custom_field.move_to_bottom |
|
67 | @custom_field.move_to_bottom | |
73 | end if params[:position] |
|
68 | end if params[:position] | |
74 | redirect_to :action => 'list', :tab => @custom_field.class.name |
|
69 | redirect_to :action => 'list', :tab => @custom_field.class.name | |
75 | end |
|
70 | end | |
76 |
|
71 | |||
77 | def destroy |
|
72 | def destroy | |
78 | @custom_field = CustomField.find(params[:id]).destroy |
|
73 | @custom_field = CustomField.find(params[:id]).destroy | |
79 | redirect_to :action => 'list', :tab => @custom_field.class.name |
|
74 | redirect_to :action => 'list', :tab => @custom_field.class.name | |
80 | rescue |
|
75 | rescue | |
81 | flash[:error] = "Unable to delete custom field" |
|
76 | flash[:error] = "Unable to delete custom field" | |
82 | redirect_to :action => 'list' |
|
77 | redirect_to :action => 'list' | |
83 | end |
|
78 | end | |
84 | end |
|
79 | end |
@@ -1,56 +1,61 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2009 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 | require 'custom_fields_controller' |
|
19 | require 'custom_fields_controller' | |
20 |
|
20 | |||
21 | # Re-raise errors caught by the controller. |
|
21 | # Re-raise errors caught by the controller. | |
22 | class CustomFieldsController; def rescue_action(e) raise e end; end |
|
22 | class CustomFieldsController; def rescue_action(e) raise e end; end | |
23 |
|
23 | |||
24 | class CustomFieldsControllerTest < Test::Unit::TestCase |
|
24 | class CustomFieldsControllerTest < Test::Unit::TestCase | |
25 | fixtures :custom_fields, :trackers |
|
25 | fixtures :custom_fields, :trackers, :users | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @controller = CustomFieldsController.new |
|
28 | @controller = CustomFieldsController.new | |
29 | @request = ActionController::TestRequest.new |
|
29 | @request = ActionController::TestRequest.new | |
30 | @response = ActionController::TestResponse.new |
|
30 | @response = ActionController::TestResponse.new | |
31 | @request.session[:user_id] = 1 |
|
31 | @request.session[:user_id] = 1 | |
32 | end |
|
32 | end | |
33 |
|
33 | |||
34 | def test_post_new_list_custom_field |
|
34 | def test_post_new_list_custom_field | |
35 | assert_difference 'CustomField.count' do |
|
35 | assert_difference 'CustomField.count' do | |
36 | post :new, :type => "IssueCustomField", |
|
36 | post :new, :type => "IssueCustomField", | |
37 | :custom_field => {:name => "test_post_new_list", |
|
37 | :custom_field => {:name => "test_post_new_list", | |
38 | :default_value => "", |
|
38 | :default_value => "", | |
39 | :min_length => "0", |
|
39 | :min_length => "0", | |
40 | :searchable => "0", |
|
40 | :searchable => "0", | |
41 | :regexp => "", |
|
41 | :regexp => "", | |
42 | :is_for_all => "1", |
|
42 | :is_for_all => "1", | |
43 | :possible_values => "0.1\n0.2\n", |
|
43 | :possible_values => "0.1\n0.2\n", | |
44 | :max_length => "0", |
|
44 | :max_length => "0", | |
45 | :is_filter => "0", |
|
45 | :is_filter => "0", | |
46 | :is_required =>"0", |
|
46 | :is_required =>"0", | |
47 | :field_format => "list", |
|
47 | :field_format => "list", | |
48 | :tracker_ids => ["1", ""]} |
|
48 | :tracker_ids => ["1", ""]} | |
49 | end |
|
49 | end | |
50 | assert_redirected_to '/custom_fields/list' |
|
50 | assert_redirected_to '/custom_fields/list' | |
51 | field = IssueCustomField.find_by_name('test_post_new_list') |
|
51 | field = IssueCustomField.find_by_name('test_post_new_list') | |
52 | assert_not_nil field |
|
52 | assert_not_nil field | |
53 | assert_equal ["0.1", "0.2"], field.possible_values |
|
53 | assert_equal ["0.1", "0.2"], field.possible_values | |
54 | assert_equal 1, field.trackers.size |
|
54 | assert_equal 1, field.trackers.size | |
55 | end |
|
55 | end | |
|
56 | ||||
|
57 | def test_invalid_custom_field_class_should_redirect_to_list | |||
|
58 | get :new, :type => 'UnknownCustomField' | |||
|
59 | assert_redirected_to '/custom_fields/list' | |||
|
60 | end | |||
56 | end |
|
61 | end |
General Comments 0
You need to be logged in to leave comments.
Login now