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