annotate test/unit/custom_field_user_format_test.rb @ 1082:997f6d7738f7 bug_531

In repo controller entry action, show the page for the file even if it's binary (so user still has access to history etc links). This makes it possible to use the entry action as the default when a file is clicked on
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 22 Nov 2012 18:04:17 +0000
parents cbb26bc654de
children 433d4f72a19b
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
Chris@441 3 #
Chris@441 4 # This program is free software; you can redistribute it and/or
Chris@441 5 # modify it under the terms of the GNU General Public License
Chris@441 6 # as published by the Free Software Foundation; either version 2
Chris@441 7 # of the License, or (at your option) any later version.
Chris@909 8 #
Chris@441 9 # This program is distributed in the hope that it will be useful,
Chris@441 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@441 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@441 12 # GNU General Public License for more details.
Chris@909 13 #
Chris@441 14 # You should have received a copy of the GNU General Public License
Chris@441 15 # along with this program; if not, write to the Free Software
Chris@441 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@441 17
Chris@441 18 require File.expand_path('../../test_helper', __FILE__)
Chris@441 19
Chris@441 20 class CustomFieldUserFormatTest < ActiveSupport::TestCase
Chris@441 21 fixtures :custom_fields, :projects, :members, :users, :member_roles, :trackers, :issues
Chris@909 22
Chris@441 23 def setup
Chris@441 24 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user')
Chris@441 25 end
Chris@909 26
Chris@441 27 def test_possible_values_with_no_arguments
Chris@441 28 assert_equal [], @field.possible_values
Chris@441 29 assert_equal [], @field.possible_values(nil)
Chris@441 30 end
Chris@909 31
Chris@441 32 def test_possible_values_with_project_resource
Chris@441 33 project = Project.find(1)
Chris@441 34 possible_values = @field.possible_values(project.issues.first)
Chris@441 35 assert possible_values.any?
Chris@441 36 assert_equal project.users.sort.collect(&:id).map(&:to_s), possible_values
Chris@441 37 end
Chris@909 38
Chris@441 39 def test_possible_values_with_nil_project_resource
Chris@441 40 project = Project.find(1)
Chris@441 41 assert_equal [], @field.possible_values(Issue.new)
Chris@441 42 end
Chris@909 43
Chris@441 44 def test_possible_values_options_with_no_arguments
Chris@441 45 assert_equal [], @field.possible_values_options
Chris@441 46 assert_equal [], @field.possible_values_options(nil)
Chris@441 47 end
Chris@909 48
Chris@441 49 def test_possible_values_options_with_project_resource
Chris@441 50 project = Project.find(1)
Chris@441 51 possible_values_options = @field.possible_values_options(project.issues.first)
Chris@441 52 assert possible_values_options.any?
Chris@441 53 assert_equal project.users.sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
Chris@441 54 end
Chris@909 55
Chris@441 56 def test_possible_values_options_with_array
Chris@441 57 projects = Project.find([1, 2])
Chris@441 58 possible_values_options = @field.possible_values_options(projects)
Chris@441 59 assert possible_values_options.any?
Chris@441 60 assert_equal (projects.first.users & projects.last.users).sort.map {|u| [u.name, u.id.to_s]}, possible_values_options
Chris@441 61 end
Chris@909 62
Chris@441 63 def test_cast_blank_value
Chris@441 64 assert_equal nil, @field.cast_value(nil)
Chris@441 65 assert_equal nil, @field.cast_value("")
Chris@441 66 end
Chris@909 67
Chris@441 68 def test_cast_valid_value
Chris@441 69 user = @field.cast_value("2")
Chris@441 70 assert_kind_of User, user
Chris@441 71 assert_equal User.find(2), user
Chris@441 72 end
Chris@909 73
Chris@441 74 def test_cast_invalid_value
Chris@441 75 assert_equal nil, @field.cast_value("187")
Chris@441 76 end
Chris@441 77 end