comparison test/unit/initializers/patches_test.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents e248c7af89ec
children
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
20 class PatchesTest < ActiveSupport::TestCase 20 class PatchesTest < ActiveSupport::TestCase
21 include Redmine::I18n 21 include Redmine::I18n
22 22
23 def setup 23 def setup
24 Setting.default_language = 'en' 24 Setting.default_language = 'en'
25 @symbols = { :a => 1, :b => 2 }
26 @keys = %w( blue green red pink orange )
27 @values = %w( 000099 009900 aa0000 cc0066 cc6633 )
28 @hash = Hash.new
29 @ordered_hash = ActiveSupport::OrderedHash.new
30
31 @keys.each_with_index do |key, index|
32 @hash[key] = @values[index]
33 @ordered_hash[key] = @values[index]
34 end
25 end 35 end
26 36
27 test "ActiveRecord::Base.human_attribute_name should transform name to field_name" do 37 test "ActiveRecord::Base.human_attribute_name should transform name to field_name" do
28 assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on') 38 assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on')
29 end 39 end
33 end 43 end
34 44
35 test "ActiveRecord::Base.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do 45 test "ActiveRecord::Base.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do
36 assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name') 46 assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name')
37 end 47 end
48
49 # https://github.com/rails/rails/pull/14198/files
50 if RUBY_VERSION >= "1.9"
51 def test_indifferent_select
52 hash = ActiveSupport::HashWithIndifferentAccess.new(@symbols).select { |_ ,v| v == 1 }
53 assert_equal({ 'a' => 1 }, hash)
54 assert_instance_of ((Rails::VERSION::MAJOR < 4 && RUBY_VERSION < "2.1") ?
55 Hash : ActiveSupport::HashWithIndifferentAccess),
56 hash
57 end
58
59 def test_indifferent_select_bang
60 indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@symbols)
61 indifferent_strings.select! { |_, v| v == 1 }
62 assert_equal({ 'a' => 1 }, indifferent_strings)
63 assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
64 end
65 end
66
67 def test_indifferent_reject
68 hash = ActiveSupport::HashWithIndifferentAccess.new(@symbols).reject { |_, v| v != 1 }
69 assert_equal({ 'a' => 1 }, hash)
70 assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash
71 end
72
73 def test_indifferent_reject_bang
74 indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@symbols)
75 indifferent_strings.reject! { |_, v| v != 1 }
76 assert_equal({ 'a' => 1 }, indifferent_strings)
77 assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings
78 end
79
80 if RUBY_VERSION >= "1.9"
81 def test_select
82 assert_equal @keys, @ordered_hash.select { true }.map(&:first)
83 new_ordered_hash = @ordered_hash.select { true }
84 assert_equal @keys, new_ordered_hash.map(&:first)
85 assert_instance_of ((Rails::VERSION::MAJOR < 4 && RUBY_VERSION < "2.1") ?
86 Hash : ActiveSupport::OrderedHash),
87 new_ordered_hash
88 end
89 end
90
91 def test_reject
92 copy = @ordered_hash.dup
93 new_ordered_hash = @ordered_hash.reject { |k, _| k == 'pink' }
94 assert_equal copy, @ordered_hash
95 assert !new_ordered_hash.keys.include?('pink')
96 assert @ordered_hash.keys.include?('pink')
97 assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash
98 end
38 end 99 end