Chris@909: # Redmine - project management software Chris@909: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@909: # Chris@909: # This program is free software; you can redistribute it and/or Chris@909: # modify it under the terms of the GNU General Public License Chris@909: # as published by the Free Software Foundation; either version 2 Chris@909: # of the License, or (at your option) any later version. Chris@909: # Chris@909: # This program is distributed in the hope that it will be useful, Chris@909: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@909: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@909: # GNU General Public License for more details. Chris@909: # Chris@909: # You should have received a copy of the GNU General Public License Chris@909: # along with this program; if not, write to the Free Software Chris@909: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@909: Chris@909: require File.expand_path('../../test_helper', __FILE__) Chris@909: require 'custom_fields_controller' Chris@909: Chris@909: # Re-raise errors caught by the controller. Chris@909: class CustomFieldsController; def rescue_action(e) raise e end; end Chris@909: Chris@909: class CustomFieldsControllerTest < ActionController::TestCase Chris@909: fixtures :custom_fields, :custom_values, :trackers, :users Chris@909: Chris@909: def setup Chris@909: @controller = CustomFieldsController.new Chris@909: @request = ActionController::TestRequest.new Chris@909: @response = ActionController::TestResponse.new Chris@909: @request.session[:user_id] = 1 Chris@909: end Chris@909: Chris@909: def test_index Chris@909: get :index Chris@909: assert_response :success Chris@909: assert_template 'index' Chris@909: end Chris@909: Chris@909: def test_get_new_issue_custom_field Chris@909: get :new, :type => 'IssueCustomField' Chris@909: assert_response :success Chris@909: assert_template 'new' Chris@909: assert_tag :select, Chris@909: :attributes => {:name => 'custom_field[field_format]'}, Chris@909: :child => { Chris@909: :tag => 'option', Chris@909: :attributes => {:value => 'user'}, Chris@909: :content => 'User' Chris@909: } Chris@909: assert_tag :select, Chris@909: :attributes => {:name => 'custom_field[field_format]'}, Chris@909: :child => { Chris@909: :tag => 'option', Chris@909: :attributes => {:value => 'version'}, Chris@909: :content => 'Version' Chris@909: } Chris@909: end Chris@909: Chris@909: def test_get_new_with_invalid_custom_field_class_should_redirect_to_list Chris@909: get :new, :type => 'UnknownCustomField' Chris@909: assert_redirected_to '/custom_fields' Chris@909: end Chris@909: Chris@909: def test_post_new_list_custom_field Chris@909: assert_difference 'CustomField.count' do Chris@909: post :new, :type => "IssueCustomField", Chris@909: :custom_field => {:name => "test_post_new_list", Chris@909: :default_value => "", Chris@909: :min_length => "0", Chris@909: :searchable => "0", Chris@909: :regexp => "", Chris@909: :is_for_all => "1", Chris@909: :possible_values => "0.1\n0.2\n", Chris@909: :max_length => "0", Chris@909: :is_filter => "0", Chris@909: :is_required =>"0", Chris@909: :field_format => "list", Chris@909: :tracker_ids => ["1", ""]} Chris@909: end Chris@909: assert_redirected_to '/custom_fields?tab=IssueCustomField' Chris@909: field = IssueCustomField.find_by_name('test_post_new_list') Chris@909: assert_not_nil field Chris@909: assert_equal ["0.1", "0.2"], field.possible_values Chris@909: assert_equal 1, field.trackers.size Chris@909: end Chris@909: Chris@909: def test_get_edit Chris@909: get :edit, :id => 1 Chris@909: assert_response :success Chris@909: assert_template 'edit' Chris@909: assert_tag 'input', :attributes => {:name => 'custom_field[name]', :value => 'Database'} Chris@909: end Chris@909: Chris@909: def test_post_edit Chris@909: post :edit, :id => 1, :custom_field => {:name => 'New name'} Chris@909: assert_redirected_to '/custom_fields?tab=IssueCustomField' Chris@909: Chris@909: field = CustomField.find(1) Chris@909: assert_equal 'New name', field.name Chris@909: end Chris@909: Chris@909: def test_destroy Chris@909: custom_values_count = CustomValue.count(:conditions => {:custom_field_id => 1}) Chris@909: assert custom_values_count > 0 Chris@909: Chris@909: assert_difference 'CustomField.count', -1 do Chris@909: assert_difference 'CustomValue.count', - custom_values_count do Chris@909: post :destroy, :id => 1 Chris@909: end Chris@909: end Chris@909: Chris@909: assert_redirected_to '/custom_fields?tab=IssueCustomField' Chris@909: assert_nil CustomField.find_by_id(1) Chris@909: assert_nil CustomValue.find_by_custom_field_id(1) Chris@909: end Chris@909: end