From f9bf53262a12f983cc8bdc3e650231ca6448cb81 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 27 Nov 2011 21:11:10 +0000 Subject: [PATCH] Adds functional tests for CustomFieldsController. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7960 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- .../custom_fields_controller_test.rb | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/functional/custom_fields_controller_test.rb b/test/functional/custom_fields_controller_test.rb index 57f0e9b8c..ce20b2b89 100644 --- a/test/functional/custom_fields_controller_test.rb +++ b/test/functional/custom_fields_controller_test.rb @@ -22,7 +22,7 @@ require 'custom_fields_controller' class CustomFieldsController; def rescue_action(e) raise e end; end class CustomFieldsControllerTest < ActionController::TestCase - fixtures :custom_fields, :trackers, :users + fixtures :custom_fields, :custom_values, :trackers, :users def setup @controller = CustomFieldsController.new @@ -31,6 +31,12 @@ class CustomFieldsControllerTest < ActionController::TestCase @request.session[:user_id] = 1 end + def test_index + get :index + assert_response :success + assert_template 'index' + end + def test_get_new_issue_custom_field get :new, :type => 'IssueCustomField' assert_response :success @@ -78,4 +84,34 @@ class CustomFieldsControllerTest < ActionController::TestCase assert_equal ["0.1", "0.2"], field.possible_values assert_equal 1, field.trackers.size end + + def test_get_edit + get :edit, :id => 1 + assert_response :success + assert_template 'edit' + assert_tag 'input', :attributes => {:name => 'custom_field[name]', :value => 'Database'} + end + + def test_post_edit + post :edit, :id => 1, :custom_field => {:name => 'New name'} + assert_redirected_to '/custom_fields?tab=IssueCustomField' + + field = CustomField.find(1) + assert_equal 'New name', field.name + end + + def test_destroy + custom_values_count = CustomValue.count(:conditions => {:custom_field_id => 1}) + assert custom_values_count > 0 + + assert_difference 'CustomField.count', -1 do + assert_difference 'CustomValue.count', - custom_values_count do + post :destroy, :id => 1 + end + end + + assert_redirected_to '/custom_fields?tab=IssueCustomField' + assert_nil CustomField.find_by_id(1) + assert_nil CustomValue.find_by_custom_field_id(1) + end end -- 2.39.5